From 453343849f34d862234a772a93d9bc52396c897c Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 15 Jun 2023 22:14:37 -0700 Subject: [PATCH] Test Combat. --- client/src/components/combat/Combat.test.tsx | 132 +++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 client/src/components/combat/Combat.test.tsx diff --git a/client/src/components/combat/Combat.test.tsx b/client/src/components/combat/Combat.test.tsx new file mode 100644 index 00000000..888e7426 --- /dev/null +++ b/client/src/components/combat/Combat.test.tsx @@ -0,0 +1,132 @@ +import { renderWithProviders } from "../../testutils"; +import Combat from "./Combat"; +import { LatLng } from "leaflet"; + +const mockPolyline = jest.fn(); +const mockPolygon = jest.fn(); +jest.mock("react-leaflet", () => ({ + Polyline: (props: any) => { + mockPolyline(props); + }, + Polygon: (props: any) => { + mockPolygon(props); + }, +})); + +describe("Combat", () => { + describe("footprint", () => { + it("is not interactive", () => { + renderWithProviders( + + ); + expect(mockPolygon).toBeCalledWith( + expect.objectContaining({ interactive: false }) + ); + }); + + // Fails because we don't handle multi-poly combat footprints correctly. + it.skip("renders single polygons", () => { + const boundary = [new LatLng(0, 0), new LatLng(0, 1), new LatLng(1, 0)]; + renderWithProviders( + + ); + expect(mockPolygon).toBeCalledWith( + expect.objectContaining({ positions: boundary }) + ); + }); + + // Fails because we don't handle multi-poly combat footprints correctly. + it.skip("renders multiple polygons", () => { + const boundary = [new LatLng(0, 0), new LatLng(0, 1), new LatLng(1, 0)]; + renderWithProviders( + + ); + expect(mockPolygon).toBeCalledTimes(2); + }); + }); + + describe("lines", () => { + it("is not interactive", () => { + renderWithProviders( + + ); + expect(mockPolyline).toBeCalledWith( + expect.objectContaining({ interactive: false }) + ); + }); + + it("renders single line", () => { + renderWithProviders( + + ); + expect(mockPolyline).toBeCalledWith( + expect.objectContaining({ + positions: [new LatLng(0, 0), new LatLng(0, 1)], + }) + ); + }); + + it("renders multiple lines", () => { + renderWithProviders( + + ); + expect(mockPolyline).toBeCalledTimes(2); + }); + }); + + it("renders nothing if no footprint or targets", () => { + const { container } = renderWithProviders( + + ); + expect(container).toBeEmptyDOMElement(); + }); +});