diff --git a/client/src/components/flightplanslayer/FlightPlansLayer.test.tsx b/client/src/components/flightplanslayer/FlightPlansLayer.test.tsx new file mode 100644 index 00000000..8b2f6985 --- /dev/null +++ b/client/src/components/flightplanslayer/FlightPlansLayer.test.tsx @@ -0,0 +1,405 @@ +import { renderWithProviders } from "../../testutils"; +import FlightPlansLayer from "./FlightPlansLayer"; +import { PropsWithChildren } from "react"; + +const mockPolyline = jest.fn(); +const mockLayerGroup = jest.fn(); +jest.mock("react-leaflet", () => ({ + LayerGroup: (props: PropsWithChildren) => { + mockLayerGroup(props); + return <>{props.children}; + }, + Polyline: (props: any) => { + mockPolyline(props); + }, +})); + +// The waypoints in test data below should all use `should_make: false`. Markers +// need useMap() to check the zoom level to decide if they should be drawn or +// not, and we don't have good options here for mocking that behavior. +describe("FlightPlansLayer", () => { + describe("unselected flights", () => { + it("are drawn", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + bar: { + id: "bar", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: null, + }, + }, + }); + expect(mockPolyline).toHaveBeenCalledTimes(2); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + it("are not drawn if wrong coalition", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + bar: { + id: "bar", + blue: false, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: null, + }, + }, + }); + expect(mockPolyline).toHaveBeenCalledTimes(1); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + it("are not drawn when only selected flights are to be drawn", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: null, + }, + }, + }); + expect(mockPolyline).not.toHaveBeenCalled(); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + }); + describe("selected flights", () => { + it("are drawn", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + bar: { + id: "bar", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: "foo", + }, + }, + }); + expect(mockPolyline).toHaveBeenCalledTimes(2); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + it("are not drawn twice", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: true, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: "foo", + }, + }, + }); + expect(mockPolyline).toHaveBeenCalledTimes(1); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + it("are not drawn if red", () => { + renderWithProviders(, { + preloadedState: { + flights: { + flights: { + foo: { + id: "foo", + blue: false, + sidc: "", + waypoints: [ + { + name: "", + position: { + lat: 0, + lng: 0, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + { + name: "", + position: { + lat: 1, + lng: 1, + }, + altitude_ft: 0, + altitude_reference: "MSL", + is_movable: true, + should_mark: false, + include_in_path: true, + timing: "", + }, + ], + }, + }, + selected: "foo", + }, + }, + }); + expect(mockPolyline).not.toHaveBeenCalled(); + expect(mockLayerGroup).toBeCalledTimes(1); + }); + }); + it("are not drawn if there are no flights", () => { + renderWithProviders(); + expect(mockPolyline).not.toHaveBeenCalled(); + expect(mockLayerGroup).toBeCalledTimes(1); + }); +});