Skip to content

Fix the stale unit tests revealed by the jsdom/Vitest migration#153

Open
CarsonDavis wants to merge 2 commits into
tests-jsdomfrom
tests-stale-fixes
Open

Fix the stale unit tests revealed by the jsdom/Vitest migration#153
CarsonDavis wants to merge 2 commits into
tests-jsdomfrom
tests-stale-fixes

Conversation

@CarsonDavis

Copy link
Copy Markdown

What this does

Fixes the 9 stale unit tests that #150 (the Vitest + jsdom migration) left red by design. With the unit suite finally running, these previously-dead specs execute and fail — not because of the migration, but because they were written against older behavior and never ran to catch the drift. This brings them in line with the code's current behavior so the suite is honestly green.

Implements #149. Stacked on #150 (tests-jsdom).

Changes

Test content only — no production source changed.

  • 8 panel-manager specs asserted on a removed window.dispatchEvent. The app now broadcasts panel-layout changes over the in-app mitt event bus (mmgisAPI.emit('mmgis-panel-layout-changed', { panels })), so the old listener observed nothing. They now subscribe to the bus and assert the notification fires (and, where applicable, that the { panels } payload is present and sorted by priority). The shared __mocks__/mmgisAPI.js stub (added by Run unit tests in a jsdom environment via Vitest #150) is upgraded from a no-op to a real mitt() instance so specs can subscribe to it.
  • 1 validator spec over-asserted a required icon. Resolved deliberately: a tool icon is optional. getValidIconClass (ToolMetadataUtils.js) falls back to a default icon and only warns when one is missing, and the modern UI renders every tool through it — so the runtime tolerates a missing icon by design. The over-assertion is dropped and DashboardConfigValidator.js is left unchanged (keeping this a test-only PR).

The producer (PanelManager_.ts) is intentionally not changed — the mitt bus is the current, correct mechanism; reintroducing a window event would be the wrong fix.

Result

npx vitest run669 passed (38 files), 0 failures. The unit suite is fully green; combined with #150, CI's unit leg goes green once both land.

Notes for reviewers

Observe panel layout-changed notifications over the mitt event bus
instead of the removed window.dispatchEvent (8 panelManager specs), and
drop the over-asserted required-icon check in the dashboard config
validator spec. A tool icon is optional by design: getValidIconClass
falls back to a default when one is missing, so the validator correctly
does not require it. Test-only; no production source changes.
mockLayoutChangedEvents subscribed to the module-singleton mmgisAPI mitt
bus and relied on the caller's restore() to unsubscribe. Register the
teardown via vitest's onTestFinished so a spec that forgets restore()
cannot leak the handler across tests. restore() is kept for explicit use.
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.

1 participant