Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// replace the newly uploaded file
const uuid = await uploadFile(dropzone, onChange, 'test2.pdf', 'pdf', 'newtest1.pdf');
wrapper.update();
const fileEntry = getFileEntryForFileType(wrapper, 2);
checkFileEntry(fileEntry, 'test2.pdf', 'trash');
// perform an undo - this needs to go back to an empty file list
await act(async () => {
fileEntry.find('FileAction').simulate('click');
mockAxios.mockResponse(
undefined,
mockAxios.mustGetReqByUrl(`flask://files.delete_file/uuid=${uuid}`)
);
});
expect(mockAxios.delete).toHaveBeenCalledWith(`flask://files.delete_file/uuid=${uuid}`);
expect(onChange).toHaveBeenCalledWith({});
});
async function uploadFile(dropzone, onChange, name, type, deletedFile = null) {
const uuid = await simulateFileUpload(dropzone, name, type);
expect(onChange).toHaveBeenCalledWith({'2': [uuid]});
if (deletedFile) {
const deleteUrl = `flask://files.delete_file/uuid=${deletedFile}`;
expect(mockAxios.delete).toHaveBeenCalledWith(deleteUrl);
await act(async () => {
mockAxios.mockResponse(undefined, mockAxios.mustGetReqByUrl(deleteUrl));
});
} else {
expect(mockAxios.delete).not.toHaveBeenCalled();
}
onChange.mockClear();
mockAxios.delete.mockClear();
return uuid;
}