test(worker): History — fill gaps + lifecycle test
This commit is contained in:
@@ -283,3 +283,31 @@ Guaranteed behaviors:
|
||||
> implemented** in the current code (there is no global 401 interceptor; `apiFetch` throws
|
||||
> `ApiError` and callers surface it via React Query). Left as-is (missing feature, not a defect);
|
||||
> not tested and not filed as a bug.
|
||||
|
||||
## History — worker client
|
||||
|
||||
Src covered (worker `apps/worker`): `src/screens/History.tsx` and `src/lib/export.ts` — both at
|
||||
100% stmts/branch/funcs/lines. No `c8 ignore`s needed.
|
||||
|
||||
Guaranteed behaviors:
|
||||
|
||||
- History renders the Dutch header (`Geschiedenis`) and the `Exporteer CSV` button.
|
||||
- Sessions render in the order the API returns them (`GET /api/sessions` is newest-first), one
|
||||
`.session-card` per session, showing the activity name and its formatted duration.
|
||||
- `formatDuration` renders the legacy format: `Hh Mm` when hours are present (`3661 → 1h 1m`),
|
||||
`Mm Ss` when only minutes (`125 → 2m 5s`), and just seconds under a minute (`45 → 45s`); a null
|
||||
`duration_seconds` renders `0s`.
|
||||
- A card falls back to `"Onbekende handeling"` when `activity_name` is absent, omits the insole-type
|
||||
pill when `insole_type` is null, and uses the singular noun (`inlegzool`) only for a pair count of
|
||||
1 (`inlegzolen` otherwise).
|
||||
- A `Pauze <duration>` line shows only when `paused_seconds > 0` (absent when it is 0).
|
||||
- The empty state (`Nog geen opgeslagen sessies.`) shows only once loading has finished and there are
|
||||
no sessions; while the query is still loading, neither the empty state nor any cards render.
|
||||
- Clicking `Exporteer CSV` calls `downloadExport`; when it rejects, the card surfaces the
|
||||
`Kan de export niet openen` error message instead of throwing.
|
||||
- `downloadExport` (`src/lib/export.ts`): fetches `GET /api/export` with the bearer token when one is
|
||||
stored (no `Authorization` header when there is none), then triggers a client-side download via an
|
||||
object URL (`createObjectURL` → anchor `click` → `revokeObjectURL`); it throws
|
||||
`"Kan de export niet openen"` when the response is not ok.
|
||||
- Lifecycle (`src/screens/History.test.tsx`): the list renders a completed session showing both its
|
||||
worked duration and its `Pauze` line, then the export action invokes the download path.
|
||||
|
||||
Reference in New Issue
Block a user