feat(manager): products and categories on v2, a product in several categories, allergens (platform-v2 step 6.3)

- Management/ProductsTab + ProductFormModal (3.1k lines) → src/pages/products/: category tree,
  list/grid, toolbar + filters (search folds accents and Latin letters), bulk actions, category
  dialogs; the editor in editor/ (details, sold at, cost, fiscal; the waiter's choices).
  Arithmetic in productsLogic.js / editor/formLogic.js (tests/products.test.mjs).
- Several categories per product with a main one (D-23): edited in the editor, "also in" on the
  rows, each category's list ordered on its own (drag or up/down → PUT /reorder with category_id);
  bulk "move to" / "also list in". The waiter's picker now shows a product in every category.
- Allergens: products.allergens (Alembic 0032, core/allergens.py: 14 EU, contains | may_contain,
  catalog.allergen), in the API, POS menu, menu tablet, catalogue bundles and the cloud snapshot
  (C-2); @xenia/access allergens.js + <Allergens> shown on the phone, the counter, the tablet.
- Bell: only the newest load sets the list (an older answer could hide a live notification).
- e2e: manager (two categories, order per category, allergens), terminal / menu tablet / waiter
  (allergens shown); media saves by test id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:04:35 +02:00
co-authored by Claude Opus 5.5
parent 8a02173450
commit 5048f82a4c
53 changed files with 2812 additions and 3179 deletions
+43
View File
@@ -857,6 +857,49 @@ try {
&& !(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()
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]))
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') })
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(() => {})
+1 -1
View File
@@ -144,7 +144,7 @@ try {
await row.getByTestId('product-edit').click()
await page.getByTestId('product-photo').waitFor({ timeout: 10_000 })
}
const save = async () => { await page.getByRole('button', { name: 'Αποθήκευση', exact: true }).last().click(); await sleep(1200) }
const save = async () => { await page.getByTestId('product-save').click(); await page.getByTestId('product-editor').waitFor({ state: 'detached', timeout: 10_000 }).catch(() => {}) }
await edit(p1.name)
await page.getByTestId('product-photo').getByTestId('media-field-pick').click()
+3
View File
@@ -36,6 +36,7 @@ try {
await api('PUT', '/api/platform/modules/menu_tablet', { token: boss, body: { enabled: true } }).catch(() => {})
const products = (await api('GET', '/api/products/?sold_at=in_store', { token: boss })).filter(p => !p.is_service_item && p.lifecycle_status === 'active')
const souvlaki = products.find(p => /Σουβλάκι/.test(p.name)) || products[0]
await api('PUT', `/api/products/${souvlaki.id}`, { token: boss, body: { allergens: { gluten: 'contains', mustard: 'may_contain' } } })
const tab = await (await browser.newContext({ viewport: { width: 1180, height: 820 }, hasTouch: true })).newPage()
tab.on('pageerror', e => errors.push(e.message))
@@ -55,6 +56,8 @@ try {
await hit.click()
r.check('…and opens it big with its price', await shown(tab, 'menu-details', 5000)
&& (await tab.getByTestId('menu-details').getByTestId('menu-price').textContent()).includes(souvlaki.base_price.toFixed(2)))
r.check('6.3: …with its allergens', await tab.getByTestId('menu-details').locator('[data-allergen="gluten"][data-level="contains"]').count() === 1
&& await tab.getByTestId('menu-details').locator('[data-allergen="mustard"][data-level="may_contain"]').count() === 1)
await tab.keyboard.press('Escape')
await tab.getByTestId('menu-search').fill('zzzz')
r.check('nothing found: says so', await shown(tab, 'menu-no-results', 5000))
+4 -1
View File
@@ -332,7 +332,7 @@ try {
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' }],
ingredients: [{ name: 'Onion' }], allergens: { gluten: 'contains', sesame: 'may_contain' },
} })
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))
@@ -359,6 +359,9 @@ try {
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)
r.check('6.3: …and its allergens (contains gluten, may contain sesame)',
await page.getByTestId('product-dialog').locator('[data-allergen="gluten"][data-level="contains"]').count() === 1
&& await page.getByTestId('product-dialog').locator('[data-allergen="sesame"][data-level="may_contain"]').count() === 1)
await page.keyboard.press('Escape')
await burgerCard.locator('button').first().click()
await page.getByTestId('product-dialog').waitFor({ timeout: 5000 })
+13
View File
@@ -177,6 +177,19 @@ try {
.catch(async e => { await a.screenshot({ path: path.join(OUT, 'waiter-add-items.png') }); throw e })
const onScreen = await a.locator('[data-testid="product-card"]:has([data-testid="product-quick-add"])').evaluateAll(els => els.map(e => e.dataset.name))
const [plain, other] = prods.filter(p => simple(p) && onScreen.includes(p.name))
// 6.3: allergens set in the manager reach the phone (live) and show in the product's details (hold it)
await api('PUT', `/api/products/${other.id}`, { token: boss, body: { allergens: { milk: 'contains', nuts: 'may_contain' } } })
await sleep(1500)
const held = a.locator(`[data-testid="product-card"][data-name="${other.name}"]`).first()
await held.hover()
await a.mouse.down()
await sleep(1600)
await a.mouse.up()
const info = a.getByTestId('allergens')
r.check('6.3: holding a product shows its allergens on the phone', await info.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
&& await info.locator('[data-allergen="milk"][data-level="contains"]').count() === 1 && await info.locator('[data-allergen="nuts"][data-level="may_contain"]').count() === 1)
await a.mouse.click(5, 5)
await info.waitFor({ state: 'detached', timeout: 3000 }).catch(() => {})
// a price the phone's menu doesn't know (a price modifier): only the server can say it
const mod = await api('POST', '/api/pricing/modifiers', { token: boss, body: {
name: 'e2e 4.4', scope: 'item', item_id: plain.id, action_type: 'set', action_value: 1.2 } })