fix: search modal refresh on typing (#1938)

The whole page was being refreshed while searching content from course
outline page due to fetching of waffle flag on changes in location
search field.
This commit is contained in:
Navin Karkera
2025-05-12 16:42:59 +00:00
committed by GitHub
parent d5dc8b5ebe
commit 26c6a71624
3 changed files with 13 additions and 12 deletions

View File

@@ -97,12 +97,6 @@ jest.mock('./data/api', () => ({
getTagsCount: () => jest.fn().mockResolvedValue({}),
}));
jest.mock('../studio-home/hooks', () => ({
useStudioHome: () => ({
librariesV2Enabled: true,
}),
}));
// Mock ComponentPicker to call onComponentSelected on click
jest.mock('../library-authoring/component-picker', () => ({
ComponentPicker: (props) => {
@@ -160,7 +154,9 @@ describe('<CourseOutline />', () => {
pathname: mockPathname,
});
store = initializeStore();
store = initializeStore({
studioHome: { studioHomeData: { librariesV2Enabled: true } },
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
.onGet(getCourseOutlineIndexApiUrl(courseId))
@@ -179,6 +175,10 @@ describe('<CourseOutline />', () => {
await executeThunk(fetchCourseOutlineIndexQuery(courseId), store.dispatch);
});
afterEach(() => {
jest.restoreAllMocks();
});
it('render CourseOutline component correctly', async () => {
const { getByText } = render(<RootWrapper />);

View File

@@ -3,7 +3,7 @@ import React, {
useContext, useEffect, useState, useRef, useCallback,
} from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { useSearchParams } from 'react-router-dom';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Button, StandardModal, useToggle } from '@openedx/paragon';
@@ -25,8 +25,8 @@ import messages from './messages';
import { ComponentPicker } from '../../library-authoring';
import { COMPONENT_TYPES } from '../../generic/block-type-utils/constants';
import { ContainerType } from '../../generic/key-utils';
import { useStudioHome } from '../../studio-home/hooks';
import { ContentType } from '../../library-authoring/routes';
import { getStudioHomeData } from '../../studio-home/data/selectors';
const SubsectionCard = ({
section,
@@ -57,7 +57,7 @@ const SubsectionCard = ({
const [isFormOpen, openForm, closeForm] = useToggle(false);
const namePrefix = 'subsection';
const { sharedClipboardData, showPasteUnit } = useClipboard();
const { librariesV2Enabled } = useStudioHome();
const { librariesV2Enabled } = useSelector(getStudioHomeData);
const [
isAddLibraryUnitModalOpen,
openAddLibraryUnitModal,

View File

@@ -24,8 +24,9 @@ jest.mock('react-router-dom', () => ({
}),
}));
jest.mock('../../studio-home/hooks', () => ({
useStudioHome: () => ({
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: () => ({
librariesV2Enabled: true,
}),
}));