Skip to content

Commit 569d45a

Browse files
authored
UILD-816: Fix regression issues that appeared after refactoring (#404)
1 parent e3f679a commit 569d45a

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
* Fix duplicate Work cannot be saved. Fixes [UILD-821].
88
* Refactor services providers and simple lookup data loading. Refs [UILD-816].
99
* Refactor imports and add import boundary rules. Refs [UILD-816].
10+
* Fix regression issues that appeared after refactoring. Refs [UILD-816], [UILD-827].
1011

1112
[UILD-744]:https://folio-org.atlassian.net/browse/UILD-744
1213
[UILD-816]:https://folio-org.atlassian.net/browse/UILD-816
1314
[UILD-821]:https://folio-org.atlassian.net/browse/UILD-821
15+
[UILD-827]:https://folio-org.atlassian.net/browse/UILD-827
1416

1517
## 2.0.4 (2026-06-03)
1618
* Fix default profile type persistence across edit form and profile settings. Fixes [UILD-820].

src/features/edit/components/modals/Prompt/Prompt.test.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { setInitialGlobalState } from '@/test/__mocks__/store';
44

55
import { RouterProvider, createMemoryRouter } from 'react-router-dom';
66

7-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
7+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
88

9-
import { useConfigStore } from '@/store';
9+
import { useConfigStore, useLoadingStateStore } from '@/store';
1010

1111
import { Prompt } from './Prompt';
1212

@@ -15,6 +15,7 @@ const mockedUseBlocker = {
1515
proceed: jest.fn(),
1616
};
1717

18+
const mockResetIsLoading = jest.fn();
1819
const setIsModalOpen = jest.fn();
1920
const openModal = jest.fn();
2021
const dispatchEvent = jest.fn();
@@ -60,6 +61,10 @@ const renderPrompt = (isBlocking = true) => {
6061
store: useConfigStore,
6162
state: { customEvents: { TRIGGER_MODAL: 'triggermodal' } },
6263
},
64+
{
65+
store: useLoadingStateStore,
66+
state: { resetIsLoading: mockResetIsLoading },
67+
},
6368
]);
6469

6570
return render(
@@ -102,4 +107,16 @@ describe('Prompt', () => {
102107

103108
expect(addEventListener).toHaveBeenCalled();
104109
});
110+
111+
test('calls resetIsLoading when navigation is blocked', () => {
112+
expect(mockResetIsLoading).toHaveBeenCalled();
113+
});
114+
115+
test('does not call resetIsLoading when "when" prop is false', () => {
116+
cleanup();
117+
mockResetIsLoading.mockClear();
118+
renderPrompt(false);
119+
120+
expect(mockResetIsLoading).not.toHaveBeenCalled();
121+
});
105122
});

src/features/edit/components/modals/Prompt/Prompt.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useNavigateToEditPage } from '@/common/hooks/useNavigateToEditPage';
1010

1111
import { useRecordMutations } from '@/features/resources';
1212

13-
import { useStatusState } from '@/store';
13+
import { useLoadingState, useStatusState } from '@/store';
1414

1515
import { ModalCloseRecord } from '../ModalCloseRecord';
1616
import { ModalSwitchToNewRecord } from '../ModalSwitchToNewRecord';
@@ -43,6 +43,7 @@ export const Prompt: FC<Props> = ({ when: shouldPrompt }) => {
4343
const { dispatchProceedNavigationEvent, dispatchUnblockEvent } = useContainerEvents({
4444
onTriggerModal: () => setIsCloseRecordModalOpen(true),
4545
});
46+
const { resetIsLoading } = useLoadingState(['resetIsLoading']);
4647

4748
const closeAllModals = () => {
4849
setIsCloseRecordModalOpen(false);
@@ -59,6 +60,8 @@ export const Prompt: FC<Props> = ({ when: shouldPrompt }) => {
5960
// ID we receive from the update operation
6061

6162
if (shouldPrompt) {
63+
resetIsLoading();
64+
6265
const forceNavigateToDest = getForceNavigateToDest(pathname, search);
6366

6467
if (forceNavigateToDest) {

src/features/edit/hooks/useEditPage.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ jest.mock('@/configs/resourceTypes', () => ({
5353
getReference: jest.fn(),
5454
}));
5555

56+
const mockSelectedEntriesServiceSet = jest.fn();
57+
58+
jest.mock('@/common/hooks/useSchemaPipeline', () => ({
59+
useSchemaPipeline: () => ({
60+
selectedEntriesService: { set: mockSelectedEntriesServiceSet },
61+
}),
62+
}));
63+
5664
const mockSetIsLoading = jest.fn();
5765
const mockSetSelectedProfile = jest.fn();
5866
const mockSetInitialSchemaKey = jest.fn();
@@ -123,6 +131,20 @@ describe('useEditPage', () => {
123131
setupStores();
124132
});
125133

134+
describe('applyToStores', () => {
135+
it('calls selectedEntriesService.set with selectedEntries from the processed resource', async () => {
136+
mockProcessResource.mockResolvedValue(mockProcessedResource);
137+
138+
const { result } = renderHook(() => useEditPage());
139+
140+
await act(async () => {
141+
await result.current.initNewResource();
142+
});
143+
144+
expect(mockSelectedEntriesServiceSet).toHaveBeenCalledWith(mockProcessedResource.selectedEntries);
145+
});
146+
});
147+
126148
describe('initNewResource', () => {
127149
it('calls processResource and applies result to stores on success', async () => {
128150
mockProcessResource.mockResolvedValue(mockProcessedResource);

src/features/edit/hooks/useEditPage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
unwrapRecordValuesFromCommonContainer,
1515
wrapRecordValuesWithCommonContainer,
1616
} from '@/common/helpers/record.helper';
17+
import { useSchemaPipeline } from '@/common/hooks/useSchemaPipeline';
1718
import { logger } from '@/common/services/logger';
1819
import { UserNotificationFactory } from '@/common/services/userNotification';
1920
import {
@@ -47,6 +48,7 @@ export const useEditPage = () => {
4748
const { processResource } = useResourceProcessing();
4849
const queryClient = useQueryClient();
4950
const navigate = useNavigate();
51+
const { selectedEntriesService } = useSchemaPipeline();
5052

5153
const { setIsLoading } = useLoadingState(['setIsLoading']);
5254
const { setSelectedProfile, setInitialSchemaKey, setSchema } = useProfileState([
@@ -99,6 +101,7 @@ export const useEditPage = () => {
99101
setUserValues(result.userValues);
100102
setSelectedEntries(result.selectedEntries);
101103
setSelectedRecordBlocks(result.selectedRecordBlocks);
104+
selectedEntriesService.set(result.selectedEntries);
102105

103106
if (record !== undefined) setRecord(record);
104107

0 commit comments

Comments
 (0)