Skip to content

Commit 3da710e

Browse files
committed
♻️(frontend) Joanie api client load in test
Joanie's api client shouldn't be loaded on test that don't use it.
1 parent 3401235 commit 3da710e

File tree

8 files changed

+16
-11
lines changed

8 files changed

+16
-11
lines changed

src/frontend/js/components/TeacherDashboardCourseList/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('components/TeacherDashboardCourseList', () => {
6767

6868
await expectNoSpinner('Loading courses...');
6969
expect(
70-
screen.getByRole('heading', { name: /TeacherDashboardCourseList test title/ }),
70+
await screen.findByRole('heading', { name: /TeacherDashboardCourseList test title/ }),
7171
).toBeInTheDocument();
7272

7373
const calledUrls = fetchMock.calls().map((call) => call[0]);

src/frontend/js/hooks/useDefaultOrganizationId/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fetchMock from 'fetch-mock';
33
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie';
44
import { OrganizationFactory } from 'utils/test/factories/joanieLegacy';
55
import { Organization } from 'types/Joanie';
6-
import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
6+
import JoanieAppWrapper, { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
77
import useDefaultOrganizationId from '.';
88

99
jest.mock('utils/context', () => ({

src/frontend/js/hooks/useResources/index.spec.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ describe('useResources (omniscient)', () => {
106106
wrapper: Wrapper,
107107
});
108108

109-
await waitFor(() => expect(result.current.states.isPending).toBe(true));
109+
await waitFor(() => expect(screen.queryByText('loading...')).not.toBeInTheDocument());
110+
expect(result.current.states.isPending).toBe(true);
110111
expect(result.current.states.fetching).toBe(true);
111112
expect(result.current.items).toEqual([]);
112113

@@ -222,8 +223,9 @@ describe('useResources (omniscient)', () => {
222223
wrapper: Wrapper,
223224
},
224225
);
225-
226-
expect(result.current.states.isPending).toBe(true);
226+
await waitFor(() => {
227+
expect(result.current.states.isPending).toBe(true);
228+
});
227229
expect(result.current.item).toBe(undefined);
228230
expect(fetchMock.called('https://example.com/api/todos')).toBe(false);
229231

src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/components/CourseLearnersFiltersBar/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('<CourseLearnersFiltersBar/>', () => {
3636
);
3737

3838
// Two selects should have rendered
39-
const organizationFilter: HTMLInputElement = screen.getByRole('combobox', {
39+
const organizationFilter: HTMLInputElement = await screen.findByRole('combobox', {
4040
name: 'Organization',
4141
});
4242

src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CourseProductRelationFactory,
77
OrganizationFactory,
88
} from 'utils/test/factories/joanieLegacy';
9-
import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
9+
import JoanieAppWrapper, { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper';
1010
import useCourseLearnersFilters from '.';
1111

1212
jest.mock('utils/context', () => ({

src/frontend/js/utils/test/render.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { RenderResult, screen, render as testingLibraryRender } from '@testing-library/react';
2-
import React, { ReactElement } from 'react';
2+
import React, { ReactElement, lazy } from 'react';
33
import { Nullable } from 'types/utils';
44
import { AppWrapperProps } from './wrappers/types';
5-
import { JoanieAppWrapper } from './wrappers/JoanieAppWrapper';
5+
6+
const JoanieAppWrapper = lazy(() => import('./wrappers/JoanieAppWrapper'));
67

78
// ------- setup -------
89

src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const setupJoanieSession = () => {
1919
};
2020
};
2121

22-
export const JoanieAppWrapper = ({
22+
const JoanieAppWrapper = ({
2323
children,
2424
intlOptions,
2525
queryOptions,
@@ -35,3 +35,5 @@ export const JoanieAppWrapper = ({
3535
</BaseJoanieAppWrapper>
3636
);
3737
};
38+
39+
export default JoanieAppWrapper;

src/frontend/js/widgets/Dashboard/components/TeacherDashboardCourseSidebar/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('<TeacherDashboardCourseSidebar/>', () => {
5454
});
5555

5656
await expectNoSpinner('Loading course...');
57-
const link = screen.getByRole('link', {
57+
const link = await screen.findByRole('link', {
5858
name: intl.formatMessage(messages.syllabusLinkLabel),
5959
});
6060
expect(link).toHaveAttribute('href', `/redirects/courses/${course.code}`);

0 commit comments

Comments
 (0)