-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.test.tsx
More file actions
116 lines (103 loc) · 3.2 KB
/
page.test.tsx
File metadata and controls
116 lines (103 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @jest-environment node
*/
import ViewSubmittedNHSAppTemplatePage from '@app/(nhs-app)/view-submitted-nhs-app-template/[templateId]/page';
import { ViewNHSAppTemplate } from '@molecules/ViewNHSAppTemplate/ViewNHSAppTemplate';
import { NHSAppTemplate } from 'nhs-notify-web-template-management-utils';
import { getTemplate } from '@utils/form-actions';
import { redirect } from 'next/navigation';
import { TemplateDto } from 'nhs-notify-backend-client';
import {
EMAIL_TEMPLATE,
NHS_APP_TEMPLATE,
SMS_TEMPLATE,
} from '../../../helpers';
jest.mock('@utils/form-actions');
jest.mock('next/navigation');
const redirectMock = jest.mocked(redirect);
const getTemplateMock = jest.mocked(getTemplate);
describe('ViewSubmittedNHSAppTemplatePage', () => {
beforeEach(jest.resetAllMocks);
it('should load page', async () => {
const templateDTO = {
id: 'template-id',
templateType: 'NHS_APP',
templateStatus: 'SUBMITTED',
name: 'template-name',
message: 'template-message',
createdAt: '2025-01-13T10:19:25.579Z',
updatedAt: '2025-01-13T10:19:25.579Z',
} satisfies TemplateDto;
const submittedNHSAppTemplate: NHSAppTemplate = {
...templateDTO,
templateType: 'NHS_APP',
templateStatus: 'SUBMITTED',
};
getTemplateMock.mockResolvedValueOnce(templateDTO);
const page = await ViewSubmittedNHSAppTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(page).toEqual(
<ViewNHSAppTemplate initialState={submittedNHSAppTemplate} />
);
});
it('should redirect to invalid-template when no template is found', async () => {
await ViewSubmittedNHSAppTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});
test.each([
{
...EMAIL_TEMPLATE,
templateStatus: 'SUBMITTED' as const,
},
{
...SMS_TEMPLATE,
templateStatus: 'SUBMITTED' as const,
},
{
...NHS_APP_TEMPLATE,
message: undefined as unknown as string,
templateStatus: 'SUBMITTED' as const,
},
{
...NHS_APP_TEMPLATE,
name: undefined as unknown as string,
templateStatus: 'SUBMITTED' as const,
},
{
...NHS_APP_TEMPLATE,
name: null as unknown as string,
message: null as unknown as string,
templateStatus: 'SUBMITTED' as const,
},
{
...NHS_APP_TEMPLATE,
name: null as unknown as string,
message: null as unknown as string,
templateStatus: 'SUBMITTED' as const,
},
{
...NHS_APP_TEMPLATE,
name: 'template-name',
message: 'template-message',
templateStatus: 'NOT_YET_SUBMITTED' as const,
},
])(
'should redirect to invalid-template when template is $templateType, name is $name, message is $message, and status is $templateStatus',
async (value) => {
getTemplateMock.mockResolvedValueOnce(value);
await ViewSubmittedNHSAppTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
}
);
});