Skip to content

Commit 91152c4

Browse files
CCM-11537: Channel select template screens (#758)
1 parent 5235568 commit 91152c4

File tree

179 files changed

+11290
-1418
lines changed

Some content is hidden

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

179 files changed

+11290
-1418
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ lambdas/backend-api/src/email/email-template.json
9393
# vscode
9494
.vscode/settings.local.json
9595

96+
# github
97+
.github/copilot-instructions.md
98+
9699
test-runs

frontend/src/__tests__/app/choose-templates/__snapshots__/page.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ exports[`ChooseTemplatesPage renders correctly for a message plan with multiple
102102
class="nhsuk-u-margin-bottom-2"
103103
data-testid="template-name-NHSAPP"
104104
>
105-
name
105+
app template name
106106
</p>
107107
<ul
108108
class="channel-template-actions"
@@ -275,7 +275,7 @@ exports[`ChooseTemplatesPage renders correctly for a message plan with multiple
275275
class="nhsuk-u-margin-bottom-2"
276276
data-testid="template-name-SMS"
277277
>
278-
name
278+
sms template name
279279
</p>
280280
<ul
281281
class="channel-template-actions"
@@ -586,7 +586,7 @@ exports[`ChooseTemplatesPage renders correctly for a message plan with multiple
586586
class="nhsuk-u-margin-bottom-2"
587587
data-testid="template-name-LETTER"
588588
>
589-
name
589+
letter template name
590590
</p>
591591
<ul
592592
class="channel-template-actions"
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ChooseEmailTemplate page renders Email template selection 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-full"
15+
>
16+
<span
17+
class="nhsuk-caption-l"
18+
>
19+
Autumn Campaign Plan
20+
</span>
21+
<h1
22+
class="nhsuk-heading-l"
23+
>
24+
Choose an email template
25+
</h1>
26+
<form
27+
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().')"
28+
>
29+
<input
30+
name="form-id"
31+
readonly=""
32+
type="hidden"
33+
value="choose-channel-template"
34+
/>
35+
<input
36+
name="csrf_token"
37+
readonly=""
38+
type="hidden"
39+
value="no_token"
40+
/>
41+
<dl
42+
class="nhsuk-summary-list"
43+
data-testid="previous-selection-summary"
44+
>
45+
<div
46+
class="nhsuk-summary-list__row"
47+
>
48+
<dt
49+
class="nhsuk-summary-list__key"
50+
>
51+
Previously selected template
52+
</dt>
53+
<dd
54+
class="nhsuk-summary-list__value"
55+
>
56+
email template name
57+
</dd>
58+
</div>
59+
</dl>
60+
<div
61+
class="nhsuk-grid-row"
62+
>
63+
<div
64+
class="nhsuk-grid-column-full"
65+
>
66+
<div
67+
class="nhsuk-hint"
68+
>
69+
Choose one option
70+
</div>
71+
<div
72+
class="nhsuk-form-group"
73+
>
74+
<div
75+
class="nhsuk-radios"
76+
id="channelTemplate"
77+
>
78+
<table
79+
class="nhsuk-table-responsive"
80+
data-testid="channel-templates-table"
81+
id="channel-templates-table"
82+
>
83+
<thead
84+
class="nhsuk-table__head"
85+
role="rowgroup"
86+
>
87+
<tr
88+
class="nhsuk-table__row"
89+
>
90+
<th
91+
class="nhsuk-table__header"
92+
data-testid="channel-templates-table-header-template-select"
93+
scope="col"
94+
>
95+
Select
96+
</th>
97+
<th
98+
class="nhsuk-table__header"
99+
data-testid="channel-templates-table-header-template-name"
100+
scope="col"
101+
>
102+
Name
103+
</th>
104+
<th
105+
class="nhsuk-table__header"
106+
data-testid="channel-templates-table-header-template-type"
107+
scope="col"
108+
>
109+
Type
110+
</th>
111+
<th
112+
class="nhsuk-table__header"
113+
data-testid="channel-templates-table-header-template-last-edited"
114+
scope="col"
115+
>
116+
Last edited
117+
</th>
118+
<th
119+
class="nhsuk-table__header"
120+
data-testid="channel-templates-table-header-template-action"
121+
scope="col"
122+
/>
123+
</tr>
124+
</thead>
125+
<tbody
126+
class="nhsuk-table__body"
127+
>
128+
<tr
129+
class="nhsuk-table__row"
130+
>
131+
<td
132+
class="nhsuk-table__cell"
133+
role="cell"
134+
>
135+
<span
136+
aria-hidden="true"
137+
class="nhsuk-table-responsive__heading"
138+
>
139+
Select
140+
</span>
141+
<div
142+
class="nhsuk-radios__item"
143+
>
144+
<input
145+
checked=""
146+
class="nhsuk-radios__input"
147+
data-testid="email-template-id-radio"
148+
id="channelTemplate-email-template-id"
149+
name="channelTemplate"
150+
type="radio"
151+
value="email-template-id"
152+
/>
153+
<label
154+
class="nhsuk-label nhsuk-radios__label"
155+
for="channelTemplate-email-template-id"
156+
id="channelTemplate-email-template-id--label"
157+
>
158+
159+
</label>
160+
</div>
161+
</td>
162+
<td
163+
class="nhsuk-table__cell"
164+
role="cell"
165+
>
166+
<span
167+
aria-hidden="true"
168+
class="nhsuk-table-responsive__heading"
169+
>
170+
Name
171+
</span>
172+
email template name
173+
</td>
174+
<td
175+
class="nhsuk-table__cell"
176+
role="cell"
177+
>
178+
<span
179+
aria-hidden="true"
180+
class="nhsuk-table-responsive__heading"
181+
>
182+
Type
183+
</span>
184+
Email
185+
</td>
186+
<td
187+
class="nhsuk-table__cell"
188+
role="cell"
189+
>
190+
<span
191+
aria-hidden="true"
192+
class="nhsuk-table-responsive__heading"
193+
>
194+
Last edited
195+
</span>
196+
13th Jan 2025
197+
<br />
198+
10:19
199+
</td>
200+
<td
201+
class="nhsuk-table__cell"
202+
role="cell"
203+
>
204+
<span
205+
aria-hidden="true"
206+
class="nhsuk-table-responsive__heading"
207+
>
208+
209+
</span>
210+
<div
211+
class="actionLinksWrapper"
212+
>
213+
<a
214+
aria-label="Preview"
215+
data-testid="email-template-id-preview-link"
216+
href="/message-plans/choose-email-template/fbb81055-79b9-4759-ac07-d191ae57be34/preview-template/email-template-id"
217+
id="preview-template-link-0"
218+
>
219+
Preview
220+
</a>
221+
</div>
222+
</td>
223+
</tr>
224+
</tbody>
225+
</table>
226+
</div>
227+
</div>
228+
</div>
229+
</div>
230+
<div
231+
class="nhsuk-form-group"
232+
data-testid="channel-template-actions"
233+
>
234+
<button
235+
aria-disabled="false"
236+
class="nhsuk-button"
237+
data-testid="submit-button"
238+
id="channel-template-submit-button"
239+
type="submit"
240+
>
241+
Save and continue
242+
</button>
243+
<a
244+
class="nhsuk-u-font-size-19 inline-block nhsuk-u-margin-left-3 nhsuk-u-padding-top-3"
245+
href="/message-plans/choose-templates/fbb81055-79b9-4759-ac07-d191ae57be34"
246+
>
247+
Go back
248+
</a>
249+
</div>
250+
</form>
251+
</div>
252+
</div>
253+
</main>
254+
</DocumentFragment>
255+
`;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import ChooseEmailTemplate, {
2+
generateMetadata,
3+
} from '@app/message-plans/choose-email-template/[routingConfigId]/page';
4+
import { EMAIL_TEMPLATE, ROUTING_CONFIG } from '@testhelpers/helpers';
5+
import { render } from '@testing-library/react';
6+
import { getTemplates } from '@utils/form-actions';
7+
import { getRoutingConfig } from '@utils/message-plans';
8+
import { redirect } from 'next/navigation';
9+
10+
jest.mock('@utils/message-plans');
11+
jest.mock('@utils/form-actions');
12+
jest.mock('next/navigation');
13+
14+
const getRoutingConfigMock = jest.mocked(getRoutingConfig);
15+
const getTemplatesMock = jest.mocked(getTemplates);
16+
const redirectMock = jest.mocked(redirect);
17+
18+
describe('ChooseEmailTemplate page', () => {
19+
it('should redirect to invalid page with invalid routing config id', async () => {
20+
getRoutingConfigMock.mockResolvedValueOnce(undefined);
21+
22+
await ChooseEmailTemplate({
23+
params: Promise.resolve({
24+
routingConfigId: 'invalid-id',
25+
}),
26+
});
27+
28+
expect(getRoutingConfigMock).toHaveBeenCalledWith('invalid-id');
29+
30+
expect(redirectMock).toHaveBeenCalledWith(
31+
'/message-plans/invalid',
32+
'replace'
33+
);
34+
});
35+
36+
it('should redirect to invalid if plan has no email cascade entry', async () => {
37+
getRoutingConfigMock.mockResolvedValueOnce({
38+
...ROUTING_CONFIG,
39+
cascade: ROUTING_CONFIG.cascade.filter(
40+
(item) => item.channel !== 'EMAIL'
41+
),
42+
});
43+
44+
await ChooseEmailTemplate({
45+
params: Promise.resolve({
46+
routingConfigId: ROUTING_CONFIG.id,
47+
}),
48+
});
49+
50+
expect(getRoutingConfigMock).toHaveBeenCalledWith(ROUTING_CONFIG.id);
51+
52+
expect(redirectMock).toHaveBeenCalledWith(
53+
'/message-plans/invalid',
54+
'replace'
55+
);
56+
});
57+
58+
it('renders Email template selection', async () => {
59+
getRoutingConfigMock.mockResolvedValueOnce(ROUTING_CONFIG);
60+
getTemplatesMock.mockResolvedValueOnce([EMAIL_TEMPLATE]);
61+
62+
const page = await ChooseEmailTemplate({
63+
params: Promise.resolve({
64+
routingConfigId: ROUTING_CONFIG.id,
65+
}),
66+
});
67+
68+
const container = render(page);
69+
70+
expect(getRoutingConfigMock).toHaveBeenCalledWith(ROUTING_CONFIG.id);
71+
expect(getTemplatesMock).toHaveBeenCalledWith({
72+
templateType: 'EMAIL',
73+
});
74+
75+
expect(await generateMetadata()).toEqual({
76+
title: 'Choose an email template - NHS Notify',
77+
});
78+
expect(container.asFragment()).toMatchSnapshot();
79+
});
80+
});

0 commit comments

Comments
 (0)