Skip to content

Commit

Permalink
don't reverse(), add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Dec 3, 2024
1 parent 9afebe9 commit 5f44a70
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ it("should not have any accessibility violations", async () => {
const results = await axe(container);
expect(results).toHaveNoViolations();
});

it.todo("should hide the 'Continue' button if it's the final card in the flow");

it.todo(
"should show the 'Continue' button if it is not the final card in the flow",
);
24 changes: 24 additions & 0 deletions editor.planx.uk/src/@planx/components/shared/Preview/Card.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Button from "@mui/material/Button";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { act, screen, waitFor } from "@testing-library/react";
import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import React from "react";
Expand Down Expand Up @@ -50,6 +51,29 @@ describe("Card component", () => {
expect(screen.queryByText(saveButtonText)).not.toBeInTheDocument();
});

it("hides the Save/Resume option if the user has already passed Send", () => {
act(() =>
setState({
path: ApplicationPath.SaveAndReturn,
flow: {
_root: { edges: ["Send", "Confirmation", "Feedback", "Notice"] },
Send: { type: TYPES.Send },
Confirmation: { type: TYPES.Confirmation },
Feedback: { type: TYPES.Feedback },
Notice: { type: TYPES.Notice },
},
breadcrumbs: { Send: { auto: false } },
}),
);
const children = <h1>Confirmation Page</h1>;
setup(<Card handleSubmit={handleSubmit} children={children}></Card>);

expect(screen.queryByText("Confirmation Page")).toBeInTheDocument();
expect(screen.queryByText("Continue")).toBeInTheDocument();
expect(screen.queryByText(resumeButtonText)).not.toBeInTheDocument();
expect(screen.queryByText(saveButtonText)).not.toBeInTheDocument();
});

it("updates state to navigate to the 'Resume' page if the 'Resume' button is clicked", async () => {
act(() => setState({ path: ApplicationPath.SaveAndReturn }));
const children = <Button>Testing 123</Button>;
Expand Down
10 changes: 4 additions & 6 deletions editor.planx.uk/src/@planx/components/shared/Preview/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ const Card: React.FC<Props> = ({
]);

// Check if we have a Send node in our breadcrumbs
// This is a better/more immediate proxy for "Submitted" because actual send events that populate lowcal_sessions.submitted_at are queued via Hasura
const hasSent = Object.keys(breadcrumbs)
.reverse()
.some(
(breadcrumbNodeId: string) => flow[breadcrumbNodeId]?.type === TYPES.Send,
);
// This is a better/more immediate proxy for "submitted" in the frontend because actual send events that populate lowcal_sessions.submitted_at are queued via Hasura
const hasSent = Object.keys(breadcrumbs).some(
(breadcrumbNodeId: string) => flow[breadcrumbNodeId]?.type === TYPES.Send,
);

const showSaveResumeButton =
path === ApplicationPath.SaveAndReturn && handleSubmit && !hasSent;
Expand Down

0 comments on commit 5f44a70

Please sign in to comment.