mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
useEditFolder: Fix and improve tests
This commit is contained in:
parent
d73beb0eeb
commit
c684bc73d4
@ -25,7 +25,7 @@ console.error = jest.fn().mockImplementation();
|
|||||||
jest.mock('../../utils', () => ({
|
jest.mock('../../utils', () => ({
|
||||||
...jest.requireActual('../../utils'),
|
...jest.requireActual('../../utils'),
|
||||||
axiosInstance: {
|
axiosInstance: {
|
||||||
put: jest.fn().mockResolvedValue({ name: 'folder-created' }),
|
put: jest.fn().mockResolvedValue({ name: 'folder-edited' }),
|
||||||
post: jest.fn().mockResolvedValue({ name: 'folder-created' }),
|
post: jest.fn().mockResolvedValue({ name: 'folder-created' }),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@ -84,7 +84,7 @@ describe('useEditFolder', () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calls the proper endpoint when creating a folder', async () => {
|
test('calls the proper endpoint when creating a folder (post)', async () => {
|
||||||
const {
|
const {
|
||||||
result: { current },
|
result: { current },
|
||||||
} = await setup();
|
} = await setup();
|
||||||
@ -97,6 +97,19 @@ describe('useEditFolder', () => {
|
|||||||
expect(axiosInstance.post).toHaveBeenCalledWith('/upload/folders', expect.any(Object));
|
expect(axiosInstance.post).toHaveBeenCalledWith('/upload/folders', expect.any(Object));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('calls the proper endpoint when creating a folder (put)', async () => {
|
||||||
|
const {
|
||||||
|
result: { current },
|
||||||
|
} = await setup();
|
||||||
|
const { editFolder } = current;
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
await editFolder(FOLDER_EDIT_FIXTURE);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(axiosInstance.put).toHaveBeenCalledWith('/upload/folders', expect.any(Object));
|
||||||
|
});
|
||||||
|
|
||||||
test('calls the proper endpoint when editing a folder', async () => {
|
test('calls the proper endpoint when editing a folder', async () => {
|
||||||
const {
|
const {
|
||||||
result: { current },
|
result: { current },
|
||||||
@ -144,7 +157,7 @@ describe('useEditFolder', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('calls toggleNotification in case of an error', async () => {
|
test('calls toggleNotification in case of an error', async () => {
|
||||||
axiosInstance.post.mockRejectedValue({ message: 'err-test' });
|
axiosInstance.put.mockRejectedValue({ message: 'err-test' });
|
||||||
|
|
||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const {
|
const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user