Skip to content

Commit ad0b0ee

Browse files
Fix unit tests
1 parent 87ce4d0 commit ad0b0ee

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

frontend/src/__tests__/components/forms/SubmitTemplate/SubmitTemplate.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jest.mock('@utils/amplify-utils');
55

66
jest.mock('@forms/SubmitTemplate/server-action', () => ({
77
submitTemplate: {
8-
bind: () => {},
8+
bind: () => '/action',
99
},
1010
}));
1111

frontend/src/__tests__/components/forms/SubmitTemplate/__snapshots__/SubmitTemplate.test.tsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ exports[`SubmitTemplate component should render 1`] = `
6262
<p>
6363
If you want to change a submitted template, you must create and submit a new template to replace it.
6464
</p>
65-
<form>
65+
<form
66+
action="/action"
67+
>
6668
<input
6769
name="form-id"
6870
readonly=""

frontend/src/__tests__/components/molecules/NHSNotifyFormWrapper.test.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import { mockDeep } from 'jest-mock-extended';
12
import { render } from '@testing-library/react';
2-
import { NHSNotifyFormWrapper } from '@molecules/NHSNotifyFormWrapper/NHSNotifyFormWrapper';
3+
import {
4+
NHSNotifyFormWrapper,
5+
csrfServerAction,
6+
} from '@molecules/NHSNotifyFormWrapper/NHSNotifyFormWrapper';
7+
8+
jest.mock('@utils/csrf-utils');
39

410
test('Renders back button', () => {
511
const container = render(
@@ -10,3 +16,23 @@ test('Renders back button', () => {
1016

1117
expect(container.asFragment()).toMatchSnapshot();
1218
});
19+
20+
describe('csrfServerAction', () => {
21+
test('string action', async () => {
22+
const action = csrfServerAction('/action');
23+
24+
expect(action).toEqual('/action');
25+
});
26+
27+
test('server action', async () => {
28+
const action = csrfServerAction(() => 'response');
29+
30+
if (typeof action === 'string') {
31+
throw new TypeError('Expected server action');
32+
}
33+
34+
const response = await action(mockDeep<FormData>());
35+
36+
expect(response).toEqual('response');
37+
});
38+
});

0 commit comments

Comments
 (0)