-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIBULKED-497: "Are you sure" preview displays outdated values after U…
…ser changed selection on bulk edit form and clicked "Confirm changes"
- Loading branch information
1 parent
88d2325
commit 3703609
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { JOB_STATUSES } from '../constants'; | ||
|
||
export const pollForStatus = (ky, id) => { | ||
const interval = 1000; | ||
return new Promise((resolve, reject) => { | ||
const intervalId = setInterval(async () => { | ||
try { | ||
const data = await ky.get(`bulk-operations/${id}`).json(); | ||
if (data.status !== JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS) { | ||
clearInterval(intervalId); resolve(data.status); | ||
} | ||
} catch (error) { clearInterval(intervalId); reject(error); } | ||
}, interval); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
import { JOB_STATUSES } from '../constants'; | ||
import { pollForStatus } from './pollForStatus'; | ||
|
||
describe('pollForStatus', () => { | ||
const mockGet = jest.fn(() => ({ | ||
json: (data) => Promise.resolve(data), | ||
})); | ||
jest.useFakeTimers(); | ||
|
||
beforeEach(() => { | ||
mockGet.mockClear(); | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: mockGet, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); // Сбрасываем все моки после каждого теста | ||
}); | ||
|
||
it('should resolve with the final status when status is not DATA_MODIFICATION_IN_PROGRESS', async () => { | ||
const finalStatus = 'COMPLETED'; | ||
mockGet | ||
.mockImplementationOnce(() => ({ | ||
json: () => Promise.resolve({ status: JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS }), | ||
})) | ||
.mockImplementationOnce(() => ({ | ||
json: () => Promise.resolve({ status: finalStatus }), | ||
})); | ||
|
||
const promise = pollForStatus(useOkapiKy(), 'mockId'); | ||
|
||
// Эмулируем интервалы вручную | ||
jest.advanceTimersByTime(1000); | ||
await Promise.resolve(); | ||
jest.advanceTimersByTime(1000); | ||
await Promise.resolve(); | ||
|
||
await expect(promise).resolves.toBe(finalStatus); | ||
expect(mockGet).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('should reject with an error if the request fails', async () => { | ||
const error = new Error('Request failed'); | ||
mockGet.mockImplementationOnce(() => { | ||
throw error; | ||
}); | ||
|
||
const promise = pollForStatus(useOkapiKy(), 'mockId'); | ||
|
||
jest.advanceTimersByTime(1000); | ||
await Promise.resolve(); | ||
|
||
await expect(promise).rejects.toThrow('Request failed'); | ||
expect(mockGet).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |