Skip to content

feat: Set up frontend unit testing framework and write component tests #28

Description

@aGallea

Problem

The frontend has no unit test framework configured. Only Playwright E2E tests exist (e2e/search.spec.ts). Issue #12 (Cluster Drill-Down and Annotation) specified frontend component tests as a requirement, but the infrastructure to run them does not exist.

Proposed Solution

1. Set up Vitest + React Testing Library + jsdom

Install and configure:

  • vitest as the test runner
  • @testing-library/react + @testing-library/jest-dom for component testing
  • jsdom as the test environment
  • @testing-library/user-event for user interaction simulation

Add vitest.config.ts and a test:unit script to package.json.

2. Write component tests for issue #12 features

ClusterDetailDrawer.test.tsx

  • Renders drawer with cluster items (metadata, thumbnails)
  • Pagination controls work correctly
  • Inline cluster name editing
  • Notes textarea updates
  • Tags input
  • Calls correct API functions on interaction

SubClusterView.test.tsx

  • Renders mini scatter plot with sub-cluster data
  • Sub-cluster count selector triggers re-computation
  • Handles loading and error states

ClusterLegend.test.tsx

  • Click on cluster name opens detail drawer (not just toggle visibility)
  • Visibility toggle checkbox still works independently
  • Shows annotation indicator when cluster has notes

plotStore.test.ts

  • openClusterDetail() action fetches and stores cluster items
  • subCluster() action triggers sub-cluster computation
  • updateAnnotation() action persists annotation changes
  • selectedCluster and clusterItems derived state

3. Add to CI

Add a test:unit job to .github/workflows/ci.yml that runs npm run test:unit in the frontend directory.

Acceptance Criteria

  • Vitest + React Testing Library configured and working
  • npm run test:unit script added to package.json
  • Component tests for ClusterDetailDrawer, SubClusterView, ClusterLegend
  • Store tests for plotStore drill-down and annotation actions
  • CI job runs frontend unit tests
  • All tests pass

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions