Files
bonaminandClaude Opus 5.5 f31bdf42aa feat: printing problems shown and handled; printing set-up on v2 (platform-v2 step 6.10)
- a ticket that doesn't print is a problem for whoever sent it and the managers:
  GET /api/print-problems (the order, table, dishes, printer, since when, tries,
  last error, who sent it) and three ways out: print again, send to another
  printer, handled (services/print_problems.py; print_jobs.resolved_by /
  redirected_to, Alembic 0036); live event print.problems from the print paths
- phone: the red printer button opens the problems sheet, the table page warns
  (usePrintProblems replaces the 8 s poll); counter POS: a red button under the
  modes with the shared panel (@xenia/ordering PrintProblemsPanel + pure rules);
  manager: a card on the overview (top), the Tables page and the order page
- manager: Settings -> Printing (printers with reachability, test print, network
  scan; ticket layout + test ticket, beep, fonts with previews, dot leader,
  dividers) and Management -> Prep zones (cards + zone dialog with the ticket
  language, printers, copies, sorting, category order, kitchen screen) rebuilt in
  src/pages/printing; v1 PrintFontsTab, PrepZonesConfigPage, PendingPrints and
  /api/orders/pending-prints removed
- access: printer add/edit/delete/scan need core.settings.manage, prep zone
  changes catalog.menu.manage (were any dashboard user)
- tests: test_print_problems.py, @xenia/ordering printProblems, manager
  printing.test.mjs, e2e print_problems.mjs (done-when) + manager.mjs printing

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

61 lines
3.3 KiB
JavaScript

// Printing set-up as plain data (plan step 6.10).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
beepBytes, beepSettings, decodeBeep, decodeDots, decodeFont, encodeDots, encodeFont, move, orderedCategories, printerBody,
printerProblems, setBypass, setMain, toggleSecond, zoneBody, zoneForm, zoneProblem,
} from '../src/pages/printing/printingLogic.js'
test('fonts and the dot leader round-trip; bad values fall back', () => {
assert.deepEqual(decodeFont('48:1:0'), { size: '48', bold: true, caps: false })
assert.equal(encodeFont({ size: '16', bold: false, caps: true }), '16:0:1')
assert.deepEqual(decodeFont('99:x'), { size: '0', bold: false, caps: false })
assert.equal(encodeDots(decodeDots('dash_space:32:1')), 'dash_space:32:1')
assert.deepEqual(decodeDots(''), { style: 'dot_space', size: '0', bold: false })
})
test('beep: presets, custom, off, and what the test sends', () => {
assert.deepEqual(decodeBeep('triple', 'true'), { preset: 'triple', n1: 1, n2: 1, n3: 3 })
assert.deepEqual(decodeBeep('custom:3:2:4', 'true'), { preset: 'custom', n1: 3, n2: 2, n3: 4 })
assert.equal(decodeBeep('double', 'false').preset, 'off')
assert.deepEqual(beepSettings({ preset: 'off' }), [['print.beep_on_ticket', 'false']])
assert.deepEqual(beepSettings({ preset: 'custom', n1: 99, n2: 0, n3: 2.4 }), [['print.beep_on_ticket', 'true'], ['print.beep_pattern', 'custom:30:1:2']])
assert.deepEqual(beepBytes({ preset: 'long' }), { n1: 5, n2: 2, n3: 1 })
})
test('printer form: what is wrong, and the body', () => {
assert.deepEqual(printerProblems({ name: ' ', ip_address: '10.0.0.300', port: 0, line_width: 48 }), ['name', 'ip_address', 'port'])
assert.deepEqual(printerProblems({ name: 'Bar', ip_address: '192.168.1.20', port: '9100', line_width: '42' }), [])
assert.deepEqual(printerBody({ name: ' Bar ', ip_address: '192.168.1.20 ', port: '9100', line_width: '42', codepage_n: '24' }),
{ name: 'Bar', ip_address: '192.168.1.20', port: 9100, protocol: 'escpos_tcp', line_width: 42, codepage_n: 24, is_active: true })
})
test('zones: main and second printers, the kitchen screen switches, what is missing, the body', () => {
let f = zoneForm(null)
assert.equal(zoneProblem(f), 'name')
f = { ...f, name: ' Grill ' }
assert.equal(zoneProblem(f), 'printer')
f = setMain(f, 3)
assert.deepEqual(f.printer_ids, [3])
f = toggleSecond(toggleSecond(f, 5), 3) // the main one can't be unticked
assert.deepEqual(f.printer_ids, [3, 5])
assert.equal(zoneProblem(f), null)
f = setBypass(f, 'bypass_kds', true)
assert.equal(f.bypass_pending, true)
f = setBypass(f, 'bypass_pending', false)
assert.equal(f.bypass_kds, false)
const body = zoneBody({ ...f, description: ' ', master_copies: 20 })
assert.equal(body.name, 'Grill')
assert.equal(body.description, null)
assert.equal(body.language, null)
assert.equal(body.master_copies, 9)
assert.equal(zoneForm({ name: 'Bar', group_by_category: 1, language: null }).group_by_category, true)
})
test('category order: ranked first, then the rest; moving within bounds', () => {
const cats = [{ id: 1 }, { id: 2 }, { id: 3 }]
assert.deepEqual(orderedCategories(cats, [3, 9]).map(c => c.id), [3, 1, 2])
assert.deepEqual(move([1, 2, 3], 0, -1), [1, 2, 3])
assert.deepEqual(move([1, 2, 3], 2, -1), [1, 3, 2])
})