Skip to content

Commit bd18e87

Browse files
Fix broken StudioHome tests (#2291)
There were a ton of problems with these tests, but the main one was the use of `waitFor` without `await`, causing all of the code inside each `waitFor` block to essentially be ignored. Other problems fixed: * Rendering a router inside a router was causing most of the render() calls to fail (our custom `render()` already provides a router so there's no need to provide one in the test case) * Use of `testid` instead of queries based on what users see * Tests could match on content in the body when trying to make assertions about the header * Mock imported via `index.js` was causing `jest-haste-map` to print warnings about duplicate mock names (this is still happening for other mocks) * Passing `courses: null` instead of `courses: []` was causing a broken render on two of the tests. I also made other cleanups to follow best practices.
1 parent 2db6d89 commit bd18e87

21 files changed

Lines changed: 271 additions & 325 deletions

File tree

src/course-rerun/CourseRerun.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
fireEvent,
66
render,
77
waitFor,
8-
} from '../testUtils';
9-
import { studioHomeMock } from '../studio-home/__mocks__';
8+
} from '@src/testUtils';
9+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1010
import { getStudioHomeApiUrl } from '../studio-home/data/api';
1111
import { RequestStatus } from '../data/constants';
1212
import messages from './messages';

src/course-rerun/course-rerun-form/CourseRerunForm.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { initializeMockApp } from '@edx/frontend-platform';
55
import { IntlProvider } from '@edx/frontend-platform/i18n';
66
import { AppProvider } from '@edx/frontend-platform/react';
77

8-
import { studioHomeMock } from '../../studio-home/__mocks__';
8+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
99
import initializeStore from '../../store';
1010
import CourseRerunForm from '.';
1111

src/generic/create-or-rerun-course/CreateOrRerunCourseForm.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
1414
import { AppProvider } from '@edx/frontend-platform/react';
1515
import MockAdapter from 'axios-mock-adapter';
1616

17-
import { studioHomeMock } from '../../studio-home/__mocks__';
17+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1818
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
1919
import { fetchStudioHomeData } from '../../studio-home/data/thunks';
2020
import { RequestStatus } from '../../data/constants';

src/generic/create-or-rerun-course/factories/mockApiResponses.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RequestStatus } from '../../../data/constants';
2-
import { studioHomeMock } from '../../../studio-home/__mocks__';
1+
import { RequestStatus } from '@src/data/constants';
2+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
33

44
export const courseId = 'course-v1:edX+DemoX+Demo_Course';
55

src/library-authoring/LibraryAuthoringPage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
screen,
99
waitFor,
1010
within,
11-
} from '../testUtils';
11+
} from '@src/testUtils';
12+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1213
import mockResult from './__mocks__/library-search.json';
1314
import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json';
1415
import {
@@ -19,7 +20,6 @@ import {
1920
mockXBlockFields,
2021
} from './data/api.mocks';
2122
import { mockContentSearchConfig } from '../search-manager/data/api.mock';
22-
import { studioHomeMock } from '../studio-home/__mocks__';
2323
import { getStudioHomeApiUrl } from '../studio-home/data/api';
2424
import { LibraryLayout } from '.';
2525
import { getLibraryCollectionsApiUrl, getLibraryContainersApiUrl } from './data/api';

src/library-authoring/add-content/AddContentWorkflow.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
waitFor,
99
screen,
1010
initializeMocks,
11-
} from '../../testUtils';
11+
} from '@src/testUtils';
12+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1213
import mockResult from '../__mocks__/library-search.json';
1314
import editorCmsApi from '../../editors/data/services/cms/api';
1415
import * as textEditorHooks from '../../editors/containers/TextEditor/hooks';
@@ -19,7 +20,6 @@ import {
1920
} from '../data/api.mocks';
2021
import { mockClipboardEmpty } from '../../generic/data/api.mock';
2122
import { mockContentSearchConfig, mockSearchResult } from '../../search-manager/data/api.mock';
22-
import { studioHomeMock } from '../../studio-home/__mocks__';
2323
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
2424
import LibraryLayout from '../LibraryLayout';
2525

src/library-authoring/add-content/PickLibraryContentModal.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { mockContentSearchConfig, mockSearchResult } from '../../search-manager/data/api.mock';
1+
import { mockContentSearchConfig, mockSearchResult } from '@src/search-manager/data/api.mock';
22
import {
33
fireEvent,
44
render as baseRender,
55
waitFor,
66
screen,
77
initializeMocks,
8-
} from '../../testUtils';
9-
import { studioHomeMock } from '../../studio-home/__mocks__';
8+
} from '@src/testUtils';
9+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
1010
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
1111
import mockResult from '../__mocks__/library-search.json';
1212
import { LibraryProvider } from '../common/context/LibraryContext';

src/library-authoring/create-library/CreateLibrary.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
render,
99
screen,
1010
waitFor,
11-
} from '../../testUtils';
12-
import { studioHomeMock } from '../../studio-home/__mocks__';
13-
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
14-
import { getApiWaffleFlagsUrl } from '../../data/api';
11+
} from '@src/testUtils';
12+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
13+
import { getStudioHomeApiUrl } from '@src/studio-home/data/api';
14+
import { getApiWaffleFlagsUrl } from '@src/data/api';
1515
import { CreateLibrary } from '.';
1616
import { getContentLibraryV2CreateApiUrl } from './data/api';
1717

src/library-authoring/routes.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useEffect } from 'react';
22
import fetchMock from 'fetch-mock-jest';
3+
import { initializeMocks, render } from '@src/testUtils';
4+
import studioHomeMock from '@src/studio-home/__mocks__/studioHomeMock';
35
import {
46
mockContentLibrary,
57
} from './data/api.mocks';
68
import { LibraryLayout } from '.';
79
import { ContentType, useLibraryRoutes } from './routes';
810
import mockResult from './__mocks__/library-search.json';
9-
import { initializeMocks, render } from '../testUtils';
10-
import { studioHomeMock } from '../studio-home/__mocks__';
1111
import { getStudioHomeApiUrl } from '../studio-home/data/api';
1212

1313
const mockNavigate = jest.fn();

0 commit comments

Comments
 (0)