diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionView.stories.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionView.stories.tsx new file mode 100644 index 0000000000..8f48c5cd91 --- /dev/null +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionView.stories.tsx @@ -0,0 +1,46 @@ +import { Meta, StoryObj } from "@storybook/react"; +import React from "react"; + +import { mockApplications } from "./mocks"; +import SubmissionsView from "./SubmissionsView"; + +const meta: Meta = { + title: "Design System/Molecules/SubmissionsView", + component: SubmissionsView, +}; + +type Story = StoryObj; + +export default meta; + +export const DefaultView: Story = { + render: () => ( + + ), +}; + +export const Loading: Story = { + render: () => ( + + ), +}; + +export const ErrorState: Story = { + render: () => ( + + ), +}; + +export const Empty: Story = { + render: () => ( + + ), +}; diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.test.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.test.tsx new file mode 100644 index 0000000000..a812d4c953 --- /dev/null +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.test.tsx @@ -0,0 +1,61 @@ +import { waitFor } from "@storybook/testing-library"; +import React from "react"; +import { axe, setup } from "testUtils"; + +import { mockApplications } from "./mocks"; +import SubmissionsView from "./SubmissionsView"; + +describe("SubmissionsView Component", () => { + test("displays the loading indicator when loading", async () => { + const { container, getByTestId } = setup( + , + ); + await waitFor(() => { + expect(getByTestId("delayed-loading-indicator")).toBeInTheDocument(); + }); + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); + + test("displays the error message when there is an error", async () => { + const errorMessage = "Test error message"; + const { container, getByText } = setup( + , + ); + expect(getByText(errorMessage)).toBeInTheDocument(); + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); + + test("displays a message when there are no applications", async () => { + const { container, getByText } = setup( + , + ); + expect( + getByText("No submitted applications found for this service."), + ).toBeInTheDocument(); + + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); + + test("displays the submissions table when there are applications", async () => { + const { container, getByText } = setup( + , + ); + mockApplications.forEach((app) => { + expect(getByText(app.sessionId)).toBeInTheDocument(); + }); + + const results = await axe(container); + expect(results).toHaveNoViolations(); + }); +}); diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.tsx index be0006150a..b6be849c31 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/SubmissionsView.tsx @@ -1,11 +1,10 @@ -import List from "@mui/material/List"; -import ListItem from "@mui/material/ListItem"; import Typography from "@mui/material/Typography"; import DelayedLoadingIndicator from "components/DelayedLoadingIndicator"; import ErrorFallback from "components/ErrorFallback"; import React from "react"; import { SubmissionData } from "./submissionData"; +import SubmissionsTable from "./SubmissionsTable"; interface SubmissionsViewProps { applications: SubmissionData[]; @@ -26,13 +25,7 @@ const SubmissionsView: React.FC = ({ No submitted applications found for this service. ); - return ( - - {applications.map((application, index) => ( - {application.sessionId} - ))} - - ); + return ; }; export default SubmissionsView;