Skip to content

Add comprehensive test suites for backend and frontend - #25

Merged
marota merged 1 commit into
mainfrom
claude/add-test-suite-CHl6G
Mar 1, 2026
Merged

marota merged 1 commit into
mainfrom
claude/add-test-suite-CHl6G

Conversation

@marota

@marota marota commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds extensive test coverage for both the backend FastAPI application and frontend React components, along with necessary test infrastructure and configuration.

Key Changes

Backend Testing

  • API Endpoint Tests (test_api_endpoints.py): Comprehensive test suite for all FastAPI endpoints using TestClient with mocked services, covering:

    • Branch and voltage level retrieval
    • Network and N-1 diagrams
    • Analysis execution with streaming NDJSON responses
    • Action variant diagrams and focused diagrams
    • Manual action simulation
    • Error handling and edge cases
  • Network Service Tests (test_network_service.py): Tests for network loading and querying:

    • File and directory loading with .xiidm and .xml support
    • Disconnectable elements retrieval
    • Voltage level and nominal voltage queries
    • Error handling for missing networks
  • Recommender Service Tests (test_compute_deltas.py): Tests for flow delta computation:

    • Delta calculation between network states
    • Categorization of deltas (positive, negative, grey)
    • Threshold-based filtering logic
  • Utility Tests (test_sanitize.py): Tests for JSON sanitization utility:

    • NumPy type conversion (int32, int64, float32, float64)
    • Array and nested structure handling
    • Dictionary key conversion and deep recursion
  • Test Infrastructure (conftest.py): Shared pytest fixtures and mocking:

    • Mock modules for unavailable domain packages (pypowsybl, expert_op4grid_recommender)
    • Mock network fixture with realistic test data
    • Mock network service fixture

Frontend Testing

  • API Client Tests (api.test.ts): Tests for axios-based API client:

    • Configuration updates
    • Data retrieval endpoints
    • Streaming response parsing (NDJSON)
    • Error handling
  • SVG Utilities Tests (svgUtils.test.ts): Tests for SVG processing:

    • ViewBox extraction and parsing
    • SVG optimization for large grids
    • Metadata indexing and querying
    • Action target line identification
  • Component Tests:

    • VisualizationPanel.test.tsx: Tab switching, diagram loading, zoom controls
    • OverloadPanel.test.tsx: Overload display and asset click handling

Configuration

  • pytest.ini: Pytest configuration for backend test discovery
  • vite.config.ts: Updated with Vitest configuration for frontend testing
  • frontend/package.json: Added test and test:watch scripts
  • frontend/src/test/setup.ts: Test environment setup for React Testing Library

Notable Implementation Details

  • Backend tests use unittest.mock to patch singleton services before app import, ensuring clean test isolation
  • Streaming response tests verify NDJSON format parsing with proper event type handling
  • Frontend tests use Vitest with React Testing Library for component testing
  • Mock modules are installed into sys.modules before production imports to handle unavailable domain packages in CI environments
  • Tests cover both happy paths and error scenarios with appropriate assertions

https://claude.ai/code/session_011cg6PjoX5hfQ1yNWRfmpv7

Backend (pytest, 80 tests):
- test_sanitize.py: sanitize_for_json with NumPy types, nested structures, edge cases
- test_compute_deltas.py: flow delta computation, threshold categorization, direction logic
- test_network_service.py: NetworkService load/query with mocked pypowsybl
- test_api_endpoints.py: all FastAPI endpoints via TestClient with mocked services
- conftest.py: module-level mocks for domain packages (pypowsybl, expert_op4grid_recommender)

Frontend (vitest + testing-library, 66 tests):
- svgUtils.test.ts: processSvg, boostSvgForLargeGrid, buildMetadataIndex,
  getActionTargetLines, getActionTargetVoltageLevel
- OverloadPanel.test.tsx: rendering, click callbacks, overload display
- VisualizationPanel.test.tsx: tab rendering, loading states, zoom controls,
  view mode toggle, convergence warnings
- api.test.ts: all API client methods, NDJSON streaming parser, error handling

https://claude.ai/code/session_011cg6PjoX5hfQ1yNWRfmpv7
@marota
marota merged commit 3fbb30f into main Mar 1, 2026
marota pushed a commit that referenced this pull request Apr 30, 2026
Rewrites Phase 1 from the abstract CHANGELOG summary into a six-week
chronology grounded in PR descriptions:

- 1.1 Bootstrap (pre-#1) — scaffolding pushed direct to main
- 1.2 End-to-end loop (PRs #1–#15) — NAD scaling, multi-tab pan/zoom,
  manual actions, action variants, action scoring, svgUtils + usePanZoom
- 1.3 UX maturation (PRs #16–#24) — settings panel, OverloadPanel,
  monitoring factor, action filters, state-switching SLDs
- 1.4 Robustness + CI (PRs #25–#46) — backend/frontend test suites,
  CircleCI + GitHub Actions, lazy loading, divergence UI
- 1.5 Persistence + complex actions (PRs #47–#56) — save/reload sessions,
  combined actions w/ persistence, islanding MW, App.tsx Phase 1 hooks
- 1.6 Two-step + replay logging + rebrand (PRs #57–#65) — split analysis,
  config.json persistence, load shedding, MW Start, SLD highlights,
  InteractionLogger, ExpertAssist → Co-Study4Grid

Sections 2–4 left untouched (will be reconciled in a follow-up).

https://claude.ai/code/session_01Pg7fuCUG2edfm5PyHS6SbN
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.

2 participants