Files
xenia-pos-local/packages/i18n/tests/format.test.mjs
T
bonaminandClaude Opus 5.5 8a02173450 feat(manager): the overview, online orders and the day summary on v2 (platform-v2 step 6.2)
- DashboardPage (2.8k lines) → src/pages/overview/: OverviewPage + cards (shifts, tables,
  pending prints, notes, bookings, messages) and dialogs (order at a glance, shift review /
  end with the cash handover, day summary with cash count and checks); arithmetic in
  overviewLogic.js (tests/overview.test.mjs). Data via useLiveQuery: orders and tables
  live, day and shifts every 15 s. Bookings typed in venue time; decline reason in a dialog.
- OnlineOrdersPage → src/pages/online/ on react-query + live events; unused API helpers dropped.
- WorkdaySummaryModal → overview/DaySummaryDialog + DaySummaryTabs.
- Every text in manager.json (en + el, 342 keys); tokens only; v2.json adds overview, hooks.
- Backend: business day open/close answer only with codes (license.locked, license.expired,
  business_day.orders_open); XeniaError's v1 `detail` removed.
- @xenia/i18n: formatDateTime with Intl options threw "unknown date style" (fixed, tested).
- e2e manager.mjs: open the day, a shift (start, stats, end short), a live table, a booking,
  day stats, Greek, close the day (forced), online orders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 09:01:51 +02:00

81 lines
4.1 KiB
JavaScript

// Formatting in the venue's zone. The test process may run in any zone: force a far one
// so a formatter that used the device zone would fail.
process.env.TZ = 'America/New_York'
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { createFormatters, toDate } from '../src/format.js'
const el = createFormatters({ language: 'el', timeZone: 'Europe/Athens', currency: 'EUR' })
const en = createFormatters({ language: 'en', timeZone: 'Europe/Athens', currency: 'EUR' })
const nbsp = s => s.replace(/[\u00a0\u202f]/g, ' ')
test('times are venue time, not device time (summer UTC+3, winter UTC+2)', () => {
assert.equal(new Date('2026-07-01T10:00:00Z').getHours(), 6, 'the process really runs in New York')
assert.equal(el.formatTime('2026-07-01T10:00:00Z'), '13:00')
assert.equal(el.formatTime('2026-01-15T10:00:00Z'), '12:00')
assert.equal(en.formatTime('2026-07-01T22:30:00Z'), '01:30')
})
test('the venue day, across midnight', () => {
assert.equal(el.formatDate('2026-07-01T22:30:00Z'), '02/07/2026')
assert.equal(el.venueDateKey('2026-07-01T22:30:00Z'), '2026-07-02')
assert.equal(el.venueDateKey('2026-07-01T20:59:00Z'), '2026-07-01')
})
test('DST changes in Athens (§7.3)', () => {
// 25 Oct 2026, 04:00 local happens twice: 00:59Z is 03:59 EEST, 01:00Z is 03:00 EET
assert.equal(el.formatTime('2026-10-25T00:59:00Z'), '03:59')
assert.equal(el.formatTime('2026-10-25T01:00:00Z'), '03:00')
// 29 Mar 2026, 03:00 local is skipped: 00:59Z is 02:59 EET, 01:00Z is 04:00 EEST
assert.equal(el.formatTime('2026-03-29T00:59:00Z'), '02:59')
assert.equal(el.formatTime('2026-03-29T01:00:00Z'), '04:00')
})
test('business dates (YYYY-MM-DD) are never shifted', () => {
const ny = createFormatters({ language: 'en', timeZone: 'America/Los_Angeles' })
assert.equal(ny.formatDate('2026-11-13'), '13/11/2026')
assert.equal(el.formatDate('2026-11-13'), '13/11/2026')
assert.match(el.formatDate('2026-11-13', 'dateLong'), /Παρασκευή.*13.*Νοεμβρίου.*2026/)
assert.match(en.formatDate('2026-11-13', 'dateLong'), /Friday.*13.*November.*2026/)
})
test('backend strings without an offset are UTC', () => {
assert.equal(toDate('2026-07-01 10:00:00.123456').toISOString(), '2026-07-01T10:00:00.123Z')
assert.equal(toDate('2026-07-01T10:00:00').toISOString(), '2026-07-01T10:00:00.000Z')
assert.equal(toDate('2026-07-01T13:00:00+03:00').toISOString(), '2026-07-01T10:00:00.000Z')
assert.equal(toDate('nonsense'), null)
assert.equal(el.formatDateTime(null), '')
})
test('date-time styles use a 24-hour clock in both languages', () => {
assert.equal(el.formatDateTime('2026-07-01T16:05:00Z'), '01/07/2026, 19:05')
assert.equal(en.formatDateTime('2026-07-01T16:05:00Z'), '01/07/2026, 19:05')
assert.equal(en.formatTime('2026-07-01T16:05:09Z', 'timeSeconds'), '19:05:09')
})
test('a style can also be Intl options (each cached on its own)', () => {
assert.equal(el.formatDateTime('2026-07-01T16:05:00Z', { hour: '2-digit', hourCycle: 'h23' }), '19')
assert.equal(en.formatDate('2026-07-01T16:05:00Z', { month: 'long' }), 'July')
assert.equal(en.formatDate('2026-07-01T16:05:00Z', { year: 'numeric' }), '2026')
})
test('money and numbers per language', () => {
assert.equal(nbsp(el.formatMoney(1234.5)), '1.234,50 €')
assert.equal(en.formatMoney(1234.5), '€1,234.50')
assert.equal(nbsp(el.formatMoney(-3)), '-3,00 €')
assert.equal(el.formatMoney(null), '')
assert.equal(el.formatNumber(1234.567), '1.234,57')
assert.equal(en.formatNumber(2.5, { decimals: 2 }), '2.50')
assert.equal(nbsp(el.formatPercent(0.235)), '23,5%')
})
test('relative times', () => {
const now = Date.parse('2026-07-01T10:00:00Z')
assert.equal(en.formatRelative('2026-07-01T09:55:00Z', now), '5 minutes ago')
assert.equal(el.formatRelative('2026-07-01T09:55:00Z', now), 'πριν από 5 λεπτά')
assert.equal(en.formatRelative('2026-07-01T09:59:40Z', now), 'now')
assert.equal(en.formatRelative('2026-06-30T10:00:00Z', now), 'yesterday')
assert.equal(en.formatRelative('2026-07-01T12:00:00Z', now), 'in 2 hours')
assert.equal(en.formatRelative('2026-04-01T10:00:00Z', now), '01/04/2026')
})