Skip to content

test: expand component test coverage - #34

Merged
lstebner merged 7 commits into
mainfrom
test/expand-component-coverage
Jul 11, 2026
Merged

test: expand component test coverage#34
lstebner merged 7 commits into
mainfrom
test/expand-component-coverage

Conversation

@lstebner

Copy link
Copy Markdown
Owner

Summary

  • Extracts normalize()/matchScore() from ArtistList.svelte into src/lib/search.ts and sortAlbums() from AlbumGrid.svelte into src/lib/sort.ts so that logic is independently testable
  • Fixes the binding_property_non_reactive Svelte warning in ThemeSwitcher.svelte (optionElements was not $state, same bug already fixed in Dropdown.svelte)
  • Updates vitest.setup.ts to mock $lib/api/commands with per-command sensible defaults (stopped snapshot, empty EQ gains, etc.) and adds a convertFileSrc mock — this unblocks tests for any component that imports a store which calls commands on init
  • Adds tests for search, sort, ThemeSwitcher, TransportBar, AlbumGrid, TrackTable, and NowPlayingDrawer (129 tests total across 12 files, all passing)

Connected component tests use vi.hoisted() to create shared mock state objects that vi.mock() factories capture by reference, letting individual tests repoint the snapshot or toggle flags before each render without hitting the module-singleton problem.

Test plan

  • npm run test — all 129 tests pass
  • npm run check — no new type errors (one pre-existing unused @ts-expect-error in vite.config.js unrelated to this PR)
  • Spot-check that the ThemeSwitcher keyboard navigation still works in the running app

🤖 Generated with Claude Code

lstebner and others added 7 commits July 10, 2026 20:55
Adds happy-dom environment, vitest.config.ts (using bare svelte() plugin
to avoid SSR mode), a global setup file that mocks Tauri IPC and registers
cleanup, and 19 Dropdown tests covering rendering, keyboard nav, and ARIA.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Svelte 5 requires bind:this on array indices to use a $state array so
the binding can be tracked reactively.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Installs @vitest/coverage-v8, adds coverage section to vitest.config.ts
scoped to src/lib, and ignores the generated /coverage directory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- TrackRow: rendering, track number vs play icon, playing class, onclick
- StarRating: display for null/whole/half/full ratings, readonly mode,
  full-star and half-star click, toggle-off on current rating
- ui store: tests factory via exported createUiStore for isolation;
  covers initial state and all mutual-exclusivity constraints between
  settings, device sync, and the now-playing drawer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a Testing section to CLAUDE.md covering: what to test and in what
priority order, what to skip, mocking rules, and the framework stack.
The guiding principle: coverage reports show gaps, not correctness.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…, and connected components

- Update vitest.setup.ts to mock $lib/api/commands with per-command
  sensible defaults so stores that fetch on init (player, theme) work
  correctly in tests; add convertFileSrc mock for art-path components

- Extract normalize() and matchScore() from ArtistList.svelte into
  src/lib/search.ts so they are independently testable; add 16 tests

- Extract sortAlbums() from AlbumGrid.svelte into src/lib/sort.ts so
  the three sort modes are independently testable; add 12 tests

- Fix binding_property_non_reactive warning in ThemeSwitcher.svelte
  (optionElements array was not reactive, same fix already applied to
  Dropdown.svelte); add 20 keyboard-navigation and interaction tests

- Add component tests for TransportBar (stopped/playing rendering,
  disabled states, control click handlers), AlbumGrid (empty-state
  prompt, loading state, Settings link), TrackTable (back button),
  and NowPlayingDrawer (dialog rendering, focus management, Escape
  and backdrop close)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TypeScript now resolves the NodeJS process global from type definitions,
so the suppression directive is unused and fails svelte-check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lstebner
lstebner force-pushed the test/expand-component-coverage branch from fc63b4b to 9259720 Compare July 11, 2026 03:55
@lstebner
lstebner merged commit c3e45ca into main Jul 11, 2026
2 checks passed
@lstebner
lstebner deleted the test/expand-component-coverage branch July 11, 2026 04:04
@lstebner lstebner mentioned this pull request Jul 11, 2026
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.

1 participant