# Testing before it goes live

## Layers
1. **Unit tests** for `logic.js` with `node --test` (or plain asserts): totals, streaks, edge cases (no data, one entry, ties, midnight, time zones, a season stored only as totals). Use made-up data shaped like real data.
2. **API tests** against `wrangler dev`: sign-in, validation rejects bad input, one household can't read another's data, rate limits.
3. **Click-through** in a real browser (Playwright) at 390×844: sign up, log things, edit, undo, delete, settings, sign out. Two browser contexts as two people to test sharing. `context.setOffline(true)` to test the queue. Collect `pageerror`s and fail on any.
4. **Visual check**: screenshots at phone and desktop width, opened and looked at. Also check `scrollWidth - clientWidth === 0` (no sideways scroll) on every page.

## An automated design check (run on every page, phone and desktop, light and dark)
In a real browser, scroll each page so animations run, then measure: text contrast (composite each element's background up to the page), text under 12px, anything wider than the screen, tap targets under ~30px, images without alt or failing to load, duplicate ids, page errors, broken links. Fix everything it finds, then look at the screenshots: tools miss what eyes catch (e.g. shapes that should be square, things overlapping mid-animation).

## Make tests reliable
- Stub pop-ups that depend on time or first-run (tours, badges, check-ins) so they don't cover buttons.
- Clear local rate limits before a run (`DELETE FROM login_attempts`).
- Unregister service workers and clear caches between runs, or the browser serves old files.
- Wait for elements, not fixed times, where you can.
- When a test fails because the app changed on purpose, update the test in the same commit.

## Before every deploy
Run all of it, show the user the results and screenshots, and say plainly if anything failed or was skipped.
