Skip to content

Commit 5acf4e4

Browse files
fix: resolve TypeScript and test issues after dependency update
1 parent f43ac7b commit 5acf4e4

File tree

9 files changed

+12785
-9226
lines changed

9 files changed

+12785
-9226
lines changed

jest.config.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,4 @@ const config = createConfig('jest', {
2424

2525
// delete config.testURL;
2626

27-
config.reporters = [...(config.reporters || []), ["jest-console-group-reporter", {
28-
// change this setting if need to see less details for each test
29-
// reportType: "summary" | "details",
30-
// enable: true | false,
31-
afterEachTest: {
32-
enable: true,
33-
filePaths: false,
34-
reportType: "details",
35-
},
36-
afterAllTests: {
37-
reportType: "summary",
38-
enable: true,
39-
filePaths: true,
40-
},
41-
}]];
42-
4327
module.exports = config;

package-lock.json

Lines changed: 12641 additions & 9195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/courseware/course/new-sidebar/SidebarContextProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const SidebarProvider: React.FC<Props> = ({
2626
const { verifiedMode } = useModel('courseHomeMeta', courseId);
2727
const topic = useModel('discussionTopics', unitId);
2828
const windowWidth = useWindowSize().width ?? window.innerWidth;
29-
const shouldDisplayFullScreen = windowWidth < breakpoints.large.minWidth;
30-
const shouldDisplaySidebarOpen = windowWidth > breakpoints.medium.minWidth;
29+
const shouldDisplayFullScreen = windowWidth < (breakpoints.large.minWidth ?? 992);
30+
const shouldDisplaySidebarOpen = windowWidth > (breakpoints.medium.minWidth ?? 768);
3131
const query = new URLSearchParams(window.location.search);
3232
const isInitiallySidebarOpen = shouldDisplaySidebarOpen || query.get('sidebar') === 'true';
3333
const sidebarKey = `sidebar.${courseId}`;

src/courseware/course/new-sidebar/sidebars/discussions-notifications/notifications/NotificationsWidget.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('NotificationsWidget', () => {
4444
}
4545

4646
beforeEach(async () => {
47-
global.innerWidth = breakpoints.large.minWidth;
47+
global.innerWidth = breakpoints.large.minWidth ?? 992;
4848
store = initializeStore();
4949
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
5050
axiosMock.onGet(courseMetadataUrl).reply(200, defaultMetadata);

src/courseware/course/sequence/Unit/ContentIFrame.test.jsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,57 @@ jest.mock('@edx/frontend-platform/react', () => ({ ErrorPage: () => <div>ErrorPa
77

88
jest.mock('@src/generic/PageLoading', () => jest.fn(() => <div>PageLoading</div>));
99

10+
jest.mock('@openedx/paragon', () => {
11+
const actual = jest.requireActual('@openedx/paragon');
12+
const PropTypes = jest.requireActual('prop-types');
13+
14+
const MockModalDialog = ({ children, isOpen, onClose }) => {
15+
if (!isOpen) { return null; }
16+
17+
return (
18+
<div role="dialog" aria-modal="true" className="mock-modal">
19+
<button
20+
type="button"
21+
data-testid="modal-backdrop"
22+
onClick={onClose}
23+
aria-label="Close"
24+
>
25+
26+
</button>
27+
<div className="mock-modal-content">
28+
{children}
29+
</div>
30+
</div>
31+
);
32+
};
33+
34+
MockModalDialog.propTypes = {
35+
children: PropTypes.node,
36+
isOpen: PropTypes.bool,
37+
onClose: PropTypes.func,
38+
};
39+
40+
const createSubComponent = (baseClass) => {
41+
const Component = ({ children, className }) => (
42+
<div className={`${baseClass} ${className || ''}`}>{children}</div>
43+
);
44+
Component.propTypes = {
45+
children: PropTypes.node,
46+
className: PropTypes.string,
47+
};
48+
return Component;
49+
};
50+
51+
MockModalDialog.Body = createSubComponent('mock-modal-body');
52+
MockModalDialog.Header = createSubComponent('mock-modal-header');
53+
MockModalDialog.Footer = createSubComponent('mock-modal-footer');
54+
55+
return {
56+
...actual,
57+
ModalDialog: MockModalDialog,
58+
};
59+
});
60+
1061
jest.mock('./hooks', () => ({
1162
useIFrameBehavior: jest.fn(),
1263
useModalIFrameData: jest.fn(),

src/plugin-slots/LearnerToolsSlot/index.test.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import * as auth from '@edx/frontend-platform/auth';
55

66
import { LearnerToolsSlot } from './index';
77

8-
jest.mock('@openedx/frontend-plugin-framework', () => ({
9-
PluginSlot: jest.fn(() => <div data-testid="plugin-slot">Plugin Slot</div>),
10-
}));
11-
128
jest.mock('@edx/frontend-platform/auth', () => ({
139
getAuthenticatedUser: jest.fn(),
1410
}));
@@ -98,7 +94,7 @@ describe('LearnerToolsSlot', () => {
9894

9995
render(<LearnerToolsSlot {...defaultProps} />);
10096

101-
// The portal should render to document.body
102-
expect(document.body.querySelector('[data-testid="plugin-slot"]')).toBeInTheDocument();
97+
// The portal should render to document.body with the id as testid
98+
expect(document.body.querySelector('[data-testid="org.openedx.frontend.learning.learner_tools.v1"]')).toBeInTheDocument();
10399
});
104100
});

src/setupTest.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import { getCourseOutlineStructure } from './courseware/data/thunks';
2626
import { appendBrowserTimezoneToUrl, executeThunk } from './utils';
2727
import buildSimpleCourseAndSequenceMetadata from './courseware/data/__factories__/sequenceMetadata.factory';
2828
import { buildOutlineFromBlocks } from './courseware/data/__factories__/learningSequencesOutline.factory';
29-
import MockedPluginSlot from './tests/MockedPluginSlot';
3029

31-
jest.mock('@openedx/frontend-plugin-framework', () => ({
32-
...jest.requireActual('@openedx/frontend-plugin-framework'),
33-
Plugin: () => 'Plugin',
34-
PluginSlot: MockedPluginSlot,
35-
}));
30+
jest.mock('@openedx/frontend-plugin-framework', () => {
31+
const MockedPluginSlot = jest.requireActual('./tests/MockedPluginSlot').default;
32+
33+
return {
34+
Plugin: () => 'Plugin',
35+
PluginSlot: jest.fn(MockedPluginSlot),
36+
};
37+
});
3638

3739
jest.mock('@src/generic/plugin-store', () => ({
3840
...jest.requireActual('@src/generic/plugin-store'),

webpack.dev.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const { createConfig } = require('@openedx/frontend-build');
3+
const sass = require('sass');
34

45
const config = createConfig('webpack-dev');
56

@@ -8,4 +9,43 @@ config.resolve.alias = {
89
'@src': path.resolve(__dirname, 'src'),
910
};
1011

12+
// Fix for react-focus-on webpack 5 compatibility issue
13+
// The package has ES modules without file extensions in imports
14+
config.module.rules.push({
15+
test: /\.m?js$/,
16+
resolve: {
17+
fullySpecified: false,
18+
},
19+
});
20+
21+
// Fix for sass-loader deprecation warnings
22+
config.module.rules.forEach((rule) => {
23+
if (rule.oneOf) {
24+
rule.oneOf.forEach((oneOfRule) => {
25+
if (oneOfRule.use) {
26+
oneOfRule.use.forEach((loaderConfig) => {
27+
if (loaderConfig.loader && loaderConfig.loader.includes('sass-loader')) {
28+
// eslint-disable-next-line no-param-reassign
29+
loaderConfig.options = {
30+
...loaderConfig.options,
31+
api: 'modern',
32+
implementation: sass,
33+
sassOptions: {
34+
...loaderConfig.options?.sassOptions,
35+
silenceDeprecations: [
36+
'import',
37+
'abs-percent',
38+
'color-functions',
39+
'global-builtin',
40+
'legacy-js-api',
41+
],
42+
},
43+
};
44+
}
45+
});
46+
}
47+
});
48+
}
49+
});
50+
1151
module.exports = config;

webpack.prod.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22
const { createConfig } = require('@openedx/frontend-build');
33
const CopyPlugin = require('copy-webpack-plugin');
4+
const sass = require('sass');
45

56
const config = createConfig('webpack-prod');
67

@@ -20,4 +21,43 @@ config.resolve.alias = {
2021
'@src': path.resolve(__dirname, 'src'),
2122
};
2223

24+
// Fix for react-focus-on webpack 5 compatibility issue
25+
// The package has ES modules without file extensions in imports
26+
config.module.rules.push({
27+
test: /\.m?js$/,
28+
resolve: {
29+
fullySpecified: false,
30+
},
31+
});
32+
33+
// Fix for sass-loader deprecation warnings
34+
config.module.rules.forEach((rule) => {
35+
if (rule.oneOf) {
36+
rule.oneOf.forEach((oneOfRule) => {
37+
if (oneOfRule.use) {
38+
oneOfRule.use.forEach((loaderConfig) => {
39+
if (loaderConfig.loader && loaderConfig.loader.includes('sass-loader')) {
40+
// eslint-disable-next-line no-param-reassign
41+
loaderConfig.options = {
42+
...loaderConfig.options,
43+
api: 'modern',
44+
implementation: sass,
45+
sassOptions: {
46+
...loaderConfig.options?.sassOptions,
47+
silenceDeprecations: [
48+
'import',
49+
'abs-percent',
50+
'color-functions',
51+
'global-builtin',
52+
'legacy-js-api',
53+
],
54+
},
55+
};
56+
}
57+
});
58+
}
59+
});
60+
}
61+
});
62+
2363
module.exports = config;

0 commit comments

Comments
 (0)