Skip to content

Commit

Permalink
test: add test in application form
Browse files Browse the repository at this point in the history
  • Loading branch information
AntBush committed Sep 23, 2024
1 parent 088154f commit 40e1ce8
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions app/tests/components/Form/ApplicationForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,68 @@ describe('The application form', () => {

expect(removeButton).toBeInTheDocument();
});

it('upload of template file', async () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent((data) => ({
application: data.application,
pageNumber: 11,
query: data.query,
}));

const file = new File([new ArrayBuffer(1)], 'file.xls', {
type: 'application/vnd.ms-excel',
});

global.fetch = jest.fn((url) => {
console.log(url, url.includes('templateNumber'));

Check warning

Code scanning / ESLint

Disallow the use of `console` Warning test

Unexpected console statement.
if (url.includes('templateNumber')) {
return Promise.resolve({
status: 300,
ok: false,
json: () => Promise.resolve({}),
});
}
return Promise.resolve({
status: 200,
ok: true,
json: () => Promise.resolve({}),
});
});

const addTemplateOneFileInput = screen.getAllByTestId('file-test')[0];

const addTemplateTwoFileInput = screen.getAllByTestId('file-test')[1];

await act(async () => {
fireEvent.change(addTemplateOneFileInput, { target: { files: [file] } });
});

await act(async () => {
fireEvent.change(addTemplateTwoFileInput, { target: { files: [file] } });
});

await act(async () => {
fireEvent.click(
screen.getByRole('button', { name: 'Save and continue' })
);
});

expect(global.fetch).toHaveBeenCalledWith(
'/api/email/notifyFailedReadOfTemplateData',
{
body: JSON.stringify({
applicationId: 42,
host: 'http://localhost',
params: {
templateNumber: 2,
},
}),
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
}
);
});
});

0 comments on commit 40e1ce8

Please sign in to comment.