Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jan 2, 2024
1 parent 5c83739 commit aed6223
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 41 deletions.
11 changes: 1 addition & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { createConfig } = require('@edx/frontend-build');

module.exports = createConfig('jest', {
setupFiles: [
'<rootDir>/src/setupTest.js',
],
setupFilesAfterEnv: [
'<rootDir>/src/setupTest.js',
'<rootDir>/src/setupTestEnv.js',
],
coveragePathIgnorePatterns: [
Expand All @@ -27,13 +25,6 @@ module.exports = createConfig('jest', {
roots: [
'<rootDir>src/',
],
coveragePathIgnorePatterns: [
'src/setupTest.js',
'jest.config.js',
'src/i18n',
'/node_modules/',
'/specs/'
],
moduleNameMapper: {
'^lodash-es$': 'lodash',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
"start:with-theme": "paragon install-theme && npm start && npm install",
"test": "fedx-scripts jest --coverage --passWithNoTests",
"test": "fedx-scripts jest --coverage",
"test:watch": "fedx-scripts jest --coverage --watchAll --watch",
"clear-jest": "fedx-scripts jest --clearCache",
"types": "tsc --noEmit"
Expand Down
29 changes: 15 additions & 14 deletions src/CourseAuthoringRoutes.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import CourseAuthoringRoutes from './CourseAuthoringRoutes';
import initializeStore from './store';

const courseId = 'course-v1:edX+TestX+Test_Course';
const pagesAndResourcesMockText = 'Pages And Resources';
const editorContainerMockText = 'Editor Container';
const videoSelectorContainerMockText = 'Video Selector Container';
const customPagesMockText = 'Custom Pages';
const mockCourseId = courseId;
const mockPageAndResourcesText = 'Pages And Resources';
const mockEditorContainerText = 'Editor Container';
const mockVideoSelectorContainerText = 'Video Selector Container';
const mockCustomPagesText = 'Custom Pages';
let store;
const mockComponentFn = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({
courseId,
courseId: mockCourseId,
}),
}));

Expand All @@ -33,19 +34,19 @@ jest.mock('@edx/frontend-lib-content-components', () => ({

jest.mock('./pages-and-resources/PagesAndResources', () => (props) => {
mockComponentFn(props);
return pagesAndResourcesMockText;
return mockPageAndResourcesText;
});
jest.mock('./editors/EditorContainer', () => (props) => {
mockComponentFn(props);
return editorContainerMockText;
return mockEditorContainerText;
});
jest.mock('./selectors/VideoSelectorContainer', () => (props) => {
mockComponentFn(props);
return videoSelectorContainerMockText;
return mockVideoSelectorContainerText;
});
jest.mock('./custom-pages/CustomPages', () => (props) => {
mockComponentFn(props);
return customPagesMockText;
return mockCustomPagesText;
});

describe('<CourseAuthoringRoutes>', () => {
Expand All @@ -70,7 +71,7 @@ describe('<CourseAuthoringRoutes>', () => {
</AppProvider>,
);

expect(screen.getByText(pagesAndResourcesMockText)).toBeVisible();
expect(screen.getByText(mockPageAndResourcesText)).toBeVisible();
expect(mockComponentFn).toHaveBeenCalledWith(
expect.objectContaining({
courseId,
Expand All @@ -87,8 +88,8 @@ describe('<CourseAuthoringRoutes>', () => {
</AppProvider>,
);

expect(screen.queryByText(editorContainerMockText)).toBeInTheDocument();
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
expect(screen.queryByText(mockEditorContainerText)).toBeInTheDocument();
expect(screen.queryByText(mockPageAndResourcesText)).not.toBeInTheDocument();
expect(mockComponentFn).toHaveBeenCalledWith(
expect.objectContaining({
courseId,
Expand All @@ -105,8 +106,8 @@ describe('<CourseAuthoringRoutes>', () => {
</AppProvider>,
);

expect(screen.queryByText(videoSelectorContainerMockText)).toBeInTheDocument();
expect(screen.queryByText(pagesAndResourcesMockText)).not.toBeInTheDocument();
expect(screen.queryByText(mockVideoSelectorContainerText)).toBeInTheDocument();
expect(screen.queryByText(mockPageAndResourcesText)).not.toBeInTheDocument();
expect(mockComponentFn).toHaveBeenCalledWith(
expect.objectContaining({
courseId,
Expand Down
6 changes: 3 additions & 3 deletions src/export-page/CourseExportPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ let store;
let axiosMock;
let cookies;
const courseId = '123';
const courseName = 'About Node JS';
const mockCourseName = 'About Node JS';

jest.mock('../generic/model-store', () => ({
useModel: jest.fn().mockReturnValue({
name: courseName,
name: mockCourseName,
}),
}));

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('<CourseExportPage />', () => {
await waitFor(() => {
const helmet = Helmet.peek();
expect(helmet.title).toEqual(
`${messages.headingTitle.defaultMessage} | ${courseName} | ${process.env.SITE_NAME}`,
`${messages.headingTitle.defaultMessage} | ${mockCourseName} | ${process.env.SITE_NAME}`,
);
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/import-page/CourseImportPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ let store;
let axiosMock;
let cookies;
const courseId = '123';
const courseName = 'About Node JS';
const mockCourseName = 'About Node JS';

jest.mock('../generic/model-store', () => ({
useModel: jest.fn().mockReturnValue({
name: courseName,
name: mockCourseName,
}),
}));

Expand Down Expand Up @@ -66,7 +66,7 @@ describe('<CourseImportPage />', () => {
await waitFor(() => {
const helmet = Helmet.peek();
expect(helmet.title).toEqual(
`${messages.headingTitle.defaultMessage} | ${courseName} | ${process.env.SITE_NAME}`,
`${messages.headingTitle.defaultMessage} | ${mockCourseName} | ${process.env.SITE_NAME}`,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import instructorMessages from './instructor-container/messages';
import InstructorsSection from '.';

const onChangeMock = jest.fn();
const courseIdMock = 'course-id-bar';
const mockCourseId = 'course-id-bar';

// Mock the TextareaAutosize component
jest.mock('react-textarea-autosize', () => jest.fn((props) => (
Expand All @@ -29,7 +29,7 @@ jest.mock('react-redux', () => ({
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useParams: () => ({
courseId: courseIdMock,
courseId: mockCourseId,
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ let store;

const onDeleteMock = jest.fn();
const onChangeMock = jest.fn();
const courseIdMock = 'course-id-bar';
const mockCourseId = 'course-id-bar';
jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useParams: () => ({
courseId: courseIdMock,
courseId: mockCourseId,
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import entranceExamMessages from './entrance-exam/messages';
import RequirementsSection from '.';

const onChangeMock = jest.fn();
const courseIdMock = 'course-id-bar';
const mockCourseId = 'course-id-bar';

jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useParams: () => ({
courseId: courseIdMock,
courseId: mockCourseId,
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import messages from './messages';
import EntranceExam from '.';

const onChangeMock = jest.fn();
const courseIdMock = 'course-id-bar';
const mockCourseId = 'course-id-bar';

jest.mock('react-router', () => ({
...jest.requireActual('react-router'),
useParams: () => ({
courseId: courseIdMock,
courseId: mockCourseId,
}),
}));

Expand Down
4 changes: 2 additions & 2 deletions src/taxonomy/TaxonomyLayout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import initializeStore from '../store';
import TaxonomyLayout from './TaxonomyLayout';

let store;
const toastMessage = 'Hello, this is a toast!';
const mockToastMessage = 'Hello, this is a toast!';
jest.mock('../header', () => jest.fn(() => <div data-testid="mock-header" />));
jest.mock('@edx/frontend-component-footer', () => ({
StudioFooter: jest.fn(() => <div data-testid="mock-footer" />),
Expand All @@ -22,7 +22,7 @@ jest.mock('react', () => ({
...jest.requireActual('react'),
useState: jest.fn((initial) => {
if (initial === null) {
return [toastMessage, jest.fn()];
return [mockToastMessage, jest.fn()];
}
return [initial, jest.fn()];
}),
Expand Down

0 comments on commit aed6223

Please sign in to comment.