From 5f44a70c9713109801fac756905d78f829dbf65a Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Tue, 3 Dec 2024 11:36:21 +0100 Subject: [PATCH] don't reverse(), add tests --- .../components/Confirmation/Public.test.tsx | 6 +++++ .../components/shared/Preview/Card.test.tsx | 24 +++++++++++++++++++ .../@planx/components/shared/Preview/Card.tsx | 10 ++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/Confirmation/Public.test.tsx b/editor.planx.uk/src/@planx/components/Confirmation/Public.test.tsx index 5d98b00970..6439b92a99 100644 --- a/editor.planx.uk/src/@planx/components/Confirmation/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/Confirmation/Public.test.tsx @@ -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", +); diff --git a/editor.planx.uk/src/@planx/components/shared/Preview/Card.test.tsx b/editor.planx.uk/src/@planx/components/shared/Preview/Card.test.tsx index 949d8abe02..b7c40da8e8 100644 --- a/editor.planx.uk/src/@planx/components/shared/Preview/Card.test.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Preview/Card.test.tsx @@ -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"; @@ -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 =

Confirmation Page

; + setup(); + + 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 = ; diff --git a/editor.planx.uk/src/@planx/components/shared/Preview/Card.tsx b/editor.planx.uk/src/@planx/components/shared/Preview/Card.tsx index d49ad2c13a..de4372a8b8 100644 --- a/editor.planx.uk/src/@planx/components/shared/Preview/Card.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Preview/Card.tsx @@ -57,12 +57,10 @@ const Card: React.FC = ({ ]); // 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;