Skip to content

Commit

Permalink
test: PR feedback - better USRN tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 18, 2024
1 parent 44e449a commit e0dd5f8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { axe } from "vitest-axe";

import classifiedRoadsResponseMock from "./mocks/classifiedRoadsResponseMock";
import digitalLandResponseMock from "./mocks/digitalLandResponseMock";
import { simpleBreadcrumbs, simpleFlow } from "./mocks/simpleFlow";
import { breadcrumbsWithoutUSRN, simpleBreadcrumbs, simpleFlow } from "./mocks/simpleFlow";
import PlanningConstraints from "./Public";

const { setState } = useStore;

beforeEach(() => vi.clearAllMocks());

const swrMock = (swr as jest.Mock).mock;

vi.mock("swr", () => ({
Expand Down Expand Up @@ -66,9 +70,9 @@ describe("error state", () => {
});

describe("following a FindProperty component", () => {
beforeAll(() => {
beforeEach(() => {
act(() =>
useStore.setState({
setState({
breadcrumbs: simpleBreadcrumbs,
flow: simpleFlow,
teamIntegrations: {
Expand Down Expand Up @@ -134,7 +138,7 @@ describe("following a FindProperty component", () => {
expect(swrResponse).toEqual({ data: digitalLandResponseMock });
});

it("fetches classified roads only when we have a siteBoundary", () => {
it("fetches classified roads when a USRN is provided", () => {
setup(
<PlanningConstraints
title="Planning constraints"
Expand All @@ -155,6 +159,44 @@ describe("following a FindProperty component", () => {
expect(swrResponse).toEqual({ data: classifiedRoadsResponseMock });
});

it("does not fetch classified roads when a USRN is not provided", async () => {
act(() =>
setState({
breadcrumbs: breadcrumbsWithoutUSRN,
flow: simpleFlow,
teamIntegrations: {
hasPlanningData: true,
},
})
);

setup(
<PlanningConstraints
title="Planning constraints"
description="Things that might affect your project"
fn="property.constraints.planning"
disclaimer="This page does not include information about historic planning conditions that may apply to this property."
handleSubmit={vi.fn()}
/>,
);

expect(swr).toHaveBeenCalled();

// Planning constraints API still called
const planingConstraintsURL = swrMock.calls[0][0]();
const planingConstraintsResponse = swrMock.results[0].value;

expect(planingConstraintsURL).toContain("/gis");
expect(planingConstraintsResponse).toEqual({ data: digitalLandResponseMock });

// Classified roads API not called due to missing USRN
const swrURL = swrMock.calls[1][0]();
const swrResponse = swrMock.results[1].value;

expect(swrURL).toBeNull();
expect(swrResponse).toEqual({ data: null });
});

test("basic layout and interactions", async () => {
const { user, getByRole, queryByRole, getByTestId } = setup(
<PlanningConstraints
Expand Down Expand Up @@ -191,4 +233,4 @@ describe("following a FindProperty component", () => {
expect(negativeConstraintsContainer).toBeVisible();
expect(getByRole("heading", { name: /Ecology/ })).toBeVisible();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneDeep, merge } from "lodash";
import { Store } from "pages/FlowEditor/lib/store";

export const simpleFlow: Store.Flow = {
Expand Down Expand Up @@ -93,3 +94,5 @@ export const simpleBreadcrumbs: Store.Breadcrumbs = {
},
},
};

export const breadcrumbsWithoutUSRN = merge(cloneDeep(simpleBreadcrumbs), { findProperty: { data: { _address: { usrn: null }}}});

0 comments on commit e0dd5f8

Please sign in to comment.