diff --git a/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage.tsx b/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage.tsx index c8003d543..9a6f021c4 100644 --- a/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage.tsx +++ b/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage.tsx @@ -38,7 +38,9 @@ function CreationBeneficiaireFranceTravailPage(): ReactElement { email: nouveauBeneficiaire.email, }) - setPortefeuille(portefeuille.concat(beneficiaireCree)) + setPortefeuille( + portefeuille.concat({ ...beneficiaireCree, estAArchiver: false }) + ) setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id) router.push('/mes-jeunes') } catch (error) { diff --git a/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireMiloPage.tsx b/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireMiloPage.tsx index b817a304c..cfe324e6f 100644 --- a/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireMiloPage.tsx +++ b/app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireMiloPage.tsx @@ -59,7 +59,9 @@ function CreationBeneficiaireMiloPage() { surcharge ) - setPortefeuille(portefeuille.concat(beneficiaireCree)) + setPortefeuille( + portefeuille.concat({ ...beneficiaireCree, estAArchiver: false }) + ) setAlerte(AlerteParam.creationBeneficiaire, beneficiaireCree.id) router.push('/mes-jeunes') router.refresh() diff --git a/fixtures/beneficiaire.ts b/fixtures/beneficiaire.ts index a0f2f828f..03fb8a265 100644 --- a/fixtures/beneficiaire.ts +++ b/fixtures/beneficiaire.ts @@ -5,6 +5,7 @@ import { BeneficiaireAvecCompteursActionsRdvs, BeneficiaireEtChat, BeneficiaireFromListe, + BeneficiaireWithActivity, CategorieSituation, Chat, ConseillerHistorique, @@ -35,6 +36,16 @@ export const uneBaseBeneficiaire = ( return { ...defaults, ...overrides } } +export const unBeneficiaireWithActivity = ( + overrides: Partial = {} +): BeneficiaireWithActivity => { + const defaults: BeneficiaireWithActivity = { + ...uneBaseBeneficiaire(), + estAArchiver: false, + } + return { ...defaults, ...overrides } +} + export const unDetailBeneficiaire = ( overrides: Partial = {} ): DetailBeneficiaire => { @@ -103,10 +114,9 @@ export const unItemBeneficiaire = ( overrides: Partial = {} ): BeneficiaireFromListe => { const defaults: BeneficiaireFromListe = { - ...uneBaseBeneficiaire(), + ...unBeneficiaireWithActivity({ lastActivity: '2021-12-07T17:30:07.756Z' }), isActivated: true, isReaffectationTemporaire: false, - lastActivity: '2021-12-07T17:30:07.756Z', situationCourante: CategorieSituation.SANS_SITUATION, } return { ...defaults, ...overrides } @@ -167,6 +177,7 @@ export const unItemBeneficiaireJson = ( id: 'beneficiaire-1', firstName: 'Kenji', lastName: 'Jirac', + estAArchiver: false, isActivated: true, isReaffectationTemporaire: false, lastActivity: '2021-12-07T17:30:07.756Z', @@ -311,12 +322,6 @@ export const desConseillersBeneficiaireJson = })) } -export function extractBaseBeneficiaire( - base: BaseBeneficiaire -): BaseBeneficiaire { - return { id: base.id, nom: base.nom, prenom: base.prenom } -} - export const desIndicateursSemaineJson = ( overrides: Partial = {} ): IndicateursSemaineJson => { diff --git a/interfaces/beneficiaire.ts b/interfaces/beneficiaire.ts index 10642c3a0..9b8c9fe0f 100644 --- a/interfaces/beneficiaire.ts +++ b/interfaces/beneficiaire.ts @@ -1,7 +1,6 @@ import { DateTime } from 'luxon' import { StatutDemarche } from 'interfaces/json/beneficiaire' -import { compareDates, compareDatesDesc } from 'utils/date' export enum EtatSituation { EN_COURS = 'en cours', @@ -21,16 +20,23 @@ export enum CategorieSituation { SANS_SITUATION = 'Sans situation', } -export interface BaseBeneficiaire { +export type Portefeuille = BeneficiaireWithActivity[] + +export type BaseBeneficiaire = { id: string prenom: string nom: string } -export interface BeneficiaireFromListe extends BaseBeneficiaire { +export type BeneficiaireWithActivity = BaseBeneficiaire & { + estAArchiver: boolean + lastActivity?: string + dateFinCEJ?: string +} + +export type BeneficiaireFromListe = BeneficiaireWithActivity & { isActivated: boolean isReaffectationTemporaire: boolean - lastActivity?: string conseillerPrecedent?: { nom: string prenom: string @@ -38,10 +44,9 @@ export interface BeneficiaireFromListe extends BaseBeneficiaire { } situationCourante: CategorieSituation structureMilo?: { id: string } - dateFinCEJ?: string } -export interface DetailBeneficiaire extends BaseBeneficiaire { +export type DetailBeneficiaire = BaseBeneficiaire & { creationDate: string isActivated: boolean isReaffectationTemporaire: boolean @@ -60,7 +65,7 @@ export interface DetailBeneficiaire extends BaseBeneficiaire { structureMilo?: { id: string } } -export interface MetadonneesFavoris { +export type MetadonneesFavoris = { autoriseLePartage: boolean offres: { total: number @@ -95,7 +100,7 @@ export type BeneficiaireEtablissement = { dateDerniereActivite?: string } -export interface Chat { +export type Chat = { chatId: string seenByConseiller: boolean flaggedByConseiller: boolean @@ -110,7 +115,7 @@ export interface Chat { export type BeneficiaireEtChat = BaseBeneficiaire & Chat -export interface DossierMilo { +export type DossierMilo = { id: string prenom: string nom: string @@ -119,7 +124,7 @@ export interface DossierMilo { email?: string } -export interface ConseillerHistorique { +export type ConseillerHistorique = { id: string nom: string prenom: string @@ -163,13 +168,6 @@ export function compareBeneficiairesByNom( ) } -export function compareBeneficiairesByLastNameDesc( - beneficiaire1: BaseBeneficiaire, - beneficiaire2: BaseBeneficiaire -): number { - return -compareBeneficiairesByNom(beneficiaire1, beneficiaire2) -} - export function compareBeneficiairesBySituation( beneficiaire1: BeneficiaireFromListe, beneficiaire2: BeneficiaireFromListe @@ -179,13 +177,6 @@ export function compareBeneficiairesBySituation( ) } -export function compareBeneficiairesBySituationDesc( - beneficiaire1: BeneficiaireFromListe, - beneficiaire2: BeneficiaireFromListe -): number { - return -compareBeneficiairesBySituation(beneficiaire1, beneficiaire2) -} - export function compareBeneficiaireChat( a: BeneficiaireEtChat, b: BeneficiaireEtChat @@ -197,34 +188,6 @@ export function compareBeneficiaireChat( ) } -export function compareBeneficiairesByLastActivity( - beneficiaire1: BeneficiaireFromListe, - beneficiaire2: BeneficiaireFromListe, - sortStatutCompteActif: number -) { - const date1 = beneficiaire1.lastActivity - ? DateTime.fromISO(beneficiaire1.lastActivity) - : undefined - const date2 = beneficiaire2.lastActivity - ? DateTime.fromISO(beneficiaire2.lastActivity) - : undefined - return compareDates(date1, date2) || sortStatutCompteActif -} - -export function compareBeneficiairesByLastActivityDesc( - beneficiaire1: BeneficiaireFromListe, - beneficiaire2: BeneficiaireFromListe, - sortStatutCompteActif: number -) { - const date1 = beneficiaire1.lastActivity - ? DateTime.fromISO(beneficiaire1.lastActivity) - : undefined - const date2 = beneficiaire2.lastActivity - ? DateTime.fromISO(beneficiaire2.lastActivity) - : undefined - return compareDatesDesc(date1, date2) || -sortStatutCompteActif -} - export function getNomBeneficiaireComplet( b: Pick ): string { @@ -265,3 +228,20 @@ function comparerParDate(a: BeneficiaireEtChat, b: BeneficiaireEtChat): number { } return 0 } + +export function extractBaseBeneficiaire( + base: BaseBeneficiaire +): BaseBeneficiaire { + return { id: base.id, nom: base.nom, prenom: base.prenom } +} + +export function extractBeneficiaireWithActivity( + beneficiaire: BeneficiaireWithActivity +): BeneficiaireWithActivity { + return { + ...extractBaseBeneficiaire(beneficiaire), + estAArchiver: beneficiaire.estAArchiver, + lastActivity: beneficiaire.lastActivity, + dateFinCEJ: beneficiaire.dateFinCEJ, + } +} diff --git a/interfaces/json/beneficiaire.ts b/interfaces/json/beneficiaire.ts index 96765c479..4f2766b2f 100644 --- a/interfaces/json/beneficiaire.ts +++ b/interfaces/json/beneficiaire.ts @@ -32,6 +32,7 @@ export interface BaseBeneficiaireJson { export interface ItemBeneficiaireJson extends BaseBeneficiaireJson { isActivated: boolean isReaffectationTemporaire: boolean + estAArchiver: boolean lastActivity?: string situationCourante?: Situation dateFinCEJ?: string diff --git a/tests/components/ChatContainer.test.tsx b/tests/components/ChatContainer.test.tsx index b8df581d5..d599a8c53 100644 --- a/tests/components/ChatContainer.test.tsx +++ b/tests/components/ChatContainer.test.tsx @@ -5,11 +5,10 @@ import React from 'react' import ChatContainer from 'components/chat/ChatContainer' import { desItemsBeneficiaires, - extractBaseBeneficiaire, unBeneficiaireChat, } from 'fixtures/beneficiaire' import { desListesDeDiffusion } from 'fixtures/listes-de-diffusion' -import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire' +import { BaseBeneficiaire, BeneficiaireEtChat, extractBaseBeneficiaire } from 'interfaces/beneficiaire' import { getConseillersDuJeuneClientSide } from 'services/beneficiaires.service' import { getListesDeDiffusionClientSide } from 'services/listes-de-diffusion.service' import { getMessageImportant } from 'services/messages.service' diff --git a/tests/components/ChatRoom.test.tsx b/tests/components/ChatRoom.test.tsx index 57e84d053..8ecc46052 100644 --- a/tests/components/ChatRoom.test.tsx +++ b/tests/components/ChatRoom.test.tsx @@ -9,11 +9,14 @@ import ChatRoom from 'components/chat/ChatRoom' import AlerteDisplayer from 'components/layouts/AlerteDisplayer' import { desItemsBeneficiaires, - extractBaseBeneficiaire, unBeneficiaireChat, } from 'fixtures/beneficiaire' import { unConseiller } from 'fixtures/conseiller' -import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire' +import { + BaseBeneficiaire, + BeneficiaireEtChat, + extractBaseBeneficiaire, +} from 'interfaces/beneficiaire' import { desactiverMessageImportant, getMessageImportant, diff --git a/tests/pages/CreationBeneficiaireFranceTravailPage.test.tsx b/tests/pages/CreationBeneficiaireFranceTravailPage.test.tsx index 0fa28245d..c448b34e1 100644 --- a/tests/pages/CreationBeneficiaireFranceTravailPage.test.tsx +++ b/tests/pages/CreationBeneficiaireFranceTravailPage.test.tsx @@ -1,16 +1,18 @@ import { screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { axe } from 'jest-axe' -import { Mock } from 'jest-mock' import { useRouter } from 'next/navigation' import CreationBeneficiaireFranceTravailPage from 'app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireFranceTravailPage' import { desItemsBeneficiaires, - extractBaseBeneficiaire, + unBeneficiaireWithActivity, uneBaseBeneficiaire, } from 'fixtures/beneficiaire' -import { BaseBeneficiaire } from 'interfaces/beneficiaire' +import { + extractBeneficiaireWithActivity, + Portefeuille, +} from 'interfaces/beneficiaire' import { AlerteParam } from 'referentiel/alerteParam' import { createCompteJeuneFranceTravail } from 'services/beneficiaires.service' import renderWithContexts from 'tests/renderWithContexts' @@ -21,17 +23,17 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => { let container: HTMLElement let submitButton: HTMLElement - let push: Function + let push: () => void let alerteSetter: (key: AlerteParam | undefined, target?: string) => void - let portefeuilleSetter: (updatedBeneficiaires: BaseBeneficiaire[]) => void - let portefeuille: BaseBeneficiaire[] + let portefeuilleSetter: (updatedBeneficiaires: Portefeuille) => void + let portefeuille: Portefeuille const emailLabel: string = '* E-mail (ex : monemail@exemple.com)' beforeEach(async () => { - push = jest.fn(() => Promise.resolve()) + push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) alerteSetter = jest.fn() portefeuilleSetter = jest.fn() - portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire) + portefeuille = desItemsBeneficiaires().map(extractBeneficiaireWithActivity) ;({ container } = renderWithContexts( , { @@ -139,7 +141,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => { it('a11y', async () => { // Given - ;(createCompteJeuneFranceTravail as Mock).mockResolvedValue( + ;(createCompteJeuneFranceTravail as jest.Mock).mockResolvedValue( uneBaseBeneficiaire() ) @@ -153,7 +155,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => { it('devrait revenir sur la page des jeunes du conseiller', async () => { // Given - ;(createCompteJeuneFranceTravail as Mock).mockResolvedValue( + ;(createCompteJeuneFranceTravail as jest.Mock).mockResolvedValue( uneBaseBeneficiaire() ) @@ -170,7 +172,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => { expect(portefeuilleSetter).toHaveBeenCalledWith([ ...portefeuille, - uneBaseBeneficiaire(), + unBeneficiaireWithActivity(), ]) expect(alerteSetter).toHaveBeenCalledWith( 'creationBeneficiaire', @@ -181,7 +183,7 @@ describe('CreationBeneficiaireFranceTravailPage client side', () => { it("devrait afficher un message d'erreur en cas de création de compte en échec", async () => { // Given - ;(createCompteJeuneFranceTravail as Mock).mockRejectedValue({ + ;(createCompteJeuneFranceTravail as jest.Mock).mockRejectedValue({ message: "un message d'erreur", }) diff --git a/tests/pages/CreationBeneficiaireMiloPage.test.tsx b/tests/pages/CreationBeneficiaireMiloPage.test.tsx index 358c64c63..6f542fef6 100644 --- a/tests/pages/CreationBeneficiaireMiloPage.test.tsx +++ b/tests/pages/CreationBeneficiaireMiloPage.test.tsx @@ -6,11 +6,14 @@ import { useRouter } from 'next/navigation' import CreationBeneficiaireMiloPage from 'app/(connected)/(with-sidebar)/(with-chat)/mes-jeunes/creation-jeune/CreationBeneficiaireMiloPage' import { desItemsBeneficiaires, - extractBaseBeneficiaire, + unBeneficiaireWithActivity, uneBaseBeneficiaire, } from 'fixtures/beneficiaire' import { unDossierMilo } from 'fixtures/milo' -import { BaseBeneficiaire } from 'interfaces/beneficiaire' +import { + extractBeneficiaireWithActivity, + Portefeuille, +} from 'interfaces/beneficiaire' import { createCompteJeuneMilo, getDossierJeune, @@ -70,12 +73,14 @@ describe('CreationBeneficiaireMiloPage client side', () => { }) describe('quand on a recherché un dossier', () => { - let push: Function - let refresh: Function + let push: () => void + let refresh: () => void let setAlerte: () => void - let setPortefeuille: (updatedBeneficiaires: BaseBeneficiaire[]) => void + let setPortefeuille: (updatedBeneficiaires: Portefeuille) => void const dossier = unDossierMilo() - const portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire) + const portefeuille = desItemsBeneficiaires().map( + extractBeneficiaireWithActivity + ) beforeEach(async () => { // Given ;(getDossierJeune as jest.Mock).mockResolvedValue(dossier) @@ -83,7 +88,7 @@ describe('CreationBeneficiaireMiloPage client side', () => { uneBaseBeneficiaire() ) - push = jest.fn(() => Promise.resolve()) + push = jest.fn() refresh = jest.fn() setAlerte = jest.fn() setPortefeuille = jest.fn() @@ -138,7 +143,7 @@ describe('CreationBeneficiaireMiloPage client side', () => { expect(setPortefeuille).toHaveBeenCalledWith([ ...portefeuille, - uneBaseBeneficiaire(), + unBeneficiaireWithActivity(), ]) expect(setAlerte).toHaveBeenCalledWith( 'creationBeneficiaire', diff --git a/tests/pages/EnvoiMessageGroupePage.test.tsx b/tests/pages/EnvoiMessageGroupePage.test.tsx index 0aaf65e79..e98f11da6 100644 --- a/tests/pages/EnvoiMessageGroupePage.test.tsx +++ b/tests/pages/EnvoiMessageGroupePage.test.tsx @@ -34,7 +34,7 @@ describe('EnvoiMessageGroupePage client side', () => { let push: Function beforeEach(async () => { alerteSetter = jest.fn() - push = jest.fn(() => Promise.resolve()) + push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) beneficiaires = desItemsBeneficiaires() @@ -250,7 +250,7 @@ describe('EnvoiMessageGroupePage client side', () => { let newMessage: string let file: File beforeEach(async () => { - push = jest.fn(() => Promise.resolve()) + push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) ;(uploadFichier as jest.Mock).mockResolvedValue({ id: 'id-fichier', diff --git a/tests/pages/MessageriePage.test.tsx b/tests/pages/MessageriePage.test.tsx index 8f0c7b60e..f977d6ec2 100644 --- a/tests/pages/MessageriePage.test.tsx +++ b/tests/pages/MessageriePage.test.tsx @@ -5,12 +5,11 @@ import React from 'react' import MessageriePage from 'app/(connected)/(with-sidebar)/messagerie/MessageriePage' import { desItemsBeneficiaires, - extractBaseBeneficiaire, unBeneficiaireChat, } from 'fixtures/beneficiaire' import { desListesDeDiffusion } from 'fixtures/listes-de-diffusion' import { desMessagesListeDeDiffusionParJour } from 'fixtures/message' -import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire' +import { BaseBeneficiaire, BeneficiaireEtChat, extractBaseBeneficiaire } from 'interfaces/beneficiaire' import { StructureConseiller } from 'interfaces/conseiller' import { ByDay, MessageListeDiffusion } from 'interfaces/message' import { getListesDeDiffusionClientSide } from 'services/listes-de-diffusion.service' diff --git a/tests/pages/PartageRecherchePage.test.tsx b/tests/pages/PartageRecherchePage.test.tsx index f4538c894..1c2ed4ccf 100644 --- a/tests/pages/PartageRecherchePage.test.tsx +++ b/tests/pages/PartageRecherchePage.test.tsx @@ -39,7 +39,7 @@ describe('Partage Recherche', () => { describe('pour tous les partages de recherche', () => { beforeEach(() => { alerteSetter = jest.fn() - push = jest.fn(() => Promise.resolve()) + push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) ;({ container } = renderWithContexts( { ;( getBeneficiairesDuConseillerClientSide as jest.Mock ).mockResolvedValue([]) - push = jest.fn(() => Promise.resolve()) + push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) // When diff --git a/tests/pages/agenda/AgendaConseiller.page.test.tsx b/tests/pages/agenda/AgendaConseiller.page.test.tsx index e8cec68c2..85852c32d 100644 --- a/tests/pages/agenda/AgendaConseiller.page.test.tsx +++ b/tests/pages/agenda/AgendaConseiller.page.test.tsx @@ -1,5 +1,6 @@ import { act, screen, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' +import { AxeResults } from 'axe-core' import { axe } from 'jest-axe' import { DateTime } from 'luxon' import { useRouter } from 'next/navigation' @@ -114,8 +115,13 @@ describe('Agenda - Onglet conseiller', () => { }) it('a11y', async () => { - const results = await axe(container) - expect(results).toHaveNoViolations() + let results: AxeResults + + await act(async () => { + results = await axe(container) + }) + + expect(results!).toHaveNoViolations() }) it('a deux boutons de navigation', () => { diff --git a/tests/pages/edition-rdv/EditionRdvPage.test.tsx b/tests/pages/edition-rdv/EditionRdvPage.test.tsx index 76e2e93cd..c78d1c867 100644 --- a/tests/pages/edition-rdv/EditionRdvPage.test.tsx +++ b/tests/pages/edition-rdv/EditionRdvPage.test.tsx @@ -82,7 +82,7 @@ describe('EditionRdvPage client side', () => { typesRendezVous = typesEvenement() alerteSetter = jest.fn() - push = jest.fn(() => Promise.resolve()) + push = jest.fn() refresh = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push, refresh }) }) @@ -1455,7 +1455,7 @@ describe('EditionRdvPage client side', () => { typesRendezVous = typesAnimationCollective() alerteSetter = jest.fn() - push = jest.fn(() => Promise.resolve()) + push = jest.fn() refresh = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push, refresh }) }) diff --git a/tests/pages/fiche-jeune/GestionCompte.test.tsx b/tests/pages/fiche-jeune/GestionCompte.test.tsx index 24042b72d..03d82f310 100644 --- a/tests/pages/fiche-jeune/GestionCompte.test.tsx +++ b/tests/pages/fiche-jeune/GestionCompte.test.tsx @@ -10,11 +10,14 @@ import { unAgenda } from 'fixtures/agenda' import { desIndicateursSemaine, desItemsBeneficiaires, - extractBaseBeneficiaire, unDetailBeneficiaire, } from 'fixtures/beneficiaire' import { desMotifsDeSuppression } from 'fixtures/referentiel' -import { BaseBeneficiaire, DetailBeneficiaire } from 'interfaces/beneficiaire' +import { + DetailBeneficiaire, + extractBeneficiaireWithActivity, + Portefeuille, +} from 'interfaces/beneficiaire' import { StructureConseiller } from 'interfaces/conseiller' import { MotifSuppressionBeneficiaire } from 'interfaces/referentiel' import { AlerteParam } from 'referentiel/alerteParam' @@ -36,16 +39,16 @@ describe('Gestion du compte dans la fiche jeune', () => { let motifsSuppression: MotifSuppressionBeneficiaire[] let alerteSetter: jest.Mock - let portefeuilleSetter: (updatedBeneficiaires: BaseBeneficiaire[]) => void + let portefeuilleSetter: (updatedBeneficiaires: Portefeuille) => void let push: jest.Mock - let portefeuille: BaseBeneficiaire[] + let portefeuille: Portefeuille beforeEach(async () => { push = jest.fn() ;(useRouter as jest.Mock).mockReturnValue({ push }) alerteSetter = jest.fn() portefeuilleSetter = jest.fn() - portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire) + portefeuille = desItemsBeneficiaires().map(extractBeneficiaireWithActivity) motifsSuppression = desMotifsDeSuppression() ;(getMotifsSuppression as jest.Mock).mockResolvedValue(motifsSuppression) @@ -352,7 +355,7 @@ describe('Gestion du compte dans la fiche jeune', () => { async function renderFicheBeneficiaire( beneficiaire: DetailBeneficiaire, - portefeuilleSetter?: (updatedBeneficiaires: BaseBeneficiaire[]) => void, + portefeuilleSetter?: (updatedBeneficiaires: Portefeuille) => void, alerteSetter?: (key: AlerteParam | undefined, target?: string) => void ) { await act(async () => { diff --git a/tests/pages/layouts/LayoutWhenConnected.test.tsx b/tests/pages/layouts/LayoutWhenConnected.test.tsx index 96e0663c2..e1df6f6d1 100644 --- a/tests/pages/layouts/LayoutWhenConnected.test.tsx +++ b/tests/pages/layouts/LayoutWhenConnected.test.tsx @@ -5,10 +5,10 @@ import { getServerSession } from 'next-auth' import LayoutWhenConnected, { generateMetadata } from 'app/(connected)/layout' import { desItemsBeneficiaires, - extractBaseBeneficiaire, + } from 'fixtures/beneficiaire' import { unConseiller } from 'fixtures/conseiller' -import { BeneficiaireFromListe } from 'interfaces/beneficiaire' +import { BeneficiaireFromListe, extractBaseBeneficiaire, extractBeneficiaireWithActivity } from 'interfaces/beneficiaire' import { Conseiller, StructureConseiller } from 'interfaces/conseiller' import { getBeneficiairesDuConseillerServerSide } from 'services/beneficiaires.service' import { getConseillerServerSide } from 'services/conseiller.service' @@ -121,7 +121,7 @@ describe('LayoutWhenConnected', () => { expect(PortefeuilleProvider).toHaveBeenCalledWith( expect.objectContaining({ portefeuille: [portefeuille[2], portefeuille[0], portefeuille[1]].map( - extractBaseBeneficiaire + extractBeneficiaireWithActivity ), }), undefined diff --git a/tests/pages/pilotage/PilotagePage.sessions.test.tsx b/tests/pages/pilotage/PilotagePage.sessions.test.tsx index 5a874d0af..480d07b06 100644 --- a/tests/pages/pilotage/PilotagePage.sessions.test.tsx +++ b/tests/pages/pilotage/PilotagePage.sessions.test.tsx @@ -2,16 +2,12 @@ import { act, screen, within } from '@testing-library/react' import { AxeResults } from 'axe-core' import { axe } from 'jest-axe' import { useRouter } from 'next/navigation' -import React from 'react' import Pilotage from 'app/(connected)/(with-sidebar)/(with-chat)/pilotage/PilotagePage' import { desCategories } from 'fixtures/action' import { uneListeDeSessionsAClore } from 'fixtures/session' import { StructureConseiller } from 'interfaces/conseiller' -import { - getSessionsACloreServerSide, - SessionsAClore, -} from 'services/sessions.service' +import { getSessionsACloreServerSide } from 'services/sessions.service' import getByDescriptionTerm from 'tests/querySelector' import renderWithContexts from 'tests/renderWithContexts' diff --git a/tests/renderWithContexts.tsx b/tests/renderWithContexts.tsx index 66f5a67c1..0b84d8a8c 100644 --- a/tests/renderWithContexts.tsx +++ b/tests/renderWithContexts.tsx @@ -1,14 +1,15 @@ import { render, RenderResult } from '@testing-library/react' -import React, { Dispatch, ReactNode, SetStateAction } from 'react' +import { Dispatch, ReactNode, SetStateAction } from 'react' import { uneActualite } from 'fixtures/actualites' -import { - desItemsBeneficiaires, - extractBaseBeneficiaire, -} from 'fixtures/beneficiaire' +import { desItemsBeneficiaires } from 'fixtures/beneficiaire' import { unConseiller } from 'fixtures/conseiller' import { ActualitesParsees } from 'interfaces/actualites' -import { BaseBeneficiaire, BeneficiaireEtChat } from 'interfaces/beneficiaire' +import { + BeneficiaireEtChat, + extractBeneficiaireWithActivity, + Portefeuille, +} from 'interfaces/beneficiaire' import { Conseiller } from 'interfaces/conseiller' import { AlerteParam } from 'referentiel/alerteParam' import { ActualitesProvider } from 'utils/actualitesContext' @@ -32,8 +33,8 @@ export default function renderWithContexts( options: { customConseiller?: Partial customPortefeuille?: Partial<{ - value: BaseBeneficiaire[] - setter: (portefeuille: BaseBeneficiaire[]) => void + value: Portefeuille + setter: (portefeuille: Portefeuille) => void }> customChats?: BeneficiaireEtChat[] customCurrentConversation?: Partial<{ @@ -71,7 +72,7 @@ export default function renderWithContexts( ...customPortefeuille, value: customPortefeuille?.value ?? - desItemsBeneficiaires().map(extractBaseBeneficiaire), + desItemsBeneficiaires().map(extractBeneficiaireWithActivity), } const currentConversation = { ...customCurrentConversation } @@ -107,8 +108,8 @@ function provideContexts( children: ReactNode, conseiller: Conseiller, portefeuille: Partial<{ - value: BaseBeneficiaire[] - setter: (portefeuille: BaseBeneficiaire[]) => void + value: Portefeuille + setter: (portefeuille: Portefeuille) => void }>, chats: BeneficiaireEtChat[] | undefined, currentConversation: Partial<{ diff --git a/tests/utils/chatsContext.test.tsx b/tests/utils/chatsContext.test.tsx index 0a24d2387..5e8d289b7 100644 --- a/tests/utils/chatsContext.test.tsx +++ b/tests/utils/chatsContext.test.tsx @@ -1,13 +1,15 @@ -import { act, render, RenderResult } from '@testing-library/react' +import { act, render } from '@testing-library/react' import React from 'react' import { desItemsBeneficiaires, - extractBaseBeneficiaire, unBeneficiaireChat, } from 'fixtures/beneficiaire' import { unConseiller } from 'fixtures/conseiller' -import { BeneficiaireEtChat } from 'interfaces/beneficiaire' +import { + BeneficiaireEtChat, + extractBeneficiaireWithActivity, +} from 'interfaces/beneficiaire' import { observeConseillerChats } from 'services/messages.service' import { ChatCredentialsProvider } from 'utils/chat/chatCredentialsContext' import { ChatsProvider } from 'utils/chat/chatsContext' @@ -17,14 +19,16 @@ import { PortefeuilleProvider } from 'utils/portefeuilleContext' jest.mock('services/messages.service') const mockAudio = jest.fn() -// @ts-ignore +// @ts-expect-error trop compliqué de redéfinir tout Audio global.Audio = class FakeAudio { play = mockAudio } describe('ChatsProvider', () => { let updateChatsRef: (chats: BeneficiaireEtChat[]) => void - const portefeuille = desItemsBeneficiaires().map(extractBaseBeneficiaire) + const portefeuille = desItemsBeneficiaires().map( + extractBeneficiaireWithActivity + ) const conversations = [ unBeneficiaireChat({ ...portefeuille[0], @@ -61,10 +65,9 @@ describe('ChatsProvider', () => { token: 'tokenFirebase', cleChiffrement: 'cleChiffrement', } - let renderResult: RenderResult beforeEach(async () => { // When - renderResult = await act(async () => + await act(async () => render( <> @@ -86,7 +89,7 @@ describe('ChatsProvider', () => { // Then expect(observeConseillerChats).toHaveBeenCalledWith( 'cleChiffrement', - portefeuille.map(extractBaseBeneficiaire), + portefeuille, expect.any(Function) ) }) diff --git a/utils/AppContextProviders.tsx b/utils/AppContextProviders.tsx index 202415fcc..d8d72a260 100644 --- a/utils/AppContextProviders.tsx +++ b/utils/AppContextProviders.tsx @@ -4,10 +4,10 @@ import { apm } from '@elastic/apm-rum' import { ThemeProvider } from 'next-themes' import React, { ReactNode } from 'react' -import { extractBaseBeneficiaire } from 'fixtures/beneficiaire' import { BeneficiaireFromListe, compareBeneficiairesByNom, + extractBeneficiaireWithActivity, } from 'interfaces/beneficiaire' import { Conseiller, estPassEmploi } from 'interfaces/conseiller' import { ActualitesProvider } from 'utils/actualitesContext' @@ -31,7 +31,7 @@ export default function AppContextProviders({ children: ReactNode }) { const portefeuilleTrie = portefeuille - .map(extractBaseBeneficiaire) + .map(extractBeneficiaireWithActivity) .sort(compareBeneficiairesByNom) const theme = estPassEmploi(conseiller) ? 'darker' : 'neutral' diff --git a/utils/portefeuilleContext.tsx b/utils/portefeuilleContext.tsx index be6e191d9..b2e38742c 100644 --- a/utils/portefeuilleContext.tsx +++ b/utils/portefeuilleContext.tsx @@ -2,11 +2,11 @@ import { createContext, ReactNode, useContext, useState } from 'react' -import { BaseBeneficiaire } from 'interfaces/beneficiaire' +import { Portefeuille } from 'interfaces/beneficiaire' type PortefeuilleState = [ - BaseBeneficiaire[], - (updatedBeneficiaires: BaseBeneficiaire[]) => void, + Portefeuille, + (updatedBeneficiaires: Portefeuille) => void, ] const PortefeuilleContext = createContext( @@ -19,10 +19,10 @@ export function PortefeuilleProvider({ setterForTests, }: { children: ReactNode - portefeuille: BaseBeneficiaire[] - setterForTests?: (updatedBeneficiaires: BaseBeneficiaire[]) => void + portefeuille: Portefeuille + setterForTests?: (updatedBeneficiaires: Portefeuille) => void }) { - const [state, setPortefeuille] = useState(portefeuille) + const [state, setPortefeuille] = useState(portefeuille) const setter = setterForTests ?? setPortefeuille return (