- Settings: tabs in the address (?tab=), Fiscal only with the fiscal app, Appearance only with the waiter app - General: version / update / license / state / uptime, the local network (address by hand or found, the pairing QR), what is set up, export / import of the catalogue and the tables (a wrong file refused, two confirmations), support lock - Sign-in & security: idle lock / sign-out (seconds..hours, warning when sign-out comes first), recovery codes - Operation: role permissions, waiters' own shifts and takings, card payments, tables and orders, courses (add, rename, colour, order), quick notes, table flags (emoji, colour, white/black text, on/off), quick messages, send the QR menu now - Appearance: the waiter app's table-card colours per state, light and dark, flash, colour picker with opacity, reset - Fiscal: on/off, driver, folders with a reachability check, clerk / card terminal numbers, receipt end lines, VAT groups - Development: pretend printing - dropped: the v1 'automatic store schedule' switches (kept in the browser only, nothing read them) and the second time-zone card - backend: JSON settings must be JSON (validation.setting_value); fiscal folders are plain paths (were typed json) - venue colour data in sections/venueColours.js (guard DATA); store/tableColourStore and Settings/tabs deleted - tests: settings.test.mjs (5), test_settings_json.py, e2e manager.mjs 'settings v2' (12 checks) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1498 lines
117 KiB
JavaScript
1498 lines
117 KiB
JavaScript
// Manager suite (Playwright + Edge): the manager on the shared packages (plan steps 2.5, 2.6).
|
||
// The demo venue has no venue.language set, so the shell starts in English.
|
||
// Starts a backend on a demo-seeded database (:8057, licensing off) and the manager's Vite
|
||
// dev server (:5186) proxied to it. Checks login and the platform bootstrap through
|
||
// @xenia/api + @xenia/access, the 401 rules (wrong password / wrong PIN stay on screen, an
|
||
// ended session logs out), a module turned off, and the manager-approval dialog.
|
||
// node manager.mjs
|
||
import { spawn } from 'node:child_process'
|
||
import { openSync, readFileSync } from 'node:fs'
|
||
import path from 'node:path'
|
||
import { chromium } from 'playwright'
|
||
import { BROWSER_CHANNEL, CS, OUT, reporter, sleep } from './lib/env.mjs'
|
||
import { killTree, startBackend, startTerminalVite, waitHttp } from './lib/proc.mjs'
|
||
import { SUPPORT_MASTER, codeFor, siteSecret, supportLogin } from './lib/support.mjs'
|
||
|
||
const PORT = 5186
|
||
const APP = `http://localhost:${PORT}`
|
||
const backend = await startBackend({ port: 8057, siteId: 'test-site-1' })
|
||
const log = openSync(path.join(OUT, `vite-${PORT}.log`), 'w')
|
||
const vite = spawn('npx', ['vite', '--port', String(PORT), '--strictPort'], {
|
||
cwd: path.join(CS, 'manager_dashboard'), shell: process.platform === 'win32', detached: process.platform !== 'win32',
|
||
stdio: ['ignore', log, log], env: { ...process.env, XENIA_BACKEND: backend.url },
|
||
})
|
||
const term = await startTerminalVite({ port: 5188, backendUrl: backend.url }) // the owner flow's kitchen screen (3.1c)
|
||
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
||
const r = reporter('manager: login + bootstrap on @xenia/api / @xenia/access')
|
||
|
||
const addDaysIso = (key, n) => new Date(Date.parse(`${key}T12:00:00Z`) + n * 86_400_000).toISOString().slice(0, 10)
|
||
|
||
async function api(method, url, { token, body } = {}) {
|
||
const res = await fetch(backend.url + url, {
|
||
method, headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
||
body: body === undefined ? undefined : JSON.stringify(body),
|
||
})
|
||
const text = await res.text()
|
||
let data = null
|
||
try { data = JSON.parse(text) } catch { data = text }
|
||
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
|
||
}
|
||
// A paired screen's live connection (plan 3.1a): the device token goes in the first frame.
|
||
function deviceSocket(token) {
|
||
const ws = new WebSocket(`${backend.url.replace(/^http/, 'ws')}/api/ws/connect`)
|
||
const s = { messages: [], closeCode: null }
|
||
s.ready = new Promise(resolve => {
|
||
ws.onopen = () => ws.send(JSON.stringify({ cursor: 0, device: token }))
|
||
ws.onmessage = e => { const m = JSON.parse(e.data); s.messages.push(m); if (m.type === 'ready') resolve(true) }
|
||
ws.onclose = e => { s.closeCode = e.code; resolve(false) }
|
||
})
|
||
s.closed = () => new Promise(resolve => { const t = setInterval(() => { if (s.closeCode != null) { clearInterval(t); resolve(s.closeCode) } }, 50); setTimeout(() => { clearInterval(t); resolve(s.closeCode) }, 8000) })
|
||
s.close = () => ws.close()
|
||
return s
|
||
}
|
||
const asDevice = (token, url) => fetch(`${backend.url}${url}`, { headers: { 'X-Xenia-Device': token } })
|
||
const loginApi = (username, secret) => api('POST', '/api/auth/login', { body: { client: 'manager', username, ...secret } }).then(d => d.access_token)
|
||
|
||
async function uiLogin(page, password) {
|
||
await page.goto(`${APP}/login`)
|
||
await page.getByTestId('login-form').waitFor({ timeout: 60_000 })
|
||
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
|
||
await page.getByLabel('Password').fill(password)
|
||
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
|
||
}
|
||
const typePin = async (page, pin) => { for (const d of pin) { await page.keyboard.type(d); await sleep(80) } await page.keyboard.press('Enter') }
|
||
const setSetting = (token, key, value) => api('PUT', `/api/settings/${key}`, { token, body: { value } })
|
||
|
||
try {
|
||
await waitHttp(`${APP}/`)
|
||
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } })
|
||
const page = await ctx.newPage()
|
||
const errors = []
|
||
page.on('pageerror', e => errors.push(e.message))
|
||
const bootstraps = []
|
||
page.on('request', q => { if (q.url().includes('/api/platform/bootstrap')) bootstraps.push(q.headers().authorization || 'anonymous') })
|
||
const managerWs = []
|
||
page.on('websocket', ws => managerWs.push(ws.url()))
|
||
|
||
// ── Wrong password: the message shows, no reload ───────────────────────────
|
||
await uiLogin(page, 'wrong-password')
|
||
await page.evaluate(() => { window.__noReload = true })
|
||
await sleep(1500)
|
||
r.check('bootstrap loaded before login (anonymous)', bootstraps[0] === 'anonymous', bootstraps.join(','))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-login-wrong-password.png') })
|
||
r.check('wrong password: error shown, page not reloaded',
|
||
await page.getByText('Wrong username or password').count() > 0 && await page.evaluate(() => window.__noReload === true))
|
||
|
||
// ── Right password: dashboard, bootstrap again with the session ────────────
|
||
await page.getByLabel('Password').fill('password')
|
||
await page.getByRole('button', { name: 'Sign in', exact: true }).click()
|
||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {})
|
||
await sleep(1500)
|
||
r.check('login → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
|
||
r.check('bootstrap reloaded with the session token', bootstraps.some(b => b.startsWith('Bearer ')), bootstraps.join(','))
|
||
const sidebar = page.getByTestId('sidebar')
|
||
r.check('sidebar built from modules + keys (Management, Reports)',
|
||
await sidebar.getByText('Management').count() > 0 && await sidebar.getByText('Reports').count() > 0)
|
||
await page.goto(`${APP}/management/products`)
|
||
await sleep(1500)
|
||
r.check('a guarded page renders for the manager', await page.getByTestId('route-guard').count() === 0 && (await page.evaluate(() => document.body.innerText.length)) > 200)
|
||
r.check('page title from the nav (Management › Products)', (await page.locator('header nav').first().innerText()).replace(/\s+/g, ' ').includes('Management Products'))
|
||
|
||
// ── 2.6a: a module turned off disappears from the sidebar and its route ────
|
||
const mgrNotes = await page.evaluate(() => localStorage.getItem('manager_token'))
|
||
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: false } })
|
||
await page.goto(`${APP}/notes`)
|
||
await sleep(2000)
|
||
await sidebar.getByText('Management').click().catch(() => {})
|
||
r.check('notes off: no "Notes" in the sidebar', await sidebar.getByText('Notes', { exact: true }).count() === 0)
|
||
r.check('notes off: /notes shows "turned off"', await page.getByTestId('route-guard').getByText('This feature is turned off').count() === 1)
|
||
await api('PUT', '/api/platform/modules/notes', { token: mgrNotes, body: { enabled: true } })
|
||
await page.goto(`${APP}/notes`)
|
||
await sleep(2000)
|
||
r.check('notes on again: the page and the item are back', await page.getByTestId('route-guard').count() === 0 && await sidebar.getByText('Notes', { exact: true }).count() === 1)
|
||
|
||
// ── 2.6a: the profile menu language switch (live, then saved) ──────────────
|
||
await page.goto(`${APP}/dashboard`)
|
||
await sleep(1500)
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Διαχείριση'), null, { timeout: 5000 }).catch(() => {})
|
||
r.check('language → Ελληνικά: the shell changes live', await sidebar.getByText('Διαχείριση').count() > 0 && await page.evaluate(() => document.documentElement.lang) === 'el')
|
||
await page.reload()
|
||
await sleep(2500)
|
||
r.check('…and it was saved (still Greek after a reload)', await sidebar.getByText('Διαχείριση').count() > 0)
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="sidebar"]')?.innerText.includes('Management'), null, { timeout: 5000 }).catch(() => {})
|
||
r.check('language → English again', await sidebar.getByText('Management').count() > 0)
|
||
|
||
// ── 2.6c: Apps page: module cards, toggles, dependency warning ─────────────
|
||
await page.goto(`${APP}/apps`)
|
||
await page.getByTestId('module-notes').waitFor({ timeout: 15_000 })
|
||
const card = key => page.getByTestId(`module-${key}`)
|
||
r.check('apps: cards for device apps, features and core', await card('kds').count() === 1 && await card('notes').count() === 1 && await card('core').count() === 1)
|
||
r.check('apps: core is "Always on" with no switch', await card('core').getAttribute('data-state') === 'always' && await card('core').getByRole('switch').count() === 0)
|
||
await card('notes').getByRole('switch').click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="module-notes"]')?.dataset.state === 'off', null, { timeout: 8000 }).catch(() => {})
|
||
await sidebar.getByText('Management').click().catch(() => {})
|
||
r.check('apps: notes switched off from its card → state off, gone from the sidebar',
|
||
await card('notes').getAttribute('data-state') === 'off' && await sidebar.getByText('Notes', { exact: true }).count() === 0)
|
||
await card('notes').getByRole('switch').click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="module-notes"]')?.dataset.state === 'on', null, { timeout: 8000 }).catch(() => {})
|
||
r.check('apps: notes back on', await card('notes').getAttribute('data-state') === 'on' && await sidebar.getByText('Notes', { exact: true }).count() === 1)
|
||
await card('ordering').getByRole('switch').click()
|
||
const stopped = await page.getByTestId('confirm-stopped').textContent({ timeout: 5000 }).catch(() => '')
|
||
r.check('apps: turning off Ordering first lists what stops with it', ['Kitchen display', 'Waiter app', 'Pricing'].every(n => stopped.includes(n)), stopped)
|
||
await page.getByRole('dialog').getByRole('button', { name: 'Cancel' }).click()
|
||
r.check('apps: Cancel leaves Ordering on', await card('ordering').getAttribute('data-state') === 'on')
|
||
// 3.2d: the KDS lives on paired screens only; its card leads to pairing one
|
||
r.check('apps: the KDS card has no "Open" (no KDS page in the manager)', await card('kds').getByRole('button', { name: 'Open' }).count() === 0)
|
||
await card('kds').getByRole('button', { name: 'Set up a screen' }).click()
|
||
await page.getByLabel('App to run').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check('apps: "Set up a screen" → Devices with the pair dialog on the kitchen display',
|
||
new URL(page.url()).pathname === '/devices' && await page.getByLabel('App to run').inputValue().catch(() => '') === 'kds', page.url())
|
||
await page.getByRole('dialog').getByRole('button', { name: 'Cancel' }).click()
|
||
await page.goto(`${APP}/kds`)
|
||
await sleep(1500)
|
||
r.check('apps: /kds is no longer a manager page', await page.getByTestId('app-kds').count() === 0 && !(await page.content()).includes('kds-board'))
|
||
|
||
// ── 2.6c: Integrations and License ─────────────────────────────────────────
|
||
await page.goto(`${APP}/integrations`)
|
||
await card('fiscal').waitFor({ timeout: 15_000 })
|
||
r.check('integrations: only integrations (fiscal, caller ID)', await card('caller_id').count() === 1 && await card('kds').count() === 0)
|
||
await page.goto(`${APP}/license`)
|
||
await page.getByTestId('license-status').waitFor({ timeout: 20_000 })
|
||
r.check('license: development mode, site id, a row per module',
|
||
(await page.getByTestId('license-mode').textContent()).startsWith('Development mode')
|
||
&& (await page.getByTestId('license-site').textContent()) === 'test-site-1'
|
||
&& await page.locator('[data-testid^="license-row-"]').count() >= 20)
|
||
r.check('license: limits are shown (kitchen screens: unlimited in dev)', (await page.getByTestId('license-row-kds').textContent()).includes('Kitchen screens'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-license.png'), fullPage: true })
|
||
await page.goto(`${APP}/apps`)
|
||
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.getByLabel('Sign out after').selectOption('10')
|
||
r.check('devices: the kitchen screen settings come in sections, prep zone "All zones" by default (3.2a)',
|
||
await dlg.locator('[data-config-group]').count() >= 4
|
||
&& (await dlg.getByLabel('Prep zone').locator('option:checked').textContent()) === 'All zones'
|
||
&& await dlg.locator('input[type="color"]').count() === 4)
|
||
await dlg.getByLabel('Text size').fill('110')
|
||
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))
|
||
r.check('devices: the app setting chosen when pairing reaches the device (3.1a)', me.config?.auto_sign_out_minutes === 10 && me.config?.font_scale === 110, JSON.stringify(me.config))
|
||
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'))
|
||
|
||
const sock = deviceSocket(deviceToken)
|
||
r.check('devices: the screen opens a live connection with its device token alone (3.1a)', await sock.ready)
|
||
await row.getByRole('button', { name: 'Edit' }).click()
|
||
r.check('devices: the edit dialog shows the device setting', await dlg.getByLabel('Sign out after').inputValue() === '10')
|
||
await dlg.getByLabel('Name').fill('Kitchen 1')
|
||
await dlg.getByLabel('Sign out after').selectOption('5')
|
||
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(() => {})
|
||
const me2 = await asDevice(deviceToken, '/api/devices/me').then(x => x.json())
|
||
r.check('devices: renamed, setting changed', (await row.textContent()).includes('Kitchen 1') && me2.name === 'Kitchen 1' && me2.config?.auto_sign_out_minutes === 5, JSON.stringify(me2))
|
||
await sleep(300)
|
||
r.check('devices: the screen is told at once (device.updated)', sock.messages.some(m => m.type === 'device.updated'), JSON.stringify(sock.messages))
|
||
|
||
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')
|
||
r.check('devices: changing the app closes the screen connection (4003)', await sock.closed() === 4003)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-devices.png'), fullPage: true })
|
||
const sock2 = deviceSocket(deviceToken)
|
||
await sock2.ready
|
||
|
||
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')
|
||
r.check('devices: removing it sends device.revoked and closes its connection',
|
||
await sock2.closed() === 4003 && sock2.messages.some(m => m.type === 'device.revoked'), JSON.stringify(sock2.messages))
|
||
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)
|
||
await page.locator('header button').filter({ has: page.locator('svg.lucide-lock') }).first().click()
|
||
await sleep(600)
|
||
const tokenBeforeLock = await page.evaluate(() => localStorage.getItem('manager_token'))
|
||
await typePin(page, '0000')
|
||
await sleep(1500)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-lock-wrong-pin.png') })
|
||
r.check('lock: wrong PIN → "Wrong PIN. 4 tries left…", still signed in',
|
||
await page.getByTestId('lock-screen').getByText('Wrong PIN. 4 tries left').count() === 1 && !!(await page.evaluate(() => localStorage.getItem('manager_token'))) && new URL(page.url()).pathname === '/dashboard')
|
||
await typePin(page, '1234')
|
||
await sleep(2000)
|
||
r.check('lock: right PIN unlocks the SAME session (token unchanged)',
|
||
await page.getByTestId('lock-screen').count() === 0 && new URL(page.url()).pathname === '/dashboard'
|
||
&& await page.evaluate(() => localStorage.getItem('manager_token')) === tokenBeforeLock)
|
||
|
||
// ("a module turned off shows its page as turned off" is checked with Notes above; the KDS page went in 3.2d)
|
||
const mgr = await page.evaluate(() => localStorage.getItem('manager_token'))
|
||
|
||
// ── 2.6b: five wrong PINs on the lock screen end the session ───────────────
|
||
await page.goto(`${APP}/dashboard`)
|
||
await sleep(1500)
|
||
await page.locator('header button').filter({ has: page.locator('svg.lucide-lock') }).first().click()
|
||
await sleep(500)
|
||
for (let i = 0; i < 5; i++) { await typePin(page, '0000'); await sleep(900) }
|
||
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
|
||
const endedToken = mgr
|
||
r.check('lock: 5 wrong PINs → signed out', new URL(page.url()).pathname === '/login' && !(await page.evaluate(() => localStorage.getItem('manager_token'))), page.url())
|
||
r.check('…and that session is really over on the server', await api('GET', '/api/auth/me', { token: endedToken }).then(() => false, e => e.message.includes('401')))
|
||
|
||
// ── 2.6b: PIN login mode ───────────────────────────────────────────────────
|
||
const owner = await loginApi('manager', { password: 'password', client: 'manager' })
|
||
await setSetting(owner, 'auth.manager_login_mode', 'pin')
|
||
await page.goto(`${APP}/login`)
|
||
await page.getByTestId('login-form').waitFor()
|
||
if (!(await page.getByTestId('login-account').count())) await page.getByLabel('Username').fill('manager')
|
||
r.check('pin mode: the login shows a PIN pad, no password field', await page.locator('.x-pinpad').count() === 1 && await page.getByLabel('Password').count() === 0)
|
||
await page.locator('.x-pinpad').getByRole('button', { name: '1', exact: true }).click()
|
||
for (const d of '234') await page.locator('.x-pinpad').getByRole('button', { name: d, exact: true }).click()
|
||
await page.locator('.x-pinpad').getByRole('button', { name: 'OK' }).click()
|
||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
|
||
r.check('pin mode: PIN → /dashboard', new URL(page.url()).pathname === '/dashboard', page.url())
|
||
await setSetting(owner, 'auth.manager_login_mode', 'password')
|
||
const mgr2 = await page.evaluate(() => localStorage.getItem('manager_token'))
|
||
await page.evaluate(() => { localStorage.removeItem('manager_token') })
|
||
await page.goto('about:blank') // leave first: the open page would redirect itself on the 401
|
||
await api('POST', '/api/auth/logout', { token: mgr2 })
|
||
|
||
// ── 2.6b: support access from the login screen ─────────────────────────────
|
||
await page.goto(`${APP}/login`)
|
||
await page.getByTestId('login-title').waitFor()
|
||
await page.getByRole('button', { name: 'Support access' }).click()
|
||
const challenge = (await page.getByTestId('support-challenge').textContent({ timeout: 10_000 })).trim()
|
||
await page.screenshot({ path: path.join(OUT, 'manager-support-access.png') })
|
||
r.check('support: a challenge code is shown', /^[A-Z0-9]{4}-[A-Z0-9]{4}$/.test(challenge), challenge)
|
||
await page.getByLabel("Support's code").fill('WRONGCODE1')
|
||
await page.getByRole('button', { name: 'Open support session' }).click()
|
||
await sleep(1000)
|
||
r.check('support: a wrong code is refused with a message', await page.getByText('That support code is wrong').count() === 1)
|
||
await page.getByLabel("Support's code").fill(codeFor(siteSecret(SUPPORT_MASTER, 'test-site-1'), 'test-site-1', challenge))
|
||
await page.getByRole('button', { name: 'Open support session' }).click()
|
||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
|
||
const supportOk = new URL(page.url()).pathname === '/dashboard'
|
||
if (!supportOk) await page.screenshot({ path: path.join(OUT, 'manager-support-access-FAILED.png') }) // seen failing once in ~8 runs (2.99a, 2.99d)
|
||
r.check('support: the right code opens a session', supportOk,
|
||
supportOk ? page.url() : `${page.url()} alert=${JSON.stringify(await page.getByRole('alert').allTextContents().catch(() => []))}`)
|
||
await page.evaluate(() => { localStorage.removeItem('manager_token') })
|
||
await uiLogin(page, 'password')
|
||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 10_000 }).catch(() => {})
|
||
const mgr3 = await page.evaluate(() => localStorage.getItem('manager_token'))
|
||
|
||
// ── Session ended elsewhere: the next request logs out ─────────────────────
|
||
await page.goto(`${APP}/dashboard`)
|
||
await sleep(1500)
|
||
await api('POST', '/api/auth/logout', { token: mgr3 })
|
||
await sidebar.getByText('Reports').first().click()
|
||
await sidebar.getByText('Today').first().click()
|
||
await page.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
|
||
r.check('session ended → back to /login, token cleared',
|
||
new URL(page.url()).pathname === '/login' && !(await page.evaluate(() => localStorage.getItem('manager_token'))), page.url())
|
||
|
||
// ── Manager approval (D-10): a waiter cancels without the key ──────────────
|
||
const boss = await loginApi('manager', { password: 'password' })
|
||
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
|
||
const waiter = await loginApi('demo_maria', { pin: '3302', client: 'waiter' })
|
||
await api('POST', '/api/shifts/start', { token: waiter, body: {} }).catch(() => {})
|
||
const tables = await api('GET', '/api/tables/', { token: boss })
|
||
const table = tables.find(t => !t.open_order_id && !t.current_order_id) || tables[0]
|
||
const order = await api('POST', '/api/orders/', { token: waiter, body: { table_id: table.id } })
|
||
const w = await (await browser.newContext({ viewport: { width: 1200, height: 900 } })).newPage()
|
||
w.on('pageerror', e => errors.push(e.message))
|
||
await w.goto(`${APP}/login`)
|
||
await w.evaluate(t => { localStorage.setItem('manager_token', t); localStorage.setItem('manager_username', 'demo_maria') }, waiter)
|
||
await w.goto(`${APP}/dashboard`)
|
||
await sleep(2500)
|
||
// ── 2.6a: a user without the keys: no item, and "no access" on the URL ─────
|
||
const wSidebar = w.getByTestId('sidebar')
|
||
r.check('waiter in the manager: no Reports / Management items', await wSidebar.getByText('Reports').count() === 0 && await wSidebar.getByText('Management').count() === 0)
|
||
await w.goto(`${APP}/reports/today`)
|
||
await sleep(2000)
|
||
r.check('waiter opens /reports/today by URL → "no access"', await w.getByTestId('route-guard').getByText("You don't have access to this page").count() === 1)
|
||
await w.goto(`${APP}/dashboard`)
|
||
await sleep(2000)
|
||
await w.evaluate(id => {
|
||
window.__res = window.__xeniaClient.delete(`/api/orders/${id}`) // cancel the whole order
|
||
.then(res => ({ ok: true, status: res.status }), e => ({ ok: false, code: e.xenia?.code, cancelled: !!e.xenia?.overrideCancelled }))
|
||
}, order.id)
|
||
const dialog = w.getByRole('dialog')
|
||
await dialog.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check('approval dialog opens for ordering.orders.cancel', await w.getByTestId('override-key').textContent().catch(() => '') === 'ordering.orders.cancel')
|
||
const inputs = dialog.locator('input')
|
||
await inputs.nth(0).fill('manager')
|
||
await inputs.nth(1).fill('0000')
|
||
await inputs.nth(1).press('Enter')
|
||
await sleep(1500)
|
||
r.check('wrong manager PIN: error in the dialog, waiter still signed in',
|
||
await dialog.locator('.x-field__error').count() === 1 && !!(await w.evaluate(() => localStorage.getItem('manager_token'))))
|
||
await w.screenshot({ path: path.join(OUT, 'manager-approval-wrong-pin.png') })
|
||
await inputs.nth(1).fill('1234')
|
||
await inputs.nth(1).press('Enter')
|
||
const result = await w.evaluate(() => window.__res)
|
||
r.check('right PIN: the cancel is retried and succeeds', result.ok === true && result.status === 204, JSON.stringify(result))
|
||
r.check('dialog closed', await w.getByRole('dialog').count() === 0)
|
||
const audit = await api('GET', '/api/access/overrides', { token: boss })
|
||
r.check('the approval is audited', audit[0]?.key === 'ordering.orders.cancel' && audit[0]?.target === `order:${order.id}` && !!audit[0]?.used_at, JSON.stringify(audit[0]))
|
||
await w.screenshot({ path: path.join(OUT, 'manager-after-approval.png') })
|
||
|
||
// ── 2.6e: approvals log, who is signed in, staff permissions ───────────────
|
||
await uiLogin(page, 'password')
|
||
await page.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {})
|
||
const staffList = await api('GET', '/api/waiters/', { token: boss })
|
||
const maria = staffList.find(u => u.username === 'demo_maria')
|
||
|
||
await page.goto(`${APP}/management/approvals`)
|
||
const approval = page.locator(`[data-testid="approval-${audit[0].id}"]`)
|
||
await approval.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
const approvalText = await approval.textContent().catch(() => '')
|
||
r.check('approvals: the cancel is listed: action, who asked, who approved, used on the order',
|
||
await approval.getAttribute('data-state').catch(() => '') === 'used' && approvalText.includes('Cancel items already sent') &&
|
||
approvalText.includes(maria.full_name) && approvalText.includes(`Order #${order.id}`), approvalText)
|
||
|
||
await page.goto(`${APP}/management/sessions`)
|
||
await page.getByTestId('sessions-table').waitFor({ timeout: 10_000 }).catch(() => {})
|
||
const mariaRow = page.locator(`[data-user="${maria.id}"][data-client="waiter"][data-ended="false"]`)
|
||
r.check('sessions: the waiter is listed (Waiter app) and my own row is "You, here" with no end button',
|
||
await mariaRow.count() >= 1 && (await mariaRow.first().textContent()).includes('Waiter app') &&
|
||
await page.locator('tr', { hasText: 'You, here' }).getByRole('button', { name: 'End session' }).count() === 0)
|
||
await mariaRow.first().getByRole('button', { name: 'End session' }).click()
|
||
await page.getByRole('dialog').getByRole('button', { name: 'End session' }).click()
|
||
await page.waitForFunction(id => !document.querySelector(`[data-user="${id}"][data-client="waiter"][data-ended="false"]`), maria.id, { timeout: 8000 }).catch(() => {})
|
||
const mariaMe = await fetch(`${backend.url}/api/auth/me`, { headers: { authorization: `Bearer ${waiter}` } })
|
||
r.check('sessions: "End session" → gone from the list, the waiter\'s next call is refused',
|
||
await mariaRow.count() === 0 && mariaMe.status === 401 && (await mariaMe.json()).error.code === 'auth.session_ended')
|
||
await page.getByLabel('Show ended sessions').check()
|
||
await page.waitForFunction(id => document.querySelector(`[data-user="${id}"][data-ended="true"]`), maria.id, { timeout: 8000 }).catch(() => {})
|
||
r.check('sessions: "show ended" lists it as ended by a manager',
|
||
(await page.locator(`[data-user="${maria.id}"][data-ended="true"]`).first().textContent().catch(() => '')).includes('ended by a manager'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-sessions.png'), fullPage: true })
|
||
|
||
// the permission editor: give one key, see it differ from the role, reset
|
||
const mariaPerms = () => api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })
|
||
const before = await mariaPerms()
|
||
await page.goto(`${APP}/management/staff`)
|
||
const permCell = page.getByTestId(`staff-perms-${maria.id}`)
|
||
await permCell.waitFor({ timeout: 10_000 })
|
||
r.check('staff: a Permissions column with the count instead of 13 tick columns',
|
||
(await permCell.textContent()).includes(`${before.keys.length} permissions`) && await page.getByText('Ακύρωση', { exact: true }).count() === 0)
|
||
await permCell.getByRole('button').click()
|
||
const editor = page.getByTestId('perm-editor')
|
||
await editor.waitFor({ timeout: 10_000 })
|
||
const cancelRow = page.getByTestId('perm-ordering.orders.cancel')
|
||
r.check('editor: grouped by module (Ordering, Kitchen display, Core…), cancel is off for a waiter',
|
||
await page.getByTestId('perm-group-ordering').count() === 1 && await page.getByTestId('perm-group-core').count() === 1 &&
|
||
await cancelRow.getAttribute('data-on') === 'false' && (await cancelRow.textContent()).includes('Cancel items already sent'))
|
||
await cancelRow.getByRole('switch').click()
|
||
await page.getByRole('button', { name: 'Save 1 change' }).click()
|
||
await editor.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const afterGive = await mariaPerms()
|
||
await page.waitForFunction(id => document.querySelector(`[data-testid="staff-perms-${id}"]`)?.textContent.includes('Changed from role'), maria.id, { timeout: 8000 }).catch(() => {})
|
||
r.check('editor: saved → the waiter has the key, the row says "Changed from role"',
|
||
afterGive.keys.includes('ordering.orders.cancel') && (await permCell.textContent()).includes('Changed from role'), JSON.stringify(afterGive.keys))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-staff.png'), fullPage: true })
|
||
await permCell.getByRole('button').click()
|
||
await editor.waitFor({ timeout: 10_000 })
|
||
await page.screenshot({ path: path.join(OUT, 'manager-permissions.png') })
|
||
await page.getByTestId('perm-reset').click()
|
||
await page.screenshot({ path: path.join(OUT, 'manager-permissions-reset.png') })
|
||
r.check('editor: reset → the draft is the role\'s defaults (cancel off again), saying so',
|
||
await cancelRow.getAttribute('data-on') === 'false' && await page.getByTestId('perm-note').count() === 1)
|
||
await page.getByRole('button', { name: /^Save \d+ change/ }).click()
|
||
await editor.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const afterReset = await mariaPerms()
|
||
r.check('editor: reset saved → keys = the role template',
|
||
JSON.stringify(afterReset.keys) === JSON.stringify(afterReset.role_template), JSON.stringify(afterReset.keys))
|
||
|
||
// a staff manager can't give what they don't have (disabled), and the backend's refusal is explained
|
||
const sm = await api('POST', '/api/waiters/', { token: boss, body: { username: 'e2e_staffmgr', full_name: 'Stella Staff', pin: '5151', role: 'staff_manager', is_active: true } })
|
||
// new staff have only a PIN: sign them in while managers use PINs, then back to passwords
|
||
await api('PUT', '/api/settings/auth.manager_login_mode', { token: boss, body: { value: 'pin' } })
|
||
const smToken = await loginApi('e2e_staffmgr', { pin: '5151' })
|
||
await api('PUT', '/api/settings/auth.manager_login_mode', { token: boss, body: { value: 'password' } })
|
||
const s2 = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage()
|
||
s2.on('pageerror', e => errors.push(e.message))
|
||
await s2.goto(`${APP}/login`)
|
||
await s2.evaluate(t => { localStorage.setItem('manager_token', t); localStorage.setItem('manager_username', 'e2e_staffmgr') }, smToken)
|
||
await s2.goto(`${APP}/management/staff`)
|
||
await s2.getByTestId(`staff-perms-${maria.id}`).getByRole('button').click()
|
||
await s2.getByTestId('perm-editor').waitFor({ timeout: 10_000 })
|
||
const smCancel = s2.getByTestId('perm-ordering.orders.cancel')
|
||
r.check('staff manager: "cancel" is disabled with the reason (they don\'t have it)',
|
||
await smCancel.getByRole('switch').isDisabled() && (await smCancel.textContent()).includes("You don't have this permission yourself"))
|
||
// they had "See reports" when the editor opened; the owner takes it away before they save
|
||
const smKeys = (await api('GET', `/api/waiters/${sm.id}/permissions`, { token: boss })).keys
|
||
await api('PUT', `/api/waiters/${sm.id}/permissions`, { token: boss, body: { keys: smKeys.filter(k => k !== 'reports.view') } })
|
||
await s2.getByTestId('perm-reports.view').getByRole('switch').click()
|
||
await s2.getByRole('button', { name: 'Save 1 change' }).click()
|
||
await s2.getByTestId('perm-error').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check('staff manager: the backend refuses (access.cannot_grant), named by its label',
|
||
(await s2.getByTestId('perm-error').textContent().catch(() => '')).includes('You can only give permissions you have yourself: "See reports"'))
|
||
r.check('…and nothing was saved', !(await mariaPerms()).keys.includes('reports.view'))
|
||
|
||
// ── 2.6f: notification bell (live), settings pages, log download ───────────
|
||
await page.goto(`${APP}/dashboard`)
|
||
const bell = page.getByTestId('notif-bell')
|
||
await bell.waitFor({ timeout: 10_000 })
|
||
await page.getByTestId('notif-count').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check('bell: unread count from the earlier support sign-ins', Number((await page.getByTestId('notif-count').textContent().catch(() => '0')).replace('+', '')) >= 1)
|
||
await bell.click()
|
||
const panel = page.getByTestId('notif-panel')
|
||
r.check('bell: the list says support signed in, in plain words', (await panel.textContent()).includes('Xenia support logged in'))
|
||
await page.getByTestId('notif-read-all').click()
|
||
await page.getByTestId('notif-count').waitFor({ state: 'detached', timeout: 5000 }).catch(() => {})
|
||
r.check('bell: "mark all as read" clears the count', await page.getByTestId('notif-count').count() === 0)
|
||
await bell.click() // close
|
||
await page.waitForSelector('html[data-live="ready"]', { timeout: 10_000 }).catch(() => {}) // the live socket is up
|
||
await supportLogin(backend.url)
|
||
await page.getByTestId('notif-count').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check('bell: a new one arrives live (no reload): count 1 and a toast',
|
||
await page.getByTestId('notif-count').textContent().catch(() => '') === '1' && await page.getByText('Xenia support logged in').count() >= 1)
|
||
await bell.click()
|
||
const unreadItem = panel.locator('[data-read="false"]').first()
|
||
await unreadItem.click()
|
||
await page.waitForFunction(() => !document.querySelector('[data-testid="notif-count"]'), null, { timeout: 5000 }).catch(() => {})
|
||
let notifAfter = await api('GET', '/api/platform/notifications', { token: boss })
|
||
for (let i = 0; i < 30 && notifAfter.unread !== 0; i++) { // the count clears at once; the server hears it a moment later
|
||
await sleep(100)
|
||
notifAfter = await api('GET', '/api/platform/notifications', { token: boss })
|
||
}
|
||
r.check('bell: opening it marks it read', await page.getByTestId('notif-count').count() === 0 && notifAfter.unread === 0,
|
||
JSON.stringify({ shown: await page.getByTestId('notif-count').textContent().catch(() => null), unread: notifAfter.unread }))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-notifications.png') })
|
||
await page.keyboard.press('Escape')
|
||
|
||
const settingValue = async key => (await api('GET', '/api/settings/', { token: boss }))[key].value
|
||
// KI-010: Online Orders refreshes from the shared live connection, never /api/stream
|
||
const ooUrls = []
|
||
const ooListen = req => ooUrls.push(new URL(req.url()).pathname)
|
||
page.on('request', ooListen)
|
||
await page.goto(`${APP}/online-orders`)
|
||
await sleep(5000)
|
||
page.off('request', ooListen)
|
||
r.check('online orders: loads its lists and never asks for the old /api/stream',
|
||
ooUrls.some(u => u.startsWith('/api/connect/orders')) && !ooUrls.some(u => u.startsWith('/api/stream')), [...new Set(ooUrls)].filter(u => u.startsWith('/api/')).join(' '))
|
||
|
||
// ── phase 3S S.3: delivery areas and fees, set up and tested on the real page ──
|
||
await page.goto(`${APP}/online/fees`)
|
||
r.check('fees: the page opens from the nav entry, no rules yet', await page.getByTestId('fees-page').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& await page.locator('a[href="/online/fees"]').count() >= 1 && await page.getByTestId('rule').count() === 0)
|
||
r.check('ordering link: the venue\'s ordering app address is shown, with its QR code', await page.getByTestId('ordering-link').count() === 1
|
||
&& (await page.getByTestId('ordering-link-url').textContent()).endsWith('/order/test-site-1') && await page.getByTestId('ordering-link').locator('svg').count() >= 1)
|
||
await page.getByTestId('area-add').click()
|
||
await page.getByTestId('area-name').fill('Centre')
|
||
await page.getByTestId('area-postcodes').fill('24100, 241 31')
|
||
await page.getByTestId('area-save').click()
|
||
r.check('fees: an area with postcodes', await page.getByTestId('area').filter({ hasText: 'Centre' }).waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||
&& (await page.getByTestId('area').first().textContent()).includes('241 31'))
|
||
const addRule = async (name, fill) => {
|
||
await page.getByTestId('rule-add').click()
|
||
await page.getByTestId('rule-name').fill(name)
|
||
await fill()
|
||
await page.getByTestId('rule-save').click()
|
||
await page.getByTestId('rule').filter({ hasText: name }).waitFor({ timeout: 5000 }).catch(() => {})
|
||
}
|
||
await addRule('Base', () => page.getByTestId('rule-value').fill('2'))
|
||
await addRule('Free over 25', async () => {
|
||
await page.getByTestId('rule-action').selectOption('free')
|
||
await page.getByTestId('rule-subtotal-min').fill('25')
|
||
await page.getByRole('switch', { name: 'Stop here' }).click()
|
||
})
|
||
await page.getByTestId('rule').filter({ hasText: 'Free over 25' }).getByRole('button', { name: 'Move up' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="rule"]')?.textContent.includes('Free over 25'), null, { timeout: 5000 }).catch(() => {})
|
||
r.check('fees: rules added and put in order (free over 25 first, it stops)', (await page.getByTestId('rule').first().textContent()).includes('Free over 25')
|
||
&& (await page.getByTestId('rule').first().textContent()).includes('stop here'))
|
||
const testFee = async (subtotal) => {
|
||
await page.getByTestId('test-subtotal').fill(String(subtotal))
|
||
await page.getByTestId('test-run').click()
|
||
await page.waitForFunction(st => document.querySelector('[data-testid="test-result"]') && document.querySelector('[data-testid="test-subtotal"]').value === st,
|
||
String(subtotal), { timeout: 5000 }).catch(() => {})
|
||
await sleep(300)
|
||
return page.getByTestId('test-result')
|
||
}
|
||
let res = await testFee(15)
|
||
r.check('fees: "test an order" for €15 in Centre → €2.00', await res.getAttribute('data-fee') === '2' && await res.getAttribute('data-refused') === ''
|
||
&& (await res.textContent()).includes('Base') && (await res.textContent()).includes('Centre'),
|
||
await res.textContent())
|
||
res = await testFee(30)
|
||
r.check('fees: …for €30 → free, the first rule stopped the rest', await res.getAttribute('data-fee') === '0' && await res.getAttribute('data-refused') === ''
|
||
&& (await res.textContent()).includes('Free over 25') && !(await res.textContent()).includes('Base'),
|
||
await res.textContent())
|
||
await page.getByTestId('test-subtotal').fill('8')
|
||
await page.getByRole('combobox', { name: 'Where' }).selectOption('postcode')
|
||
await page.getByTestId('test-postcode').fill('10431')
|
||
await page.getByTestId('test-run').click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="test-result"]')?.dataset.refused, null, { timeout: 5000 }).catch(() => {})
|
||
r.check('fees: …a postcode outside the areas is refused', await page.getByTestId('test-result').getAttribute('data-refused') === 'area_not_served')
|
||
// S.5: the fee's line on the bill and the receipt (a system product, never in the catalogue)
|
||
await page.getByTestId('fee-product-name').fill('Delivery')
|
||
await page.getByTestId('fee-product-vat').fill('2')
|
||
await page.getByTestId('fee-product-save').click()
|
||
let feeProduct = null
|
||
for (let i = 0; i < 30 && feeProduct?.name !== 'Delivery'; i++) {
|
||
feeProduct = (await api('GET', '/api/connect/fees', { token: boss })).fee_product
|
||
if (feeProduct?.name !== 'Delivery') await sleep(100)
|
||
}
|
||
r.check('fees: the fee line\'s name and VAT group are saved', feeProduct?.name === 'Delivery' && feeProduct?.vat_group_id === 2, JSON.stringify(feeProduct))
|
||
// S.6: table bookings online, with food ordered ahead
|
||
await page.getByTestId('booking-enabled').click()
|
||
await page.getByTestId('booking-food').click()
|
||
await page.getByTestId('booking-party').fill('8')
|
||
await page.getByTestId('booking-fire').fill('25')
|
||
await page.getByTestId('ordering-save').click()
|
||
let bookingCfg = null
|
||
for (let i = 0; i < 30 && !bookingCfg?.enabled; i++) {
|
||
bookingCfg = (await api('GET', '/api/connect/fees/ordering', { token: boss })).reservations
|
||
if (!bookingCfg?.enabled) await sleep(100)
|
||
}
|
||
r.check('ordering: table bookings on, with food, 8 people at most, the kitchen 25 min before', bookingCfg?.enabled && bookingCfg.with_food && bookingCfg.party_max === 8
|
||
&& bookingCfg.fire_minutes === 25, JSON.stringify(bookingCfg))
|
||
r.check('fees: …and it never shows in the products list', !(await api('GET', '/api/products/?all=true', { token: boss })).some(p => p.id === feeProduct?.id))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-fees.png'), fullPage: true })
|
||
|
||
// 3.5: caller ID in the manager, on the signed-in live connection
|
||
await api('PUT', '/api/platform/modules/caller_id', { token: boss, body: { enabled: true } }).catch(() => {})
|
||
await page.goto(`${APP}/apps/phone`)
|
||
await page.getByTestId('phone-page').waitFor({ timeout: 10_000 })
|
||
await page.waitForFunction(() => document.documentElement.dataset.live === 'ready', null, { timeout: 10_000 }).catch(() => {})
|
||
await fetch(`${backend.url}/api/phone/call-event?caller=2101112233&ext=101`)
|
||
r.check('caller ID: a call pops up in the manager (unknown number)', await page.getByTestId('call-popup').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& (await page.getByTestId('call-popup').textContent()).includes('2101112233'))
|
||
await page.getByTestId('call-close').click()
|
||
r.check('caller ID: …and is in the call log', await page.getByTestId('call-row').first().waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||
&& (await page.getByTestId('call-log').textContent()).includes('2101112233'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-calls.png'), fullPage: true })
|
||
|
||
// 3.4: the customer display's idle screen, the venue's choice
|
||
await api('PUT', '/api/platform/modules/customer_display', { token: boss, body: { enabled: true } }).catch(() => {})
|
||
await page.goto(`${APP}/settings`)
|
||
await page.getByTestId('settings-tab-customer-display').click()
|
||
await page.getByTestId('display-style-qr').click()
|
||
await page.getByTestId('display-qr-caption').fill('Order online')
|
||
await page.getByTestId('display-save').click()
|
||
let idleCfg = null
|
||
for (let i = 0; i < 30 && idleCfg?.style !== 'qr'; i++) {
|
||
idleCfg = (await api('GET', '/api/display/looks', { token: boss })).find(l => l.is_default)?.config
|
||
if (idleCfg?.style !== 'qr') await sleep(100)
|
||
}
|
||
r.check('settings: customer display → the default look: a QR code to the online ordering, with a caption', idleCfg?.style === 'qr'
|
||
&& idleCfg.qr_target === 'ordering' && idleCfg.qr_caption === 'Order online', JSON.stringify(idleCfg))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-display-settings.png'), fullPage: true })
|
||
|
||
// 4.3: Settings → Operation → "What each role may do" replaces the three waiter switches
|
||
await page.goto(`${APP}/settings`)
|
||
await page.getByTestId('settings-tab-operation').click()
|
||
await page.getByTestId('settings-role-permissions').waitFor({ timeout: 10_000 })
|
||
r.check('settings: Operation has "What each role may do", the old waiter switches are gone',
|
||
await page.getByText('Ακυρώσεις Παραγγελιών από Σερβιτόρους').count() === 0 && await page.getByText('Αναίρεση Πληρωμής από Σερβιτόρους').count() === 0)
|
||
await page.getByTestId('role-perm-waiter').click()
|
||
await page.getByTestId('perm-editor').waitFor({ timeout: 10_000 })
|
||
const payRow = page.getByTestId('perm-ordering.orders.close')
|
||
const payOn = await payRow.getAttribute('data-on')
|
||
await payRow.getByRole('switch').click()
|
||
await page.screenshot({ path: path.join(OUT, 'manager-role-permissions.png') })
|
||
await page.getByRole('button', { name: 'Save 1 change' }).click()
|
||
await page.getByTestId('perm-editor').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const waiterRole = await api('GET', '/api/waiters/roles/waiter/permissions', { token: boss })
|
||
r.check('settings: the waiter role loses "take payments" → so does every waiter (Maria)',
|
||
payOn === 'true' && !waiterRole.keys.includes('ordering.orders.close') && !(await mariaPerms()).keys.includes('ordering.orders.close'),
|
||
JSON.stringify(waiterRole.keys))
|
||
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: waiterRole.default_keys } })
|
||
r.check('settings: back to the role defaults → Maria takes payments again', (await mariaPerms()).keys.includes('ordering.orders.close'))
|
||
|
||
await page.goto(`${APP}/settings`)
|
||
await page.getByTestId('settings-tab-security').click()
|
||
const waiterMode = page.getByTestId('setting-auth.waiter_login_mode')
|
||
await waiterMode.waitFor({ timeout: 10_000 })
|
||
await waiterMode.selectOption('tap')
|
||
await page.getByRole('note').waitFor({ timeout: 5000 }).catch(() => {})
|
||
r.check('settings: waiter sign-in → "Tap your name" is saved and warns it needs paired devices',
|
||
await settingValue('auth.waiter_login_mode') === 'tap' && (await page.getByRole('note').textContent()).includes('only on paired devices'))
|
||
await waiterMode.selectOption('pin')
|
||
await page.getByTestId('setting-auth.manager_login_mode').selectOption('pin')
|
||
await sleep(800)
|
||
r.check('settings: manager sign-in → PIN reaches the sign-in page (bootstrap)',
|
||
(await api('GET', '/api/platform/bootstrap')).login.manager_mode === 'pin')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-settings-sign-in.png'), fullPage: true })
|
||
await page.getByTestId('setting-auth.manager_login_mode').selectOption('password')
|
||
await page.getByTestId('setting-auth.single_session_waiter').selectOption('end_old')
|
||
await sleep(800)
|
||
r.check('settings: one session per waiter → "sign out the older one"', await settingValue('auth.single_session_waiter') === 'end_old' &&
|
||
await settingValue('auth.manager_login_mode') === 'password' && await settingValue('auth.waiter_login_mode') === 'pin')
|
||
await page.getByTestId('setting-auth.single_session_waiter').selectOption('off')
|
||
const idleSel = page.getByTestId('setting-auth.idle_days')
|
||
const idleDefault = await idleSel.inputValue()
|
||
await idleSel.selectOption('30')
|
||
await sleep(800)
|
||
r.check('settings: sign out after 14 days by default; 30 days is saved', idleDefault === '14' && await settingValue('auth.idle_days') === '30', idleDefault)
|
||
await idleSel.selectOption('14')
|
||
|
||
await page.getByTestId('settings-tab-venue').click()
|
||
const tzSelect = page.getByTestId('setting-venue.timezone')
|
||
await tzSelect.waitFor({ timeout: 10_000 })
|
||
await tzSelect.selectOption('Europe/London')
|
||
await sleep(800)
|
||
await page.getByTestId('setting-venue.language').selectOption('el')
|
||
await sleep(800)
|
||
const venue = (await api('GET', '/api/platform/bootstrap')).venue
|
||
r.check('settings: time zone and venue language saved (bootstrap says Europe/London, el)', venue.timezone === 'Europe/London' && venue.language === 'el', JSON.stringify(venue))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-settings-venue.png'), fullPage: true })
|
||
await page.getByTestId('setting-venue.language').selectOption('en')
|
||
await sleep(800)
|
||
await tzSelect.selectOption('Europe/Athens')
|
||
await sleep(800)
|
||
|
||
await page.getByTestId('settings-tab-print-fonts').click()
|
||
const alertSel = page.getByTestId('setting-print.alert_after_failures')
|
||
await alertSel.waitFor({ timeout: 10_000 })
|
||
await alertSel.selectOption('5')
|
||
await sleep(800)
|
||
r.check('settings: print alert after 5 failed attempts', await settingValue('print.alert_after_failures') === '5')
|
||
await alertSel.selectOption('2')
|
||
await sleep(500)
|
||
|
||
// ── 6.14a: every settings tab on v2 ───────────────────────────────────────────
|
||
const st6 = 'settings v2:'
|
||
const waitSetting = async (key, want) => { let v; for (let i = 0; i < 30 && (v = await settingValue2(key)) !== want; i++) await sleep(150); return v }
|
||
const settingValue2 = async key => (await api('GET', '/api/settings/', { token: boss }))[key]?.value
|
||
await page.goto(`${APP}/settings`)
|
||
r.check(`${st6} General: the version, the local network, what is set up`, await page.getByTestId('system-version').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& await page.getByTestId('settings-lan').count() === 1 && (await page.getByTestId('system-stats').textContent()).includes('Categories'))
|
||
const [catFile] = await Promise.all([page.waitForEvent('download', { timeout: 10_000 }), page.getByTestId('export-catalog').click()])
|
||
const catPath = await catFile.path()
|
||
await page.getByTestId('import-tables').setInputFiles(catPath)
|
||
r.check(`${st6} importing the catalogue file as tables is refused`, await page.getByText("This isn't a Tables and zones file.").waitFor({ timeout: 5000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('import-catalog').setInputFiles(catPath)
|
||
r.check(`${st6} the exported catalogue reads back: the import asks first, with what it adds`, await page.getByTestId('import-next').waitFor({ timeout: 5000 }).then(() => true).catch(() => false))
|
||
await page.keyboard.press('Escape')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-settings-general.png'), fullPage: true })
|
||
await page.getByTestId('settings-tab-security').click()
|
||
await page.getByTestId('setting-security.auto_lock').click()
|
||
r.check(`${st6} Security: lock after a while is saved`, await waitSetting('security.auto_lock', 'true') === 'true' && await page.getByTestId('settings-recovery').count() === 1)
|
||
await page.getByTestId('setting-security.auto_lock').click()
|
||
await waitSetting('security.auto_lock', 'false')
|
||
await page.getByTestId('settings-tab-operation').click()
|
||
const coursesOn = page.getByTestId('setting-orders.courses_enabled')
|
||
await coursesOn.waitFor({ timeout: 10_000 })
|
||
if (await coursesOn.getAttribute('aria-checked') !== 'true') { await coursesOn.click(); await waitSetting('orders.courses_enabled', 'true') }
|
||
const coursesBefore = JSON.parse(await settingValue2('orders.courses') || '[]').length
|
||
await page.getByTestId('course-add').click()
|
||
let coursesNow = coursesBefore
|
||
for (let i = 0; i < 30 && coursesNow === coursesBefore; i++) { await sleep(150); coursesNow = JSON.parse(await settingValue2('orders.courses') || '[]').length }
|
||
r.check(`${st6} Operation: a course added`, coursesNow === coursesBefore + 1, `${coursesBefore} → ${coursesNow}`)
|
||
await page.getByTestId('quick-note-new').fill('E2E: well done')
|
||
await page.getByTestId('quick-note-add').click()
|
||
let notesNow = []
|
||
for (let i = 0; i < 30 && !notesNow.includes('E2E: well done'); i++) { await sleep(150); notesNow = JSON.parse(await settingValue2('orders.quick_notes') || '[]') }
|
||
r.check(`${st6} Operation: a quick note added`, notesNow.includes('E2E: well done'), JSON.stringify(notesNow))
|
||
await page.getByTestId('flag-new').click()
|
||
await page.getByTestId('flag-save').click()
|
||
r.check(`${st6} a table flag needs a name`, (await page.getByTestId('flag-dialog').textContent()).includes('Enter a name'))
|
||
await page.getByTestId('flag-name').fill('E2E VIP')
|
||
await page.getByTestId('flag-save').click()
|
||
await page.locator('[data-testid="flag-row"]', { hasText: 'E2E VIP' }).waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check(`${st6} a table flag added`, (await api('GET', '/api/flags/defs?include_inactive=true', { token: boss })).some(f => f.name === 'E2E VIP'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-settings-operation.png'), fullPage: true })
|
||
await page.getByTestId('settings-tab-colours').click()
|
||
await page.getByTestId('colours-free').first().locator('button').first().click()
|
||
await page.getByTestId('colour-hex').fill('#123456')
|
||
await page.getByTestId('colour-save').click()
|
||
let tc = null
|
||
for (let i = 0; i < 30 && tc?.light?.free?.cardBg !== '#123456'; i++) { await sleep(150); tc = JSON.parse(await settingValue2('ui.table_colours') || '{}') }
|
||
r.check(`${st6} Appearance: a table colour for the waiter app saved`, tc?.light?.free?.cardBg === '#123456', JSON.stringify(tc?.light?.free))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-settings-colours.png'), fullPage: true })
|
||
await page.getByText('Back to the default colours', { exact: true }).click()
|
||
await page.getByRole('button', { name: 'Reset', exact: true }).click()
|
||
for (let i = 0; i < 30 && tc?.light?.free?.cardBg === '#123456'; i++) { await sleep(150); tc = JSON.parse(await settingValue2('ui.table_colours') || '{}') }
|
||
await page.getByTestId('settings-tab-development').click()
|
||
await page.getByTestId('setting-dev.spoof_printing').click()
|
||
r.check(`${st6} Development: pretend printing is saved`, await waitSetting('dev.spoof_printing', 'true') === 'true')
|
||
await page.getByTestId('setting-dev.spoof_printing').click()
|
||
await waitSetting('dev.spoof_printing', 'false')
|
||
await api('PUT', '/api/platform/modules/fiscal', { token: boss, body: { enabled: true } }).catch(() => {})
|
||
await page.goto(`${APP}/settings?tab=fiscal`)
|
||
if (await page.getByTestId('settings-fiscal').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)) {
|
||
await page.getByTestId('fiscal-out').fill('/tmp/e2e-fiscal-out')
|
||
await page.getByTestId('fiscal-in').fill('/tmp/e2e-fiscal-in')
|
||
await page.getByTestId('fiscal-save-folders').click()
|
||
r.check(`${st6} Fiscal: the folders saved as plain paths`, await waitSetting('fiscal.out_folder', '/tmp/e2e-fiscal-out') === '/tmp/e2e-fiscal-out')
|
||
await api('PUT', '/api/platform/modules/fiscal', { token: boss, body: { enabled: false } }).catch(() => {})
|
||
}
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.goto(`${APP}/settings?tab=operation`)
|
||
r.check(`${st6} Settings in Greek`, await page.getByTestId('settings-tab-operation').filter({ hasText: 'Λειτουργία' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& await page.getByTestId('settings-flags').filter({ hasText: 'Σημάνσεις τραπεζιών' }).count() === 1)
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
|
||
await page.goto(`${APP}/reports/technical`)
|
||
await page.getByText('Log files', { exact: true }).click()
|
||
const today = new Date().toISOString().slice(0, 10)
|
||
const logRow = page.getByTestId(`log-${today}`)
|
||
await logRow.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check("logs: today's file is listed (still being written)", (await logRow.textContent().catch(() => '')).includes('still being written'))
|
||
const [dl] = await Promise.all([page.waitForEvent('download', { timeout: 10_000 }), logRow.getByRole('button', { name: 'Download' }).click()])
|
||
const dlText = readFileSync(await dl.path(), 'utf-8')
|
||
r.check('logs: Download saves xenia-<day>.log with the backend\'s lines', dl.suggestedFilename() === `xenia-${today}.log` && dlText.includes('session.started'), dl.suggestedFilename())
|
||
await s2.goto(`${APP}/reports/technical`)
|
||
await s2.getByText('Printer history').or(s2.getByText('Ιστορικό Εκτυπωτή')).first().waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check('logs: a staff manager has no "Log files" tab (owner-level)', await s2.getByText('Log files', { exact: true }).count() === 0)
|
||
|
||
// ── 2.6g: the owner flow (plan step 2.6 "done when") ───────────────────────
|
||
// log in → enable KDS → pair a device → give a chef kds.access → the chef logs in on it.
|
||
// The device's side is the real terminal app (3.1c), on its own Vite (:5188).
|
||
const ownerFlow = 'owner flow:'
|
||
await api('PUT', '/api/platform/modules/kds', { token: boss, body: { enabled: false } }) // start with KDS off
|
||
const chef = await api('POST', '/api/waiters/', { token: boss, body: { username: 'e2e_chef', full_name: 'Kostas Chef', pin: '4747', role: 'custom', is_active: true } })
|
||
const o = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage()
|
||
o.on('pageerror', e => errors.push(e.message))
|
||
// 1. log in
|
||
await uiLogin(o, 'password')
|
||
await o.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {})
|
||
r.check(`${ownerFlow} 1. the owner signs in`, new URL(o.url()).pathname === '/dashboard', o.url())
|
||
// 2. enable KDS on the Apps page
|
||
await o.goto(`${APP}/apps`)
|
||
const kdsCard = o.getByTestId('module-kds')
|
||
await kdsCard.waitFor({ timeout: 10_000 })
|
||
const offBefore = await kdsCard.getAttribute('data-state')
|
||
await kdsCard.getByRole('switch').click()
|
||
await o.waitForFunction(() => document.querySelector('[data-testid="module-kds"]')?.getAttribute('data-state') === 'on', null, { timeout: 8000 }).catch(() => {})
|
||
r.check(`${ownerFlow} 2. KDS turned on from its card`, offBefore === 'off' && await kdsCard.getAttribute('data-state') === 'on')
|
||
// 3. the screen (the real terminal app, 3.1c) shows a code; the owner pairs it on the Devices page
|
||
const k = await (await browser.newContext({ viewport: { width: 1280, height: 800 } })).newPage()
|
||
k.on('pageerror', e => errors.push(e.message))
|
||
await k.goto(term.url)
|
||
await k.getByTestId('pairing-code').waitFor({ timeout: 20_000 })
|
||
const kitchenCode = await k.getByTestId('pairing-code').getAttribute('data-code')
|
||
await o.goto(`${APP}/devices`)
|
||
await o.getByTestId('device-usage').waitFor({ timeout: 10_000 })
|
||
await o.getByRole('button', { name: 'Pair a device' }).first().click()
|
||
const odlg = o.getByRole('dialog')
|
||
await odlg.getByLabel('Code shown on the device').fill(kitchenCode)
|
||
await odlg.getByLabel('App to run').selectOption('kds')
|
||
await odlg.getByLabel('Name').fill('Kitchen pass')
|
||
await odlg.getByLabel('How staff sign in').selectOption('pin')
|
||
await odlg.getByRole('button', { name: 'Pair a device' }).click()
|
||
await odlg.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const onSignIn = await k.getByTestId('sign-in-screen').waitFor({ timeout: 15_000 }).then(() => true).catch(() => false)
|
||
r.check(`${ownerFlow} 3. the kitchen screen shows a code, the owner pairs it as "Kitchen pass" (PIN) and the screen asks who signs in`,
|
||
onSignIn && await k.getByTestId('sign-in-screen').getAttribute('data-mode') === 'pin' && (await k.getByTestId('sign-in-screen').textContent()).includes('Kitchen pass'))
|
||
await k.getByTestId('user-grid').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check(`${ownerFlow} …before the permission, the chef isn't offered on that screen`,
|
||
await k.locator(`[data-user="${chef.id}"]`).count() === 0)
|
||
// 4. give the chef the kitchen permissions in the editor
|
||
await o.goto(`${APP}/management/staff`)
|
||
await o.getByTestId(`staff-perms-${chef.id}`).getByRole('button').click()
|
||
await o.getByTestId('perm-editor').waitFor({ timeout: 10_000 })
|
||
await o.getByTestId('perm-kds.access').getByRole('switch').click()
|
||
await o.getByTestId('perm-kds.bump').getByRole('switch').click()
|
||
await o.getByRole('button', { name: 'Save 2 changes' }).click()
|
||
await o.getByTestId('perm-editor').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const chefKeys = (await api('GET', `/api/waiters/${chef.id}/permissions`, { token: boss })).keys
|
||
r.check(`${ownerFlow} 4. the chef now has kds.access and kds.bump`, chefKeys.includes('kds.access') && chefKeys.includes('kds.bump'), JSON.stringify(chefKeys))
|
||
// 5. the chef signs in on the kitchen screen with their PIN (the name list refreshes every 30 s; reload = now)
|
||
await k.reload()
|
||
await k.locator(`[data-user="${chef.id}"]`).click({ timeout: 15_000 })
|
||
await k.keyboard.type('4747')
|
||
await k.keyboard.press('Enter')
|
||
const inKds = await k.getByTestId('app-kds').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
r.check(`${ownerFlow} 5. the chef signs in on that screen with their PIN and lands in the kitchen display`,
|
||
inKds && (await k.getByTestId('signed-in-user').textContent()).includes('Kostas'))
|
||
await k.screenshot({ path: path.join(OUT, 'manager-owner-flow-kitchen.png') })
|
||
await o.goto(`${APP}/management/sessions`)
|
||
const chefRow = o.locator(`[data-user="${chef.id}"][data-client="terminal"]`)
|
||
await chefRow.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check(`${ownerFlow} …and the owner sees them under "Signed in now" on "Kitchen pass · Kitchen display"`,
|
||
(await chefRow.textContent().catch(() => '')).includes('Kitchen pass · Kitchen display'))
|
||
await o.screenshot({ path: path.join(OUT, 'manager-owner-flow.png'), fullPage: true })
|
||
|
||
// ── 6.2: the overview (open the day, a shift, a table, close the day), online orders ──
|
||
const ov = 'overview:'
|
||
if (await api('GET', '/api/business-day/current', { token: boss })) { // earlier steps' orders may have opened one
|
||
await api('POST', '/api/business-day/close', { token: boss, body: { force: true } })
|
||
}
|
||
await page.goto(`${APP}/dashboard`)
|
||
await page.getByTestId('overview').waitFor({ timeout: 15_000 })
|
||
const dayState = () => page.getByTestId('day-state').getAttribute('data-open')
|
||
r.check(`${ov} the landing page shows the day closed, the figures, the tables and the cards`, await dayState() === 'false'
|
||
&& await page.getByTestId('kpis').count() === 1 && await page.getByTestId('table-chip').count() > 0 && await page.getByTestId('shifts-card').count() === 1)
|
||
await page.getByTestId('day-open').click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="day-state"]')?.dataset.open === 'true', null, { timeout: 8000 }).catch(() => {})
|
||
r.check(`${ov} "Open the day" opens it`, await dayState() === 'true' && !!(await api('GET', '/api/business-day/current', { token: boss })))
|
||
const ovWaiter = (await api('GET', '/api/waiters/', { token: boss })).find(w => w.username === 'demo_maria')
|
||
await page.getByTestId('shift-start').click()
|
||
await page.getByTestId('shift-start-waiter').selectOption(String(ovWaiter.id))
|
||
await page.getByRole('dialog').getByLabel('Starting cash').fill('20,5')
|
||
await page.getByTestId('shift-start-confirm').click()
|
||
const ovRow = page.getByTestId('shift-row').filter({ hasText: ovWaiter.full_name })
|
||
r.check(`${ov} a shift started for a waiter with €20.50 (typed with a comma)`, await ovRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& (await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(s => s.waiter_id === ovWaiter.id && s.starting_cash === 20.5))
|
||
const freeTable = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id)
|
||
const ovOrder = await api('POST', '/api/orders/', { token: await loginApi('demo_maria', { pin: '3302', client: 'waiter' }), body: { table_id: freeTable.id } })
|
||
const chip = page.locator(`[data-testid="table-chip"][data-state="open"]`).filter({ hasText: freeTable.label || `T${freeTable.number}` }).first()
|
||
r.check(`${ov} a table a waiter opens turns "open" by itself (live)`, await chip.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await chip.click()
|
||
r.check(`${ov} the table opens its order at a glance`, await page.getByTestId('order-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& (await page.getByRole('dialog').textContent()).includes(`#${ovOrder.id}`))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-overview-order.png') })
|
||
await page.keyboard.press('Escape')
|
||
await ovRow.getByTestId('shift-stats').click()
|
||
await page.getByTestId('shift-dialog').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check(`${ov} shift stats: €20.50 expected in the drawer`, (await page.getByTestId('shift-expected').textContent().catch(() => '')).includes('20.50'))
|
||
await page.keyboard.press('Escape')
|
||
await ovRow.getByTestId('shift-end').click()
|
||
await page.getByTestId('shift-next').click()
|
||
await page.getByTestId('shift-counted').fill('18')
|
||
r.check(`${ov} ending it: €18 handed over shows "short"`, await page.getByTestId('shift-check').getAttribute('data-state').catch(() => '') === 'short')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-overview-shift.png') })
|
||
await page.getByTestId('shift-end-confirm').click()
|
||
await ovRow.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
r.check(`${ov} …and the shift ends with the count kept`, await ovRow.count() === 0
|
||
&& !(await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(s => s.waiter_id === ovWaiter.id))
|
||
if (await page.getByTestId('booking-new').count()) {
|
||
await page.getByTestId('booking-new').click()
|
||
await page.getByTestId('booking-name').fill('Eleni E2E')
|
||
await page.getByRole('button', { name: '+1 h' }).click()
|
||
await page.getByTestId('booking-save').click()
|
||
const bookingRow = page.getByTestId('booking-row').filter({ hasText: 'Eleni E2E' })
|
||
const want = await page.evaluate(() => Date.now() + 3600_000)
|
||
const listed = await bookingRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
const saved = (await api('GET', '/api/reservations/?tab=upcoming', { token: boss })).find(b => b.guest_name === 'Eleni E2E')
|
||
r.check(`${ov} a booking "in 1 hour" is saved at that moment (venue time) and listed`, listed
|
||
&& !!saved && Math.abs(new Date(/[zZ]|[+-]\d\d:?\d\d$/.test(saved.reserved_for) ? saved.reserved_for : `${saved.reserved_for}Z`).getTime() - want) < 3 * 60_000, saved?.reserved_for)
|
||
}
|
||
await page.getByTestId('day-stats').click()
|
||
await page.getByTestId('day-money').waitFor({ timeout: 8000 }).catch(() => {})
|
||
await page.screenshot({ path: path.join(OUT, 'manager-overview-day.png') })
|
||
r.check(`${ov} day stats: the money tab, then staff`, await page.getByTestId('day-net').count() === 1
|
||
&& await page.getByTestId('day-tab-staff').click().then(() => page.getByTestId('day-staff').waitFor({ timeout: 5000 })).then(() => true).catch(() => false))
|
||
await page.keyboard.press('Escape')
|
||
// both languages
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="tables-card"]')?.innerText.includes('Τραπέζια τώρα'), null, { timeout: 5000 }).catch(() => {})
|
||
r.check(`${ov} in Greek`, (await page.getByTestId('day-state').textContent()).includes('Ημέρα ανοιχτή') && (await page.getByTestId('tables-card').textContent()).includes('Τραπέζια τώρα'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-overview-el.png'), fullPage: true })
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="tables-card"]')?.innerText.includes('Tables now'), null, { timeout: 5000 }).catch(() => {})
|
||
await page.screenshot({ path: path.join(OUT, 'manager-overview.png'), fullPage: true })
|
||
// close the day: the table is still open → the checks say so and the close is forced
|
||
await page.getByTestId('day-close').click()
|
||
await page.getByTestId('day-to-cash').click()
|
||
await page.getByTestId('day-counted').fill('0')
|
||
await page.getByTestId('day-to-checks').click()
|
||
r.check(`${ov} closing: the checks show the open table`, await page.getByTestId('check-tables').getAttribute('data-ok').catch(() => '') === 'false')
|
||
await page.getByTestId('day-close-confirm').click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="day-state"]')?.dataset.open === 'false', null, { timeout: 8000 }).catch(() => {})
|
||
r.check(`${ov} …"Close the day" closes it and the open order with it`, await dayState() === 'false'
|
||
&& !(await api('GET', '/api/business-day/current', { token: boss }))
|
||
&& (await api('GET', `/api/orders/${ovOrder.id}`, { token: boss })).status === 'closed')
|
||
|
||
// ── 6.3: products in two categories, ordered in each; allergens ──────────────
|
||
const pr = 'products:'
|
||
const pcats = (await api('GET', '/api/products/categories', { token: boss })).filter(c => !c.parent_id)
|
||
const inCat = async id => (await api('GET', `/api/products/?category_id=${id}&all=true`, { token: boss })).map(p => p.id)
|
||
const allProducts = await api('GET', '/api/products/?all=true', { token: boss })
|
||
const [catA, catB] = pcats.filter(c => allProducts.filter(p => p.category_ids.includes(c.id) && p.lifecycle_status === 'active').length >= 2)
|
||
const prodP = allProducts.find(p => p.category_ids.length === 1 && p.category_ids[0] === catA.id && p.lifecycle_status === 'active' && !p.is_service_item)
|
||
const orderA = await inCat(catA.id)
|
||
await page.goto(`${APP}/management/products`)
|
||
const pRow = page.locator(`[data-testid="product-row"][data-name="${prodP.name}"]`).first()
|
||
await pRow.waitFor({ timeout: 15_000 })
|
||
await pRow.getByTestId('product-edit').click()
|
||
await page.getByTestId('product-editor').waitFor({ timeout: 10_000 })
|
||
await page.getByTestId('add-category').selectOption(String(catB.id))
|
||
await page.getByTestId('allergen-gluten').click()
|
||
await page.getByTestId('allergen-milk').click()
|
||
await page.getByTestId('allergen-milk').click()
|
||
await page.getByTestId('translation-el-name').fill('E2E name in Greek') // 6.4: the test venue speaks English, so the other menu language is Greek
|
||
r.check(`${pr} the editor lists both categories, the first one main; gluten "contains", milk "may contain"`,
|
||
await page.locator(`[data-testid="product-category"][data-id="${catA.id}"][data-main="true"]`).count() === 1
|
||
&& await page.locator(`[data-testid="product-category"][data-id="${catB.id}"][data-main="false"]`).count() === 1
|
||
&& await page.getByTestId('allergen-gluten').getAttribute('data-level') === 'contains' && await page.getByTestId('allergen-milk').getAttribute('data-level') === 'may_contain')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-product-editor.png') })
|
||
await page.getByTestId('product-save').click()
|
||
await page.getByTestId('product-editor').waitFor({ state: 'detached', timeout: 10_000 }).catch(() => {})
|
||
const savedP = (await api('GET', '/api/products/?all=true', { token: boss })).find(p => p.id === prodP.id)
|
||
r.check(`${pr} saved: listed in both, the main one kept, its allergens`, JSON.stringify(savedP.category_ids) === JSON.stringify([catA.id, catB.id])
|
||
&& savedP.primary_category_id === catA.id && JSON.stringify(savedP.allergens) === JSON.stringify({ gluten: 'contains', milk: 'may_contain' }), JSON.stringify([savedP.category_ids, savedP.allergens]))
|
||
r.check(`${pr} 6.4: its name for the other menu language is saved; the name itself is unchanged`, savedP.translations?.el?.name === 'E2E name in Greek' && savedP.name === prodP.name,
|
||
JSON.stringify(savedP.translations))
|
||
await page.getByTestId(`category-${catB.id}`).click()
|
||
const inB = page.locator(`[data-testid="product-group"][data-category="${catB.id}"] [data-testid="product-row"][data-id="${prodP.id}"]`)
|
||
r.check(`${pr} it shows in the second category too, marked "also in" the first`, await inB.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& (await inB.getByTestId('also-in').textContent()).includes(catA.name),
|
||
`${await page.getByTestId('products-title').textContent().catch(() => '?')} | ${await page.locator('[data-testid="product-group"]').evaluateAll(gs => gs.map(g => g.dataset.category + ':' + g.querySelectorAll('[data-testid=product-row]').length).join(','))}`)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-products-b.png') })
|
||
const orderB = await inCat(catB.id)
|
||
r.check(`${pr} …at the end of that category's list`, orderB.at(-1) === prodP.id, JSON.stringify(orderB))
|
||
await inB.hover()
|
||
await inB.getByTestId('product-up').click()
|
||
let orderB2 = orderB
|
||
for (let i = 0; i < 20 && orderB2.at(-2) !== prodP.id; i++) { await sleep(250); orderB2 = await inCat(catB.id) }
|
||
r.check(`${pr} moved up in the second category; the first category's order is untouched`, orderB2.at(-2) === prodP.id && JSON.stringify(await inCat(catA.id)) === JSON.stringify(orderA),
|
||
JSON.stringify(orderB2))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-products.png') })
|
||
|
||
// ── 6.7: pricing — a happy-hour rule made on the page prices a counter sale ──
|
||
const pg = 'pricing:'
|
||
const plain = (await api('GET', '/api/products/?all=true', { token: boss }))
|
||
.find(p => p.lifecycle_status === 'active' && !p.is_service_item && !(p.preference_sets?.length) && p.base_price >= 2)
|
||
const quote = async () => (await api('POST', '/api/pos/quote', { token: boss, body: { order_type: 'here', lines: [{ product_id: plain.id, quantity: 1 }] } })).lines[0].unit_price
|
||
const basePrice = await quote()
|
||
await page.goto(`${APP}/management/pricing`)
|
||
await page.getByTestId('pricing-rules').waitFor({ timeout: 15_000 })
|
||
await page.getByTestId('pricing-rule-new').click()
|
||
await page.getByTestId('pricing-name').fill('E2E happy hour')
|
||
await page.getByTestId('pricing-target').first().locator('select').selectOption('item')
|
||
await page.getByTestId('pricing-target-products').getByRole('textbox').fill(plain.name).catch(() => {})
|
||
await page.locator(`[data-testid="pricing-target-products"] [role="checkbox"][data-name="${plain.name}"]`).first().click()
|
||
await page.getByTestId('pricing-rule-page-when').click()
|
||
await page.getByTestId('pricing-condition-add').click()
|
||
await page.getByTestId('pricing-cond-from').fill('00:00')
|
||
await page.getByTestId('pricing-cond-to').fill('23:59')
|
||
await page.getByTestId('pricing-rule-page-price').click()
|
||
await page.getByTestId('pricing-rule-value').fill('-20')
|
||
const example = await page.getByTestId('pricing-rule-example').textContent().catch(() => '')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-pricing-rule.png') })
|
||
await page.getByTestId('pricing-save').click()
|
||
const ruleRow = page.locator('[data-testid="pricing-rule"][data-name="E2E happy hour"]')
|
||
r.check(`${pg} a new price rule (one product, all day, −20%) shows in the list`, await ruleRow.waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& (await ruleRow.getByTestId('pricing-rule-action').textContent()).includes('20%'), example)
|
||
const expected = Math.round(Math.round(basePrice * 0.8 / 0.1) * 0.1 * 100) / 100
|
||
const discounted = await quote()
|
||
r.check(`${pg} the done-when: the counter prices the product with it (${basePrice} → ${expected})`, discounted === expected, String(discounted))
|
||
await ruleRow.getByTestId('pricing-toggle').click()
|
||
await page.locator('[data-testid="pricing-rule"][data-name="E2E happy hour"][data-active="false"]').waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check(`${pg} turned off: back to the menu price`, await quote() === basePrice)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-pricing.png') })
|
||
// a price group with a schedule; the venue's discount limit
|
||
await page.getByTestId('pricing-tab-groups').click()
|
||
await page.getByTestId('pricing-group-new').click()
|
||
await page.getByTestId('pricing-name').fill('E2E summer')
|
||
await page.getByTestId('pricing-save').click()
|
||
r.check(`${pg} a price group is made`, await page.locator('[data-testid="pricing-group"][data-name="E2E summer"]').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('pricing-tab-discounts').click()
|
||
await page.getByTestId('limit-max_total_value_workday').first().fill('50,5')
|
||
await page.getByTestId('pricing-venue-save').click()
|
||
let limits = null
|
||
for (let i = 0; i < 20 && limits?.max_total_value_workday !== 50.5; i++) { await sleep(250); limits = await api('GET', '/api/pricing/discount-settings/global', { token: boss }) }
|
||
r.check(`${pg} the venue's discount limit "50,5" is saved as 50.5`, limits?.max_total_value_workday === 50.5, JSON.stringify(limits))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-pricing-discounts.png') })
|
||
await page.getByTestId('limit-max_total_value_workday').first().fill('')
|
||
await page.getByTestId('pricing-venue-save').click()
|
||
for (let i = 0; i < 20 && limits?.max_total_value_workday !== null; i++) { await sleep(250); limits = await api('GET', '/api/pricing/discount-settings/global', { token: boss }) }
|
||
r.check(`${pg} emptied: no limit`, limits?.max_total_value_workday === null, JSON.stringify(limits))
|
||
|
||
// ── 6.8: a floor plan drawn in the manager (the phones and the counter: waiter.mjs, terminal.mjs) ──
|
||
const fl = 'floor plans:'
|
||
await page.goto(`${APP}/management/tables`)
|
||
await page.getByTestId('tables-tab-floor').click()
|
||
await page.getByTestId('floor-new').first().click()
|
||
await page.getByTestId('floor-new-name').fill('E2E ground floor')
|
||
await page.getByTestId('floor-create').click()
|
||
await page.getByTestId('floor-editor').waitFor({ timeout: 10_000 })
|
||
const ownButtons = page.getByTestId('floor-own-tables').locator('button')
|
||
await ownButtons.first().waitFor({ timeout: 5000 })
|
||
const firstId = Number(await ownButtons.first().getAttribute('data-table'))
|
||
await ownButtons.first().click()
|
||
await page.keyboard.press('Escape')
|
||
await page.getByTestId('floor-canvas').click({ position: { x: 5, y: 5 } })
|
||
const secondId = Number(await ownButtons.first().getAttribute('data-table'))
|
||
await ownButtons.first().click()
|
||
await page.getByTestId('floor-shape-round').click()
|
||
await page.getByTestId('floor-canvas').click({ position: { x: 5, y: 5 } })
|
||
await page.getByTestId('floor-add-bar').click()
|
||
// drag the first table 150 px to the right
|
||
await page.locator(`[data-testid="floor-canvas"] [data-testid="floor-table"][data-table="${firstId}"]`).scrollIntoViewIfNeeded()
|
||
const tb = await page.locator(`[data-testid="floor-canvas"] [data-testid="floor-table"][data-table="${firstId}"]`).boundingBox()
|
||
await page.mouse.move(tb.x + tb.width / 2, tb.y + tb.height / 2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(tb.x + tb.width / 2 + 75, tb.y + tb.height / 2, { steps: 5 })
|
||
await page.mouse.move(tb.x + tb.width / 2 + 150, tb.y + tb.height / 2 + 60, { steps: 5 })
|
||
await page.mouse.up()
|
||
// an irregular floor: a corner more, pulled in
|
||
await page.getByTestId('floor-shape-mode').click()
|
||
await page.getByTestId('floor-corner').nth(1).click()
|
||
await page.getByTestId('floor-corner-add').click()
|
||
await page.getByTestId('floor-corner').nth(2).scrollIntoViewIfNeeded()
|
||
const corner = await page.getByTestId('floor-corner').nth(2).boundingBox()
|
||
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2)
|
||
await page.mouse.down()
|
||
await page.mouse.move(corner.x - 120, corner.y + 10, { steps: 6 })
|
||
await page.mouse.up()
|
||
await page.getByTestId('floor-shape-mode').click()
|
||
await page.screenshot({ path: path.join(OUT, 'manager-floor-editor.png') })
|
||
await page.getByTestId('floor-save').click()
|
||
let saved = null
|
||
for (let i = 0; i < 30 && !(saved?.tables?.filter(x => x.plan_id != null).length >= 2); i++) { await sleep(250); saved = await api('GET', '/api/floor-plans', { token: boss }) }
|
||
const sp = saved.plans.find(x => x.name === 'E2E ground floor')
|
||
const placedNow = saved.tables.filter(x => x.plan_id === sp?.id)
|
||
const t1 = placedNow.find(x => x.id === firstId)
|
||
r.check(`${fl} drawn and saved: two tables (one round), the bar, a five-corner floor`, placedNow.length === 2 && placedNow.find(x => x.id === secondId)?.shape === 'round'
|
||
&& sp.items.some(i => i.kind === 'bar') && sp.outline?.length === 5, JSON.stringify({ placed: placedNow.map(x => [x.id, x.x, x.y, x.shape]), outline: sp?.outline }))
|
||
r.check(`${fl} the dragged table moved, on the grid`, t1 && t1.x > 600 && t1.x % 20 === 0, JSON.stringify(t1))
|
||
await page.goto(`${APP}/tables`)
|
||
await page.getByTestId('tables-view-map').click()
|
||
r.check(`${fl} the Tables page shows the plan live`, await page.locator('[data-testid="manager-floor"] [data-testid="floor-table"]').first().waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& await page.locator('[data-testid="manager-floor"] [data-testid="floor-table"]').count() >= 2)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-floor-live.png') })
|
||
|
||
// ── 6.9: an order taken, changed, paid and closed from the manager by the phones' rules ──
|
||
const od = 'orders:'
|
||
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
|
||
await api('PUT', '/api/settings/orders.close_with_unpaid', { token: boss, body: { value: 'false' } })
|
||
const omenu = await api('GET', '/api/orders/menu', { token: boss })
|
||
const [pA, pB] = omenu.products.filter(p => p.available && !p.service && !p.prefs.length && p.price > 0)
|
||
const busyIds = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
||
const otable = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busyIds.has(x.id))
|
||
await page.goto(`${APP}/tables`)
|
||
await page.locator(`[data-testid="table-card"][data-table="${otable.id}"] [data-testid="table-open"]`).click()
|
||
await page.getByTestId('order-new').waitFor({ timeout: 10_000 }).catch(() => {})
|
||
const product = id => page.locator(`[data-testid="order-product"][data-id="${id}"]`).first()
|
||
await product(pA.id).click()
|
||
await product(pA.id).click()
|
||
r.check(`${od} a free table opens a new order; two taps make one line of 2`, (await page.getByTestId('cart-qty').first().textContent().catch(() => '')) === '2')
|
||
await page.getByTestId('order-send').click()
|
||
await page.waitForURL(/\/orders\/\d+$/, { timeout: 10_000 }).catch(() => {})
|
||
const oid = Number(page.url().split('/').pop())
|
||
let mo = oid ? await api('GET', `/api/orders/${oid}`, { token: boss }) : null
|
||
r.check(`${od} "Send" opened the table's order, priced by the server`, mo?.table_id === otable.id && mo.items.length === 1
|
||
&& mo.items[0].quantity === 2 && Math.abs(mo.items[0].unit_price - pA.price) < 0.001, JSON.stringify(mo?.items?.map(i => [i.product_id, i.quantity, i.unit_price])))
|
||
await page.getByTestId('order-page').waitFor({ timeout: 8000 }).catch(() => {})
|
||
await product(pB.id).click()
|
||
await page.getByTestId('order-send').click()
|
||
const lineB = page.locator(`[data-testid="order-line"][data-status="active"][data-name="${pB.name}"]`).first()
|
||
await lineB.waitFor({ timeout: 8000 }).catch(() => {})
|
||
await lineB.getByTestId('line-pick').check()
|
||
await page.getByTestId('lines-cancel').click()
|
||
await page.getByTestId('cancel-no-print').click()
|
||
for (let i = 0; i < 20 && !mo?.items?.some(x => x.product_id === pB.id && x.status === 'cancelled'); i++) { await sleep(250); mo = await api('GET', `/api/orders/${oid}`, { token: boss }) }
|
||
r.check(`${od} a line added, then cancelled (no ticket)`, mo.items.some(x => x.product_id === pB.id && x.status === 'cancelled'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-order.png'), fullPage: true })
|
||
await page.getByTestId('order-close').click()
|
||
const payFirst = await page.getByTestId('pay-dialog').waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||
r.check(`${od} "Close" with unpaid lines takes the payment first (close_with_unpaid off)`, payFirst
|
||
&& (await page.getByTestId('pay-amount').textContent()).includes((pA.price * 2).toFixed(2)))
|
||
await page.getByTestId('pay-cash').click()
|
||
for (let i = 0; i < 20 && mo?.status !== 'closed'; i++) { await sleep(250); mo = await api('GET', `/api/orders/${oid}`, { token: boss }) }
|
||
r.check(`${od} …paid in cash and closed`, mo.status === 'closed' && mo.items.filter(x => x.status === 'paid').every(x => x.payment_method === 'cash')
|
||
&& await page.locator('[data-testid="order-page"][data-status="closed"]').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
// a booking given a table ahead shows RESERVED on it
|
||
const soon = await page.evaluate(() => new Date(Date.now() + 3600_000).toISOString())
|
||
const kept = await api('POST', '/api/reservations/', { token: boss, body: { guest_name: 'Kept E2E', party_size: 3, reserved_for: soon, table_id: otable.id } })
|
||
await page.goto(`${APP}/tables`)
|
||
r.check(`${od} a booking given the table shows RESERVED on its card`, !!kept?.id
|
||
&& await page.locator(`[data-testid="table-card"][data-table="${otable.id}"] [data-testid="table-reserved"]`).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-tables.png'), fullPage: true })
|
||
await api('PATCH', `/api/reservations/${kept.id}/status`, { token: boss, body: { status: 'cancelled' } }).catch(() => {})
|
||
|
||
// ── 6.10: printers, the ticket's look and prep zones on v2 ───────────────────
|
||
const pz = 'printing:'
|
||
await page.goto(`${APP}/settings?tab=print-fonts`)
|
||
await page.getByTestId('printers-card').waitFor({ timeout: 10_000 }).catch(() => {})
|
||
await page.getByTestId('printer-new').click()
|
||
await page.getByTestId('printer-save').click()
|
||
r.check(`${pz} a printer without a name or address isn't saved (the form says why)`, await page.getByTestId('printer-dialog').count() === 1
|
||
&& (await page.getByTestId('printer-dialog').textContent()).includes('192.168.1.50'))
|
||
await page.getByTestId('printer-name').fill('E2E Grill')
|
||
await page.getByTestId('printer-ip').fill('192.168.77.9')
|
||
await page.getByTestId('printer-save').click()
|
||
const grillRow = page.locator('[data-testid="printer-row"][data-name="E2E Grill"]')
|
||
const listed = await grillRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
const grill = (await api('GET', '/api/system/printers', { token: boss })).find(p => p.name === 'E2E Grill')
|
||
r.check(`${pz} a printer is added in Settings → Printing`, listed && grill?.ip_address === '192.168.77.9' && grill.port === 9100, JSON.stringify(grill))
|
||
await page.getByTestId('font-item_name').getByRole('button', { name: 'CAPITALS' }).click()
|
||
await page.getByTestId('ticket-beep').locator('[data-value="triple"]').click()
|
||
let fontNow = null
|
||
for (let i = 0; i < 20 && fontNow !== '16:1:1'; i++) { await sleep(250); fontNow = await settingValue2('print.font_item_name') }
|
||
r.check(`${pz} the dish name in capitals and a triple beep are saved`, fontNow === '16:1:1' && await settingValue2('print.beep_pattern') === 'triple', fontNow)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-printing.png'), fullPage: true })
|
||
await api('PUT', '/api/settings/print.font_item_name', { token: boss, body: { value: '16:1:0' } })
|
||
await api('PUT', '/api/settings/print.beep_pattern', { token: boss, body: { value: 'double' } })
|
||
// a prep zone printing on it, ticket in Greek, grouped by category
|
||
await page.goto(`${APP}/management/prep-zones`)
|
||
await page.getByTestId('zone-new').click()
|
||
await page.getByTestId('zone-save').click()
|
||
r.check(`${pz} a zone needs a name`, await page.getByTestId('zone-dialog').count() === 1)
|
||
await page.getByTestId('zone-name').fill('E2E Grill zone')
|
||
await page.getByTestId('zone-main').selectOption(String(grill.id))
|
||
await page.getByTestId('zone-language').selectOption('el')
|
||
await page.getByTestId('zone-dialog').getByRole('switch', { name: 'Grouped by category' }).click()
|
||
await page.getByTestId('zone-save').click()
|
||
const zoneCard = page.locator('[data-testid="zone-card"][data-name="E2E Grill zone"]')
|
||
await zoneCard.waitFor({ timeout: 8000 }).catch(() => {})
|
||
const savedZone = (await api('GET', '/api/prep-zones', { token: boss })).find(z => z.name === 'E2E Grill zone')
|
||
r.check(`${pz} the zone is made: main printer, Greek tickets, grouped by category`, await zoneCard.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& savedZone?.master_printer_id === grill.id && savedZone.language === 'el' && savedZone.group_by_category === true && savedZone.auto_print === 'master', JSON.stringify(savedZone))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-prep-zones.png'), fullPage: true })
|
||
if (savedZone) await api('DELETE', `/api/prep-zones/${savedZone.id}`, { token: boss })
|
||
if (grill) await api('DELETE', `/api/system/printers/${grill.id}`, { token: boss })
|
||
|
||
// ── 6.11: staff on v2; a password given by the manager works on a paired screen (KI-014) ──
|
||
const st = 'staff:'
|
||
await page.goto(`${APP}/management/staff`)
|
||
await page.getByTestId('staff-new').click()
|
||
await page.getByTestId('staff-save').click()
|
||
r.check(`${st} a new person needs their names, a username and a PIN`, await page.getByTestId('staff-dialog').count() === 1
|
||
&& (await page.getByTestId('staff-dialog').textContent()).includes('4 to 6 digits'))
|
||
await page.getByTestId('staff-full-name').fill('Eleni E2E')
|
||
await page.getByTestId('staff-nickname').fill('Eleni')
|
||
await page.getByTestId('staff-username').fill('e2e_eleni')
|
||
await page.getByTestId('staff-new-pin').fill('2580')
|
||
await page.getByTestId('staff-rate').fill('8,5')
|
||
await page.getByTestId('staff-save').click()
|
||
const eleniRow = page.locator('[data-testid="staff-row"][data-username="e2e_eleni"]')
|
||
const eleniListed = await eleniRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
let eleni = (await api('GET', '/api/waiters/', { token: boss })).find(m => m.username === 'e2e_eleni')
|
||
r.check(`${st} added from the page: a waiter with a PIN, no password, pay 8.50`, eleniListed && eleni?.role === 'waiter' && eleni.has_password === false && eleni.hourly_rate === 8.5, JSON.stringify(eleni))
|
||
await eleniRow.getByTestId('staff-password').click()
|
||
await page.getByTestId('secret-value').fill('kalimera6')
|
||
await page.getByTestId('secret-again').fill('kalimera7')
|
||
await page.getByTestId('secret-save').click()
|
||
r.check(`${st} the two passwords must match`, (await page.getByTestId('secret-dialog').textContent()).includes("don't match"))
|
||
await page.getByTestId('secret-again').fill('kalimera6')
|
||
await page.getByTestId('secret-save').click()
|
||
await page.getByTestId('secret-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
await eleniRow.getByText('PIN + password').waitFor({ timeout: 8000 }).catch(() => {})
|
||
eleni = (await api('GET', '/api/waiters/', { token: boss })).find(m => m.username === 'e2e_eleni')
|
||
r.check(`${st} the manager gives her a password: the row says "PIN + password"`, eleni.has_password === true && (await eleniRow.textContent()).includes('PIN + password'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-staff-v2.png'), fullPage: true })
|
||
// a counter screen that signs in by password
|
||
await api('PUT', '/api/platform/modules/pos_counter', { token: boss, body: { enabled: true } }).catch(() => {})
|
||
const tillReq = await deviceRequestsPairing()
|
||
await api('POST', '/api/devices', { token: boss, body: { code: tillReq.code, app_key: 'pos_counter', name: 'E2E till', login_mode: 'password' } })
|
||
const tillToken = await devicePicksUpToken(tillReq)
|
||
const tillLogin = async password => fetch(`${backend.url}/api/auth/login`, {
|
||
method: 'POST', headers: { 'content-type': 'application/json', 'X-Xenia-Device': tillToken },
|
||
body: JSON.stringify({ client: 'terminal', username: 'e2e_eleni', password }),
|
||
}).then(async x => ({ status: x.status, body: await x.json() }))
|
||
const wrongPw = await tillLogin('wrong-one')
|
||
const rightPw = await tillLogin('kalimera6')
|
||
r.check(`${st} the done-when: she signs in with that password on a paired screen (a wrong one is refused)`,
|
||
wrongPw.body?.error?.code === 'auth.invalid_credentials' && rightPw.status === 200 && rightPw.body.user?.username === 'e2e_eleni', JSON.stringify(rightPw.body).slice(0, 200))
|
||
// the schedule: a shift for her, and a clash shown before saving
|
||
await page.goto(`${APP}/management/schedule`)
|
||
const eleniPlan = page.locator('[data-testid="schedule-person"][data-name="Eleni E2E"]')
|
||
await eleniPlan.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
await eleniPlan.getByTestId('schedule-add').first().click()
|
||
await page.getByTestId('shift-start').fill('18:00')
|
||
await page.getByTestId('shift-end').fill('02:00')
|
||
await page.getByTestId('shift-save').click()
|
||
const planned = await eleniPlan.getByTestId('schedule-shift').first().waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
r.check(`${st} schedule: a shift 18:00–02:00 for her, 8 hours, costed at her pay`, planned
|
||
&& (await eleniPlan.getByTestId('schedule-shift').first().textContent()).includes('18:00–02:00')
|
||
&& (await eleniPlan.textContent()).includes('8 hours') && (await page.getByTestId('schedule-totals').textContent()).includes('€'))
|
||
await eleniPlan.getByTestId('schedule-add').first().click()
|
||
await page.getByTestId('shift-start').fill('20:00')
|
||
await page.getByTestId('shift-end').fill('22:00')
|
||
r.check(`${st} schedule: an overlapping shift is flagged and can't be saved`, await page.getByTestId('shift-clash').count() === 1 && await page.getByTestId('shift-save').isDisabled())
|
||
await page.screenshot({ path: path.join(OUT, 'manager-schedule.png'), fullPage: true })
|
||
await page.keyboard.press('Escape')
|
||
|
||
// ── 6.12a: Reports → Today on the kit; an export for Excel ──────────────────
|
||
const rp = 'reports:'
|
||
const current = (await api('GET', '/api/reports/business-days/current', { token: boss })).business_day
|
||
await page.goto(`${APP}/reports/today`)
|
||
const todayRevenue = page.getByTestId('today-revenue')
|
||
await todayRevenue.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check(`${rp} Today shows the day's revenue as the backend counts it`, !!current
|
||
&& (await todayRevenue.textContent()).replace(/[\s,]/g, '').includes(current.revenue.toFixed(2)), `${current?.revenue} vs ${await todayRevenue.textContent().catch(() => '')}`)
|
||
const firstOrder = page.getByTestId('today-order').first()
|
||
if (await firstOrder.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)) {
|
||
await firstOrder.click()
|
||
r.check(`${rp} an order opens with its lines and totals`, await page.getByTestId('report-order-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& await page.getByTestId('order-dialog-totals').count() === 1)
|
||
await page.keyboard.press('Escape')
|
||
}
|
||
const [download] = await Promise.all([page.waitForEvent('download', { timeout: 10_000 }), page.getByTestId('report-export').click()])
|
||
const csvText = (await import('node:fs')).readFileSync(await download.path(), 'utf8')
|
||
r.check(`${rp} the export is for Excel: UTF-8 mark, times in venue time with the zone in the header`,
|
||
csvText.charCodeAt(0) === 0xFEFF && csvText.split(/\r?\n/)[0].includes('opened_at (Europe/Athens)') && /\d{4}-\d\d-\d\d \d\d:\d\d/.test(csvText), csvText.slice(0, 160))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-today.png'), fullPage: true })
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="report-today"] h1')?.textContent === 'Σήμερα', null, { timeout: 5000 }).catch(() => {})
|
||
r.check(`${rp} Today in Greek`, (await page.locator('[data-testid="report-today"] h1').textContent()) === 'Σήμερα' && (await todayRevenue.textContent()).includes('Έσοδα'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-today-el.png'), fullPage: true })
|
||
// 6.12b: the venue and products reports, still in Greek for one tab
|
||
await page.goto(`${APP}/reports/store?tab=traffic`)
|
||
r.check(`${rp} Venue → Busy times in Greek`, await page.getByTestId('traffic-weekdays').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& (await page.locator('[data-testid="report-store"] h1').textContent()) === 'Κατάστημα')
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
await page.goto(`${APP}/reports/store`)
|
||
const dayRow = page.getByTestId('report-day').first()
|
||
r.check(`${rp} Venue → Business days lists the days`, await dayRow.waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||
await dayRow.click()
|
||
r.check(`${rp} a day opens with its orders and shifts`, await page.getByTestId('report-day-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-day.png'), fullPage: true })
|
||
await page.keyboard.press('Escape')
|
||
for (const [tab, testId] of [['orders', 'report-order'], ['trends', 'trend-chart'], ['tables', 'report-period']]) {
|
||
await page.getByTestId(`report-tab-${tab}`).click()
|
||
r.check(`${rp} Venue → ${tab} opens`, await page.getByTestId(testId).first().waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||
}
|
||
await page.goto(`${APP}/reports/products`)
|
||
const prodRevenue = page.getByTestId('products-revenue')
|
||
await prodRevenue.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
const venueDay = new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Athens' }).format(new Date()) // the venue's date, as the page's default period
|
||
const perf = (await api('GET', `/api/reports/products/performance?from=${addDaysIso(venueDay, -29)}T00:00:00&to=${venueDay}T23:59:59`, { token: boss })).products
|
||
const perfTotal = perf.reduce((s, p) => s + p.revenue, 0)
|
||
r.check(`${rp} Products: the revenue is the backend's (no delivery-fee product)`, (await prodRevenue.textContent()).replace(/[\s,]/g, '').includes(perfTotal.toFixed(2))
|
||
&& !perf.some(p => /delivery|αποστολ/i.test(p.product_name)), `${perfTotal} vs ${await prodRevenue.textContent()}`)
|
||
await page.getByTestId('report-tab-categories').click()
|
||
r.check(`${rp} Products → Categories opens`, await page.getByTestId('categories-share').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-categories.png'), fullPage: true })
|
||
// 6.12c: staff, cancellations and discounts, technical, prep zones, expenses
|
||
const opens = async (url, testId, what) => {
|
||
await page.goto(`${APP}${url}`)
|
||
r.check(`${rp} ${what} opens`, await page.getByTestId(testId).first().waitFor({ timeout: 10_000 }).then(() => true).catch(() => false))
|
||
}
|
||
await opens('/reports/staff', 'report-shift', 'Staff → Shifts (rows)')
|
||
await page.getByTestId('report-shift').first().click()
|
||
r.check(`${rp} a shift opens its details`, await page.getByTestId('shift-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.keyboard.press('Escape')
|
||
await page.getByTestId('report-tab-cash').click()
|
||
r.check(`${rp} Staff → Cash handover`, await page.getByTestId('staff-handover').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('report-tab-people').click()
|
||
r.check(`${rp} Staff → Sales by person ranks people`, await page.getByTestId('staff-ranking').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-staff.png'), fullPage: true })
|
||
await opens('/reports/misc', 'cancellations-count', 'Cancellations')
|
||
await page.getByTestId('report-tab-discounts').click()
|
||
r.check(`${rp} Discounts opens`, await page.getByTestId('report-period').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await opens('/reports/technical', 'printing-total', 'Technical → Printing')
|
||
await opens('/reports/prep-zones', 'report-period', 'Prep zones')
|
||
await opens('/reports/expenses', 'expenses-total', 'Expenses')
|
||
await page.screenshot({ path: path.join(OUT, 'manager-report-expenses.png'), fullPage: true })
|
||
|
||
// ── 6.13a: a supplier, an expense paid in two parts, a tab paid and closed ──────
|
||
const fi = 'finance:'
|
||
for (const m of ['expenses', 'crm', 'tabs']) await api('PUT', `/api/platform/modules/${m}`, { token: boss, body: { enabled: true } }).catch(() => {})
|
||
await page.goto(`${APP}/crm/contacts`)
|
||
await page.getByTestId('contact-new').click()
|
||
await page.getByTestId('contact-save').click()
|
||
r.check(`${fi} a contact needs a name`, (await page.getByTestId('contact-dialog').textContent()).includes('Enter a name'))
|
||
await page.getByTestId('contact-name').fill('E2E Dairy')
|
||
await page.getByTestId('contact-phone').fill('2310 555 000')
|
||
await page.getByTestId('contact-save').click()
|
||
const dairyRow = page.locator('[data-testid="contact-row"]', { hasText: 'E2E Dairy' })
|
||
r.check(`${fi} the supplier is in the book`, await dairyRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
const dairy = (await api('GET', '/api/contacts/', { token: boss })).find(c => c.name === 'E2E Dairy')
|
||
await page.goto(`${APP}/financials/expenses`)
|
||
await page.getByTestId('expense-new').click()
|
||
await page.getByTestId('expense-save').click()
|
||
r.check(`${fi} an expense needs what it is and an amount`, (await page.getByTestId('expense-dialog').textContent()).includes('Say what it is'))
|
||
await page.getByTestId('expense-description').fill('E2E milk November')
|
||
await page.getByTestId('expense-amount').fill('120,50')
|
||
await page.getByTestId('expense-supplier').selectOption(String(dairy?.id))
|
||
await page.getByTestId('expense-due-date').fill(addDaysIso(venueDay, -1))
|
||
await page.getByTestId('expense-save').click()
|
||
const milkRow = page.locator('[data-testid="expense-row"]', { hasText: 'E2E milk November' })
|
||
await milkRow.waitFor({ timeout: 8000 }).catch(() => {})
|
||
let milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.description === 'E2E milk November')
|
||
r.check(`${fi} entered from the page: 120.50 to the supplier, due yesterday, shown as late`, milk?.total_amount === 120.5 && milk.contact_id === dairy?.id && milk.status === 'due'
|
||
&& (await milkRow.textContent()).includes('Late'), JSON.stringify(milk))
|
||
await milkRow.getByTestId('expense-pay').click()
|
||
await page.getByTestId('expense-pay-amount').fill('70')
|
||
await page.getByTestId('expense-pay-save').click()
|
||
await page.getByTestId('expense-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
for (let i = 0; i < 20 && milk?.status !== 'partial'; i++) { await sleep(250); milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.id === milk.id) }
|
||
r.check(`${fi} a payment of 70: partly paid, 50.50 still due`, milk.status === 'partial' && milk.due_amount === 50.5, JSON.stringify(milk))
|
||
await milkRow.getByTestId('expense-pay').click()
|
||
await page.getByTestId('expense-pay-amount').fill('60')
|
||
await page.getByTestId('expense-pay-save').click()
|
||
r.check(`${fi} paying more than what is due is refused before saving`, (await page.getByTestId('expense-pay-dialog').textContent()).includes('no more than'))
|
||
await page.getByTestId('expense-pay-amount').fill('50,50')
|
||
await page.getByTestId('expense-pay-save').click()
|
||
const gone = await milkRow.waitFor({ state: 'detached', timeout: 8000 }).then(() => true).catch(() => false)
|
||
milk = (await api('GET', '/api/expenses/', { token: boss })).find(e => e.id === milk.id)
|
||
r.check(`${fi} the rest paid: it shows paid and leaves the "not fully paid" list`, gone && milk.status === 'paid' && milk.payments.length === 2, JSON.stringify(milk))
|
||
await page.getByTestId('expenses-status').selectOption('paid')
|
||
await page.locator('[data-testid="expense-row"]', { hasText: 'E2E milk November' }).click()
|
||
r.check(`${fi} the expense opens with its two payments`, await page.getByTestId('expense-view').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& await page.locator('[data-testid="expense-view"] li').count() === 2)
|
||
await page.screenshot({ path: path.join(OUT, 'manager-expenses.png'), fullPage: true })
|
||
await page.keyboard.press('Escape')
|
||
// a tab: a line of a customer's order goes on the tab, paid in two parts on the page, then closed
|
||
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
|
||
const tabCustomer = await api('POST', '/api/customers/', { token: boss, body: { name: 'Tab E2E', phone: '6900000013' } })
|
||
const tabMenu = await api('GET', '/api/orders/menu', { token: boss })
|
||
const tabProduct = tabMenu.products.find(x => x.available && !x.service && !x.prefs.length && x.price > 0)
|
||
const tabOrder = await api('POST', '/api/orders/', { token: boss, body: { order_type: 'takeaway' } })
|
||
await api('PUT', `/api/orders/${tabOrder.id}/customer`, { token: boss, body: { customer_id: tabCustomer.id } })
|
||
await api('POST', `/api/orders/${tabOrder.id}/items`, { token: boss, body: { lines: [{ product_id: tabProduct.id, quantity: 2 }] } })
|
||
const tabLine = (await api('GET', `/api/orders/${tabOrder.id}`, { token: boss })).items.find(x => x.product_id === tabProduct.id)
|
||
await api('POST', `/api/orders/${tabOrder.id}/items/${tabLine.id}/tab`, { token: boss })
|
||
const owes = Math.round(tabLine.unit_price * 2 * 100) / 100
|
||
await page.goto(`${APP}/financials/tabs`)
|
||
const tabCard = page.locator('[data-testid="tab-card"]', { hasText: 'Tab E2E' })
|
||
await tabCard.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
r.check(`${fi} the customer's tab is open with what the line cost`, (await tabCard.getByTestId('tab-balance').textContent()).replace(/[\s,]/g, '').includes(owes.toFixed(2)), `${owes} vs ${await tabCard.textContent()}`)
|
||
await tabCard.locator('button[aria-expanded]').click()
|
||
await tabCard.getByTestId('tab-pay').click()
|
||
await page.getByTestId('tab-pay-amount').fill('1')
|
||
await page.getByRole('radio', { name: 'Card' }).click()
|
||
await page.getByTestId('tab-pay-save').click()
|
||
await page.getByTestId('tab-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
for (let i = 0; i < 30 && (await tabCard.getByTestId('tab-balance').textContent()).replace(/[\s,]/g, '').includes(owes.toFixed(2)); i++) await sleep(250) // the first payment shows
|
||
await tabCard.getByTestId('tab-pay').click()
|
||
await page.getByTestId('tab-pay-save').click() // the rest (the default)
|
||
await page.getByTestId('tab-pay-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const closeBtn = tabCard.getByTestId('tab-close')
|
||
r.check(`${fi} paid in two parts (card, then the rest): nothing owed, it can be closed`, await closeBtn.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-tabs.png'), fullPage: true })
|
||
await closeBtn.click()
|
||
await tabCard.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
const settled = (await api('GET', '/api/tabs/?tab_status=settled', { token: boss })).find(x => x.customer_id === tabCustomer.id)
|
||
r.check(`${fi} closed: it leaves the open tabs; payments card + cash`, settled?.status === 'closed' && settled.payments.map(x => x.payment_method).join(',') === 'card,cash', JSON.stringify(settled?.payments))
|
||
await page.getByTestId('tabs-view-settled').click()
|
||
r.check(`${fi} it is listed with the settled tabs`, await page.locator('[data-testid="tab-card"]', { hasText: 'Tab E2E' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
// 6.13c: the tab line is sold, not paid; the tab money is recorded as received (the manager had no shift: in no drawer)
|
||
const daySum = await api('GET', '/api/business-day/summary', { token: boss })
|
||
const mine = (daySum.tabs?.payments ?? []).filter(x => x.tab_id === settled?.id)
|
||
const outside = mine.filter(x => x.shift_id === null).reduce((n, x) => n + x.amount, 0)
|
||
r.check(`${fi} the day records both tab payments with who took them (in their shift's drawer, or in none)`, mine.length === 2 && mine.every(x => x.received_by_name)
|
||
&& Math.round(mine.reduce((n, x) => n + x.amount, 0) * 100) === Math.round(owes * 100) && daySum.tabs.received_outside_shifts.total >= outside - 0.005, JSON.stringify(daySum.tabs).slice(0, 300))
|
||
await page.goto(`${APP}/reports/today`)
|
||
r.check(`${fi} Today shows what is on tabs and what was paid on them`, await page.getByTestId('today-on-tab').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||
&& await page.getByTestId('today-tab-received').count() === 1)
|
||
await page.goto(`${APP}/financials/tabs`)
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.waitForFunction(() => document.querySelector('[data-testid="tabs-page"] h1')?.textContent === 'Καρτέλες', null, { timeout: 5000 }).catch(() => {})
|
||
r.check(`${fi} Tabs in Greek`, (await page.locator('[data-testid="tabs-page"] h1').textContent()) === 'Καρτέλες')
|
||
await page.goto(`${APP}/financials/expenses`)
|
||
r.check(`${fi} Expenses in Greek`, await page.locator('[data-testid="expenses-page"] h1', { hasText: 'Δαπάνες' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
|
||
// ── 6.13b: a customer found without accents, a throwaway with its cost, a note and a to-do done ──
|
||
const cr = 'customers, waste, notes:'
|
||
for (const m of ['crm', 'inventory', 'notes']) await api('PUT', `/api/platform/modules/${m}`, { token: boss, body: { enabled: true } }).catch(() => {})
|
||
await page.goto(`${APP}/crm/customers`)
|
||
await page.getByTestId('customer-new').click()
|
||
await page.getByTestId('customer-save').click()
|
||
r.check(`${cr} a customer needs a name`, (await page.getByTestId('customer-dialog').textContent()).includes('Enter a name'))
|
||
await page.getByTestId('customer-name').fill('Γιώργος Ε2Ε')
|
||
await page.getByTestId('customer-phone').fill('697 700 1122')
|
||
await page.getByTestId('customer-notes').fill('Nut allergy')
|
||
await page.getByTestId('customer-save').click()
|
||
await page.getByTestId('customer-dialog').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||
await page.getByTestId('customer-search').fill('γιωργος ε2ε')
|
||
const georgeRow = page.locator('[data-testid="customer-row"]', { hasText: 'Γιώργος Ε2Ε' })
|
||
r.check(`${cr} found by typing the name without accents, in lower case`, await georgeRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& await page.getByTestId('customer-row').count() === 1)
|
||
await page.getByTestId('customer-search').fill('7001122')
|
||
r.check(`${cr} found by part of the phone number`, await georgeRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await georgeRow.click()
|
||
r.check(`${cr} the card shows the allergy`, await page.getByTestId('customer-card').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
&& (await page.getByTestId('customer-card').textContent()).includes('Nut allergy'))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-customer-card.png'), fullPage: true })
|
||
await page.keyboard.press('Escape')
|
||
await page.goto(`${APP}/inventory/throwaways`)
|
||
const wasteProduct = page.getByTestId('waste-product')
|
||
await wasteProduct.waitFor({ timeout: 10_000 }).catch(() => {})
|
||
await page.getByTestId('waste-log').click()
|
||
r.check(`${cr} a throwaway needs a product`, (await page.getByTestId('waste-form').textContent()).includes('Choose what was thrown away'))
|
||
const wasteOption = await wasteProduct.locator('option:not([value=""])').first().getAttribute('value')
|
||
await wasteProduct.selectOption(wasteOption)
|
||
await page.getByTestId('waste-qty').fill('1,5')
|
||
await page.getByRole('radio', { name: 'Dropped' }).click()
|
||
await page.getByTestId('waste-log').click()
|
||
const wasteRow = page.getByTestId('waste-today-row').first()
|
||
await wasteRow.waitFor({ timeout: 8000 }).catch(() => {})
|
||
const dayNow = await api('GET', '/api/business-day/current', { token: boss })
|
||
const logged = (await api('GET', `/api/waste/?business_day_id=${dayNow?.id}`, { token: boss })).entries.find(e => String(e.product_id) === wasteOption)
|
||
r.check(`${cr} logged from the page: 1.5, dropped, in today's list`, logged?.quantity === 1.5 && logged.reason === 'dropped' && (await wasteRow.textContent()).includes('Dropped'), JSON.stringify(logged))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-throwaways.png'), fullPage: true })
|
||
await page.goto(`${APP}/notes`)
|
||
await page.getByTestId('note-new').fill('E2E: the fridge door sticks')
|
||
await page.getByTestId('note-add').click()
|
||
await page.getByTestId('todo-new').fill('E2E: call the plumber')
|
||
await page.getByRole('switch', { name: 'Urgent' }).click()
|
||
await page.getByTestId('todo-add').click()
|
||
const todoRow = page.locator('[data-testid="todo-row"]', { hasText: 'E2E: call the plumber' })
|
||
await todoRow.waitFor({ timeout: 8000 }).catch(() => {})
|
||
r.check(`${cr} the note and the urgent to-do are listed`, await page.locator('[data-testid="note-card"]', { hasText: 'the fridge door sticks' }).count() === 1
|
||
&& (await todoRow.textContent()).includes('URGENT'))
|
||
await todoRow.getByTestId('todo-done').click()
|
||
let plumber = null
|
||
for (let i = 0; i < 20 && !plumber?.is_done; i++) { await sleep(250); plumber = (await api('GET', '/api/notes/todos', { token: boss })).find(x => x.body === 'E2E: call the plumber') }
|
||
r.check(`${cr} the to-do ticked: done, and who did it is kept`, plumber?.is_done === true && !!plumber.done_by_name, JSON.stringify(plumber))
|
||
await page.screenshot({ path: path.join(OUT, 'manager-notes.png'), fullPage: true })
|
||
await page.goto(`${APP}/inventory/stock`)
|
||
r.check(`${cr} Stock says it isn't available yet`, await page.getByTestId('stock-page').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||
await page.goto(`${APP}/crm/customers`)
|
||
r.check(`${cr} Customers in Greek`, await page.locator('[data-testid="customers-page"] h1', { hasText: 'Πελάτες' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.goto(`${APP}/notes`)
|
||
r.check(`${cr} Notes in Greek`, await page.locator('[data-testid="notes-page"] h1', { hasText: 'Σημειώσεις' }).waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||
await page.getByTestId('user-menu').click()
|
||
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||
|
||
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
||
await page.goto(`${APP}/online-orders`)
|
||
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})
|
||
const noNew = await page.getByText('No new online orders.').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
await page.getByTestId('online-tab-history').click()
|
||
const past = await page.getByTestId('online-order').first().waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||
r.check(`${ov} online orders: nothing new; the history lists the earlier online orders`, noNew && past
|
||
&& await page.locator('[data-testid="online-order"]:not([data-status="delivered"]):not([data-status="rejected"])').count() === 0)
|
||
|
||
r.check('live: the manager connection carries no token in its address (4.0)', managerWs.some(u => u.includes('/api/ws/')) && managerWs.filter(u => u.includes('/api/')).every(u => !/token=/.test(u)), managerWs.filter(u => u.includes('/api/')).join(' ')) // (Vite's own dev socket has its token)
|
||
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||
} finally {
|
||
await browser.close()
|
||
killTree(vite)
|
||
term.stop()
|
||
await backend.stop()
|
||
}
|
||
process.exit(r.done() ? 1 : 0)
|