Skip to content

test: incremental unit test coverage (67.7% -> 83.7%) - #21

Merged
dkapanidis merged 1 commit into
mainfrom
chore/unit-tests-2026-09-01
Sep 1, 2026
Merged

test: incremental unit test coverage (67.7% -> 83.7%)#21
dkapanidis merged 1 commit into
mainfrom
chore/unit-tests-2026-09-01

Conversation

@dkapanidis

Copy link
Copy Markdown
Member

What

This is the first automated coverage run on this repo (no prior .coverage-ledger.json).

Config fix first: ui/vite.config.ts's test.coverage block had no include, so the v8 provider only reported files a test happened to import — 15 of 41 source files — and showed a misleading 99.5%. Added coverage.include: ['src/**/*.{ts,tsx}'] (with tests/setup/main.tsx excluded) so the report reflects the whole src/ tree. That alone dropped the honest starting baseline to ui/: 220/370 stmts (59.5%). Combined with the backend's unchanged 250/324 (77.2%), the true starting total was 470/694 = 67.7%.

New tests, following the repo's existing testify/vitest conventions:

  • ui/src/actions/utils.test.ts — the fetch wrapper's get/post/put/delete, including the non-JSON error-body fallback path
  • ui/src/hooks/use-mousetrap.test.ts — bind/unbind/rebind lifecycle, mocking the mousetrap package
  • ui/src/shortcuts/KeyboardShortcuts.test.tsxg h / g m navigate wiring
  • ui/src/pages/movies/list.test.tsx — loading/error/empty/populated states and the create-dialog toolbar button, rendered against the real DataTable
  • ui/src/routes.test.tsx — route param parsing for /movies/:id and /movies/:id/edit, exercised through the real router and SideMenu layout

Also added a ResizeObserver stub to ui/src/test/setup.ts — jsdom doesn't implement it, and SideMenu's react-resizable-panels needs it just to mount, so nothing rendering that layout could be tested before this.

Rendering list.tsx and routes.tsx against the real component tree (rather than mocking child components) transitively covered several previously-0% shadcn primitives they actually use: data-table.tsx, table.tsx, resizable.tsx, toast.tsx, toaster.tsx.

No production code was changed — only the coverage config and new/modified test files.

Coverage delta

Statements %
Backend (unchanged) 250/324 77.2%
UI before 220/370 59.5%
UI after 331/370 89.5%
Combined before 470/694 67.7%
Combined after 581/694 83.7%

+16.0pp against the +15pp target — met.

Measured with:

cd backend && go test -coverprofile=cov.out ./... && go tool cover -func=cov.out | tail -1
cd ui && yarn test:coverage

What was skipped, and why

  • ui/src/components/ui/alert-dialog.tsx (27 stmts, 0%) is dead code — not imported anywhere in src/. Testing it would be padding; it should probably be deleted instead (left as-is here since that's a separate call).
  • Backend cmd/movie-catalog/main.go's run() (44 stmts) blocks on a real net.Listener/OS signals; testing it meaningfully needs an injectable-listener refactor, which felt like a deliberate decision rather than a nightly one.
  • Backend ui.go's "UI is built" branch — the existing ui_test.go already documents this as intentionally untested, since dist/ only ever holds a real build artifact in this repo, not a test fixture. Respected that convention rather than working around it.

Suggested next target

toast.tsx's dismiss/update/pause-on-hover branches and toaster.tsx's empty-state render need a test driving useToast() directly (5+1 stmts). App.tsx (2 stmts) just needs a smoke-render test of the real component. On the backend, main.go's run() is the largest remaining gap, pending the listener-injection refactor mentioned above.

Test plan

  • cd backend && go test ./... — all pre-existing tests pass, unmodified
  • cd ui && yarn test — 73/73 tests pass (8 pre-existing files + 5 new)
  • cd ui && npx tsc -b --noEmit — type-checks clean

Generated by Claude Code

Adds vitest coverage for previously-untested ui/ logic (actions/utils,
use-mousetrap, KeyboardShortcuts, the movies list page, and route param
parsing), and fixes the vitest coverage config to report all source
files instead of only the ones a test happened to import.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Test coverage

Suite Coverage
Backend (Go, statements) 77.2%
UI (lines) 89.1%

@dkapanidis
dkapanidis merged commit 552e07a into main Sep 1, 2026
3 checks passed
@dkapanidis
dkapanidis deleted the chore/unit-tests-2026-09-01 branch September 1, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants