Skip to content

Conversation

@jbarson
Copy link
Owner

@jbarson jbarson commented Aug 12, 2025

This PR increases test coverage significantly.\n\nHighlights:\n- Add unit tests for MapStateImpl core functions (toggles, onWindowResize, controls change, animate, cleanup)\n- Add tests for app module wiring (DOMContentLoaded, slider + toggles)\n- Add data shape tests for jumpLinks and systemsList\n- Minor fixes to tests to satisfy ESLint and jsdom quirks\n\nResults:\n- 23 tests, all passing\n- High overall coverage (near 99% statements).\n\nNotes:\n- Optional follow-ups: raise branch coverage for mapState.ts and utils/dom.ts to 100% by adding a couple of focused tests.

…ata validation

- Introduced new test files for app module, jump links, map state, systems list, and utility functions.
- Implemented coverage reporting for tests using Vitest.
- Created mocks for dependencies to isolate tests and ensure predictable behavior.
- Validated data structures and ensured integrity of jump links and systems.
- Enhanced DOM manipulation tests to verify rendering logic and visibility toggling.
- Established utility tests for type validation and system ID management.
Copilot AI review requested due to automatic review settings August 12, 2025 16:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR significantly improves test coverage by adding comprehensive unit and integration tests for core application functionality. The addition targets MapStateImpl core functions, app module wiring, and data validation while achieving near 99% statement coverage.

Key changes:

  • Add unit tests for MapStateImpl core functions (toggles, window resize, controls, animation, cleanup)
  • Add integration tests for app module bootstrap with DOM event handling and UI controls
  • Add data shape validation tests for jumpLinks and systemsList modules

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scripts/utils/dom.test.ts Tests DOM builder functions for star and link elements with proper fallback behavior
scripts/types.test.ts Tests type utilities including system ID set building, data validation, and jump type mappings
scripts/systemsList.test.ts Validates system data structure integrity and unique ID constraints
scripts/mapState.unit.test.ts Unit tests for MapStateImpl with mocked Three.js controls and core functionality
scripts/mapState.int.test.ts Integration tests for MapStateImpl including label visibility based on camera distance
scripts/jumpLinks.test.ts Validates jump link data structure, year bounds, and prevents self-referential bridges
scripts/app.module.test.ts Tests app bootstrap process with mocked dependencies and UI event handling
package.json Adds coverage script and vitest coverage dependency

declare global {
var __testMapState: MapStateImplMock | undefined;
}

Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Using global variables for test state can lead to test pollution and coupling issues. Consider using a more controlled approach like returning the mock instance from the module or using a test context pattern.

Suggested change

Copilot uses AI. Check for mistakes.
const map = new MapStateImpl(systems, jumps);
const renderSpy = vi.spyOn(map, "render");
map.init();
// @ts-expect-error using mock helper
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The @ts-expect-error directive suppresses type checking for accessing the mock's trigger method. Consider typing the mock properly or using a more type-safe approach to avoid bypassing TypeScript's type safety.

Suggested change
// @ts-expect-error using mock helper

Copilot uses AI. Check for mistakes.
type LabelRefs = WeakMap<object, LabelEntry>;
const labelRefs = (map as unknown as { labelRefs: LabelRefs }).labelRefs;
const firstLabels = labelRefs.get(map.systems[0])!;
const secondLabels = labelRefs.get(map.systems[1])!;
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

Using type assertion to access private properties breaks encapsulation and makes tests brittle to implementation changes. Consider exposing a test-friendly method or using public APIs to verify the behavior.

Suggested change
const secondLabels = labelRefs.get(map.systems[1])!;
const firstLabels = map.getLabelEntry(map.systems[0])!;
const secondLabels = map.getLabelEntry(map.systems[1])!;

Copilot uses AI. Check for mistakes.
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