test(admin): Reports + date-range — fill gaps + lifecycle test

This commit is contained in:
Bas van Rossem
2026-07-23 14:53:38 +02:00
parent e7eefe8f62
commit 5aa6febd65
4 changed files with 229 additions and 4 deletions

View File

@@ -450,3 +450,32 @@ Guaranteed behaviors:
- Lifecycle (`src/screens/Sessions.test.tsx`): open the create form → fill a valid manual session →
submit → it appears in the list; then edit that row (change the handeling) → the change persists in
the refreshed list.
## Reports + date-range — admin client
Src covered (admin `apps/admin`): `src/screens/Reports.tsx`, `src/api/reports.ts`, and
`src/lib/date-range.ts` — all three at 100% stmts/branch/funcs/lines. No `c8 ignore` needed.
Guaranteed behaviors:
- Date-range helpers derive ISO instants in the admin's local timezone: `dayStartISO` → local
00:00:00.000 of the picked day, `dayEndISO` → local 23:59:59.999; `toDateStr` zero-pads month/day.
- Presets map to the correct `YYYY-MM-DD` windows: `thisWeek` = Monday..today, `thisMonth` =
1st..today, `allTime` = fixed floor `2000-01-01`..today.
- `filtersToQuery` always serializes `from`/`to` and only emits `user_id`/`insole_type`/`activity_id`
when set (empty optionals are omitted).
- `useReport` calls `GET /api/admin/report?<query>`; clicking a preset (`Deze week`/`Deze maand`/
`Alles`), changing the Van/Tot date inputs, or picking a Medewerker/Type/Handeling filter re-issues
the report query with the new params (verified against the emitted querystring).
- The screen renders headline totals (`worked`/`pairs`/`sessions`/`paused`) and the three breakdown
tables (`Per medewerker`/`Per handeling`/`Per type`) from the response rows.
- Loading state renders `Laden…`; the query error state renders `Kon rapport niet laden.`; a report
with no data falls back to zero totals and shows `Geen gegevens.` in every table (the `?? 0` / `?? []`
defensive fallbacks).
- `Exporteer CSV` calls `downloadExport` with the current filters; a rejected download surfaces
`Export mislukt. Probeer opnieuw.`.
- `downloadExport` fetches `/api/admin/export?<query>` with a `Bearer` header when a token exists (and
no `Authorization` header when it doesn't), throws on a non-ok response, names the file from the
`content-disposition` header, and falls back to `solelog-report.csv` when that header is absent.
- Lifecycle (`src/screens/Reports.test.tsx`): pick `Deze maand` + a Medewerker filter → the report
query reflects both (`from` = this-month start, `user_id` set) and the returned rows still render.