Skip to content

Commit 6b7f4b5

Browse files
committed
refactor: Nits and details to finish migration
1 parent 1466370 commit 6b7f4b5

11 files changed

Lines changed: 108 additions & 176 deletions

File tree

plugins/course-apps/live/BbbSettings.test.jsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import {
44
getByRole,
55
getAllByRole,
66
waitForElementToBeRemoved,
7-
} from '@testing-library/react';
7+
initializeMocks,
8+
} from 'CourseAuthoring/testUtils';
89

910
import ReactDOM from 'react-dom';
10-
import { Routes, Route, MemoryRouter } from 'react-router-dom';
11-
import { initializeMockApp } from '@edx/frontend-platform';
12-
import MockAdapter from 'axios-mock-adapter';
13-
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
14-
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
15-
import { IntlProvider } from '@edx/frontend-platform/i18n';
1611

1712
import userEvent from '@testing-library/user-event';
18-
import initializeStore from 'CourseAuthoring/store';
1913
import { executeThunk } from 'CourseAuthoring/utils';
2014
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
2115

16+
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
2217
import LiveSettings from './Settings';
2318
import {
2419
generateLiveConfigurationApiResponse,
@@ -40,17 +35,20 @@ ReactDOM.createPortal = jest.fn(node => node);
4035

4136
const renderComponent = () => {
4237
const wrapper = render(
43-
<IntlProvider locale="en">
44-
<AppProvider store={store} wrapWithRouter={false}>
45-
<PagesAndResourcesProvider courseId={courseId}>
46-
<MemoryRouter initialEntries={[liveSettingsUrl]}>
47-
<Routes>
48-
<Route path={liveSettingsUrl} element={<PageWrap><LiveSettings onClose={() => {}} /></PageWrap>} />
49-
</Routes>
50-
</MemoryRouter>
51-
</PagesAndResourcesProvider>
52-
</AppProvider>
53-
</IntlProvider>,
38+
<CourseAuthoringProvider courseId={courseId}>
39+
<PagesAndResourcesProvider courseId={courseId}>
40+
<LiveSettings onClose={() => {}} />
41+
</PagesAndResourcesProvider>
42+
</CourseAuthoringProvider>,
43+
{
44+
path: liveSettingsUrl,
45+
routerProps: {
46+
initialEntries: [liveSettingsUrl],
47+
},
48+
params: {
49+
courseId,
50+
},
51+
},
5452
);
5553
container = wrapper.container;
5654
};
@@ -74,16 +72,9 @@ const mockStore = async ({
7472

7573
describe('BBB Settings', () => {
7674
beforeEach(async () => {
77-
initializeMockApp({
78-
authenticatedUser: {
79-
userId: 3,
80-
username: 'abc123',
81-
administrator: false,
82-
roles: [],
83-
},
84-
});
85-
store = initializeStore(initialState);
86-
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
75+
const mocks = initializeMocks({ initialState });
76+
store = mocks.reduxStore;
77+
axiosMock = mocks.axiosMock;
8778
});
8879

8980
test('Plan dropdown to be visible and enabled in UI', async () => {

plugins/course-apps/live/Settings.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import AppSettingsModal from 'CourseAuthoring/pages-and-resources/app-settings-m
1111
import { useModel } from 'CourseAuthoring/generic/model-store';
1212
import Loading from 'CourseAuthoring/generic/Loading';
1313
import { RequestStatus } from 'CourseAuthoring/data/constants';
14+
import { useCourseAuthoringContext } from 'CourseAuthoring/CourseAuthoringContext';
1415

1516
import { fetchLiveData, saveLiveConfiguration, saveLiveConfigurationAsDraft } from './data/thunks';
1617
import { selectApp } from './data/slice';
@@ -25,7 +26,7 @@ const LiveSettings = ({
2526
const intl = useIntl();
2627
const navigate = useNavigate();
2728
const dispatch = useDispatch();
28-
const courseId = useSelector(state => state.courseDetail.courseId);
29+
const { courseId } = useCourseAuthoringContext();
2930
const availableProviders = useSelector((state) => state.live.appIds);
3031
const {
3132
piiSharingAllowed, selectedAppId, enabled, status,

plugins/course-apps/live/Settings.test.jsx

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ import {
88
queryByText,
99
getByRole,
1010
waitForElementToBeRemoved,
11-
} from '@testing-library/react';
11+
initializeMocks,
12+
} from 'CourseAuthoring/testUtils';
1213

1314
import ReactDOM from 'react-dom';
14-
import { Routes, Route, MemoryRouter } from 'react-router-dom';
15-
import { initializeMockApp } from '@edx/frontend-platform';
16-
import MockAdapter from 'axios-mock-adapter';
17-
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
18-
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
19-
import { IntlProvider } from '@edx/frontend-platform/i18n';
20-
21-
import initializeStore from 'CourseAuthoring/store';
2215
import { executeThunk } from 'CourseAuthoring/utils';
2316
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
2417

18+
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
2519
import LiveSettings from './Settings';
2620
import {
2721
generateLiveConfigurationApiResponse,
@@ -44,17 +38,20 @@ ReactDOM.createPortal = jest.fn(node => node);
4438

4539
const renderComponent = () => {
4640
const wrapper = render(
47-
<IntlProvider locale="en">
48-
<AppProvider store={store} wrapWithRouter={false}>
49-
<PagesAndResourcesProvider courseId={courseId}>
50-
<MemoryRouter initialEntries={[liveSettingsUrl]}>
51-
<Routes>
52-
<Route path={liveSettingsUrl} element={<PageWrap><LiveSettings onClose={() => {}} /></PageWrap>} />
53-
</Routes>
54-
</MemoryRouter>
55-
</PagesAndResourcesProvider>
56-
</AppProvider>
57-
</IntlProvider>,
41+
<PagesAndResourcesProvider courseId={courseId}>
42+
<CourseAuthoringProvider>
43+
<LiveSettings onClose={() => {}} />
44+
</CourseAuthoringProvider>
45+
</PagesAndResourcesProvider>,
46+
{
47+
path: liveSettingsUrl,
48+
routerProps: {
49+
initialEntries: [liveSettingsUrl],
50+
},
51+
params: {
52+
courseId,
53+
},
54+
},
5855
);
5956
container = wrapper.container;
6057
};
@@ -77,16 +74,11 @@ const mockStore = async ({
7774

7875
describe('LiveSettings', () => {
7976
beforeEach(async () => {
80-
initializeMockApp({
81-
authenticatedUser: {
82-
userId: 3,
83-
username: 'abc123',
84-
administrator: false,
85-
roles: [],
86-
},
77+
const mocks = initializeMocks({
78+
initialState,
8779
});
88-
store = initializeStore(initialState);
89-
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
80+
store = mocks.reduxStore;
81+
axiosMock = mocks.axiosMock;
9082
});
9183

9284
test('Live Configuration modal is visible', async () => {

plugins/course-apps/live/ZoomSettings.test.jsx

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ import {
33
queryByTestId,
44
getByRole,
55
waitForElementToBeRemoved,
6-
} from '@testing-library/react';
6+
initializeMocks,
7+
} from 'CourseAuthoring/testUtils';
78

89
import ReactDOM from 'react-dom';
9-
import { Routes, Route, MemoryRouter } from 'react-router-dom';
10-
import { initializeMockApp } from '@edx/frontend-platform';
11-
import MockAdapter from 'axios-mock-adapter';
12-
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
13-
import { AppProvider, PageWrap } from '@edx/frontend-platform/react';
14-
import { IntlProvider } from '@edx/frontend-platform/i18n';
15-
16-
import initializeStore from 'CourseAuthoring/store';
10+
1711
import { executeThunk } from 'CourseAuthoring/utils';
1812
import PagesAndResourcesProvider from 'CourseAuthoring/pages-and-resources/PagesAndResourcesProvider';
13+
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
1914
import LiveSettings from './Settings';
2015
import {
2116
generateLiveConfigurationApiResponse,
@@ -38,17 +33,20 @@ ReactDOM.createPortal = jest.fn(node => node);
3833

3934
const renderComponent = () => {
4035
const wrapper = render(
41-
<IntlProvider locale="en">
42-
<AppProvider store={store} wrapWithRouter={false}>
43-
<PagesAndResourcesProvider courseId={courseId}>
44-
<MemoryRouter initialEntries={[liveSettingsUrl]}>
45-
<Routes>
46-
<Route path={liveSettingsUrl} element={<PageWrap><LiveSettings onClose={() => {}} /></PageWrap>} />
47-
</Routes>
48-
</MemoryRouter>
49-
</PagesAndResourcesProvider>
50-
</AppProvider>
51-
</IntlProvider>,
36+
<CourseAuthoringProvider courseId={courseId}>
37+
<PagesAndResourcesProvider courseId={courseId}>
38+
<LiveSettings onClose={() => {}} />
39+
</PagesAndResourcesProvider>
40+
</CourseAuthoringProvider>,
41+
{
42+
path: liveSettingsUrl,
43+
routerProps: {
44+
initialEntries: [liveSettingsUrl],
45+
},
46+
params: {
47+
courseId,
48+
},
49+
},
5250
);
5351
container = wrapper.container;
5452
};
@@ -71,16 +69,9 @@ const mockStore = async ({
7169

7270
describe('Zoom Settings', () => {
7371
beforeEach(async () => {
74-
initializeMockApp({
75-
authenticatedUser: {
76-
userId: 3,
77-
username: 'abc123',
78-
administrator: false,
79-
roles: [],
80-
},
81-
});
82-
store = initializeStore(initialState);
83-
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
72+
const mocks = initializeMocks({ initialState });
73+
store = mocks.reduxStore;
74+
axiosMock = mocks.axiosMock;
8475
});
8576

8677
test('LTI fields are visible when pii sharing is enabled', async () => {

src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { Button } from '@openedx/paragon';
55
import { Plus as PlusIcon, ContentPasteGo as ContentPasteGoIcon } from '@openedx/paragon/icons';
66
import { useIntl } from '@edx/frontend-platform/i18n';
77

8+
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
89
import { changeEditTitleFormOpen, updateQueryPendingStatus } from '../../data/slice';
9-
import { getCourseUnitData, getCourseId, getSequenceId } from '../../data/selectors';
10+
import { getCourseUnitData, getSequenceId } from '../../data/selectors';
1011
import messages from '../messages';
1112
import { useIndexOfLastVisibleChild } from '../hooks';
1213
import SequenceNavigationDropdown from './SequenceNavigationDropdown';
@@ -19,7 +20,7 @@ const SequenceNavigationTabs = ({
1920
const dispatch = useDispatch();
2021
const navigate = useNavigate();
2122
const sequenceId = useSelector(getSequenceId);
22-
const courseId = useSelector(getCourseId);
23+
const { courseId } = useCourseAuthoringContext();
2324
const courseUnit = useSelector(getCourseUnitData);
2425
const sequenceChildAddable = courseUnit?.ancestorInfo?.ancestors?.[0]?.actions?.childAddable;
2526

src/course-unit/course-sequence/sequence-navigation/UnitButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { Button } from '@openedx/paragon';
44
import { Link } from 'react-router-dom';
55

66
import { DeprecatedReduxState } from '@src/store';
7-
import { getCourseId, getSequenceId } from '@src/course-unit/data/selectors';
7+
import { getSequenceId } from '@src/course-unit/data/selectors';
8+
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
9+
810
import UnitIcon from './UnitIcon';
911

1012
interface Props {
@@ -20,7 +22,7 @@ const UnitButton: FC<Props> = ({
2022
isActive, // passed from parent (SequenceNavigationTabs)
2123
showTitle = false,
2224
}) => {
23-
const courseId = useSelector(getCourseId);
25+
const { courseId } = useCourseAuthoringContext();
2426
const sequenceId = useSelector(getSequenceId);
2527

2628
const unit = useSelector((state: DeprecatedReduxState) => state.models.units[unitId]);

src/course-unit/data/selectors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const getErrorMessage = (state) => state.courseUnit.errorMessage;
1010
export const getSequenceStatus = (state) => state.courseUnit.sequenceStatus;
1111
export const getSequenceIds = (state) => state.courseUnit.courseSectionVertical.courseSequenceIds;
1212
export const getCourseSectionVertical = (state) => state.courseUnit.courseSectionVertical;
13-
export const getCourseId = (state) => state.courseDetail.courseId;
1413
export const getSequenceId = (state) => state.courseUnit.sequenceId;
1514
export const getCourseVerticalChildren = (state) => state.courseUnit.courseVerticalChildren;
1615
export const getCourseOutlineInfo = (state) => state.courseUnit.courseOutlineInfo;

src/course-updates/update-form/UpdateForm.test.jsx

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import React from 'react';
21
import {
32
render,
43
fireEvent,
54
waitFor,
65
act,
7-
} from '@testing-library/react';
8-
import { AppProvider } from '@edx/frontend-platform/react';
9-
import { IntlProvider } from '@edx/frontend-platform/i18n';
10-
import { initializeMockApp } from '@edx/frontend-platform';
6+
initializeMocks,
7+
} from '@src/testUtils';
118
import moment from 'moment/moment';
129

13-
import initializeStore from '../../store';
10+
import { CourseAuthoringProvider } from '@src/CourseAuthoringContext';
1411
import { REQUEST_TYPES } from '../constants';
1512
import { courseHandoutsMock, courseUpdatesMock } from '../__mocks__';
1613
import UpdateForm from './UpdateForm';
1714
import messages from './messages';
1815

19-
let store;
2016
const closeMock = jest.fn();
2117
const onSubmitMock = jest.fn();
2218
const addNewUpdateMock = { id: 0, date: moment().utc().toDate(), content: 'Some content' };
@@ -53,31 +49,20 @@ const courseUpdatesInitialValues = (requestType) => {
5349
};
5450

5551
const renderComponent = ({ requestType }) => render(
56-
<AppProvider store={store}>
57-
<IntlProvider locale="en">
58-
<UpdateForm
59-
isOpen
60-
close={closeMock}
61-
requestType={requestType}
62-
onSubmit={onSubmitMock}
63-
courseUpdatesInitialValues={courseUpdatesInitialValues(requestType)}
64-
/>
65-
</IntlProvider>
66-
</AppProvider>,
52+
<CourseAuthoringProvider courseId="1">
53+
<UpdateForm
54+
isOpen
55+
close={closeMock}
56+
requestType={requestType}
57+
onSubmit={onSubmitMock}
58+
courseUpdatesInitialValues={courseUpdatesInitialValues(requestType)}
59+
/>,
60+
</CourseAuthoringProvider>,
6761
);
6862

6963
describe('<UpdateForm />', () => {
7064
beforeEach(() => {
71-
initializeMockApp({
72-
authenticatedUser: {
73-
userId: 3,
74-
username: 'abc123',
75-
administrator: true,
76-
roles: [],
77-
},
78-
});
79-
80-
store = initializeStore();
65+
initializeMocks();
8166
});
8267
it('render Add new update form correctly', async () => {
8368
const { getByText, getByDisplayValue, getByRole } = renderComponent({ requestType: REQUEST_TYPES.add_new_update });

src/generic/WysiwygEditor.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React from 'react';
21
import PropTypes from 'prop-types';
3-
import { useSelector } from 'react-redux';
2+
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
43
import TinyMceWidget, { prepareEditorRef } from '../editors/sharedComponents/TinyMceWidget';
54

65
import { DEFAULT_EMPTY_WYSIWYG_VALUE } from '../constants';
@@ -14,7 +13,7 @@ export const WysiwygEditor = ({
1413
initialValue, editorType, onChange, minHeight,
1514
}) => {
1615
const { editorRef, refReady, setEditorRef } = prepareEditorRef();
17-
const { courseId } = useSelector((state) => state.courseDetail);
16+
const { courseId } = useCourseAuthoringContext();
1817
const isEquivalentCodeExtraSpaces = (first, second) => {
1918
// Utils allows to compare code extra spaces
2019
const removeWhitespace = (str) => str.replace(/\s/g, '');

0 commit comments

Comments
 (0)