From 6a0889abc3fc1b3e0f467c7a71d0f9ce34c5c38d Mon Sep 17 00:00:00 2001 From: Caroline Denis Date: Wed, 29 Jul 2026 10:06:37 +0200 Subject: [PATCH 1/2] Fix: Reopen rollback status after conflict response --- .../lib/components/WbActions/WbRollback.tsx | 2 + .../WbActions/__tests__/WbRollback.test.tsx | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx 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..990a7d8282c --- /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(); + } +}); \ No newline at end of file From 80cb7091fc51eaa79519dc1956e8d3b0333b1abe Mon Sep 17 00:00:00 2001 From: Caroline Denis Date: Wed, 29 Jul 2026 08:10:33 +0000 Subject: [PATCH 2/2] Lint code with ESLint and Prettier Triggered by 6a0889abc3fc1b3e0f467c7a71d0f9ce34c5c38d on branch refs/heads/issue-8158 --- .../lib/components/WbActions/__tests__/WbRollback.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 990a7d8282c..b9eb31e886e 100644 --- a/specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx +++ b/specifyweb/frontend/js_src/lib/components/WbActions/__tests__/WbRollback.test.tsx @@ -54,4 +54,4 @@ test('reopens rollback status after conflict response', async () => { } finally { consoleError.mockRestore(); } -}); \ No newline at end of file +});