generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-action.test.ts
More file actions
68 lines (55 loc) · 1.83 KB
/
server-action.test.ts
File metadata and controls
68 lines (55 loc) · 1.83 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
import { redirect } from 'next/navigation';
import { previewNhsAppTemplateAction } from '@forms/PreviewNHSAppTemplate';
import { getMockFormData } from '@testhelpers';
import {
NHSAppTemplate,
TemplateFormState,
} from 'nhs-notify-web-template-management-utils';
jest.mock('next/navigation');
const redirectMock = jest.mocked(redirect);
describe('previewNhsAppTemplateAction', () => {
const currentState: TemplateFormState<NHSAppTemplate> = {
id: 'template-id',
templateType: 'NHS_APP',
templateStatus: 'NOT_YET_SUBMITTED',
name: 'Example name',
message: 'Example message',
errorState: undefined,
createdAt: '2025-01-13T10:19:25.579Z',
updatedAt: '2025-01-13T10:19:25.579Z',
};
beforeEach(() => jest.clearAllMocks());
it('should return validation errors when no choice is selected', () => {
const formData = getMockFormData({});
const newState = previewNhsAppTemplateAction(currentState, formData);
expect(newState).toEqual({
...currentState,
errorState: {
fieldErrors: {
previewNHSAppTemplateAction: ['Select an option'],
},
formErrors: [],
},
});
});
it('should return submit page when submit action is chosen', () => {
const formData = getMockFormData({
previewNHSAppTemplateAction: 'nhsapp-submit',
});
previewNhsAppTemplateAction(currentState, formData);
expect(redirectMock).toHaveBeenCalledWith(
'/submit-nhs-app-template/template-id',
'push'
);
});
it('should return previous edit page when edit action is chosen', () => {
const formData = getMockFormData({
previewNHSAppTemplateAction: 'nhsapp-edit',
});
previewNhsAppTemplateAction(currentState, formData);
expect(redirectMock).toHaveBeenCalledWith(
'/edit-nhs-app-template/template-id',
'push'
);
});
});