Skip to content

Commit 1919eb4

Browse files
authored
fix: search modal refresh on typing (openedx#1938) (openedx#1948)
1 parent 3d6e221 commit 1919eb4

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/course-outline/CourseOutline.test.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ jest.mock('./data/api', () => ({
9797
getTagsCount: () => jest.fn().mockResolvedValue({}),
9898
}));
9999

100-
jest.mock('../studio-home/hooks', () => ({
101-
useStudioHome: () => ({
102-
librariesV2Enabled: true,
103-
}),
104-
}));
105-
106100
// Mock ComponentPicker to call onComponentSelected on click
107101
jest.mock('../library-authoring/component-picker', () => ({
108102
ComponentPicker: (props) => {
@@ -160,7 +154,9 @@ describe('<CourseOutline />', () => {
160154
pathname: mockPathname,
161155
});
162156

163-
store = initializeStore();
157+
store = initializeStore({
158+
studioHome: { studioHomeData: { librariesV2Enabled: true } },
159+
});
164160
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
165161
axiosMock
166162
.onGet(getCourseOutlineIndexApiUrl(courseId))
@@ -179,6 +175,10 @@ describe('<CourseOutline />', () => {
179175
await executeThunk(fetchCourseOutlineIndexQuery(courseId), store.dispatch);
180176
});
181177

178+
afterEach(() => {
179+
jest.restoreAllMocks();
180+
});
181+
182182
it('render CourseOutline component correctly', async () => {
183183
const { getByText } = render(<RootWrapper />);
184184

src/course-outline/subsection-card/SubsectionCard.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {
33
useContext, useEffect, useState, useRef, useCallback,
44
} from 'react';
55
import PropTypes from 'prop-types';
6-
import { useDispatch } from 'react-redux';
6+
import { useDispatch, useSelector } from 'react-redux';
77
import { useSearchParams } from 'react-router-dom';
88
import { useIntl } from '@edx/frontend-platform/i18n';
99
import { Button, StandardModal, useToggle } from '@openedx/paragon';
@@ -25,8 +25,8 @@ import messages from './messages';
2525
import { ComponentPicker } from '../../library-authoring';
2626
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
2727
import { ContainerType } from '../../generic/key-utils';
28-
import { useStudioHome } from '../../studio-home/hooks';
2928
import { ContentType } from '../../library-authoring/routes';
29+
import { getStudioHomeData } from '../../studio-home/data/selectors';
3030

3131
const SubsectionCard = ({
3232
section,
@@ -57,7 +57,12 @@ const SubsectionCard = ({
5757
const [isFormOpen, openForm, closeForm] = useToggle(false);
5858
const namePrefix = 'subsection';
5959
const { sharedClipboardData, showPasteUnit } = useClipboard();
60-
const { librariesV2Enabled } = useStudioHome();
60+
// WARNING: Do not use "useStudioHome" to get "librariesV2Enabled" flag below,
61+
// as it has a useEffect that fetches course waffle flags whenever
62+
// location.search is updated. Course search updates location.search when
63+
// user types, which will then trigger the useEffect and reload the page.
64+
// See https://github.com/openedx/frontend-app-authoring/pull/1938.
65+
const { librariesV2Enabled } = useSelector(getStudioHomeData);
6166
const [
6267
isAddLibraryUnitModalOpen,
6368
openAddLibraryUnitModal,

src/course-outline/subsection-card/SubsectionCard.test.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ jest.mock('react-router-dom', () => ({
2424
}),
2525
}));
2626

27-
jest.mock('../../studio-home/hooks', () => ({
28-
useStudioHome: () => ({
27+
jest.mock('react-redux', () => ({
28+
...jest.requireActual('react-redux'),
29+
useSelector: () => ({
2930
librariesV2Enabled: true,
3031
}),
3132
}));

0 commit comments

Comments
 (0)