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
81 lines (64 loc) · 2.34 KB
/
page.test.tsx
File metadata and controls
81 lines (64 loc) · 2.34 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
/**
* @jest-environment node
*/
import EditSmsTemplatePage from '@app/edit-text-message-template/[templateId]/page';
import { getTemplate } from '@utils/form-actions';
import { redirect } from 'next/navigation';
import { SmsTemplateForm } from '@forms/SmsTemplateForm/SmsTemplateForm';
import { TemplateDto } from 'nhs-notify-backend-client';
import { SMSTemplate } from 'nhs-notify-web-template-management-utils';
jest.mock('@utils/form-actions');
jest.mock('next/navigation');
jest.mock('@forms/SmsTemplateForm/SmsTemplateForm');
const getTemplateMock = jest.mocked(getTemplate);
const redirectMock = jest.mocked(redirect);
const templateDTO = {
id: 'template-id',
templateType: 'SMS',
templateStatus: 'NOT_YET_SUBMITTED',
name: 'name',
message: 'message',
createdAt: '2025-01-13T10:19:25.579Z',
updatedAt: '2025-01-13T10:19:25.579Z',
} satisfies TemplateDto;
describe('EditSmsTemplatePage', () => {
beforeEach(jest.resetAllMocks);
it('should redirect to invalid-template when no templateId is found', async () => {
getTemplateMock.mockResolvedValueOnce(undefined);
await EditSmsTemplatePage({
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 SMS', async () => {
getTemplateMock.mockResolvedValueOnce({
...templateDTO,
templateType: 'NHS_APP',
});
await EditSmsTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(getTemplateMock).toHaveBeenCalledWith('template-id');
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});
it('should render CreateSmsTemplate component when templateId is found', async () => {
getTemplateMock.mockResolvedValueOnce(templateDTO);
const smsTemplate: SMSTemplate = {
...templateDTO,
templateType: 'SMS',
templateStatus: 'NOT_YET_SUBMITTED',
};
const page = await EditSmsTemplatePage({
params: Promise.resolve({
templateId: 'template-id',
}),
});
expect(getTemplateMock).toHaveBeenCalledWith('template-id');
expect(page).toEqual(<SmsTemplateForm initialState={smsTemplate} />);
});
});