Files
xenia-pos-local/manager_dashboard/tests/shell.test.mjs
T
bonaminandClaude Opus 5.5 294b769850 feat(manager): the setup wizard and the shell on v2; all of src on the v2 rules (platform-v2 step 6.14b)
- setup wizard (src/pages/setup): welcome (pick the language: the wizard switches at once), the owner's account, the venue
  (kind, name, staff language, time zone), an optional lock-screen PIN, finish -> sign in; English and Greek
- shell (src/shell): AppLayout (license banner in both languages, header, lock button, idle lock / sign-out), Sidebar on a
  new 'nav' token set in @xenia/ui (light + dark), ProfileDialog (name, username, password, 4-6 digit PIN), licenseContext;
  App.jsx loads the session and the setup state with react-query (no setState in effects); the header's dead search box gone
- Management -> Tables -> List (src/pages/tables, was TablesConfigTab): zones as tabs (drag to reorder), zone name / prefix /
  colour, add many numbered on, a table's name (6 chars) / zone / seats, twice-used names flagged, off / on / delete,
  pick several to move, rename in a series or delete (says how many failed)
- the old src/ui kit, layouts/, components/Sidebar + EditProfileModal, the 'primary' palette and the .btn/.card/.input classes deleted;
  NotificationBell / UserMenuButton on tokens; @xenia/ui: nav tokens, 'scrim' in the Tailwind preset
- v2.json paths = src (the guards cover all of it); npm run lint = eslint src; argsIgnorePattern for components in JSX
- tests: shell.test.mjs (3), e2e setup.mjs (new: a fresh install through the wizard in Greek to the overview, in run-all),
  manager.mjs 'tables list' (zone, 3 tables, rename series, profile PIN, rail tokens)

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

47 lines
3.2 KiB
JavaScript

// The shell, the setup wizard and the tables list as plain data (plan step 6.14b).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { profileProblems } from '../src/shell/profileLogic.js'
import { accountProblems, pinProblems, setupBody, startLanguage, venueProblems } from '../src/pages/setup/setupLogic.js'
import { duplicateNames, nextNumber, reorder, series, tableBody, tableProblems, tablesOf } from '../src/pages/tables/tablesLogic.js'
const fields = list => list.map(([f, k]) => `${f}:${k}`)
test('the profile: password and PIN only when typed', () => {
const base = { username: 'maria', current: '', next: '', again: '', pin: '', pin2: '' }
assert.deepEqual(profileProblems(base), [])
assert.deepEqual(fields(profileProblems({ ...base, next: 'abc', again: 'abd' })), ['current:current', 'next:short', 'again:mismatch'])
assert.deepEqual(fields(profileProblems({ ...base, pin: '12', pin2: '12' })), ['pin:pin'])
assert.deepEqual(fields(profileProblems({ ...base, pin: '123456', pin2: '123457' })), ['pin2:pinMismatch'])
assert.deepEqual(fields(profileProblems({ ...base, username: ' ' })), ['username:username'])
})
test('the setup wizard: account, venue, PIN, what is sent', () => {
const a = { username: 'owner', fullName: 'Olga', email: '', password: 'secret1', confirm: 'secret1' }
assert.deepEqual(accountProblems(a), [])
assert.deepEqual(fields(accountProblems({ ...a, username: 'o w', email: 'x@', confirm: 'nope' })), ['username:spaces', 'email:email', 'confirm:mismatch'])
assert.deepEqual(fields(venueProblems({ types: [], name: '' })), ['types:pickOne', 'name:required'])
assert.deepEqual(pinProblems('', ''), [])
assert.deepEqual(fields(pinProblems('123', '123')), ['pin:pin'])
assert.deepEqual(fields(pinProblems('1234', '1235')), ['again:pinMismatch'])
assert.deepEqual(setupBody(a, { types: ['bar', 'restaurant'], name: ' Golden ', language: 'el', timezone: 'Europe/Athens' }, ''),
{ username: 'owner', password: 'secret1', email: null, full_name: 'Olga', venue_type: 'bar,restaurant', venue_name: 'Golden', language: 'el', timezone: 'Europe/Athens', pin: undefined })
assert.equal(startLanguage('el-GR'), 'el')
assert.equal(startLanguage('en-US'), 'en')
})
test('the tables list: tabs, twice-used names, numbering on, series, reordering zones', () => {
const tables = [{ id: 1, group_id: 7, label: 'BS-1' }, { id: 2, group_id: 7, label: 'BS-4' }, { id: 3, group_id: null, label: 'B3' }, { id: 4, group_id: 8, label: 'B3' }]
assert.deepEqual(tablesOf(tables, 'none').map(x => x.id), [3])
assert.deepEqual(tablesOf(tables, 7).map(x => x.id), [1, 2])
assert.deepEqual([...duplicateNames(tables)], ['B3'])
assert.equal(nextNumber(tables, 7, 'BS-'), 5)
assert.equal(nextNumber(tables, 8, 'BS-'), 1)
assert.deepEqual(series('T-', 9, 3), { names: ['T-9', 'T-10', 'T-11'], last: 'T-11', tooLong: false })
assert.equal(series('BAR-', 99, 2).tooLong, true) // BAR-100 is 7 characters
assert.deepEqual(reorder([1, 2, 3], 1, 3), [2, 3, 1])
assert.deepEqual(reorder([1, 2, 3], 3, 0), [3, 1, 2])
assert.deepEqual(tableBody({ label: ' ', group_id: '7', seats: '4' }), { label: null, group_id: 7, seat_count: 4 })
assert.deepEqual(tableProblems({ label: 'TOOLONG', seats: '0' }), ['label', 'seats'])
})