Skip to content

test(data): add zustand store unit tests and fix annotation-store selector hooks#452

Open
WilliamBerryiii wants to merge 2 commits intomainfrom
feature/zustand-store-tests
Open

test(data): add zustand store unit tests and fix annotation-store selector hooks#452
WilliamBerryiii wants to merge 2 commits intomainfrom
feature/zustand-store-tests

Conversation

@WilliamBerryiii
Copy link
Copy Markdown
Member

Comprehensive unit tests for all Zustand stores in the Dataset Analysis Tool frontend, targeting 80%+ coverage for Issue #217. Alongside the new tests, a performance bug was discovered and fixed in annotation-store.ts where selector hooks created new object references on every store update, causing unnecessary component re-renders.

Description

Closes #217

Bug Fix

The five selector hooks in annotation-store.ts (useAnnotationDirtyState, useTaskCompletenessState, useTrajectoryQualityState, useDataQualityState, useAnomalyState) returned new object references on each store update. Wrapped all five with useShallow from zustand/react/shallow and extracted an EMPTY_ANOMALIES constant to stabilize return values and prevent unnecessary re-renders.

Test Coverage

Added and expanded tests across seven test files covering the full Zustand store layer:

  • Annotation store — 5 new selector hook tests validating dirty state, task completeness, trajectory quality, data quality, and anomaly reference stability
  • Edit store action factories — 14 frame action tests, subtask CRUD and reorder tests, and transform action tests using reusable state factory helpers
  • Edit store helpers — tests for buildOriginalEditState, buildEditOperations, hasEditContent, computeDirty, and persistEditStateDraft
  • Edit store selectors — 6 selector hooks tested via renderHook covering transforms, frame removal/insertion, subtask operations, dirty state, and trajectory adjustments
  • Edit store frame utilities — 11 edge case tests for frame index mapping and frame count calculations with boundary conditions
  • Episode storesetLoading action test plus 3 selector hook tests for episode index, navigation, and playback
  • Joint config store — idempotency guard test for initDefaults

All tests follow existing codebase conventions: renderHook() for hook isolation, vi.mock() for dependencies, beforeEach cleanup, and act() wrapping for state mutations.

Type of Change

  • 🐛 Bug fix (non-breaking change fixing an issue)
  • ✨ New feature (non-breaking change adding functionality)
  • 💥 Breaking change (fix or feature causing existing functionality to change)
  • 📚 Documentation update
  • 🏗️ Infrastructure change (Terraform/IaC)
  • ♻️ Refactoring (no functional changes)

Component(s) Affected

  • data-management/viewer/frontend/src/stores/ — Zustand stores and tests

Testing Performed

  • 658 tests passing via Vitest 4.1.0 + Happy DOM 20.8.9
  • All new and existing store tests pass
  • No new linting warnings introduced

Documentation Impact

  • No documentation changes needed
  • Documentation updated in this PR
  • Documentation issue filed

Bug Fix Checklist

  • Linked to issue being fixed
  • Regression test included
    • Selector hook tests verify useShallow wrapping produces stable references

Checklist

🤖 - Generated by Copilot

…ector hooks

- add selector hook tests for annotation, episode, and edit stores
- add edge-case tests for edit-store frame utils and action factories
- fix annotation-store hooks to use useShallow preventing infinite re-renders
- add stable EMPTY_ANOMALIES constant to avoid reference instability

🧪 - Generated by Copilot
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA e93457c.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.80%. Comparing base (5fb6d58) to head (e93457c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #452      +/-   ##
==========================================
+ Coverage   64.41%   64.80%   +0.38%     
==========================================
  Files         251      251              
  Lines       15435    15441       +6     
  Branches     2108     2060      -48     
==========================================
+ Hits         9942    10006      +64     
+ Misses       5205     5146      -59     
- Partials      288      289       +1     
Flag Coverage Δ
pester 82.24% <ø> (ø)
pytest 92.40% <ø> (ø)
pytest-dataviewer 63.87% <ø> (ø)
pytest-fuzz 1.59% <ø> (ø)
vitest 51.77% <100.00%> (+0.97%) ⬆️
Files with missing lines Coverage Δ
...ent/viewer/frontend/src/stores/annotation-store.ts 85.71% <100.00%> (+9.65%) ⬆️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

test(dataviewer): add tests for Zustand stores

3 participants