Skip to content

Commit f8068f1

Browse files
CCM-9066: Request Proof (#445)
Co-authored-by: Nicki Derrick <[email protected]>
1 parent a8f9eea commit f8068f1

File tree

97 files changed

+2756
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2756
-473
lines changed

frontend/src/__tests__/app/create-and-submit-templates/__snapshots__/page.test.tsx.snap

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,84 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`matches the snapshot 1`] = `
4+
<div>
5+
<main
6+
class="nhsuk-main-wrapper"
7+
id="maincontent"
8+
role="main"
9+
>
10+
<div
11+
class="nhsuk-grid-row"
12+
data-testid="page-content-wrapper"
13+
>
14+
<div
15+
class="nhsuk-grid-column-two-thirds"
16+
>
17+
<h1
18+
class="nhsuk-heading-xl"
19+
data-testid="page-heading"
20+
>
21+
Create and submit a template to NHS Notify
22+
</h1>
23+
<p>
24+
Use this tool to create and submit templates you want to send as messages using NHS Notify.
25+
</p>
26+
<p>
27+
You can create templates for:
28+
</p>
29+
<ul
30+
class="nhsuk-list nhsuk-list--bullet"
31+
>
32+
<li>
33+
NHS App messages
34+
</li>
35+
<li>
36+
emails
37+
</li>
38+
<li>
39+
text messages (SMS)
40+
</li>
41+
<li>
42+
letters
43+
</li>
44+
</ul>
45+
<p>
46+
When you submit a template, it will be used by NHS Notify to set up the messages you want to send.
47+
</p>
48+
<h2
49+
class="nhsuk-heading-l"
50+
data-testid="page-sub-heading"
51+
>
52+
Before you start
53+
</h2>
54+
<p>
55+
Only use this tool if your message content has been approved by the relevant stakeholders in your team.
56+
</p>
57+
<p>
58+
You can save a template as a draft and edit it later.
59+
</p>
60+
<p>
61+
If you want to change a submitted template, you must create a new template to replace it.
62+
</p>
63+
<p>
64+
You can access this tool by signing in with your Care Identity.
65+
</p>
66+
<a
67+
aria-disabled="false"
68+
class="nhsuk-button"
69+
draggable="false"
70+
href="/templates/message-templates"
71+
role="button"
72+
>
73+
Start now
74+
</a>
75+
</div>
76+
</div>
77+
</main>
78+
</div>
79+
`;
80+
81+
exports[`matches the snapshot with letters feature flag disabled 1`] = `
482
<div>
583
<main
684
class="nhsuk-main-wrapper"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import { render } from '@testing-library/react';
22
import HomePage from '@app/create-and-submit-templates/page';
33

4+
const OLD_ENV = { ...process.env };
5+
6+
beforeEach(() => {
7+
jest.resetAllMocks();
8+
process.env.NEXT_PUBLIC_ENABLE_LETTERS = 'true';
9+
});
10+
11+
afterAll(() => {
12+
process.env = OLD_ENV;
13+
});
14+
415
it('matches the snapshot', () => {
516
const { container } = render(<HomePage />);
617
expect(container).toMatchSnapshot();
718
});
19+
20+
it('matches the snapshot with letters feature flag disabled', () => {
21+
process.env.NEXT_PUBLIC_ENABLE_LETTERS = 'false';
22+
23+
const { container } = render(<HomePage />);
24+
expect(container).toMatchSnapshot();
25+
});
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
import RequestProofPage, {
5+
generateMetadata,
6+
} from '@app/request-proof-of-template/[templateId]/page';
7+
import { RequestProof } from '@forms/RequestProof/RequestProof';
8+
import { redirect } from 'next/navigation';
9+
import { getTemplate } from '@utils/form-actions';
10+
import { TemplateDto } from 'nhs-notify-backend-client';
11+
import {
12+
EMAIL_TEMPLATE,
13+
LETTER_TEMPLATE,
14+
NHS_APP_TEMPLATE,
15+
SMS_TEMPLATE,
16+
} from '../../helpers';
17+
import content from '@content/content';
18+
19+
const { pageTitle } = content.components.requestProof;
20+
21+
jest.mock('@utils/form-actions');
22+
jest.mock('next/navigation');
23+
jest.mock('@forms/RequestProof/RequestProof');
24+
25+
const getTemplateMock = jest.mocked(getTemplate);
26+
const redirectMock = jest.mocked(redirect);
27+
28+
describe('RequestProofPage', () => {
29+
beforeEach(jest.resetAllMocks);
30+
31+
test('should load page', async () => {
32+
const state = {
33+
id: 'template-id',
34+
templateType: 'LETTER',
35+
templateStatus: 'NOT_YET_SUBMITTED',
36+
name: 'template-name',
37+
letterType: 'x0',
38+
language: 'en',
39+
files: {
40+
pdfTemplate: {
41+
virusScanStatus: 'PASSED',
42+
currentVersion: 'a',
43+
fileName: 'a.pdf',
44+
},
45+
},
46+
} satisfies Partial<TemplateDto>;
47+
48+
getTemplateMock.mockResolvedValue({
49+
...state,
50+
createdAt: 'today',
51+
updatedAt: 'today',
52+
});
53+
54+
const page = await RequestProofPage({
55+
params: Promise.resolve({
56+
templateId: 'template-id',
57+
}),
58+
});
59+
60+
expect(await generateMetadata()).toEqual({
61+
title: pageTitle,
62+
});
63+
64+
expect(page).toEqual(
65+
<RequestProof
66+
templateName={state.name}
67+
templateId={state.id}
68+
channel='LETTER'
69+
/>
70+
);
71+
});
72+
73+
test('should handle invalid template', async () => {
74+
getTemplateMock.mockResolvedValue(undefined);
75+
76+
await RequestProofPage({
77+
params: Promise.resolve({
78+
templateId: 'template-id',
79+
}),
80+
});
81+
82+
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
83+
});
84+
85+
test.each([
86+
SMS_TEMPLATE,
87+
NHS_APP_TEMPLATE,
88+
EMAIL_TEMPLATE,
89+
{
90+
...LETTER_TEMPLATE,
91+
name: undefined as unknown as string,
92+
},
93+
])(
94+
'should redirect to invalid-template when template is $templateType and name is $name',
95+
async (value) => {
96+
getTemplateMock.mockResolvedValueOnce(value);
97+
98+
await RequestProofPage({
99+
params: Promise.resolve({
100+
templateId: 'template-id',
101+
}),
102+
});
103+
104+
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
105+
}
106+
);
107+
});

frontend/src/__tests__/app/submit-email-template/page.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ describe('SubmitEmailTemplatePage', () => {
5252
<SubmitDigitalTemplate
5353
templateName={state.name}
5454
templateId={state.id}
55-
goBackPath='preview-email-template'
56-
submitPath='email-template-submitted'
55+
channel='EMAIL'
5756
/>
5857
);
5958
});

frontend/src/__tests__/app/submit-letter-template/page.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ describe('SubmitLetterTemplatePage', () => {
4343
<SubmitLetterTemplate
4444
templateName={LETTER_TEMPLATE.name}
4545
templateId={LETTER_TEMPLATE.id}
46-
goBackPath='preview-letter-template'
47-
submitPath='letter-template-submitted'
4846
/>
4947
);
5048
});

frontend/src/__tests__/app/submit-nhs-app-template/page.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ describe('SubmitNhsAppTemplatePage', () => {
5656
<SubmitDigitalTemplate
5757
templateName={state.name}
5858
templateId={state.id}
59-
goBackPath='preview-nhs-app-template'
60-
submitPath='nhs-app-template-submitted'
59+
channel='NHS_APP'
6160
/>
6261
);
6362
});

frontend/src/__tests__/app/submit-text-message-template/page.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ describe('SubmitSmsTemplatePage', () => {
5656
<SubmitDigitalTemplate
5757
templateName={state.name}
5858
templateId={state.id}
59-
goBackPath='preview-text-message-template'
60-
submitPath='text-message-template-submitted'
59+
channel='SMS'
6160
/>
6261
);
6362
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { RequestProof } from '@forms/RequestProof/RequestProof';
2+
import { render } from '@testing-library/react';
3+
4+
jest.mock('@utils/amplify-utils');
5+
6+
jest.mock('react', () => {
7+
const originalModule = jest.requireActual('react');
8+
9+
return {
10+
...originalModule,
11+
useActionState: jest.fn((action, initialState) => {
12+
return [initialState, action];
13+
}),
14+
};
15+
});
16+
17+
jest.mock('@forms/RequestProof/server-action', () => ({
18+
requestTemplateProof: '/action',
19+
}));
20+
21+
describe('RequestProof component', () => {
22+
it('should render', () => {
23+
const container = render(
24+
<RequestProof
25+
templateId='template-id'
26+
templateName='template-name'
27+
channel='LETTER'
28+
/>
29+
);
30+
31+
expect(container.asFragment()).toMatchSnapshot();
32+
});
33+
});
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`RequestProof component should render 1`] = `
4+
<DocumentFragment>
5+
<main
6+
class="nhsuk-main-wrapper"
7+
id="maincontent"
8+
role="main"
9+
>
10+
<div
11+
class="nhsuk-grid-row"
12+
>
13+
<div
14+
class="nhsuk-grid-column-two-thirds"
15+
>
16+
<h1
17+
id="request-proof"
18+
>
19+
Request a proof of 'template-name'
20+
</h1>
21+
<h2
22+
class="nhsuk-heading-m"
23+
>
24+
Before you request a proof of this template
25+
</h2>
26+
<p>
27+
You should only request a proof of the final version of a template you’ve created. This means that your template:
28+
</p>
29+
<ul>
30+
<li>
31+
is approved by the relevant stakeholders in your team
32+
</li>
33+
<li>
34+
does not have any spelling errors
35+
</li>
36+
<li>
37+
is formatted correctly
38+
</li>
39+
</ul>
40+
<p>
41+
If your template uses personalisation, check that you’ve uploaded your example personalisation data.
42+
</p>
43+
<p>
44+
It can take 5 to 10 working days to get a proof of your template.
45+
</p>
46+
<form
47+
action="javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')"
48+
>
49+
<input
50+
name="form-id"
51+
readonly=""
52+
type="hidden"
53+
value="request-proof-form"
54+
/>
55+
<input
56+
name="csrf_token"
57+
readonly=""
58+
type="hidden"
59+
value="no_token"
60+
/>
61+
<input
62+
name="templateId"
63+
readonly=""
64+
type="hidden"
65+
value="template-id"
66+
/>
67+
<a
68+
aria-disabled="false"
69+
class="nhsuk-button nhsuk-button--secondary nhsuk-u-margin-right-3"
70+
draggable="false"
71+
href="/templates/preview-letter-template/template-id"
72+
id="go-back-button"
73+
role="button"
74+
>
75+
Go back
76+
</a>
77+
<button
78+
aria-disabled="false"
79+
class="nhsuk-button"
80+
id="request-proof-button"
81+
type="submit"
82+
>
83+
Request a proof
84+
</button>
85+
</form>
86+
</div>
87+
</div>
88+
</main>
89+
</DocumentFragment>
90+
`;

0 commit comments

Comments
 (0)