Operations
Testing
What is tested, how to run it, and how to write a good test for the engine.
Most tests target the code where a bug costs someone money: everything in src/lib/. They are plain Vitest unit tests that run in Node in a few hundred milliseconds. The design system adds token tests (Node) and component interaction tests (jsdom + Testing Library).
npm test # run once
npm run test:watch # re-run on save
npm run check # typecheck + lint + format check + tests
What is covered
| File | Covers |
|---|---|
money.test.ts | Parsing both decimal conventions, thousands heuristics, zero-decimal currencies, formatting, round-trips. |
allocate.test.ts | Largest remainder, weights, negatives, zero weights, the BigInt path, and a 2,000-case property check that parts always sum to the total. |
engine.test.ts | The hand-computed worked example, unassigned items, per-person/proportional/discount adjustments, the cent invariant, settlement in all three modes (balances end at zero), and reducer rules (duplicates, late arrivals, cleanup on removal, 0% service). |
pix.test.ts | The BCB manual's reference payload (CRC 1D3D), CRC check value, amounts, the 99-char template limit, key normalization, text sanitizing. |
parse-item.test.ts | Receipt shorthand ("2x Chopp 14,90", "Pizza 89") and name lists ("Ana, Bruno e Carla"). |
share-and-migrate.test.ts | Share-link round trips (same totals after encode/decode), garbage rejection, v1 → v2 migration and v1 date parsing. |
migrate-sqlite.test.ts | Importing a Splitmize 1.1 SQLite database built from the 1.1 migrations (both schema versions): same math as v1, stable legacy ids, catalogs becoming suggestions. |
Design system (src/design-system/):
| File | Covers |
|---|---|
tokens/__tests__/tokens.test.ts | WCAG contrast of every declared foreground/background pair in both themes, generated CSS (both themes, every role), breakpoints mirrored in Sass, and that every var(--token) referenced in any .scss file exists. |
components/__tests__/interaction.test.tsx | Field label/hint/error wiring, SegmentedControl roving focus and arrow keys, MoneyInput draft/normalize/clamp, Switch and Stepper state, Button defaults and buttonClassName parity. |
Files ending in .test.ts run in Node; .test.tsx component tests opt into jsdom with a // @vitest-environment jsdom docblock. Query by role and label, the way a screen reader would.
Writing a good engine test
- Use real-looking bills. A bar tab with names and prices is easier to verify by hand than
item1,item2. - Assert exact cents. Not "close to" — the whole point is exactness.
- Always assert the invariant:
Σ person totals === grandTotal === assignedTotal + Σ adjustments. - Build bills through the reducer (
applyActions), not by hand-writing objects. That way tests exercise the same paths the UI does.
let bill = createBill({ currency: 'BRL' });
bill = applyActions(bill, [
{ type: 'person/add', names: ['Ana', 'Bruno'] },
{ type: 'item/add', name: 'Pizza', quantity: 1, price: 8990 },
]);
expect(computeBreakdown(bill).people.map((p) => p.total)).toEqual([4495, 4495]);
Manual checks before a release
The UI has no automated end-to-end suite yet. Visual states are reviewed in Storybook (check the axe panel in both themes). Before shipping, walk through:
- Add people by pasting "Ana, Bruno e Carla"; add items with shorthand; toggle a consumer; use portions.
- Service at 0% and 13%; a cover charge per person; a discount.
- Settle in all three modes; set a Pix key; open a QR code.
- Copy the share link, open it in a private window, pick a person.
- Reload — the bill must come back. Open history, duplicate, delete, undo.
- Toggle dark mode; switch language; check a phone-width viewport.
- Print (Ctrl/⌘+P) — only the receipt should be on the page.