diff --git a/specifyweb/frontend/js_src/lib/components/WbActions/WbRollback.tsx b/specifyweb/frontend/js_src/lib/components/WbActions/WbRollback.tsx index 1928ca44f85..8b0bfffbaf7 100644 --- a/specifyweb/frontend/js_src/lib/components/WbActions/WbRollback.tsx +++ b/specifyweb/frontend/js_src/lib/components/WbActions/WbRollback.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { useBooleanState } from '../../hooks/useBooleanState'; import { commonText } from '../../localization/common'; +import { Http } from '../../utils/ajax/definitions'; import { ping } from '../../utils/ajax/ping'; import { Button } from '../Atoms/Button'; import { dialogIcons } from '../Atoms/Icons'; @@ -67,6 +68,7 @@ function RollbackConfirmation({ loading( ping(`/api/workbench/unupload/${datasetId}/`, { method: 'POST', + expectedErrors: [Http.CONFLICT], }) .then(handleRollback) .finally(handleClose) diff --git a/specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx b/specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx new file mode 100644 index 00000000000..b9eb31e886e --- /dev/null +++ b/specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx @@ -0,0 +1,57 @@ +import { waitFor, within } from '@testing-library/react'; +import React from 'react'; + +import { overrideAjax } from '../../../tests/ajax'; +import { mount } from '../../../tests/reactUtils'; +import { Http } from '../../../utils/ajax/definitions'; +import { LoadingContext } from '../../Core/Contexts'; +import { UnloadProtectsContext } from '../../Router/UnloadProtect'; +import { datasetVariants } from '../../WbUtils/datasetVariants'; +import { WbRollback } from '../WbRollback'; + +const datasetId = 7; +const viewerLocalization = datasetVariants.workbench.localization.viewer; + +overrideAjax(`/api/workbench/unupload/${datasetId}/`, '', { + method: 'POST', + responseCode: Http.CONFLICT, +}); + +test('reopens rollback status after conflict response', async () => { + const consoleError = jest.spyOn(console, 'error').mockImplementation(); + const handleStatus = jest.fn(); + const loadingHandler = jest.fn((promise: Promise) => { + void promise; + }); + + try { + const { getByRole, queryByRole, user } = mount( + + + + + + ); + + await user.click(getByRole('button', { name: viewerLocalization.undo })); + + const dialog = getByRole('dialog'); + await user.click( + within(dialog).getByRole('button', { name: viewerLocalization.undo }) + ); + + await waitFor(() => { + expect(handleStatus).toHaveBeenCalledWith('unupload'); + }); + expect(loadingHandler).toHaveBeenCalledTimes(1); + await waitFor(() => { + expect(queryByRole('dialog')).toBeNull(); + }); + } finally { + consoleError.mockRestore(); + } +});