-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.test.tsx
More file actions
101 lines (88 loc) · 2.8 KB
/
page.test.tsx
File metadata and controls
101 lines (88 loc) · 2.8 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
/**
* @jest-environment node
*/
import PreviewEmailTemplatePage from '@app/(email)/preview-email-template/[templateId]/page';
import { PreviewEmailTemplate } from '@forms/PreviewEmailTemplate';
import { EmailTemplate } from 'nhs-notify-web-template-management-utils';
import { redirect } from 'next/navigation';
import { getTemplate } from '@utils/form-actions';
import { TemplateDto } from 'nhs-notify-backend-client';
import {
EMAIL_TEMPLATE,
LETTER_TEMPLATE,
NHS_APP_TEMPLATE,
SMS_TEMPLATE,
} from '../../../helpers';
jest.mock('@utils/form-actions');
jest.mock('next/navigation');
jest.mock('@forms/PreviewEmailTemplate');
const redirectMock = jest.mocked(redirect);
const getTemplateMock = jest.mocked(getTemplate);
describe('PreviewEmailTemplatePage', () => {
beforeEach(jest.resetAllMocks);
it('should load page', async () => {
const templateDTO = {
id: 'template-id',
templateType: 'EMAIL',
templateStatus: 'NOT_YET_SUBMITTED',
name: 'template-name',
subject: 'template-subject-line',
message: 'template-message',
createdAt: '2025-01-13T10:19:25.579Z',
updatedAt: '2025-01-13T10:19:25.579Z',
} satisfies TemplateDto;
const emailTemplate: EmailTemplate = {
...templateDTO,
subject: 'template-subject-line',
templateType: 'EMAIL',
templateStatus: 'NOT_YET_SUBMITTED',
};
getTemplateMock.mockResolvedValueOnce(templateDTO);
const page = await PreviewEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(page).toEqual(<PreviewEmailTemplate initialState={emailTemplate} />);
});
it('should redirect to invalid-template when no templateId is found', async () => {
await PreviewEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});
test.each([
SMS_TEMPLATE,
NHS_APP_TEMPLATE,
LETTER_TEMPLATE,
{
...EMAIL_TEMPLATE,
name: undefined as unknown as string,
},
{
...EMAIL_TEMPLATE,
subject: undefined as unknown as string,
},
{
...EMAIL_TEMPLATE,
message: undefined as unknown as string,
},
{
...EMAIL_TEMPLATE,
message: null as unknown as string,
},
])(
'should redirect to invalid-template when template is $templateType and name is $emailTemplateName and subjectLine is $$emailTemplateSubjectLine and message is $emailTemplateMessage',
async (value) => {
getTemplateMock.mockResolvedValueOnce(value);
await PreviewEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
}
);
});