Files
xenia-pos-local/packages/access/tests/menuText.test.mjs
T
bonaminandClaude Opus 5.5 0840247768 feat: staff apps show the menu in the reader's language (plan 6R.L)
The waiters' phones and the counter show categories, products and every
choice (quick options, extras and sub-choices, preferences, shared sets,
ingredients, groups) in the signed-in person's language, falling back to
the stored text. Display only: carts, lines, tickets and the kitchen keep
the venue's text (ids, sub-choices by stored name). In the venue's own
language nothing changes.

- @xenia/access: menuText / useMenuText (mt, mt.choice, mt.line, mt.matches)
- /api/pos/menu carries translations for products, categories and choices
- shared ProductDialog takes a text() prop (the counter passes useMenuText)
- search finds a product by its name in any language (counter, waiter)
- waiter: useMenuNames for sent lines; picker, drawer, cart, summary,
  table lines, quantity / price history, favourites setup
- counter: categories, cards, dialog, cart lines, table lines, payment rows
- tests: access menuText, ordering search, test_pos per-language,
  e2e waiter.mjs and terminal.mjs 6R.L blocks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:18:10 +02:00

78 lines
4.3 KiB
JavaScript

// Staff apps in the device's language (plan 6R.L): display only, the venue's text kept underneath.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { choiceTexts, menuText } from '../src/menuLanguages.js'
const pita = {
id: 1, name: 'Πίτα γύρος', description: 'Με τζατζίκι',
translations: { el: { name: 'Πίτα γύρος' }, en: { name: 'Gyros pita' } }, // no English description
quick_options: [{ id: 5, name: 'Χωρίς κρεμμύδι', translations: { en: 'No onion' } }],
options: [{ id: 7, name: 'Πατάτες', translations: { el: 'Πατάτες', en: 'Fries' },
sub_choices: [{ name: 'Λίγες', translations: { en: 'A few' } }, { name: 'Πολλές' }] }],
ingredients: [{ id: 9, name: 'Ντομάτα', translations: { en: 'Tomato' } }],
preference_sets: [{ id: 3, name: 'Κρέας', translations: { en: 'Meat' },
choices: [{ id: 30, name: 'Χοιρινό', translations: { en: 'Pork' } }],
shared_subset: { name: 'Ψήσιμο', translations: { en: 'Cooking' }, choices: [{ name: 'Καλοψημένο', translations: { en: 'Well done' } }] } }],
image: { id: 4, name: 'photo.jpg' },
}
test('an English phone at a Greek venue sees English, Greek where there is none', () => {
const mt = menuText('en', 'el')
assert.equal(mt.same, false)
assert.equal(mt(pita), 'Gyros pita')
assert.equal(mt(pita, 'description'), 'Με τζατζίκι')
assert.equal(mt(pita.options[0]), 'Fries')
assert.equal(mt(pita.options[0].sub_choices[1]), 'Πολλές')
assert.equal(mt({ name: 'Ορεκτικά', translations: { en: { name: 'Starters' } } }), 'Starters')
})
test('a phone in the venue language shows the stored text, untouched', () => {
const mt = menuText('el', 'el')
assert.equal(mt.same, true)
assert.equal(mt(pita), 'Πίτα γύρος')
assert.equal(mt({ name: 'Only English', translations: { en: { name: 'Only English' } } }), 'Only English')
assert.equal(mt.choice(pita, 'Πατάτες'), 'Πατάτες')
})
test('a language that is not a menu language changes nothing', () => {
assert.equal(menuText('de', 'el').same, true)
assert.equal(menuText(undefined, 'el').same, true)
})
test('choices kept by their base name are shown translated; counts kept', () => {
const mt = menuText('en', 'el')
assert.equal(mt.choice(pita, 'Χωρίς κρεμμύδι'), 'No onion')
assert.equal(mt.choice(pita, 'Χωρίς κρεμμύδι x2'), 'No onion x2')
assert.equal(mt.choice(pita, 'Λίγες'), 'A few')
assert.equal(mt.choice(pita, 'Ντομάτα'), 'Tomato')
assert.equal(mt.choice(pita, 'Χοιρινό'), 'Pork')
assert.equal(mt.choice(pita, 'Καλοψημένο'), 'Well done')
assert.equal(mt.choice(pita, 'Πολλές'), 'Πολλές') // no English: the base text
assert.equal(mt.choice(pita, 'Unknown'), 'Unknown')
assert.equal(mt.choice(null, 'Λίγες'), 'Λίγες')
})
test('the counter menu shape (quick / options.subs / prefs.shared) is walked too', () => {
const counter = { id: 1, name: 'Καφές', translations: {}, prefs: [{ id: 1, name: 'Ζάχαρη', translations: { en: 'Sugar' },
choices: [{ id: 2, name: 'Γλυκός', translations: { en: 'Sweet' }, subs: [] }],
shared: { name: 'Γάλα', translations: { en: 'Milk' }, subs: [{ name: 'Φρέσκο', translations: { en: 'Fresh' } }] } }] }
const map = choiceTexts(counter, 'en')
assert.deepEqual([...map], [['Ζάχαρη', 'Sugar'], ['Γλυκός', 'Sweet'], ['Γάλα', 'Milk'], ['Φρέσκο', 'Fresh']])
assert.equal(choiceTexts(pita, 'en').has('photo.jpg'), false)
})
test('an ordered line: the product translation, else the name it was ordered under', () => {
assert.equal(menuText('en', 'el').line(pita, 'Πίτα γύρος (παλιά)'), 'Gyros pita')
assert.equal(menuText('en', 'el').line({ name: 'Νέο', translations: {} }, 'Παλιό'), 'Παλιό')
assert.equal(menuText('en', 'el').line(undefined, 'Παλιό'), 'Παλιό')
assert.equal(menuText('el', 'el').line(pita, 'Πίτα γύρος (παλιά)'), 'Πίτα γύρος (παλιά)')
})
test('search finds an item by either language', () => {
const mt = menuText('en', 'el')
assert.ok(mt.matches(pita, 'gyros'))
assert.ok(mt.matches(pita, 'γύρος'))
assert.ok(!mt.matches(pita, 'burger'))
assert.ok(mt.matches(pita, ''))
})