diff --git a/client/src/components/cullingexclusionzones/CullingExclusionZones.test.tsx b/client/src/components/cullingexclusionzones/CullingExclusionZones.test.tsx new file mode 100644 index 00000000..3e78ae1c --- /dev/null +++ b/client/src/components/cullingexclusionzones/CullingExclusionZones.test.tsx @@ -0,0 +1,78 @@ +import { renderWithProviders } from "../../testutils"; +import CullingExclusionZones from "./CullingExclusionZones"; +import { PropsWithChildren } from "react"; + +const mockCircle = jest.fn(); +const mockLayerGroup = jest.fn(); +const mockLayerControlOverlay = jest.fn(); +jest.mock("react-leaflet", () => ({ + LayerGroup: (props: PropsWithChildren) => { + mockLayerGroup(props); + return <>{props.children}; + }, + LayersControl: { + Overlay: (props: PropsWithChildren) => { + mockLayerControlOverlay(props); + return <>{props.children}; + }, + }, + Circle: (props: any) => { + mockCircle(props); + }, +})); + +describe("CullingExclusionZones", () => { + it("is empty there are no exclusion zones", () => { + renderWithProviders(); + expect(mockCircle).not.toHaveBeenCalled(); + expect(mockLayerGroup).toHaveBeenCalledTimes(1); + expect(mockLayerControlOverlay).toHaveBeenCalledTimes(1); + }); + + describe("zone circles", () => { + it("are drawn in the correct locations", () => { + renderWithProviders(, { + preloadedState: { + unculledZones: { + zones: [ + { + position: { + lat: 0, + lng: 0, + }, + radius: 10, + }, + { + position: { + lat: 1, + lng: 1, + }, + radius: 2, + }, + ], + }, + }, + }); + expect(mockCircle).toHaveBeenCalledTimes(2); + expect(mockCircle).toHaveBeenCalledWith( + expect.objectContaining({ + center: { + lat: 0, + lng: 0, + }, + radius: 10, + }) + ); + expect(mockCircle).toHaveBeenCalledWith( + expect.objectContaining({ + center: { + lat: 1, + lng: 1, + }, + radius: 2, + }) + ); + }); + it("are not interactive", () => {}); + }); +}); diff --git a/client/src/components/cullingexclusionzones/CullingExclusionZones.tsx b/client/src/components/cullingexclusionzones/CullingExclusionZones.tsx index 8e8bc12d..6fe0cc8b 100644 --- a/client/src/components/cullingexclusionzones/CullingExclusionZones.tsx +++ b/client/src/components/cullingexclusionzones/CullingExclusionZones.tsx @@ -30,18 +30,10 @@ const CullingExclusionCircles = (props: CullingExclusionCirclesProps) => { export default function CullingExclusionZones() { const data = useAppSelector(selectUnculledZones).zones; - var cez = <>; - if (!data) { - console.log("Empty response when loading culling exclusion zones"); - } else { - cez = ( - - ); - } return ( - {cez} + ); }