-
Notifications
You must be signed in to change notification settings - Fork 0
Add aircraft fusion engine + fused live state (M3.1) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { act } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { TrackList } from "./TrackList"; | ||
| import { emptyState } from "../../state/liveState"; | ||
| import { useStore, type ProvenanceFilter } from "../../state/store"; | ||
| import type { TrackRecord } from "../../types/records"; | ||
|
|
||
| // jsdom client render: zustand's server snapshot is memoized at store creation, | ||
| // so renderToStaticMarkup would read stale empty state. The test environment is | ||
| // jsdom, so we render on a real DOM node and read innerHTML before unmounting. | ||
| (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = | ||
| true; | ||
|
|
||
| const NOW = "2026-06-15T00:00:00Z"; | ||
|
|
||
| function track( | ||
| id: string, | ||
| locally_received: boolean, | ||
| over: Partial<TrackRecord> = {}, | ||
| ): TrackRecord { | ||
| return { | ||
| schema_version: 2, | ||
| kind: "track", | ||
| id, | ||
| source: "demo", | ||
| observed_at: NOW, | ||
| received_at: NOW, | ||
| published_at: NOW, | ||
| correlation_key: id, | ||
| provenance: [], | ||
| tags: [], | ||
| attributes: {}, | ||
| track_type: "aircraft", | ||
| label: id, | ||
| geometry: { type: "Point", coordinates: [-95, 40] }, | ||
| altitude_m: null, | ||
| speed_mps: null, | ||
| heading_deg: null, | ||
| vertical_rate_mps: null, | ||
| locally_received, | ||
| classification: null, | ||
| valid_until: null, | ||
| predicted: false, | ||
| ...over, | ||
| }; | ||
| } | ||
|
|
||
| function setTracks(tracks: TrackRecord[], filter: ProvenanceFilter = "all") { | ||
| const live = emptyState(); | ||
| live.tracks = new Map(tracks.map((t) => [t.id, t])); | ||
| useStore.setState({ live, provenanceFilter: filter }); | ||
| } | ||
|
|
||
| /** Render TrackList against current store state and return its HTML. */ | ||
| function render(): string { | ||
| const el = document.createElement("div"); | ||
| const root = createRoot(el); | ||
| act(() => { | ||
| root.render(<TrackList />); | ||
| }); | ||
| const html = el.innerHTML; | ||
| act(() => { | ||
| root.unmount(); | ||
| }); | ||
| return html; | ||
| } | ||
|
|
||
| const FUSED = track("aircraft:icao:demo01", true, { | ||
| label: "DEMO-FUSE", | ||
| attributes: { | ||
| fusion: { | ||
| active_source: "local_adsb", | ||
| contributors: [ | ||
| { source: "demo", local_rf: true, observed_at: NOW, freshness: "live" }, | ||
| { source: "demo-net", local_rf: false, observed_at: NOW, freshness: "live" }, | ||
| ], | ||
| field_sources: { geometry: "demo", speed_mps: "demo-net" }, | ||
| field_freshness: { geometry: "live", speed_mps: "live" }, | ||
| last_local_rf_at: NOW, | ||
| fused_count: 2, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| describe("TrackList", () => { | ||
| beforeEach(() => { | ||
| useStore.setState({ live: emptyState(), provenanceFilter: "all" }); | ||
| }); | ||
| afterEach(() => { | ||
| useStore.setState({ live: emptyState(), provenanceFilter: "all" }); | ||
| }); | ||
|
|
||
| it("shows a contributor badge and LOCAL provenance for a fused track", () => { | ||
| setTracks([FUSED]); | ||
| const html = render(); | ||
| expect(html).toContain("×2"); // contributor badge for fused_count > 1 | ||
| expect(html).toContain("LOCAL"); // locally_received drives the prov badge | ||
| expect(html).toContain("DEMO-FUSE"); | ||
| }); | ||
|
|
||
| it("changes the N of M count when the provenance filter changes", () => { | ||
| const tracks = [track("a", true), track("b", false)]; | ||
| setTracks(tracks, "all"); | ||
| expect(render()).toContain("Tracks (2)"); | ||
|
|
||
| setTracks(tracks, "local"); | ||
| const localHtml = render(); | ||
| expect(localHtml).toContain("Tracks (1 of 2)"); | ||
| }); | ||
|
|
||
| it("renders a track with no fusion attributes without crashing", () => { | ||
| setTracks([track("plain", false)]); | ||
| const html = render(); | ||
| expect(html).toContain("NET"); | ||
| expect(html).not.toContain("×"); // no contributor badge | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a defensive check for
meta.contributorsbeing null or undefined. If a malformed track record is received wherecontributorsis missing, calling.map()directly will throw aTypeErrorand crash the React render tree.