From 47816873f409d2877d67efd060c8977a84e973c9 Mon Sep 17 00:00:00 2001 From: Romain Le Cellier Date: Thu, 7 Mar 2024 16:19:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(frontend)=20Joanie=20api=20c?= =?UTF-8?q?lient=20load=20in=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Joanie's api client shouldn't be loaded on test that don't use it. --- .../js/components/TeacherDashboardCourseList/index.spec.tsx | 2 +- .../js/hooks/useDefaultOrganizationId/index.spec.tsx | 2 +- .../hooks/useCourseLearnersFilters/index.spec.tsx | 2 +- src/frontend/js/utils/test/render.tsx | 5 +++-- src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx | 4 +++- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/frontend/js/components/TeacherDashboardCourseList/index.spec.tsx b/src/frontend/js/components/TeacherDashboardCourseList/index.spec.tsx index e94c38ea9c..41a43a343f 100644 --- a/src/frontend/js/components/TeacherDashboardCourseList/index.spec.tsx +++ b/src/frontend/js/components/TeacherDashboardCourseList/index.spec.tsx @@ -67,7 +67,7 @@ describe('components/TeacherDashboardCourseList', () => { await expectNoSpinner('Loading courses...'); expect( - screen.getByRole('heading', { name: /TeacherDashboardCourseList test title/ }), + await screen.findByRole('heading', { name: /TeacherDashboardCourseList test title/ }), ).toBeInTheDocument(); const calledUrls = fetchMock.calls().map((call) => call[0]); diff --git a/src/frontend/js/hooks/useDefaultOrganizationId/index.spec.tsx b/src/frontend/js/hooks/useDefaultOrganizationId/index.spec.tsx index bdb7ede73c..55024aabae 100644 --- a/src/frontend/js/hooks/useDefaultOrganizationId/index.spec.tsx +++ b/src/frontend/js/hooks/useDefaultOrganizationId/index.spec.tsx @@ -3,7 +3,7 @@ import fetchMock from 'fetch-mock'; import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie'; import { OrganizationFactory } from 'utils/test/factories/joanieLegacy'; import { Organization } from 'types/Joanie'; -import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper'; +import JoanieAppWrapper, { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper'; import useDefaultOrganizationId from '.'; jest.mock('utils/context', () => ({ diff --git a/src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx b/src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx index e29d389894..4241878507 100644 --- a/src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx +++ b/src/frontend/js/pages/TeacherDashboardCourseLearnersLayout/hooks/useCourseLearnersFilters/index.spec.tsx @@ -6,7 +6,7 @@ import { CourseProductRelationFactory, OrganizationFactory, } from 'utils/test/factories/joanieLegacy'; -import { JoanieAppWrapper, setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper'; +import JoanieAppWrapper, { setupJoanieSession } from 'utils/test/wrappers/JoanieAppWrapper'; import useCourseLearnersFilters from '.'; jest.mock('utils/context', () => ({ diff --git a/src/frontend/js/utils/test/render.tsx b/src/frontend/js/utils/test/render.tsx index 5df309d26d..852ff3165c 100644 --- a/src/frontend/js/utils/test/render.tsx +++ b/src/frontend/js/utils/test/render.tsx @@ -1,8 +1,9 @@ import { RenderResult, screen, render as testingLibraryRender } from '@testing-library/react'; -import React, { ReactElement } from 'react'; +import React, { ReactElement, lazy } from 'react'; import { Nullable } from 'types/utils'; import { AppWrapperProps } from './wrappers/types'; -import { JoanieAppWrapper } from './wrappers/JoanieAppWrapper'; + +const JoanieAppWrapper = lazy(() => import('./wrappers/JoanieAppWrapper')); // ------- setup ------- diff --git a/src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx b/src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx index 1ca3038e63..2745bef967 100644 --- a/src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx +++ b/src/frontend/js/utils/test/wrappers/JoanieAppWrapper.tsx @@ -19,7 +19,7 @@ export const setupJoanieSession = () => { }; }; -export const JoanieAppWrapper = ({ +const JoanieAppWrapper = ({ children, intlOptions, queryOptions, @@ -35,3 +35,5 @@ export const JoanieAppWrapper = ({ ); }; + +export default JoanieAppWrapper;