Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Two things about the launch screen on the phone. **No mark on it.** The photograph is the screen now — the logo that sat in the middle is gone, and so is the vignette that existed to keep that logo readable. Nothing to read, just the picture, which is what was asked for. **It no longer waits for React.** Until now the splash was a React element, so it could not appear until the bundle had downloaded, parsed and mounted — on a phone that is the long blank stretch between opening the app and seeing anything, and it is why the splash seemed to arrive late and then flash past: by the time it rendered, the app was nearly ready. index.html now paints the same photograph from inline styles, so it is on screen as soon as the HTML is parsed, with the bundle still downloading behind it. React replaces the container's contents when it mounts, and the two screens are identical — same image, same object-fit, same base colour behind it while the picture decodes — so the handover cannot be seen as anything but the app arriving. The blank before even that is iOS's own launch screen, which is what apple-touch-startup-image covers: production already serves all fourteen, so a PWA that still opens white is one that was installed before those existed. Removing the icon from the home screen and adding it again is what makes iOS pick them up — its launch images are read at install time, not on every launch.
84 lines
4.7 KiB
React
84 lines
4.7 KiB
React
// @vitest-environment happy-dom
|
|
/* The app shell, rendered once, end to end.
|
|
*
|
|
* This exists because a missing hook import in App.jsx — `useState` used, never imported — shipped
|
|
* to production and the only symptom was a background: React threw while rendering the shell, so
|
|
* neither the app nor the launch screen ever mounted, and every test in the suite passed because
|
|
* none of them rendered App. A page that only ever needs to render is still a page worth rendering
|
|
* in a test: the whole class of "the bundle parses but the tree throws" lives here. */
|
|
import React, { act } from 'react'
|
|
import { createRoot } from 'react-dom/client'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
// No network in a smoke test: the shell's boot() pulls config and state, and every one of those
|
|
// goes through lib/api.js. Everything else in that module stays real (Login reads IS_APPLE, BIO,
|
|
// passkeyLogin… from it), which is what `importOriginal` is for — a hand-listed mock would leave
|
|
// the screens importing exports that do not exist, and the error boundary would hide it.
|
|
vi.mock('./lib/api.js', async importOriginal => ({
|
|
...(await importOriginal()),
|
|
api: vi.fn(async () => ({}))
|
|
}))
|
|
vi.mock('./lib/back.js', () => ({ initBackButton: async () => () => {} }))
|
|
vi.mock('./lib/push.js', () => ({ syncPushSubscription: async () => {} }))
|
|
|
|
const { default: App } = await import('./App.jsx')
|
|
const { useStore } = await import('./store/useStore.js')
|
|
|
|
let host, root
|
|
beforeEach(() => {
|
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
|
localStorage.clear()
|
|
// The store is a module singleton, so it carries state from one test into the next: `ready` is
|
|
// left true by whichever test booted first, and a test about a boot that never finishes has to
|
|
// start from a boot that has not finished. `user` goes too, or "signed in" means nothing here.
|
|
useStore.setState({ ready: false, user: null })
|
|
host = document.createElement('div')
|
|
document.body.appendChild(host)
|
|
root = createRoot(host)
|
|
})
|
|
afterEach(() => { act(() => root.unmount()); host.remove() })
|
|
|
|
describe('the app shell', () => {
|
|
it('mounts without throwing, and shows the launch screen first', async () => {
|
|
await act(async () => { root.render(<App />) })
|
|
// The splash: the shell renders it before anything else, which is what a launch screen is.
|
|
expect(host.querySelector('.boot-splash')).toBeTruthy()
|
|
expect(host.querySelector('img.boot-photo')?.getAttribute('src')).toBe('splash.webp')
|
|
// Only the photograph: the mark that used to sit on it is gone by request.
|
|
expect(host.querySelector('.boot-splash').querySelectorAll('img').length).toBe(1)
|
|
})
|
|
|
|
it('stays long enough to be seen, then gets out of the way', async () => {
|
|
await act(async () => { root.render(<App />) })
|
|
// Past a warm boot, which finishes in milliseconds — and past the 500ms a flicker would have
|
|
// ended at. The floor is the whole point: this screen has to be readable, not a flash.
|
|
await act(async () => { await new Promise(r => setTimeout(r, 600)) })
|
|
expect(host.querySelector('.boot-splash')).toBeTruthy()
|
|
// Once the floor is up and boot has finished, the app takes over.
|
|
await act(async () => { await new Promise(r => setTimeout(r, 700)) })
|
|
expect(host.querySelector('.boot-splash')).toBeNull()
|
|
expect(host.textContent.trim().length).toBeGreaterThan(0)
|
|
})
|
|
|
|
it('keeps local data behind a boot that never finishes, but not forever', async () => {
|
|
// A signed-in device on a network that answers nothing. The splash holds while the app is
|
|
// loading — that is what a launch screen does — and the ceiling is what stops it becoming a
|
|
// screen you cannot get past: the workouts are already in local storage.
|
|
useStore.setState({ user: { id: 'u1', name: 'Test' }, ready: false })
|
|
const api = (await import('./lib/api.js')).api
|
|
api.mockImplementation(() => new Promise(() => {}))
|
|
// Fake timers from BEFORE the render: the component's two timeouts are scheduled on mount, and
|
|
// installing them afterwards leaves those on the real clock, so advancing the fake one moves
|
|
// nothing. (Learned by watching this test fail with the splash still up.)
|
|
vi.useFakeTimers()
|
|
await act(async () => { root.render(<App />) })
|
|
await act(async () => { vi.advanceTimersByTime(1300) })
|
|
expect(host.querySelector('.boot-splash')).toBeTruthy() // still loading, still showing it
|
|
// ...and the ceiling releases it, six seconds in. Driving that with fake timers is why this
|
|
// test takes milliseconds instead of six seconds.
|
|
await act(async () => { vi.advanceTimersByTime(6000) })
|
|
expect(host.querySelector('.boot-splash')).toBeNull()
|
|
vi.useRealTimers()
|
|
})
|
|
})
|