Skip to content

feat: Add unit tests for View.tsx component #276

@andeplane

Description

@andeplane

Overview

Add comprehensive unit tests for src/containers/View.tsx to improve test coverage and validate key behaviors, including the recent fix for clearing atom selection when simulation changes.

Test Plan

1. Selection Management

1.1 Auto-clear selection on simulation change (P0 - validates recent fix)

  • When simulation value changes, visualizer.clearSelection() should be called
  • selectedAtoms state should be reset to empty Set

1.2 Escape key clears selection (P1)

  • Pressing Escape when atoms are selected should clear selection
  • Pressing Escape when no atoms are selected should do nothing

1.3 Particle click handling (P3)

  • Plain click on atom should select only that atom
  • Plain click on already-selected single atom should deselect it
  • Shift+click should toggle atom in/out of multi-selection
  • Plain click when multiple atoms selected should clear and select only clicked atom

2. Responsive Behavior (P3)

2.1 Mobile/Desktop initial state

  • On desktop (width > 900), overlay should start expanded
  • On mobile (width <= 900), overlay should start collapsed

2.2 Window resize handling

  • Resizing from desktop to mobile should collapse overlay
  • Resizing from mobile to desktop should expand overlay

3. LocalStorage Persistence (P2)

3.1 Drawer visibility persistence

  • showAnalyze state should be saved to localStorage when changed
  • showAnalyze state should be loaded from localStorage on mount
  • localStorage should NOT be written to in embedded mode

4. Embedded Mode

4.1 Embed config overrides (P2)

  • embedConfig.showSimulationSummary should override localStorage preference
  • ResponsiveSimulationSummary should not render when embed config disables it

4.2 No simulation modal (P1)

  • Modal should NOT show in embedded mode even when simulation is null

5. No Simulation Modal (P2)

  • Modal should show when simulation is null and not in embedded mode
  • Modal should be dismissible via OK button
  • Modal should be dismissible via onCancel

6. Visualizer Lifecycle (P2)

6.1 Visibility handling

  • visualizer.idle should be true when visible prop is false
  • visualizer.idle should be false when visible prop is true

Implementation Notes

Mocking Strategy

The tests will require these mocks:

  1. Store hooks (useStoreState, useStoreActions) - return configurable values
  2. Visualizer class from omovi - mock clearSelection, setSelected, idle, etc.
  3. Browser APIs - localStorage, window.innerWidth, resize events
  4. Child components - mock ResponsiveSimulationSummary, SelectedAtomsInfo, ColorLegend, etc.
  5. useEmbeddedMode hook - return configurable embed config

Test File Location

src/containers/View.test.tsx

Priority Legend

Priority Description
P0 Critical - validates bug fix
P1 High - core UX behavior
P2 Medium - important functionality
P3 Low - nice to have, complex to test

References

  • Existing test patterns: src/components/ResponsiveSimulationSummary.test.tsx, src/components/Figure.test.tsx
  • Testing patterns doc: docs/testing_patterns.md
  • Recent fix commit: 054bad2 (Fix useEffect dependency: add simulation to clear selection when simulation changes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions