feat(manager): Devices page — pair by code, app, name, sign-in mode, link, change app, remove
Platform-v2 step 2.6d: - /devices (core.devices.manage, sidebar): devices from /api/devices with status (online / last seen / waiting for the device / app turned off / removed), app, sign-in mode (own or venue default), linked device; usage per device app against the license limit (devices) - pair dialog: code as typed (normalized), app (only apps that are on, "all in use" when the limit is reached), name, sign-in mode for apps with a choice, optional linked device; license.limit_reached explained with the app's limit - edit (name, sign-in mode, link), change app (signs out whoever is on it), remove with confirm (the device goes back to pairing), show removed - manager_dashboard gets node --test (tests/platform.test.mjs: module states, dependents, device status/usage/room/links), added to run-all - e2e manager.mjs: 54 checks (+ wrong code, normalized code, pair, the device picks up its token, online, rename, change app, remove → device.revoked) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ npm test -w @xenia/ui # PIN rules + WCAG contrast of every to
|
||||
npm test -w @xenia/i18n # venue-time formatting (DST), money/numbers, comma-or-dot parsing, language order, check-i18n guard, error texts vs core/errors.py
|
||||
npm test -w @xenia/api # live client = the waiter's old WebSocket behaviour (backoff, cursor, online); HTTP client vs a fake backend (headers, codes, 401, offline, approval retry)
|
||||
npm test -w @xenia/access # can(): one key, any/all
|
||||
npm test -w manager-dashboard # platform pages' logic: module states, what stops with a module, device status/usage/limits
|
||||
```
|
||||
|
||||
**DB tests** (`local_backend/tests/conftest.py`) run the real FastAPI app against a throwaway SQLite database in a temp folder (never your dev or venue DB). Fixtures: `db` (session, rolled back after each test even if the code commits), `client` (TestClient with `get_db` overridden, license check open, no lifespan), `make_user(role=..., perms=...)` (password `password`, PIN `1234`), `login(user)` (auth headers). A test that uses any of them is marked `db` automatically.
|
||||
|
||||
@@ -35,6 +35,15 @@ async function api(method, url, { token, body } = {}) {
|
||||
if (!res.ok) throw new Error(`${method} ${url} → ${res.status} ${text.slice(0, 200)}`)
|
||||
return data
|
||||
}
|
||||
// A device's side of pairing (what the terminal app will do in phase 3)
|
||||
async function deviceRequestsPairing() {
|
||||
return api('POST', '/api/devices/pair-request')
|
||||
}
|
||||
async function devicePicksUpToken(req) {
|
||||
const res = await fetch(`${backend.url}/api/devices/pair-request/${req.code}`, { headers: { 'X-Xenia-Pair-Secret': req.secret } })
|
||||
return (await res.json()).device_token
|
||||
}
|
||||
const asDevice = (token, url) => fetch(`${backend.url}${url}`, { headers: { 'X-Xenia-Device': token } })
|
||||
const loginApi = (username, secret) => api('POST', '/api/auth/login', { body: { username, ...secret } }).then(d => d.access_token)
|
||||
|
||||
async function uiLogin(page, password) {
|
||||
@@ -145,6 +154,58 @@ try {
|
||||
await card('notes').waitFor()
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-apps.png'), fullPage: true })
|
||||
|
||||
// ── 2.6d: Devices: pair by code, edit, change app, remove ──────────────────
|
||||
await page.goto(`${APP}/devices`)
|
||||
await page.getByTestId('device-usage').waitFor({ timeout: 15_000 })
|
||||
r.check('devices: empty state before any pairing', await page.getByText('No devices yet').count() === 1)
|
||||
const dlg = page.getByRole('dialog')
|
||||
await page.getByRole('button', { name: 'Pair a device' }).first().click()
|
||||
await dlg.getByLabel('Code shown on the device').fill('zz-zz-zz')
|
||||
await dlg.getByLabel('App to run').selectOption('kds')
|
||||
await dlg.getByLabel('Name').fill('Kitchen')
|
||||
await dlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await page.getByTestId('pair-error').waitFor({ timeout: 5000 }).catch(() => {})
|
||||
r.check('devices: a wrong code is refused with a message', (await page.getByTestId('pair-error').textContent().catch(() => '')).includes('pairing code is wrong'))
|
||||
const req = await deviceRequestsPairing()
|
||||
const typed = `${req.code.slice(0, 3).toLowerCase()}-${req.code.slice(3).toLowerCase()}`
|
||||
await dlg.getByLabel('Code shown on the device').fill(typed)
|
||||
r.check('devices: the code is normalized as typed (lower case, dash)', await dlg.getByLabel('Code shown on the device').inputValue() === req.code)
|
||||
await dlg.getByLabel('How staff sign in').selectOption('pin')
|
||||
await dlg.getByRole('button', { name: 'Pair a device' }).click()
|
||||
await page.waitForFunction(() => document.querySelectorAll('[data-testid^="device-"][data-status]').length === 1, null, { timeout: 8000 }).catch(() => {})
|
||||
const row = page.locator('[data-testid^="device-"][data-status]').first()
|
||||
r.check('devices: paired → listed as "waiting for the device"', await row.getAttribute('data-status') === 'waiting' && (await row.textContent()).includes('Kitchen'))
|
||||
const deviceToken = await devicePicksUpToken(req)
|
||||
const me = await asDevice(deviceToken, '/api/devices/me').then(x => x.json())
|
||||
r.check('devices: the device got its token and runs the kitchen display', me.app_key === 'kds' && me.name === 'Kitchen' && me.login_mode === 'pin', JSON.stringify(me))
|
||||
await page.reload()
|
||||
await row.waitFor({ timeout: 10_000 })
|
||||
r.check('devices: after it connected → "Online", sign-in PIN', await row.getAttribute('data-status') === 'online' && (await row.textContent()).includes('PIN'))
|
||||
r.check('devices: usage shows kitchen screens in use', (await page.getByTestId('device-usage').textContent()).includes('Kitchen screens: 1'))
|
||||
|
||||
await row.getByRole('button', { name: 'Edit' }).click()
|
||||
await dlg.getByLabel('Name').fill('Kitchen 1')
|
||||
await dlg.getByRole('button', { name: 'Save' }).click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid^="device-"][data-status]')?.textContent.includes('Kitchen 1'), null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('devices: renamed', (await row.textContent()).includes('Kitchen 1') && (await asDevice(deviceToken, '/api/devices/me').then(x => x.json())).name === 'Kitchen 1')
|
||||
|
||||
await row.getByRole('button', { name: 'Change app' }).click()
|
||||
await dlg.getByLabel('App to run').selectOption('pos_counter')
|
||||
await dlg.getByRole('button', { name: 'Save' }).click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid^="device-"][data-status]')?.textContent.includes('Counter POS'), null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('devices: app changed to Counter POS (the device follows)', (await row.textContent()).includes('Counter POS') && (await asDevice(deviceToken, '/api/devices/me').then(x => x.json())).app_key === 'pos_counter')
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-devices.png'), fullPage: true })
|
||||
|
||||
await row.getByRole('button', { name: 'Remove' }).click()
|
||||
await dlg.getByRole('button', { name: 'Remove' }).click()
|
||||
await page.getByText('No devices yet').waitFor({ timeout: 8000 }).catch(() => {})
|
||||
const after = await asDevice(deviceToken, '/api/devices/me')
|
||||
r.check('devices: removed → gone from the list, the device is refused (device.revoked)',
|
||||
await page.getByText('No devices yet').count() === 1 && after.status === 401 && (await after.json()).error.code === 'device.revoked')
|
||||
await page.getByLabel('Show removed devices').check()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid^="device-"][data-status="removed"]'), null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('devices: "show removed" lists it as removed', await page.locator('[data-status="removed"]').count() === 1)
|
||||
|
||||
// ── Lock screen: a wrong PIN stays locked (no logout), the right one unlocks ─
|
||||
await page.goto(`${APP}/dashboard`)
|
||||
await sleep(1500)
|
||||
|
||||
@@ -12,6 +12,7 @@ const suites = [
|
||||
['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],
|
||||
['unit: packages/access (node --test)', 'npm', ['test', '--silent', '-w', '@xenia/access'], CS],
|
||||
['unit: manager_dashboard (node --test)', 'npm', ['test', '--silent', '-w', 'manager-dashboard'], CS],
|
||||
['install.sh', 'node', ['install.mjs'], E2E],
|
||||
['license (cloud + site)', PYTHON, ['license_e2e.py'], E2E],
|
||||
['browser', 'node', ['browser.mjs'], E2E],
|
||||
|
||||
Reference in New Issue
Block a user