Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -160,7 +154,9 @@ describe('<CourseOutline />', () => {
pathname: mockPathname,
});

store = initializeStore();
store = initializeStore({
studioHome: { studioHomeData: { librariesV2Enabled: true } },
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
.onGet(getCourseOutlineIndexApiUrl(courseId))
Expand All @@ -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 />);

Expand Down
6 changes: 3 additions & 3 deletions src/course-outline/subsection-card/SubsectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put a warning here or in useStudioHome? These two lines look very similar, that it's easy to imagine someone introducing a similar bug again in the future.

@navinkarkera navinkarkera May 13, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a useEffect in useStudioHome hook that fetches course waffle flag whenever location.search is updated. So it is not always an issue to use it, but in this case where we update location.search on each change in search, it is not suitable.

We can add a small warning here explaining this issue.
Created #1945

const [
isAddLibraryUnitModalOpen,
openAddLibraryUnitModal,
Expand Down
5 changes: 3 additions & 2 deletions src/course-outline/subsection-card/SubsectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}));
Expand Down