Skip to content

Commit 3c5d4e6

Browse files
committed
fix: tests
1 parent 400240c commit 3c5d4e6

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
@@ -598,8 +598,17 @@ describe('<TagListTable />', () => {
598598
expect(screen.getByText(/invalid character/i)).toBeInTheDocument();
599599
});
600600

601-
it('should show an inline duplicate-name error when the entered root tag already exists', async () => {
602-
axiosMock.onPost(createTagUrl).reply(400, ['Tag with this name already exists']);
601+
it('should show failure feedback when creating a duplicate root tag name', async () => {
602+
axiosMock.onPost(createTagUrl).reply(() => {
603+
const error = new Error('Request failed with status code 400');
604+
error.name = 'AxiosError';
605+
error.response = {
606+
data: {
607+
tag: ['Tag with this name already exists'],
608+
},
609+
};
610+
return Promise.reject(error);
611+
});
603612

604613
fireEvent.click(await screen.findByLabelText('Create Tag'));
605614
const draftRow = await screen.findAllByRole('row');
@@ -609,12 +618,19 @@ describe('<TagListTable />', () => {
609618
fireEvent.change(input, { target: { value: 'root tag 1' } });
610619
fireEvent.click(saveButton);
611620

612-
expect(await screen.findByText('Tag with this name already exists')).toBeInTheDocument();
621+
expect(await screen.findByText('Error creating tag: Tag with this name already exists')).toBeInTheDocument();
613622
});
614623

615624
it('should keep the inline row and show a failure toast when save request fails', async () => {
616-
axiosMock.onPost(createTagUrl).reply(500, {
617-
error: 'Internal server error',
625+
axiosMock.onPost(createTagUrl).reply(() => {
626+
const error = new Error('Request failed with status code 500');
627+
error.name = 'AxiosError';
628+
error.response = {
629+
data: {
630+
tag: ['Internal server error'],
631+
},
632+
};
633+
return Promise.reject(error);
618634
});
619635

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

0 commit comments

Comments
 (0)