From 647d1f57f90f47c6495c8f2af78ee49666dce971 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 15 Jun 2023 22:24:18 -0700 Subject: [PATCH] Add tests for CombatLayer. --- .../combatlayer/CombatLayer.test.tsx | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 client/src/components/combatlayer/CombatLayer.test.tsx 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(); + }); +});