diff --git a/client/src/components/combatlayer/CombatLayer.test.tsx b/client/src/components/combatlayer/CombatLayer.test.tsx new file mode 100644 index 00000000..46aa8d25 --- /dev/null +++ b/client/src/components/combatlayer/CombatLayer.test.tsx @@ -0,0 +1,48 @@ +import { renderWithProviders } from "../../testutils"; +import CombatLayer from "./CombatLayer"; +import { LatLng } from "leaflet"; +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); + }, +})); + +describe("CombatLayer", () => { + it("renders each combat", () => { + renderWithProviders(, { + preloadedState: { + combat: { + combat: { + foo: { + id: "foo", + flight_position: new LatLng(0, 0), + target_positions: [new LatLng(0, 1)], + footprint: null, + }, + bar: { + id: "foo", + flight_position: new LatLng(0, 0), + target_positions: [new LatLng(0, 1)], + footprint: null, + }, + }, + }, + }, + }); + expect(mockPolyline).toBeCalledTimes(2); + }); + + it("renders LayerGroup but no contents if no combat", () => { + renderWithProviders(); + expect(mockLayerGroup).toBeCalledTimes(1); + expect(mockPolyline).not.toHaveBeenCalled(); + }); +});