test(admin): Live view — fill gaps + lifecycle test

Drove Live.tsx from 93.24% to 100% (stmts/branch/funcs/lines); elapsed.ts already 100%. Added tests for the error state, non-array payload fallback, placeholder labels (missing name/activity/type), the busy/disabled action buttons, the loading state, and a combined running+paused lifecycle test. No production behavior changed; no bugs found.
This commit is contained in:
Bas van Rossem
2026-07-23 14:30:26 +02:00
parent 64911a0052
commit 77db308e41
2 changed files with 124 additions and 0 deletions

View File

@@ -380,3 +380,30 @@ Guaranteed behaviors:
- Lifecycle (`src/screens/Login.test.tsx`): from the unauthenticated app, worker credentials are
rejected with the `"Geen toegang — alleen beheerders."` message and the shell never renders; admin
credentials then flip the gate so the authed shell (Sidebar nav) renders.
## Live view — admin client
Src covered (admin `apps/admin`): `src/screens/Live.tsx` and `src/lib/elapsed.ts` — both at
100% stmts/branch/funcs/lines. No `c8 ignore`s needed.
Guaranteed behaviors:
- Live renders one `.live-card` per active session under a `Actief nu (<count>)` header, each card
showing the worker name, the activity, the pair count, and a running worked-time timer.
- The per-card worked time is server-authoritative: `worked = (base − start_time) − paused_seconds`,
where `base` is `now` while running (a 1s client tick counts it up between the 5s server polls) and
the frozen `paused_at` moment while paused, floored at 0. `formatTime` (in `elapsed.ts`) renders it
as zero-padded `HH:MM:SS` and never returns a negative time.
- A running (not-paused) card's timer keeps counting up on the 1s tick; a paused card shows the
`Gepauzeerd` badge and its worked timer stays frozen at the pause moment across ticks.
- The `Pauze <duration>` total line shows only when `paused_seconds > 0` (absent when it is 0).
- Placeholder fallbacks: a missing `user_name` renders `Onbekend`, a missing `activity_name` renders
`Onbekende handeling`, and a null `insole_type` omits the type pill.
- Each card exposes `Stop` and `Annuleer` buttons that call `POST /api/admin/sessions/:id/stop` and
`.../discard` for that session; both buttons are disabled while either mutation is in flight.
- Loading state renders `Laden…`; the error state renders `Kon gegevens niet laden.` (and no header);
the empty state renders `Niemand is nu aan het werk.`; a non-array payload is treated as zero active
sessions (defensive `Array.isArray` fallback).
- Lifecycle (`src/screens/Live.test.tsx`): active-sessions data renders a running card and a paused
card side by side, with exactly the paused session showing the `Gepauzeerd` badge and its
`Pauze 00:01:30` total.