Skip to content

feat: add unit tests for View.tsx#306

Merged
andeplane merged 1 commit intomainfrom
feat/view-tests-276
Feb 26, 2026
Merged

feat: add unit tests for View.tsx#306
andeplane merged 1 commit intomainfrom
feat/view-tests-276

Conversation

@andeplane
Copy link
Owner

Summary

Closes #276.

  • P0 – Auto-clear selection on simulation change: verifies clearSelection is called and selectedAtoms resets whenever the simulation store value changes.
  • P1 – Escape key: no-op when nothing selected; clears selection (and calls visualizer.clearSelection) when atoms are selected.
  • P1 – Embedded mode: no-simulation modal is suppressed when isEmbeddedMode=true.
  • P2 – localStorage: showAnalyze is read from localStorage on mount and written back when not in embedded mode; writes are skipped in embedded mode.
  • P2embedConfig.showSimulationSummary gates whether ResponsiveSimulationSummary renders in embedded mode.
  • P2visualizer.idle is toggled correctly by the visible prop.

Mocking strategy

Concern Approach
useStoreState / useStoreActions vi.fn() + mutable shared mockState object updated in beforeEach; selectors run against real state shape
Visualizer (omovi) vi.fn() at module level; regular-function mockImplementation used in the Escape test so new Visualizer() succeeds
antd Layout / Modal / Button Lightweight JSX stubs; Layout.Header attached as static property
Child components Minimal stubs with data-testid attributes
THREE.js / geometry utils Mocked to prevent WebGL errors in jsdom
localStorage vi.spyOn(Storage.prototype) in a nested beforeEach/afterEach

Test plan

  • npm test -- --run View → 17/17 pass
  • Full suite (npm test) → 250/250 pass, no regressions

🤖 Generated with Claude Code

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andeplane, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the frontend's robustness by introducing a comprehensive suite of unit tests for the View.tsx component. These tests validate critical user interaction flows, state management, and rendering logic, particularly concerning atom selection, simulation changes, and embedded mode behavior. Concurrently, it cleans up the backend by removing a previously used test router and its database migration, streamlining the codebase.

Highlights

  • Unit Tests for View.tsx: Added comprehensive unit tests for the View.tsx component, covering various functionalities and edge cases related to simulation display and user interaction.
  • Auto-clear Selection on Simulation Change: Implemented and tested logic to automatically clear atom selections when the active simulation changes, ensuring clearSelection is called and selectedAtoms resets.
  • Escape Key Behavior: Verified that pressing the Escape key clears the current atom selection when atoms are selected, and performs no operation otherwise.
  • Embedded Mode Modal Suppression: Ensured that the 'no-simulation' modal is suppressed when the application is running in embedded mode, providing a cleaner experience for embedded viewers.
  • localStorage Persistence for showAnalyze: Validated the persistence mechanism for the showAnalyze setting, confirming it reads from localStorage on mount and writes back when not in embedded mode, while skipping writes in embedded mode.
  • embedConfig.showSimulationSummary Control: Confirmed that the embedConfig.showSimulationSummary setting correctly gates whether the ResponsiveSimulationSummary component renders in embedded mode.
  • Visualizer Idle State Management: Tested that the visualizer.idle property is correctly toggled based on the visible prop of the View component, optimizing rendering performance when the view is not active.
  • Backend Test Endpoint Removal: Removed the test router, its associated database migration, and related imports from the backend, cleaning up development-specific code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • backend/migrations/env.py
    • Removed an unused import of TestRecord.
    • Removed a trailing newline.
  • backend/migrations/versions/20251222_1017_2da813b175f0_initial_test_schema.py
    • Removed the entire database migration file for the test_records table.
  • backend/src/atomify_api/db/database.py
    • Removed an unused import of TestRecord.
    • Removed a trailing newline.
  • backend/src/atomify_api/main.py
    • Removed the import of the test_router.
    • Removed the inclusion of the test_router in the FastAPI application.
  • backend/src/atomify_api/routers/init.py
    • Removed test_router from the __all__ export list.
  • backend/src/atomify_api/routers/test.py
    • Removed the entire test router module, including its models and endpoints.
  • src/containers/View.test.tsx
    • Added a new file containing extensive unit tests for the View component.
Activity
  • The pull request introduces unit tests for View.tsx covering auto-clear selection, Escape key behavior, embedded mode modal suppression, localStorage persistence for showAnalyze, embedConfig.showSimulationSummary overrides, and visualizer.idle toggling.
  • A detailed mocking strategy is outlined for useStoreState, Visualizer, antd components, child components, THREE.js, and localStorage.
  • The test plan confirms that npm test -- --run View passes all 17 tests and the full suite (npm test) passes all 250 tests with no regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of unit tests for the View.tsx component, which is a great addition for ensuring its stability and correctness. The tests are well-structured and cover a wide range of functionality.

The scope of this PR also includes the removal of a backend test feature, including its associated database model, API router, and Alembic migration file. While this cleanup is likely beneficial, it's worth noting that these backend changes are not mentioned in the pull request description. In particular, deleting a migration file (2da813b175f0_initial_test_schema.py) can break the migration history if it has been applied to any persistent database. Please ensure this is not the case.

I've added a few minor suggestions in the new test file to enhance type safety by replacing some instances of any with more specific types. Overall, this is a solid contribution.

Comprehensive tests covering:
- Auto-clear selection on simulation change (P0)
- Escape key clears selection (P1)
- Particle click handling (shift/plain/deselect)
- No simulation modal behaviour (embedded vs normal)
- localStorage persistence for showAnalyze
- Visualizer idle toggled by visible prop
- Responsive overlay initial state
@andeplane andeplane merged commit 8bfb836 into main Feb 26, 2026
2 checks passed
@andeplane andeplane deleted the feat/view-tests-276 branch February 26, 2026 12:47
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.

feat: Add unit tests for View.tsx component

1 participant