feat(terminal): counter POS screen with server-priced cart and shift gate (platform-v2 3.3a)
- Backend /api/pos (pos_counter): session (business day, the cashier's own shift, self-start, who can open the day), menu (sellable products with every kind of choice, no costs; price now from the pricing engine), quote (lines by id → the waiter's selected_options entries with DB prices → resolve_price as orders do; pos.line_invalid). - POS device settings: default order type, start category, receipt printer (new ref sources categories / printers, also in the manager's Devices dialogs). - Terminal apps/pos: shift gate (start shift with drawer cash), categories, search, product grid, price check, options dialog, cart priced by the backend. - Tests: backend test_pos (13), terminal pos.test.mjs, manager refOptions, terminal.mjs +10 POS checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -301,6 +301,70 @@ try {
|
||||
r.check('moved to Counter POS → signed out, sign-in for the POS',
|
||||
await page.getByTestId('sign-in-screen').count() === 1 && (await page.getByTestId('sign-in-screen').textContent()).includes('Kitchen'))
|
||||
|
||||
// ── 3.3a: the counter POS ────────────────────────────────────────────────
|
||||
const cats = await api('GET', '/api/products/categories', { token: boss })
|
||||
const burgerP = await api('POST', '/api/products/', { token: boss, body: {
|
||||
name: 'E2E Burger', base_price: 10, primary_category_id: cats[0].id, category_ids: [cats[0].id],
|
||||
preference_sets: [{ name: 'Cooking', choices: [{ name: 'Rare' }, { name: 'Well done', extra_cost: 0.5 }] }],
|
||||
options: [{ name: 'Sauce', extra_cost: 0.5, sub_choices: [{ name: 'BBQ', extra_cost: 0.2, is_default: true }, { name: 'Mayo' }] }],
|
||||
quick_options: [{ name: 'Cheese', price: 1, allow_multiple: true }],
|
||||
ingredients: [{ name: 'Onion' }],
|
||||
} })
|
||||
const posMenu = await api('GET', '/api/pos/menu', { token: boss })
|
||||
const simple = posMenu.products.find(p => !p.prefs.length && p.id !== burgerP.id && p.categories.every(c => c.category_id !== cats[0].id))
|
||||
await page.locator(`[data-user="${mgr.id}"]`).click()
|
||||
await page.getByLabel('Password').fill('password')
|
||||
await page.getByRole('button', { name: 'Sign in' }).click()
|
||||
r.check('3.3a: the cashier is asked to start their shift (business day open, no shift yet)', await shown(page, 'pos-start-shift', 10_000))
|
||||
await page.getByTestId('starting-cash').fill('20')
|
||||
await page.getByRole('button', { name: 'Start shift' }).click()
|
||||
r.check('3.3a: shift started → the sale screen', await shown(page, 'pos-screen', 10_000))
|
||||
const posSession = await page.evaluate(async () => (await window.__xeniaClient.get('/api/pos/session')).data)
|
||||
r.check('3.3a: the shift is the cashier\'s own, with the starting cash', posSession.shift?.starting_cash === 20, JSON.stringify(posSession.shift))
|
||||
|
||||
await page.getByTestId('pos-search').fill('burg e2e')
|
||||
const burgerCard = page.locator(`[data-testid="pos-product"][data-product="${burgerP.id}"]`)
|
||||
r.check('3.3a: search finds the product by name (words in any order)', await burgerCard.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
||||
&& await page.locator('[data-testid="pos-product"]').count() === 1)
|
||||
await burgerCard.getByTestId('product-info').click()
|
||||
r.check('3.3a: price check shows the price without adding it', await shown(page, 'product-dialog', 5000)
|
||||
&& (await page.getByTestId('dialog-price').textContent()).includes('10.00') && await page.getByTestId('cart-line').count() === 0)
|
||||
await page.keyboard.press('Escape')
|
||||
await burgerCard.locator('button').first().click()
|
||||
await page.getByTestId('product-dialog').waitFor({ timeout: 5000 })
|
||||
r.check('3.3a: a product with a preference opens its choices; Add waits for the choice',
|
||||
await page.getByTestId('dialog-add').isDisabled() && await page.getByTestId('dialog-missing').count() === 1)
|
||||
const set = burgerP.preference_sets[0]
|
||||
await page.locator(`[data-choice="${set.choices[1].id}"]`).click()
|
||||
await page.locator(`[data-option="${burgerP.options[0].id}"]`).click()
|
||||
await page.locator(`[data-quick="${burgerP.quick_options[0].id}"]`).click()
|
||||
await page.locator(`[data-ingredient="${burgerP.ingredients[0].id}"]`).click()
|
||||
// 10 + 0.50 well done + 0.50 sauce + 0.20 BBQ + 1 cheese, priced by the backend
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="dialog-add"]')?.textContent.includes('12.20'), null, { timeout: 5000 }).catch(() => {})
|
||||
r.check('3.3a: the price follows the choices (priced by the backend: 12.20)', (await page.getByTestId('dialog-add').textContent()).includes('12.20'),
|
||||
await page.getByTestId('dialog-add').textContent())
|
||||
await page.getByTestId('dialog-add').click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="cart-total"]')?.textContent.includes('12.20'), null, { timeout: 5000 }).catch(() => {})
|
||||
const line1 = page.getByTestId('cart-line').first()
|
||||
r.check('3.3a: the cart has the line with its choices and the total', await page.getByTestId('cart-line').count() === 1
|
||||
&& (await line1.textContent()).includes('Well done') && (await line1.textContent()).includes('Onion')
|
||||
&& (await page.getByTestId('cart-total').textContent()).includes('12.20'))
|
||||
|
||||
await page.getByTestId('pos-search').fill('')
|
||||
const simpleCat = simple.categories[0].category_id
|
||||
await page.getByTestId(`category-${simpleCat}`).click()
|
||||
const simpleCard = page.locator(`[data-testid="pos-product"][data-product="${simple.id}"]`)
|
||||
r.check('3.3a: a category shows its products', await simpleCard.isVisible() && await burgerCard.count() === 0)
|
||||
await simpleCard.locator('button').first().click()
|
||||
await simpleCard.locator('button').first().click()
|
||||
const expected = (12.2 + 2 * simple.price).toFixed(2)
|
||||
await page.waitForFunction(x => document.querySelector('[data-testid="cart-total"]')?.textContent.includes(x), expected, { timeout: 5000 }).catch(() => {})
|
||||
r.check('3.3a: a product without choices is added by a tap; the same one twice adds up', await page.getByTestId('cart-line').count() === 2
|
||||
&& (await page.getByTestId('line-qty').nth(1).textContent()).includes('2') && (await page.getByTestId('cart-total').textContent()).includes(expected),
|
||||
`${await page.getByTestId('cart-total').textContent()} vs ${expected}`)
|
||||
await page.screenshot({ path: path.join(OUT, 'terminal-pos.png') })
|
||||
await page.getByRole('button', { name: 'Sign out' }).click()
|
||||
|
||||
// ── a customer display: no sign-in ───────────────────────────────────────
|
||||
const cd = await screen(await (await browser.newContext({ viewport: { width: 1024, height: 600 } })).newPage())
|
||||
await pairFromManager(cd, boss, { app_key: 'customer_display', name: 'Counter display' })
|
||||
|
||||
Reference in New Issue
Block a user