diff --git a/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx b/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx index 8646fbd0de..431d701fe3 100644 --- a/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx @@ -16,6 +16,7 @@ import { simpleBreadcrumbs, simpleFlow, } from "./mocks/simpleFlow"; +import { availableDatasets } from "./model"; import PlanningConstraints from "./Public"; const { setState } = useStore; @@ -259,6 +260,86 @@ describe("following a FindProperty component", () => { }); }); +describe("selectable datasets in editor", () => { + beforeEach(() => { + act(() => + setState({ + breadcrumbs: simpleBreadcrumbs, + flow: simpleFlow, + teamIntegrations: { + hasPlanningData: true, + }, + }), + ); + }); + + it("does not initiate `/roads` request when `road.classified` is not selected by an editor", async () => { + setup( + d.val !== "road.classified") + .map((d) => d.val)} + />, + ); + + expect(swr).toHaveBeenCalled(); + + // Planning constraints API still called + const planingConstraintsURL = ( + vi.mocked(useSWR).mock.calls[0][0] as () => {} + )(); + const planingConstraintsResponse = vi.mocked(useSWR).mock.results[0].value; + + expect(planingConstraintsURL).toContain("/gis"); + expect(planingConstraintsResponse).toEqual({ + data: digitalLandResponseMock, + }); + + // Roads API not called due to missing `road.classified` data value + const roadsURL = (vi.mocked(useSWR).mock.calls[1][0] as () => {})(); + const roadsResponse = vi.mocked(useSWR).mock.results[1].value; + + expect(roadsURL).toBeNull(); + expect(roadsResponse).toEqual({ data: null }); + }); + + it("does not initiate `/gis/:localAuthority` request when only `road.classified` is selected by an editor", async () => { + setup( + , + ); + + expect(swr).toHaveBeenCalled(); + + // Roads API is called + const roadsURL = (vi.mocked(useSWR).mock.calls[1][0] as () => {})(); + const roadsResponse = vi.mocked(useSWR).mock.results[1].value; + + expect(roadsURL).toContain("/roads"); + expect(roadsResponse).toEqual({ data: classifiedRoadsResponseMock }); + + // Planning constraints API not called due to missing data values + const planingConstraintsURL = ( + vi.mocked(useSWR).mock.calls[0][0] as () => {} + )(); + const planningConstraintsResponse = vi.mocked(useSWR).mock.results[0].value; + + expect(planingConstraintsURL).toBeNull(); + expect(planningConstraintsResponse).toEqual({ data: null }); + }); +}); + describe("demo state", () => { beforeEach(() => { act(() =>