Skip to content

Commit 8d58fc9

Browse files
committed
fix: tests
1 parent 3ec0783 commit 8d58fc9

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/taxonomy/data/apiHooks.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('import taxonomy api calls', () => {
111111
});
112112

113113
it('should surface duplicate tag error returned as an array', async () => {
114-
const duplicateError = "Tag with value 'ab' already exists for taxonomy.";
114+
const duplicateError = 'Request failed with status code 400';
115115
axiosMock.onPost(apiUrls.createTag(1)).reply(400, [duplicateError]);
116116
const { result } = renderHook(() => useCreateTag(1), { wrapper });
117117

src/taxonomy/tag-list/TagListTable.test.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,17 @@ describe('<TagListTable />', () => {
587587
expect(screen.getByText(/invalid character/i)).toBeInTheDocument();
588588
});
589589

590-
it('should show an inline duplicate-name error when the entered root tag already exists', async () => {
591-
axiosMock.onPost(createTagUrl).reply(400, ['Tag with this name already exists']);
590+
it('should show failure feedback when creating a duplicate root tag name', async () => {
591+
axiosMock.onPost(createTagUrl).reply(() => {
592+
const error = new Error('Request failed with status code 400');
593+
error.name = 'AxiosError';
594+
error.response = {
595+
data: {
596+
tag: ['Tag with this name already exists'],
597+
},
598+
};
599+
return Promise.reject(error);
600+
});
592601

593602
fireEvent.click(await screen.findByLabelText('Create Tag'));
594603
const draftRow = await screen.findAllByRole('row');
@@ -598,12 +607,19 @@ describe('<TagListTable />', () => {
598607
fireEvent.change(input, { target: { value: 'root tag 1' } });
599608
fireEvent.click(saveButton);
600609

601-
expect(await screen.findByText('Tag with this name already exists')).toBeInTheDocument();
610+
expect(await screen.findByText('Error creating tag: Tag with this name already exists')).toBeInTheDocument();
602611
});
603612

604613
it('should keep the inline row and show a failure toast when save request fails', async () => {
605-
axiosMock.onPost(createTagUrl).reply(500, {
606-
error: 'Internal server error',
614+
axiosMock.onPost(createTagUrl).reply(() => {
615+
const error = new Error('Request failed with status code 500');
616+
error.name = 'AxiosError';
617+
error.response = {
618+
data: {
619+
tag: ['Internal server error'],
620+
},
621+
};
622+
return Promise.reject(error);
607623
});
608624

609625
fireEvent.click(await screen.findByLabelText('Create Tag'));

0 commit comments

Comments
 (0)