generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
CCM-14583: Get ready to approve letter template #883
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
Open
bhansell1
wants to merge
9
commits into
main
Choose a base branch
from
feature/CCM-14583_user_approves_their_letter_template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f2dc755
CCM-14583: Empty page for the feature
m-salaudeen abdb796
trivvy
bhansell1 077ce73
CCM-14583: update page with content
bhansell1 afb1fcd
CCM-14583: tests
bhansell1 71140ae
lockfile
bhansell1 8be55bf
typing
bhansell1 f142503
CCM-14583: fix fallout from lintfix
bhansell1 f949db7
lockfile
bhansell1 e78bfdf
CCM-14583: lockfile
bhansell1 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
109 changes: 109 additions & 0 deletions
109
...d/src/__tests__/app/get-ready-to-approve-letter-template/__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,109 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`GetReadyToApproveLetterTemplatePage matches 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" | ||
| > | ||
| <span | ||
| class="nhsuk-caption-xl" | ||
| > | ||
| Step 1 of 2 | ||
| </span> | ||
| <h1 | ||
| class="nhsuk-heading-xl" | ||
| > | ||
| Get ready to approve 'authoring letter template name' | ||
| </h1> | ||
| <p | ||
| class="nhsuk-body-l" | ||
| > | ||
| After you approve this letter, you can use it in your message plans. | ||
| </p> | ||
| <h2 | ||
| class="nhsuk-heading-m" | ||
| id="before-you-approve" | ||
| > | ||
| Before you approve | ||
| </h2> | ||
| <p> | ||
| Make sure: | ||
| </p> | ||
| <ul> | ||
| <li> | ||
| the relevant stakeholders in your team have approved your letter template | ||
| </li> | ||
| <li> | ||
| your letter does not have any errors | ||
| </li> | ||
| </ul> | ||
| <h2 | ||
| class="nhsuk-heading-m" | ||
| id="personalisation" | ||
| > | ||
| Personalisation | ||
| </h2> | ||
| <p> | ||
| Longer personalisation data can affect the final number of pages and price of your letter. | ||
| </p> | ||
| <div | ||
| class="nhsuk-warning-callout" | ||
| > | ||
| <h3 | ||
| class="nhsuk-warning-callout__label" | ||
| > | ||
| Important | ||
| <span | ||
| class="nhsuk-u-visually-hidden" | ||
| > | ||
| : | ||
| </span> | ||
| </h3> | ||
| <p> | ||
| You cannot change your template settings after you approve this template. | ||
| </p> | ||
| <p> | ||
| If you need to make changes, edit your original template file on your computer then upload it as a new template. | ||
| </p> | ||
| </div> | ||
| <div | ||
| class="nhsuk-form-group" | ||
| > | ||
| <a | ||
| aria-disabled="false" | ||
| class="nhsuk-button" | ||
| data-testid="continue-link" | ||
| draggable="false" | ||
| href="/templates/review-and-approve-letter-template/authoring-letter-template-id" | ||
| role="button" | ||
| > | ||
| Continue | ||
| </a> | ||
| <a | ||
| aria-disabled="false" | ||
| class="nhsuk-button nhsuk-button--secondary nhsuk-u-margin-left-3" | ||
| data-testid="back-link" | ||
| draggable="false" | ||
| href="/templates/preview-letter-template/authoring-letter-template-id" | ||
| role="button" | ||
| > | ||
| Go back | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| </DocumentFragment> | ||
| `; |
109 changes: 109 additions & 0 deletions
109
frontend/src/__tests__/app/get-ready-to-approve-letter-template/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,109 @@ | ||
| import GetReadyToApproveLetterTemplatePage, { | ||
| generateMetadata, | ||
| } from '@app/get-ready-to-approve-letter-template/[templateId]/page'; | ||
| import { render } from '@testing-library/react'; | ||
| import pageContent from '@content/content'; | ||
| import { redirect } from 'next/navigation'; | ||
| import { getTemplate } from '@utils/form-actions'; | ||
| import { | ||
| EMAIL_TEMPLATE, | ||
| NHS_APP_TEMPLATE, | ||
| AUTHORING_LETTER_TEMPLATE, | ||
| SMS_TEMPLATE, | ||
| PDF_LETTER_TEMPLATE, | ||
| } from '@testhelpers/helpers'; | ||
|
|
||
| jest.mock('@utils/form-actions'); | ||
| jest.mock('next/navigation'); | ||
|
|
||
| const getTemplateMock = jest.mocked(getTemplate); | ||
| const redirectMock = jest.mocked(redirect); | ||
|
|
||
| const { | ||
| pageTitle, | ||
| continue: continueLink, | ||
| back, | ||
| } = pageContent.pages.getReadyToApproveLetterTemplate; | ||
|
|
||
| describe('GetReadyToApproveLetterTemplatePage', () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it('matches snapshot', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(AUTHORING_LETTER_TEMPLATE); | ||
|
|
||
| const page = render( | ||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: AUTHORING_LETTER_TEMPLATE.id, | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| const continueElement = page.getByRole('button', { | ||
| name: continueLink.text, | ||
| }); | ||
|
|
||
| expect(continueElement).toHaveAttribute( | ||
| 'href', | ||
| `/templates/review-and-approve-letter-template/${AUTHORING_LETTER_TEMPLATE.id}` | ||
| ); | ||
|
|
||
| const backLinkElement = page.getByRole('button', { name: back.text }); | ||
|
|
||
| expect(backLinkElement).toHaveAttribute( | ||
| 'href', | ||
| `/templates/preview-letter-template/${AUTHORING_LETTER_TEMPLATE.id}` | ||
| ); | ||
|
|
||
| expect(page.asFragment()).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should return metadata', async () => { | ||
| expect(await generateMetadata()).toEqual({ | ||
| title: pageTitle, | ||
| }); | ||
| }); | ||
|
|
||
| test.each([ | ||
| ['NHS_APP', NHS_APP_TEMPLATE], | ||
| ['SMS', SMS_TEMPLATE], | ||
| ['EMAIL', EMAIL_TEMPLATE], | ||
| ])('should redirect user when templateType is %s', async (_, template) => { | ||
| getTemplateMock.mockResolvedValueOnce(template); | ||
|
|
||
| render( | ||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: template.id, | ||
| }), | ||
| }) | ||
| ); | ||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should redirect to invalid template page when letter template is not a authoring template', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(PDF_LETTER_TEMPLATE); | ||
|
|
||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: PDF_LETTER_TEMPLATE.id, | ||
| }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should redirect to invalid template page when no template is found', async () => { | ||
| getTemplateMock.mockResolvedValueOnce(undefined); | ||
|
|
||
| await GetReadyToApproveLetterTemplatePage({ | ||
| params: Promise.resolve({ | ||
| templateId: 'template-id', | ||
| }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
| }); | ||
81 changes: 81 additions & 0 deletions
81
frontend/src/app/get-ready-to-approve-letter-template/[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,81 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { Metadata } from 'next'; | ||||||||||||||||||||||||||||||||||||||||||
| import { redirect, RedirectType } from 'next/navigation'; | ||||||||||||||||||||||||||||||||||||||||||
| import { TemplatePageProps } from 'nhs-notify-web-template-management-utils'; | ||||||||||||||||||||||||||||||||||||||||||
| import { ContentRenderer } from '@molecules/ContentRenderer/ContentRenderer'; | ||||||||||||||||||||||||||||||||||||||||||
| import { getTemplate } from '@utils/form-actions'; | ||||||||||||||||||||||||||||||||||||||||||
| import { interpolate } from '@utils/interpolate'; | ||||||||||||||||||||||||||||||||||||||||||
| import { NHSNotifyButton } from '@atoms/NHSNotifyButton/NHSNotifyButton'; | ||||||||||||||||||||||||||||||||||||||||||
| import { NHSNotifyContainer } from '@layouts/container/container'; | ||||||||||||||||||||||||||||||||||||||||||
| import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain'; | ||||||||||||||||||||||||||||||||||||||||||
| import content from '@content/content'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const pageContent = content.pages.getReadyToApproveLetterTemplate; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export async function generateMetadata(): Promise<Metadata> { | ||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||
| title: pageContent.pageTitle, | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| const GetReadyToApproveLetterTemplatePage = async ( | ||||||||||||||||||||||||||||||||||||||||||
| props: TemplatePageProps | ||||||||||||||||||||||||||||||||||||||||||
| ) => { | ||||||||||||||||||||||||||||||||||||||||||
| const { templateId } = await props.params; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const template = await getTemplate(templateId); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||
| !template || | ||||||||||||||||||||||||||||||||||||||||||
| template.templateType !== 'LETTER' || | ||||||||||||||||||||||||||||||||||||||||||
| template.letterVersion !== 'AUTHORING' | ||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||
| return redirect('/invalid-template', RedirectType.replace); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||
| <NHSNotifyContainer> | ||||||||||||||||||||||||||||||||||||||||||
| <NHSNotifyMain> | ||||||||||||||||||||||||||||||||||||||||||
| <div className='nhsuk-grid-row'> | ||||||||||||||||||||||||||||||||||||||||||
| <div className='nhsuk-grid-column-two-thirds'> | ||||||||||||||||||||||||||||||||||||||||||
| <span className='nhsuk-caption-xl'>{pageContent.stepCounter}</span> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <h1 className='nhsuk-heading-xl'> | ||||||||||||||||||||||||||||||||||||||||||
| {interpolate(pageContent.heading, { | ||||||||||||||||||||||||||||||||||||||||||
| templateName: template.name, | ||||||||||||||||||||||||||||||||||||||||||
| })} | ||||||||||||||||||||||||||||||||||||||||||
| </h1> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <ContentRenderer content={pageContent.body} /> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <div className='nhsuk-warning-callout'> | ||||||||||||||||||||||||||||||||||||||||||
| <h3 className='nhsuk-warning-callout__label'> | ||||||||||||||||||||||||||||||||||||||||||
| {pageContent.callout.label} | ||||||||||||||||||||||||||||||||||||||||||
| <span className='nhsuk-u-visually-hidden'>:</span> | ||||||||||||||||||||||||||||||||||||||||||
| </h3> | ||||||||||||||||||||||||||||||||||||||||||
| <ContentRenderer content={pageContent.callout.content} /> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <div className='nhsuk-form-group'> | ||||||||||||||||||||||||||||||||||||||||||
| <NHSNotifyButton | ||||||||||||||||||||||||||||||||||||||||||
| href={pageContent.continue.href(template.id)} | ||||||||||||||||||||||||||||||||||||||||||
| data-testid='continue-link' | ||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||
| {pageContent.continue.text} | ||||||||||||||||||||||||||||||||||||||||||
| </NHSNotifyButton> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <NHSNotifyButton | ||||||||||||||||||||||||||||||||||||||||||
| secondary | ||||||||||||||||||||||||||||||||||||||||||
| href={pageContent.back.href(template.id)} | ||||||||||||||||||||||||||||||||||||||||||
| className='nhsuk-u-margin-left-3' | ||||||||||||||||||||||||||||||||||||||||||
| data-testid='back-link' | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nitpick, ignore if you want but think it makes it more obvious its not the standard back link |
||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||
| {pageContent.back.text} | ||||||||||||||||||||||||||||||||||||||||||
| </NHSNotifyButton> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
| </NHSNotifyMain> | ||||||||||||||||||||||||||||||||||||||||||
| </NHSNotifyContainer> | ||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export default GetReadyToApproveLetterTemplatePage; | ||||||||||||||||||||||||||||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.