Skip to content

Commit

Permalink
test(story): add chromatic story to ensure thankyou page renders
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui authored and KenLSM committed Oct 15, 2024
1 parent d14477e commit 85bfc04
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
42 changes: 42 additions & 0 deletions frontend/src/features/public-form/PublicFormPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { envHandlers } from '~/mocks/msw/handlers/env'
import {
getPublicFormErrorResponse,
getPublicFormResponse,
getPublicFormSubmissionSuccessResponse,
getPublicFormWithoutSectionsResponse,
postGenerateVfnOtpResponse,
postVerifyVfnOtpResponse,
postVfnTransactionResponse,
Expand Down Expand Up @@ -790,6 +792,7 @@ FormNotFoundMobile.parameters = {
}

export const WithMyInfo = Template.bind({})
WithMyInfo.storyName = 'With MyInfo'
WithMyInfo.parameters = {
msw: [
getPublicFormResponse({
Expand Down Expand Up @@ -821,3 +824,42 @@ WithPayment.parameters = {
...DEFAULT_MSW_HANDLERS,
],
}

export const ThankYouPage = Template.bind({})
ThankYouPage.parameters = {
msw: [
getPublicFormWithoutSectionsResponse(),
getPublicFormSubmissionSuccessResponse(),
...DEFAULT_MSW_HANDLERS,
],
}
ThankYouPage.play = async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(async () => {
await expect(canvas.getByText(/yes\/no/i)).toBeInTheDocument
})
await waitFor(async () => {
const noQuestionChoice = canvas.getByRole('button', {
name: /1\. yes\/no no option, unselected/i,
})
await userEvent.click(noQuestionChoice)
})
await waitFor(
async () => {
await userEvent.click(canvas.getByRole('button', { name: /submit/i }))
},
{
timeout: 5000,
},
)
await waitFor(
async () => {
await expect(
canvas.getByRole('link', { name: /submit another form/i }),
).toBeInTheDocument()
},
{
timeout: 5000,
},
)
}
18 changes: 18 additions & 0 deletions frontend/src/mocks/msw/handlers/public-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ export const getPublicFormWithoutSectionsResponse = ({
)
}

export const getPublicFormSubmissionSuccessResponse = (
type: 'email' | 'storage' = 'email',
) => {
return rest.post(
`/api/v3/forms/:formId/submissions/${type}`,
(_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
message: 'Form submission successful.',
submissionId: '6625dfd68f4364af26332097',
timestamp: 1713758166140,
}),
)
},
)
}

export const getPublicFormErrorResponse = ({
delay = 0,
status = 404,
Expand Down

0 comments on commit 85bfc04

Please sign in to comment.