-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test coverage for
index.tsx
as well as stories (#2910)
- Loading branch information
1 parent
79f0b3d
commit d98f07c
Showing
3 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
import { vanillaStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
|
||
import Submissions from "./index"; | ||
import { mockRequests } from "./mocks"; | ||
|
||
const { setState } = vanillaStore; | ||
setState({ flowSlug: "test-service", teamSlug: "test-team" }); | ||
|
||
const meta: Meta<typeof Submissions> = { | ||
title: "Design System/Molecules/Submissions", | ||
component: Submissions, | ||
}; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export default meta; | ||
|
||
export const DefaultView: Story = { | ||
render: () => ( | ||
<MockedProvider mocks={[mockRequests[0]]} addTypename={false}> | ||
<Submissions /> | ||
</MockedProvider> | ||
), | ||
}; | ||
|
||
export const LoadingState: Story = { | ||
render: () => ( | ||
<MockedProvider | ||
mocks={[{ ...mockRequests[0], delay: 2000 }]} | ||
addTypename={false} | ||
> | ||
<Submissions /> | ||
</MockedProvider> | ||
), | ||
}; | ||
|
||
export const ErrorState: Story = { | ||
render: () => ( | ||
<MockedProvider | ||
mocks={[{ ...mockRequests[0], error: new Error("An error occurred") }]} | ||
addTypename={false} | ||
> | ||
<Submissions /> | ||
</MockedProvider> | ||
), | ||
}; | ||
|
||
export const NoResults: Story = { | ||
render: () => ( | ||
<MockedProvider | ||
mocks={[ | ||
{ | ||
...mockRequests[0], | ||
result: { | ||
data: { | ||
submissionServicesSummary: [], | ||
}, | ||
}, | ||
}, | ||
]} | ||
addTypename={false} | ||
> | ||
<Submissions /> | ||
</MockedProvider> | ||
), | ||
}; |
85 changes: 85 additions & 0 deletions
85
editor.planx.uk/src/pages/FlowEditor/components/Settings/Submissions/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { waitFor } from "@testing-library/react"; | ||
import { vanillaStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
import { axe, setup } from "testUtils"; | ||
|
||
import Submissions from "./index"; | ||
import { mockApplications, mockRequests } from "./mocks"; | ||
|
||
const { setState } = vanillaStore; | ||
|
||
describe("Submissions Component", () => { | ||
test("no results message", async () => { | ||
setState({ flowSlug: "no-results-service", teamSlug: "test-team" }); | ||
const { container, getByText } = setup( | ||
<MockedProvider mocks={mockRequests} addTypename={false}> | ||
<Submissions /> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(getByText("Submissions")).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
"View data on the user submitted applications for this service.", | ||
), | ||
).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect( | ||
getByText("No submitted applications found for this service."), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
test("basic view table with expected values", async () => { | ||
setState({ flowSlug: "test-service", teamSlug: "test-team" }); | ||
const { container, getByText } = setup( | ||
<MockedProvider mocks={mockRequests} addTypename={false}> | ||
<Submissions /> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(getByText("Submissions")).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
"View data on the user submitted applications for this service.", | ||
), | ||
).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
mockApplications.forEach((app) => { | ||
expect(getByText(app.sessionId)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
test("error renders as expected", async () => { | ||
setState({ flowSlug: "error-service", teamSlug: "test-team" }); | ||
const { container, getByText } = setup( | ||
<MockedProvider mocks={mockRequests} addTypename={false}> | ||
<Submissions /> | ||
</MockedProvider>, | ||
); | ||
|
||
expect(getByText("Submissions")).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
"View data on the user submitted applications for this service.", | ||
), | ||
).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect(getByText("An error occurred")).toBeInTheDocument(); | ||
}); | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters