-
Notifications
You must be signed in to change notification settings - Fork 1
CCM-14754: approval confirmation #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5e9cc4
init
alexnuttall 6b5ff71
tests
alexnuttall 4fc178c
add renders to factory template
alexnuttall 2c5f11e
cleanup
alexnuttall e0e9726
move selector to page obj
alexnuttall e03d999
use default login user in test
alexnuttall 22ed006
add renders in acessibility test
alexnuttall 29b1a23
fast-xml cve
alexnuttall a1865ad
component test status
alexnuttall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
frontend/src/__tests__/app/letter-template-approved/__snapshots__/page.test.tsx.snap
This file contains hidden or 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,67 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`LetterTemplateApprovedPage should render page and match snapshot 1`] = ` | ||
| <DocumentFragment> | ||
| <div | ||
| class="nhsuk-width-container" | ||
| > | ||
| <main | ||
| class="nhsuk-main-wrapper" | ||
| id="maincontent" | ||
| role="main" | ||
| > | ||
| <div | ||
| class="nhsuk-grid-row" | ||
| > | ||
| <div | ||
| class="nhsuk-grid-column-two-thirds" | ||
| > | ||
| <div | ||
| class="notify-confirmation-panel" | ||
| > | ||
| <h1 | ||
| class="nhsuk-heading-l nhsuk-u-margin-bottom-0" | ||
| id="template-submitted" | ||
| > | ||
| Letter template approved | ||
| </h1> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <dl> | ||
| <dt | ||
| class="nhsuk-heading-xs nhsuk-u-margin-top-4 nhsuk-u-margin-bottom-1" | ||
| > | ||
| Template name | ||
| </dt> | ||
| <dd | ||
| class="nhsuk-body-s nhsuk-u-margin-left-0" | ||
| data-testid="template-name" | ||
| > | ||
| authoring letter template name | ||
| </dd> | ||
| </dl> | ||
| <p> | ||
| You can now use this letter in your | ||
| <a | ||
| data-testid="message-plans-link" | ||
| href="/templates/message-plans" | ||
| > | ||
| message plans | ||
| </a> | ||
| . | ||
| </p> | ||
| <p> | ||
| Or go back to your | ||
| <a | ||
| data-testid="templates-link" | ||
| href="/templates/message-templates" | ||
| > | ||
| templates | ||
| </a> | ||
| . | ||
| </p> | ||
| </main> | ||
| </div> | ||
| </DocumentFragment> | ||
| `; |
108 changes: 108 additions & 0 deletions
108
frontend/src/__tests__/app/letter-template-approved/page.test.tsx
This file contains hidden or 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,108 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { getTemplate } from '@utils/form-actions'; | ||
| import { | ||
| AUTHORING_LETTER_TEMPLATE, | ||
| EMAIL_TEMPLATE, | ||
| NHS_APP_TEMPLATE, | ||
| PDF_LETTER_TEMPLATE, | ||
| SMS_TEMPLATE, | ||
| } from '@testhelpers/helpers'; | ||
| import Page, { | ||
| generateMetadata, | ||
| } from '@app/letter-template-approved/[templateId]/page'; | ||
| import { redirect } from 'next/navigation'; | ||
|
|
||
| jest.mock('@utils/form-actions'); | ||
| jest.mock('next/navigation'); | ||
|
|
||
| const getTemplateMock = jest.mocked(getTemplate); | ||
| const redirectMock = jest.mocked(redirect); | ||
|
|
||
| describe('LetterTemplateApprovedPage', () => { | ||
| beforeEach(jest.resetAllMocks); | ||
|
|
||
| test('should render page and match snapshot', async () => { | ||
| getTemplateMock.mockResolvedValueOnce({ | ||
| ...AUTHORING_LETTER_TEMPLATE, | ||
| templateStatus: 'PROOF_APPROVED', | ||
| }); | ||
|
|
||
| const { asFragment } = render( | ||
| await Page({ | ||
| params: Promise.resolve({ templateId: 'template-id' }), | ||
| }) | ||
| ); | ||
|
|
||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('should generate page title', async () => { | ||
| expect(await generateMetadata()).toEqual({ | ||
| title: 'Letter template approved - NHS Notify', | ||
| }); | ||
| }); | ||
|
|
||
| test('should render page with expected links', async () => { | ||
| getTemplateMock.mockResolvedValueOnce({ | ||
| ...AUTHORING_LETTER_TEMPLATE, | ||
| templateStatus: 'PROOF_APPROVED', | ||
| }); | ||
|
|
||
| render( | ||
| await Page({ | ||
| params: Promise.resolve({ templateId: 'template-id' }), | ||
| }) | ||
| ); | ||
|
|
||
| const messagePlansLink = screen.getByRole('link', { | ||
| name: 'message plans', | ||
| }); | ||
|
|
||
| expect(messagePlansLink).toHaveAttribute( | ||
| 'href', | ||
| '/templates/message-plans' | ||
| ); | ||
|
|
||
| const templatesLink = screen.getByRole('link', { name: 'templates' }); | ||
|
|
||
| expect(templatesLink).toHaveAttribute( | ||
| 'href', | ||
| '/templates/message-templates' | ||
| ); | ||
| }); | ||
|
|
||
| test.each([ | ||
| { case: 'undefined', value: undefined }, | ||
| { case: 'EMAIL', value: EMAIL_TEMPLATE }, | ||
| { case: 'SMS', value: SMS_TEMPLATE }, | ||
| { case: 'NHS_APP', value: NHS_APP_TEMPLATE }, | ||
| { case: 'PDF LETTER', value: PDF_LETTER_TEMPLATE }, | ||
| ])( | ||
| 'should redirect to /invalid-template when template is $case', | ||
| async ({ value }) => { | ||
| getTemplateMock.mockResolvedValueOnce(value); | ||
|
|
||
| await Page({ | ||
| params: Promise.resolve({ templateId: 'template-id' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| } | ||
| ); | ||
|
|
||
| test('should redirect to /preview-letter-template when templateStatus is not PROOF_APPROVED', async () => { | ||
| getTemplateMock.mockResolvedValueOnce({ | ||
| ...AUTHORING_LETTER_TEMPLATE, | ||
| templateStatus: 'NOT_YET_SUBMITTED', | ||
| }); | ||
|
|
||
| await Page({ | ||
| params: Promise.resolve({ templateId: 'template-id' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith( | ||
| '/preview-letter-template/template-id', | ||
| 'replace' | ||
| ); | ||
| }); | ||
| }); |
78 changes: 78 additions & 0 deletions
78
frontend/src/app/letter-template-approved/[templateId]/page.tsx
This file contains hidden or 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,78 @@ | ||
| 'use server'; | ||
|
|
||
| import { | ||
| TemplatePageProps, | ||
| validateLetterTemplate, | ||
| } from 'nhs-notify-web-template-management-utils'; | ||
| import { getTemplate } from '@utils/form-actions'; | ||
| import { redirect, RedirectType } from 'next/navigation'; | ||
| import content from '@content/content'; | ||
| import { Metadata } from 'next'; | ||
| import { NHSNotifyContainer } from '@layouts/container/container'; | ||
| import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain'; | ||
| import { ContentRenderer } from '@molecules/ContentRenderer/ContentRenderer'; | ||
| import { getBasePath } from '@utils/get-base-path'; | ||
|
|
||
| const { title, bannerText, nameLabel, doNext } = | ||
| content.pages.letterTemplateApproved; | ||
|
|
||
| export async function generateMetadata(): Promise<Metadata> { | ||
| return { | ||
| title, | ||
| }; | ||
| } | ||
|
|
||
| const LetterTemplateApprovedPage = async (props: TemplatePageProps) => { | ||
| const { templateId } = await props.params; | ||
|
|
||
| const template = await getTemplate(templateId); | ||
|
|
||
| const validatedTemplate = validateLetterTemplate(template); | ||
|
|
||
| if (!validatedTemplate || validatedTemplate.letterVersion !== 'AUTHORING') { | ||
| return redirect('/invalid-template', RedirectType.replace); | ||
| } | ||
|
|
||
| if (validatedTemplate.templateStatus !== 'PROOF_APPROVED') { | ||
| return redirect( | ||
| `/preview-letter-template/${templateId}`, | ||
| RedirectType.replace | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <NHSNotifyContainer> | ||
| <NHSNotifyMain> | ||
| <div className='nhsuk-grid-row'> | ||
| <div className='nhsuk-grid-column-two-thirds'> | ||
| <div className='notify-confirmation-panel'> | ||
| <h1 | ||
| id='template-submitted' | ||
| className='nhsuk-heading-l nhsuk-u-margin-bottom-0' | ||
| > | ||
| {bannerText} | ||
| </h1> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <dl> | ||
| <dt className='nhsuk-heading-xs nhsuk-u-margin-top-4 nhsuk-u-margin-bottom-1'> | ||
| {nameLabel} | ||
| </dt> | ||
| <dd | ||
| data-testid='template-name' | ||
| className='nhsuk-body-s nhsuk-u-margin-left-0' | ||
| > | ||
| {validatedTemplate.name} | ||
| </dd> | ||
| </dl> | ||
| <ContentRenderer | ||
| content={doNext} | ||
| variables={{ basePath: getBasePath() }} | ||
| /> | ||
| </NHSNotifyMain> | ||
| </NHSNotifyContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default LetterTemplateApprovedPage; | ||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.