Skip to content

Commit

Permalink
add unit tests and fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 14, 2024
1 parent 6dd45b1 commit b3af894
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ErrorBoundary FallbackComponent={ErrorFallback}>
<PlanningConstraints
Expand Down Expand Up @@ -240,3 +240,47 @@ describe("following a FindProperty component", () => {
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(
<ErrorBoundary FallbackComponent={ErrorFallback}>
<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={handleSubmit}
/>
</ErrorBoundary>,
);

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();
});
});
42 changes: 42 additions & 0 deletions editor.planx.uk/src/@planx/components/Send/Public.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<SendComponent title="Send" destinations={["bops", "uniform"]} />,
);

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(
<SendComponent
title="Send"
destinations={["bops", "uniform"]}
handleSubmit={handleSubmit}
/>,
);

const continueButton = await findByRole("button", { name: "Continue" });
expect(continueButton).toBeInTheDocument();

await user.click(continueButton);
expect(handleSubmit).toHaveBeenCalled();
});
});
3 changes: 2 additions & 1 deletion editor.planx.uk/src/@planx/components/Send/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const SendComponent: React.FC<Props> = ({
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 <SkipSendWarning {...fullProps} />;
} else if (window.location.pathname.split("/")[1] === "demo") {
} else if (teamSlug === "demo") {
return <DemoTeamWarning {...fullProps} />;
} else {
return <CreateSendEvents {...fullProps} />;
Expand Down

0 comments on commit b3af894

Please sign in to comment.