feat(waiter): the waiter app on the shared foundations (api client, access, i18n), lint clean, starts offline
Plan step 4.1. No visible change to layout or flows. - api/client.js on @xenia/api createApiClient (CS-8 baseURL, 401 → sign out, no answer → backend-offline, err.xenia, the manager-approval retry); the PIN login handles its own 401 (before, a wrong PIN reloaded the page). - <AccessProvider> at the root with an i18n instance: modules, permission keys, venue, language from bootstrap; who is signed in comes with it (no more /api/auth/me polling). packages/access: AccessProvider gains `cache` (the last bootstrap per session; used when the server can't be reached, `offline` in the context, keeps retrying) and `failed` (the app's own screen when there's nothing cached). The waiter caches per venue, shows its offline page (server search) on a first start without a server, retries every 5 s; ServerRediscovery and BundleSync run outside the bootstrap. - Role names → keys: the shift gate and the user menu use core.dashboard.access. - One shared, offline-cached read of the venue settings (api/venueSettings.js) instead of seven GET /api/settings/ calls; apiError() shows backend error codes in the user's language (17 places). - Lint: 78 errors → 0 (unused code, empty catches, two duplicate style keys, a component created during render, refs read during render → state, hooks after an early return); set-state-in-effect is a warning like the manager/terminal; lint in run-all. - Tests: tests/bootstrapCache.test.mjs; e2e browser: an offline restart stays signed in. Android rediscovery waits for what the screen shows instead of fixed sleeps: 10/10 three runs in a row (KI-009). Terminal 3.4 waits for both displays before the sale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-8
@@ -155,7 +155,12 @@ async function rediscovery() {
|
||||
await setVenues(v, { active: 'test-site-1', venues: { 'test-site-1': venue('test-site-1', `http://${H}:8055`) } })
|
||||
await v.evaluate(`localStorage.setItem('xenia:test-site-1:token', ${JSON.stringify(token)})`)
|
||||
v = await reloadApp(v)
|
||||
r.check('setup: paired and logged in', !!(await waitFor(async () => (await v.evaluate('location.pathname')) === '/tables', 30_000)))
|
||||
// waits for what the screen shows instead of fixed sleeps (KI-009): the app reloads at the
|
||||
// new address, so the WebView handle may need re-attaching meanwhile
|
||||
const onScreen = (check, ms = 30_000) => waitFor(async () => {
|
||||
try { return await check(v) } catch { v = await attach().catch(() => v); return false }
|
||||
}, ms, 500)
|
||||
r.check('setup: paired and logged in', !!(await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/tables', 45_000)))
|
||||
|
||||
const stale = async (vv) => {
|
||||
await setVenues(vv, { active: 'test-site-1', venues: { 'test-site-1': venue('test-site-1', `http://${H.replace(/\d+$/, '99')}:8055`) } })
|
||||
@@ -167,20 +172,20 @@ async function rediscovery() {
|
||||
|
||||
v = await stale(v)
|
||||
r.check('logged in: server "moved" → found and saved', !!(await found()))
|
||||
await sleep(4000); v = await attach(); await sleep(4000)
|
||||
r.check('logged in: back on /tables, live', (await v.evaluate('location.pathname')) === '/tables' && (await connectivityColor(v)) === GREEN)
|
||||
r.check('logged in: back on /tables, live', !!(await onScreen(async vv =>
|
||||
(await vv.evaluate('location.pathname')) === '/tables' && (await connectivityColor(vv)) === GREEN, 40_000)))
|
||||
|
||||
await v.evaluate("localStorage.removeItem('xenia:test-site-1:token')")
|
||||
v = await stale(v)
|
||||
r.check('logged out: found and saved', !!(await found()))
|
||||
await sleep(4000); v = await attach(); await sleep(3000)
|
||||
r.check('logged out: waiter list loads from the new address', (await v.evaluate('document.body.innerText')).includes('Manager'))
|
||||
r.check('logged out: waiter list loads from the new address', !!(await onScreen(async vv =>
|
||||
(await vv.evaluate('document.body.innerText')).includes('Manager'), 40_000)))
|
||||
|
||||
await backend.stop()
|
||||
v = await stale(v)
|
||||
await sleep(15000)
|
||||
const offlineShown = await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/offline', 45_000)
|
||||
r.check('server really down: saved address untouched', (await venuesState(v)).venues['test-site-1'].baseUrl.includes('.99:'))
|
||||
r.check('server really down: offline screen', (await v.evaluate('location.pathname')) === '/offline')
|
||||
r.check('server really down: offline screen', !!offlineShown)
|
||||
await v.evaluate("[...document.querySelectorAll('button')].find(e => e.textContent.includes('Αναζήτηση server')).click()")
|
||||
const notFound = await waitFor(async () => (await v.evaluate('document.body.innerText')).includes('Ο server δεν βρέθηκε'), 60_000)
|
||||
r.check('manual search ends with "not found" guidance', !!notFound)
|
||||
@@ -196,7 +201,7 @@ async function rediscovery() {
|
||||
await sleep(12000)
|
||||
r.check('cold start with the server down: still logged in', await v.evaluate("!!localStorage.getItem('xenia:test-site-1:token')"))
|
||||
backend = await startBackend({ port: 8055, siteId: 'test-site-1', dataDir: backend.dataDir })
|
||||
const recovered = await waitFor(async () => (await v.evaluate('location.pathname')) === '/tables', 30_000)
|
||||
const recovered = await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/tables', 45_000)
|
||||
r.check('server back → app lands on /tables by itself', !!recovered)
|
||||
v.close()
|
||||
} finally {
|
||||
|
||||
@@ -57,6 +57,17 @@ try {
|
||||
r1.check(`${m.name}: IndexedDB "${m.db}"`, dbs.includes(m.db), dbs.join(','))
|
||||
r1.check(`${m.name}: secure context = ${m.secure}`, (await page.evaluate(() => window.isSecureContext)) === m.secure)
|
||||
if (m.name.startsWith('venue')) r1.check(`${m.name}: API calls go to the venue server`, [...apiHosts].every(h => h === '127.0.0.1:8055'), [...apiHosts].join(','))
|
||||
if (m.name.startsWith('same-origin')) {
|
||||
// 4.1: the bootstrap (who is signed in, permissions, venue) is cached per venue, so a
|
||||
// phone that reopens the app without the server still starts signed in
|
||||
const cached = await page.evaluate(() => !!localStorage.getItem('bootstrap'))
|
||||
await page.context().setOffline(true)
|
||||
await page.reload().catch(() => {})
|
||||
await sleep(4000)
|
||||
const signedIn = await page.evaluate(() => location.pathname).catch(() => '')
|
||||
r1.check(`${m.name}: the bootstrap is cached and an offline restart stays signed in`, cached && signedIn.startsWith('/tables'), `${cached} ${signedIn}`)
|
||||
await page.context().setOffline(false)
|
||||
}
|
||||
await page.context().close()
|
||||
}
|
||||
failures += r1.done()
|
||||
|
||||
@@ -9,6 +9,7 @@ const shell = process.platform === 'win32'
|
||||
const suites = [
|
||||
['unit: local_backend (pytest)', PYTHON, ['-m', 'pytest', 'tests', '-q'], BACKEND],
|
||||
['unit: waiter_pwa (node --test)', 'npm', ['test', '--silent'], WAITER],
|
||||
['lint: waiter_pwa', 'npm', ['run', 'lint', '--silent'], WAITER],
|
||||
['unit: packages/ui (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/ui'], CS],
|
||||
['unit: packages/i18n (node --test + guard)', 'npm', ['test', '--silent', '-w', '@xenia/i18n'], CS],
|
||||
['unit: packages/api (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/api'], CS],
|
||||
|
||||
@@ -695,6 +695,7 @@ try {
|
||||
// its own address for the pairing rate limit (one per screen in a real venue)
|
||||
const otherDisplay = await screen(await (await browser.newContext({ viewport: { width: 1024, height: 600 }, extraHTTPHeaders: { 'x-real-ip': '10.9.0.42' } })).newPage())
|
||||
await pairFromManager(otherDisplay, boss, { app_key: 'customer_display', name: 'Display elsewhere' })
|
||||
await shown(otherDisplay, 'display-idle', 15_000) // both screens up before the sale
|
||||
r.check('3.4: a display linked to the counter shows the idle screen: the venue name (the default)',
|
||||
await shown(myDisplay, 'display-idle', 15_000) && (await myDisplay.getByTestId('display-name').textContent()) === 'Taverna E2E')
|
||||
await simpleCard.locator('button').first().click()
|
||||
|
||||
Reference in New Issue
Block a user