From 3f01ddfdb2fc33632b22aa44045d1c2f6b917325 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Fri, 10 Nov 2023 15:30:44 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA(lib-test)=20more=20options=20on=20?= =?UTF-8?q?wrapInIntlProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can now pass more options to the wrapInIntlProvider function. This will allow us to test easily translated texts. --- .../components/ClassroomAttendance/index.spec.tsx | 7 +++++-- src/frontend/packages/lib_tests/src/intl.tsx | 12 +++++++++--- src/frontend/packages/lib_tests/src/render.tsx | 10 ++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/frontend/packages/lib_classroom/src/components/ClassroomAttendance/index.spec.tsx b/src/frontend/packages/lib_classroom/src/components/ClassroomAttendance/index.spec.tsx index b96174c1a1..eaaf2fff62 100644 --- a/src/frontend/packages/lib_classroom/src/components/ClassroomAttendance/index.spec.tsx +++ b/src/frontend/packages/lib_classroom/src/components/ClassroomAttendance/index.spec.tsx @@ -180,6 +180,9 @@ describe('', () => { { intlOptions: { locale: 'fr', + messages: { + 'components.ClassroomAttendance.durationLabel': 'Durée', + }, }, }, ); @@ -188,13 +191,13 @@ describe('', () => { screen.getByRole('rowheader', { name: /1 janv. 2021, 00:00/, }).textContent, - ).toBe('1 janv. 2021, 00:00-Duration: 00:20'); + ).toBe('1 janv. 2021, 00:00-Durée: 00:20'); expect( screen.getByRole('rowheader', { name: /1 mars 2021, 00:00/, }).textContent, - ).toBe('1 mars 2021, 00:00-Duration: 00:19'); + ).toBe('1 mars 2021, 00:00-Durée: 00:19'); }); it('checks render attendees with multiple sessions', async () => { diff --git a/src/frontend/packages/lib_tests/src/intl.tsx b/src/frontend/packages/lib_tests/src/intl.tsx index 12fbe95649..958443503a 100644 --- a/src/frontend/packages/lib_tests/src/intl.tsx +++ b/src/frontend/packages/lib_tests/src/intl.tsx @@ -1,9 +1,14 @@ -import React from 'react'; +import { ComponentProps } from 'react'; import { IntlProvider, ReactIntlErrorCode } from 'react-intl'; -export const wrapInIntlProvider = (Component: JSX.Element, locale = 'en') => ( +type IntlProviderProps = ComponentProps; + +export const wrapInIntlProvider = ( + Component: JSX.Element, + option?: IntlProviderProps, +) => ( { // https://github.com/formatjs/formatjs/issues/465 if ( @@ -14,6 +19,7 @@ export const wrapInIntlProvider = (Component: JSX.Element, locale = 'en') => ( } throw err; }} + {...option} > {Component} diff --git a/src/frontend/packages/lib_tests/src/render.tsx b/src/frontend/packages/lib_tests/src/render.tsx index bdcfd45afd..030849b5ed 100644 --- a/src/frontend/packages/lib_tests/src/render.tsx +++ b/src/frontend/packages/lib_tests/src/render.tsx @@ -10,17 +10,15 @@ import { import { Grommet, ResponsiveContext, ThemeType } from 'grommet'; import MatchMediaMock from 'jest-matchmedia-mock'; import { BreadCrumbsProvider, GlobalStyles, Nullable, theme } from 'lib-common'; -import React, { CSSProperties, ReactElement } from 'react'; +import React, { CSSProperties, ComponentProps, ReactElement } from 'react'; import toast, { Toast, Toaster, useToaster } from 'react-hot-toast'; +import { IntlProvider } from 'react-intl'; import { RouteProps } from 'react-router-dom'; import { wrapInIntlProvider } from './intl'; import { wrapInRouter } from './router'; // ------- interfaces ------- -interface IntlOptions { - locale?: string; -} interface RouterOptions { routes?: RouteProps[]; componentPath?: string; @@ -48,7 +46,7 @@ interface GrommetOptions { */ export interface RenderOptions { grommetOptions: GrommetOptions; - intlOptions: IntlOptions; + intlOptions?: ComponentProps; queryOptions: QueryOptions; routerOptions: RouterOptions; testingLibraryOptions: TestingLibraryRenderOptions; @@ -123,7 +121,7 @@ export const appendUtilsElement = ( , - options?.intlOptions?.locale || 'en', + options?.intlOptions, ); };