From 484ff26217487876abff69686a37903fcf3b21c9 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Wed, 5 Feb 2025 23:12:24 +0100 Subject: [PATCH] =?UTF-8?q?feat(=C3=A9conomie-collaborative):=20ne=20pas?= =?UTF-8?q?=20afficher=20le=20bloc=20de=20questions=20si=20aucune=20questi?= =?UTF-8?q?on=20=C3=A0=20poser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/source/components/Simulation/index.tsx | 6 ++- .../ilYADesQuestions.selector.test.ts | 38 +++++++++++++++++++ .../selectors/ilYADesQuestions.selector.ts | 17 +++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 site/source/store/selectors/ilYADesQuestions.selector.test.ts create mode 100644 site/source/store/selectors/ilYADesQuestions.selector.ts diff --git a/site/source/components/Simulation/index.tsx b/site/source/components/Simulation/index.tsx index fa81a1263..fcc71d34f 100644 --- a/site/source/components/Simulation/index.tsx +++ b/site/source/components/Simulation/index.tsx @@ -10,6 +10,7 @@ import ShareOrSaveSimulationBanner, { import { Button } from '@/design-system/buttons' import { Grid, Spacing } from '@/design-system/layout' import { H3 } from '@/design-system/typography/heading' +import { ilYADesQuestionsSelector } from '@/store/selectors/ilYADesQuestions.selector' import { firstStepCompletedSelector } from '@/store/selectors/simulationSelectors' import { TrackPage } from '../ATInternetTracking' @@ -63,6 +64,7 @@ export default function Simulation({ entrepriseSelection = true, }: SimulationProps) { const firstStepCompleted = useSelector(firstStepCompletedSelector) + const ilYADesQuestions = useSelector(ilYADesQuestionsSelector) const shouldShowFeedback = getShouldAskFeedback(useLocation().pathname) return ( @@ -79,7 +81,9 @@ export default function Simulation({
{results}
- + {ilYADesQuestions && ( + + )} )} diff --git a/site/source/store/selectors/ilYADesQuestions.selector.test.ts b/site/source/store/selectors/ilYADesQuestions.selector.test.ts new file mode 100644 index 000000000..a316232ae --- /dev/null +++ b/site/source/store/selectors/ilYADesQuestions.selector.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest' + +import { RootState } from '@/store/reducers/rootReducer' +import { ilYADesQuestionsSelector } from '@/store/selectors/ilYADesQuestions.selector' + +describe('sélecteur ilYADesQuestions', () => { + it('retourne true si une question est en cours', () => { + expect( + ilYADesQuestionsSelector({ + simulation: { + currentQuestion: 'a', + questionsSuivantes: [], + }, + } as unknown as RootState) + ).toEqual(true) + }) + it('retourne true si au moins une question en attente', () => { + expect( + ilYADesQuestionsSelector({ + simulation: { + currentQuestion: undefined, + questionsSuivantes: ['a'], + }, + } as unknown as RootState) + ).toEqual(true) + }) + it('retourne true si au moins une question répondue', () => { + expect( + ilYADesQuestionsSelector({ + simulation: { + currentQuestion: undefined, + questionsSuivantes: [], + questionsRépondues: ['a'], + }, + } as unknown as RootState) + ).toEqual(true) + }) +}) diff --git a/site/source/store/selectors/ilYADesQuestions.selector.ts b/site/source/store/selectors/ilYADesQuestions.selector.ts new file mode 100644 index 000000000..3931ddeb9 --- /dev/null +++ b/site/source/store/selectors/ilYADesQuestions.selector.ts @@ -0,0 +1,17 @@ +import { createSelector } from 'reselect' + +import { currentQuestionSelector } from '@/store/selectors/currentQuestion.selector' +import { questionsRéponduesSelector } from '@/store/selectors/questionsRépondues.selector' +import { questionsSuivantesSelector } from '@/store/selectors/questionsSuivantes.selector' + +export const ilYADesQuestionsSelector = createSelector( + [ + currentQuestionSelector, + questionsSuivantesSelector, + questionsRéponduesSelector, + ], + (questionEnCours, questionsSuivantes, questionsRépondues) => + !!questionEnCours || + !!questionsSuivantes.length || + !!questionsRépondues.length +)