From b3af8946c8611b94b1e98bf0af3c14d01821c1ac Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 14 Nov 2024 17:04:48 +0000 Subject: [PATCH] add unit tests and fix typo --- .../PlanningConstraints/Public.test.tsx | 46 ++++++++++++++++++- .../@planx/components/Send/Public.test.tsx | 42 +++++++++++++++++ .../src/@planx/components/Send/Public.tsx | 3 +- 3 files changed, 89 insertions(+), 2 deletions(-) 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 eb3e1e4a11..71581e46b6 100644 --- a/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/PlanningConstraints/Public.test.tsx @@ -40,7 +40,7 @@ vi.mock("swr", () => ({ })); describe("error state", () => { - it("renders an error if no addres is present in the passport", async () => { + it("renders an error if no address is present in the passport", async () => { const { getByRole, getByTestId } = setup( { expect(getByRole("heading", { name: /Ecology/ })).toBeVisible(); }); }); + +describe("demo state", () => { + beforeEach(() => { + act(() => + setState({ + breadcrumbs: simpleBreadcrumbs, + flow: simpleFlow, + teamIntegrations: { + hasPlanningData: true, + }, + teamSlug: "demo", + }), + ); + }); + it("should render an error when teamSlug is demo", async () => { + const handleSubmit = vi.fn(); + const { queryByText, queryByRole, user, getByTestId } = setup( + + + , + ); + + const errorMessage = queryByText( + "Planning Constraints are not enabled for demo users.", + ); + expect(errorMessage).toBeVisible(); + + // Check planning constraints has not rendered + expect( + queryByRole("heading", { name: "Planning constraints" }), + ).not.toBeInTheDocument(); + + // Ensure a demo user can continue on in the application + await user.click(getByTestId("continue-button")); + + expect(handleSubmit).toHaveBeenCalled(); + }); +}); diff --git a/editor.planx.uk/src/@planx/components/Send/Public.test.tsx b/editor.planx.uk/src/@planx/components/Send/Public.test.tsx index da34e1765b..7feb633b89 100644 --- a/editor.planx.uk/src/@planx/components/Send/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/Send/Public.test.tsx @@ -210,3 +210,45 @@ it("should not have any accessibility violations", async () => { const results = await axe(container); expect(results).toHaveNoViolations(); }); + +describe("demo state", () => { + beforeEach(() => { + act(() => + setState({ + teamSlug: "demo", + }), + ); + }); + it("should render an error when teamSlug is demo", async () => { + const { queryByText } = setup( + , + ); + + const errorHeader = queryByText( + "Send is not enabled for services created in the Demo team", + ); + const errorGuidance = queryByText( + "Click continue to skip send and proceed with your application for testing.", + ); + + expect(errorHeader).toBeInTheDocument(); + expect(errorGuidance).toBeInTheDocument(); + }); + it("should allow the user to continue with their application", async () => { + const handleSubmit = vi.fn(); + + const { findByRole, user } = setup( + , + ); + + const continueButton = await findByRole("button", { name: "Continue" }); + expect(continueButton).toBeInTheDocument(); + + await user.click(continueButton); + expect(handleSubmit).toHaveBeenCalled(); + }); +}); diff --git a/editor.planx.uk/src/@planx/components/Send/Public.tsx b/editor.planx.uk/src/@planx/components/Send/Public.tsx index 9676b98daf..0e76de5287 100644 --- a/editor.planx.uk/src/@planx/components/Send/Public.tsx +++ b/editor.planx.uk/src/@planx/components/Send/Public.tsx @@ -26,13 +26,14 @@ const SendComponent: React.FC = ({ destinations = [DEFAULT_DESTINATION], ...props }) => { + const teamSlug = useStore().teamSlug; const fullProps = { destinations: destinations, ...props }; if ( window.location.pathname.endsWith("/draft") || window.location.pathname.endsWith("/preview") ) { return ; - } else if (window.location.pathname.split("/")[1] === "demo") { + } else if (teamSlug === "demo") { return ; } else { return ;