-
Notifications
You must be signed in to change notification settings - Fork 4
CCM-8409: Email send confirmation screen #971
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
ClareJonesBJSS
wants to merge
10
commits into
main
Choose a base branch
from
feature/CCM-8409_email-send-confirmation
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
10 commits
Select commit
Hold shift + click to select a range
7f84a7f
CCM-8409: Email send confirmation screen
ClareJonesBJSS 6f86520
Vale
ClareJonesBJSS c009a0b
Merge commit '42656d9f6ae7afd653212e70899170825e448e4e' into feature/…
ClareJonesBJSS b2cfd4d
Merge commit 'f14e03baa98ec7f006fe8dd737d52dbf3f79908c' into feature/…
ClareJonesBJSS 7e630fd
Code review comments
ClareJonesBJSS 563db13
Type amendment
ClareJonesBJSS e61aee7
Merge commit '63978454c13cd6d5e94665d03d7ef27bac164552' into feature/…
ClareJonesBJSS 489d691
Code review
ClareJonesBJSS 6f8223e
Don't check for submitted template
ClareJonesBJSS 903f530
Merge commit '29c577bf7345c4bff42f0020cfc7063cc2aa8c48' into feature/…
ClareJonesBJSS 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
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
54 changes: 54 additions & 0 deletions
54
...pp/test-email-message-sent/[proofingRequestId]/__tests__/__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,54 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`TestEmailMessageSentPage should 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="nhsuk-panel" | ||
| > | ||
| <h1 | ||
| class="nhsuk-heading-l nhsuk-u-margin-bottom-0" | ||
| data-testid="banner-heading" | ||
| > | ||
| Test email sent | ||
| </h1> | ||
| <p> | ||
| We've sent a test email to | ||
| <br /> | ||
| <strong> | ||
| test@example.com | ||
| </strong> | ||
| </p> | ||
| <p> | ||
| Your test email will come from | ||
| <strong> | ||
| NHS Notify - test | ||
| </strong> | ||
| </p> | ||
| </div> | ||
| <a | ||
| class="nhsuk-link" | ||
| data-testid="back-to-template-link" | ||
| href="/preview-email-template/email-template-id" | ||
| > | ||
| Back to template | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| </DocumentFragment> | ||
| `; |
102 changes: 102 additions & 0 deletions
102
frontend/src/app/test-email-message-sent/[proofingRequestId]/__tests__/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,102 @@ | ||
| import TestEmailMessageSentPage, { | ||
| generateMetadata, | ||
| } from '@app/test-email-message-sent/[proofingRequestId]/page'; | ||
| import { getProofingRequest } from '@utils/form-actions'; | ||
| import { fetchClient } from '@utils/server-features'; | ||
| import { redirect } from 'next/navigation'; | ||
| import { render } from '@testing-library/react'; | ||
| import { makeProofRequest } from '@testhelpers/helpers'; | ||
| import content from '@content/content'; | ||
|
|
||
| const { pageTitle, bannerHeading, backLink } = | ||
| content.pages.testEmailMessageSentPage; | ||
|
|
||
| jest.mock('@utils/form-actions'); | ||
| jest.mock('@utils/server-features'); | ||
| jest.mock('next/navigation'); | ||
|
|
||
| const getProofingRequestMock = jest.mocked(getProofingRequest); | ||
| const redirectMock = jest.mocked(redirect); | ||
| const fetchClientMock = jest.mocked(fetchClient); | ||
|
|
||
| describe('TestEmailMessageSentPage', () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| fetchClientMock.mockResolvedValue({ | ||
| features: { digitalProofingEmail: true }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should generate correct metadata', async () => { | ||
| const metadata = await generateMetadata(); | ||
|
|
||
| expect(metadata).toEqual({ title: pageTitle }); | ||
| }); | ||
|
|
||
| it('should render the page with email address from proofing request', async () => { | ||
| getProofingRequestMock.mockResolvedValueOnce(makeProofRequest()); | ||
|
|
||
| const page = await TestEmailMessageSentPage({ | ||
| params: Promise.resolve({ proofingRequestId: 'proof-request-id' }), | ||
| }); | ||
| const { getByTestId, getByText } = render(page); | ||
|
|
||
| expect(getProofingRequestMock).toHaveBeenCalledWith('proof-request-id'); | ||
| expect(redirectMock).not.toHaveBeenCalled(); | ||
| expect(getByTestId('banner-heading')).toHaveTextContent(bannerHeading); | ||
| expect(getByText('test@example.com')).toBeInTheDocument(); | ||
| expect(getByText(/NHS Notify - test/)).toBeInTheDocument(); | ||
| expect(getByTestId('back-to-template-link')).toHaveAttribute( | ||
| 'href', | ||
| '/preview-email-template/email-template-id' | ||
| ); | ||
| expect(getByTestId('back-to-template-link')).toHaveTextContent( | ||
| backLink.text | ||
| ); | ||
| }); | ||
|
|
||
| it('should redirect to message-templates when digitalProofingEmail is disabled', async () => { | ||
| fetchClientMock.mockResolvedValueOnce({ | ||
| features: { digitalProofingEmail: false }, | ||
| }); | ||
|
|
||
| await TestEmailMessageSentPage({ | ||
| params: Promise.resolve({ proofingRequestId: 'proof-request-id' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/message-templates', 'replace'); | ||
| expect(getProofingRequestMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should redirect to message-templates when client is null', async () => { | ||
| fetchClientMock.mockResolvedValueOnce(null); | ||
|
|
||
| await TestEmailMessageSentPage({ | ||
| params: Promise.resolve({ proofingRequestId: 'proof-request-id' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/message-templates', 'replace'); | ||
| expect(getProofingRequestMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should redirect to invalid-template when proofing request is not found', async () => { | ||
| getProofingRequestMock.mockResolvedValueOnce(undefined); | ||
|
|
||
| await TestEmailMessageSentPage({ | ||
| params: Promise.resolve({ proofingRequestId: 'not-found' }), | ||
| }); | ||
|
|
||
| expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); | ||
| }); | ||
|
|
||
| it('should match snapshot', async () => { | ||
| getProofingRequestMock.mockResolvedValueOnce(makeProofRequest()); | ||
|
|
||
| const page = await TestEmailMessageSentPage({ | ||
| params: Promise.resolve({ proofingRequestId: 'proof-request-id' }), | ||
| }); | ||
| const { asFragment } = render(page); | ||
|
|
||
| expect(asFragment()).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
79 changes: 79 additions & 0 deletions
79
frontend/src/app/test-email-message-sent/[proofingRequestId]/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,79 @@ | ||
| 'use server'; | ||
|
|
||
| import { Metadata } from 'next'; | ||
| import { redirect, RedirectType } from 'next/navigation'; | ||
| import { getProofingRequest } from '@utils/form-actions'; | ||
| import { fetchClient } from '@utils/server-features'; | ||
| import { NHSNotifyContainer } from '@layouts/container/container'; | ||
| import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain'; | ||
| import Link from 'next/link'; | ||
| import content from '@content/content'; | ||
| import { ContentRenderer } from '@molecules/ContentRenderer/ContentRenderer'; | ||
| import { interpolate } from '@utils/interpolate'; | ||
|
|
||
| const { pageTitle, bannerHeading, bannerBody, backLink } = | ||
| content.pages.testEmailMessageSentPage; | ||
|
|
||
| export async function generateMetadata(): Promise<Metadata> { | ||
| return { | ||
| title: pageTitle, | ||
| }; | ||
| } | ||
|
|
||
| type TestEmailMessageSentPageProps = { | ||
| params: Promise<{ proofingRequestId: string }>; | ||
| }; | ||
|
|
||
| const TestEmailMessageSentPage = async ( | ||
| props: TestEmailMessageSentPageProps | ||
| ) => { | ||
| const { proofingRequestId } = await props.params; | ||
|
|
||
| const client = await fetchClient(); | ||
|
|
||
| if (!client?.features.digitalProofingEmail) { | ||
| return redirect('/message-templates', RedirectType.replace); | ||
| } | ||
|
|
||
| const proofingRequest = await getProofingRequest(proofingRequestId); | ||
|
|
||
| if (!proofingRequest) { | ||
| return redirect('/invalid-template', RedirectType.replace); | ||
| } | ||
|
|
||
| return ( | ||
| <NHSNotifyContainer> | ||
| <NHSNotifyMain> | ||
| <div className='nhsuk-grid-row'> | ||
| <div className='nhsuk-grid-column-two-thirds'> | ||
| <div className='nhsuk-panel'> | ||
| <h1 | ||
| className='nhsuk-heading-l nhsuk-u-margin-bottom-0' | ||
| data-testid='banner-heading' | ||
| > | ||
| {bannerHeading} | ||
| </h1> | ||
| <ContentRenderer | ||
| content={bannerBody} | ||
| variables={{ | ||
| contactDetail: proofingRequest.contactDetailValue.trim(), | ||
| }} | ||
| /> | ||
| </div> | ||
| <Link | ||
| href={interpolate(backLink.href, { | ||
| templateId: proofingRequest.templateId, | ||
| })} | ||
| data-testid='back-to-template-link' | ||
| className='nhsuk-link' | ||
| > | ||
| {backLink.text} | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| </NHSNotifyMain> | ||
| </NHSNotifyContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default TestEmailMessageSentPage; |
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.