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:
@@ -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(() => {})
|
||||
|
||||
Reference in New Issue
Block a user