Skip to content

Commit 9f16470

Browse files
Merge pull request #164 from NHSDigital/feature/nhs-app-tests
CCM-7083: Add NHS App to submit template and template submitted tests
2 parents 2be0de8 + 0229ef9 commit 9f16470

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/app/submit-nhs-app-template/[sessionId]/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
import { redirect, RedirectType } from 'next/navigation';
44
import { SubmitTemplate } from '@forms/SubmitTemplate/SubmitTemplate';
5-
import { PageProps } from '@utils/types';
5+
import { PageProps, Session, TemplateType } from '@utils/types';
66
import { getSession } from '@utils/form-actions';
77

8+
const isValid = (session?: Session) =>
9+
session?.templateType === TemplateType.NHS_APP &&
10+
Boolean(session?.nhsAppTemplateName) &&
11+
Boolean(session?.nhsAppTemplateMessage);
12+
813
const SubmitNhsAppTemplatePage = async ({
914
params: { sessionId },
1015
}: PageProps) => {
1116
const session = await getSession(sessionId);
1217

13-
if (!session) {
18+
if (!session || !isValid(session)) {
1419
redirect('/invalid-session', RedirectType.replace);
1520
}
1621

tests/test-team/helpers/session-factory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export const SessionFactory = {
1515
});
1616
},
1717

18+
createNhsAppSession: (id: string): Session => {
19+
return SessionFactory.create({
20+
id,
21+
templateType: TemplateType.NHS_APP,
22+
});
23+
},
24+
1825
create: ({
1926
id,
2027
templateType,

tests/test-team/template-mgmt-component-tests/template-mgmt-submit-page.component.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const smsFields = {
3030
smsTemplateMessage: 'test-template-message',
3131
};
3232

33+
const nhsAppFields = {
34+
nhsAppTemplateName: 'test-template-name',
35+
nhsAppTemplateMessage: 'test-template-message',
36+
};
37+
3338
const sessions = {
3439
email: {
3540
empty: SessionFactory.createEmailSession('empty-email-submit-session'),
@@ -61,11 +66,29 @@ const sessions = {
6166
...smsFields,
6267
},
6368
},
69+
'nhs-app': {
70+
empty: SessionFactory.createNhsAppSession('empty-nhs-app-submit-session'),
71+
submit: {
72+
...SessionFactory.createNhsAppSession('submit-nhs-app-submit-session'),
73+
...nhsAppFields,
74+
},
75+
submitAndReturn: {
76+
...SessionFactory.createNhsAppSession(
77+
'submit-and-return-nhs-app-session'
78+
),
79+
...nhsAppFields,
80+
},
81+
valid: {
82+
...SessionFactory.createNhsAppSession('valid-nhs-app-submit-session'),
83+
...nhsAppFields,
84+
},
85+
},
6486
};
6587

6688
const sessionsList = [
6789
...Object.values(sessions.email),
6890
...Object.values(sessions['text-message']),
91+
...Object.values(sessions['nhs-app']),
6992
];
7093

7194
test.describe('Submit template Page', () => {
@@ -85,6 +108,7 @@ test.describe('Submit template Page', () => {
85108
for (const { channelName, channelIdentifier } of [
86109
{ channelName: 'Email', channelIdentifier: 'email' },
87110
{ channelName: 'SMS', channelIdentifier: 'text-message' },
111+
{ channelName: 'NHS App', channelIdentifier: 'nhs-app' },
88112
] as const) {
89113
test(`when user visits ${channelName} page, then page is loaded`, async ({
90114
page,

tests/test-team/template-mgmt-component-tests/template-mgmt-submitted-page.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { test, expect } from '@playwright/test';
22
import { TemplateStorageHelper } from '../helpers/template-storage-helper';
33
import {
44
assertFooterLinks,
5+
assertGoBackLinkNotPresent,
56
assertLoginLink,
67
assertNotifyBannerLink,
78
assertSkipToMainContent,
@@ -27,6 +28,14 @@ const templates = {
2728
content: 'test example content',
2829
},
2930
}),
31+
'nhs-app': TemplateFactory.create({
32+
type: TemplateType.NHS_APP,
33+
id: 'valid-nhs-app-template',
34+
name: 'test-template-nhs-app',
35+
fields: {
36+
content: 'test example content',
37+
},
38+
}),
3039
};
3140

3241
test.describe('Submit Email message template Page', () => {
@@ -45,6 +54,7 @@ test.describe('Submit Email message template Page', () => {
4554
for (const { channelName, channelIdentifier } of [
4655
{ channelName: 'Email', channelIdentifier: 'email' },
4756
{ channelName: 'SMS', channelIdentifier: 'text-message' },
57+
{ channelName: 'NHS App', channelIdentifier: 'nhs-app' },
4858
] as const) {
4959
test(`when user visits ${channelName} page, then page is loaded`, async ({
5060
page,
@@ -91,6 +101,7 @@ test.describe('Submit Email message template Page', () => {
91101
await assertNotifyBannerLink(props);
92102
await assertFooterLinks(props);
93103
await assertLoginLink(props);
104+
await assertGoBackLinkNotPresent(props);
94105
});
95106

96107
test(`when user submits clicks ${channelName} "Create another template", then user is redirected to "create-template"`, async ({

0 commit comments

Comments
 (0)