generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.test.tsx
More file actions
82 lines (65 loc) · 2.35 KB
/
page.test.tsx
File metadata and controls
82 lines (65 loc) · 2.35 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
/**
* @jest-environment node
*/
import EditEmailTemplatePage from '@app/edit-email-template/[templateId]/page';
import { getTemplate } from '@utils/form-actions';
import { redirect } from 'next/navigation';
import { EmailTemplateForm } from '@forms/EmailTemplateForm/EmailTemplateForm';
import { EmailTemplate } from 'nhs-notify-web-template-management-utils';
jest.mock('@utils/form-actions');
jest.mock('next/navigation');
jest.mock('@forms/EmailTemplateForm/EmailTemplateForm');
const getTemplateMock = jest.mocked(getTemplate);
const redirectMock = jest.mocked(redirect);
const template: EmailTemplate = {
id: 'template-id',
templateType: 'EMAIL',
templateStatus: 'NOT_YET_SUBMITTED',
name: 'name',
subject: 'subject',
message: 'message',
createdAt: '2025-01-13T10:19:25.579Z',
updatedAt: '2025-01-13T10:19:25.579Z',
};
describe('EditEmailTemplatePage', () => {
beforeEach(jest.resetAllMocks);
it('should redirect to invalid-template when no template is found', async () => {
getTemplateMock.mockResolvedValueOnce(undefined);
await EditEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(getTemplateMock).toHaveBeenCalledWith('template-id');
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});
it('should redirect to invalid-template when template type is not EMAIL', async () => {
getTemplateMock.mockResolvedValueOnce({
...template,
templateType: 'NHS_APP',
});
await EditEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(getTemplateMock).toHaveBeenCalledWith('template-id');
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});
it('should render CreateEmailTemplatePage component when template is found', async () => {
getTemplateMock.mockResolvedValueOnce(template);
const emailTemplate: EmailTemplate = {
...template,
subject: 'subject',
templateType: 'EMAIL' as const,
templateStatus: 'NOT_YET_SUBMITTED',
};
const page = await EditEmailTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(getTemplateMock).toHaveBeenCalledWith('template-id');
expect(page).toEqual(<EmailTemplateForm initialState={emailTemplate} />);
});
});