Skip to content

fix(contribution): bloquer "Afficher les informations" sans CC sélectionnée#7232

Open
maxgfr wants to merge 5 commits intodevfrom
maxgfr/afficher-les-informations
Open

fix(contribution): bloquer "Afficher les informations" sans CC sélectionnée#7232
maxgfr wants to merge 5 commits intodevfrom
maxgfr/afficher-les-informations

Conversation

@maxgfr
Copy link
Copy Markdown
Member

@maxgfr maxgfr commented Apr 11, 2026

fix #7231

…ionnée

Sur les pages contribution, cliquer sur le bouton « Afficher les
informations » sans avoir sélectionné de convention collective n'avait
aucun retour visuel pour l'utilisateur. Le clic est désormais bloqué et
un message d'erreur invite à sélectionner une convention collective ou
à utiliser le bouton « Afficher les informations sans sélectionner une
convention collective » situé en dessous.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@maxgfr maxgfr temporarily deployed to build-preproduction April 11, 2026 08:52 — with GitHub Actions Inactive
@revu-bot revu-bot bot requested a review from revu-bot April 11, 2026 08:52
Copy link
Copy Markdown
Collaborator

@revu-bot revu-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Assessment

The PR correctly addresses issue #7231 by showing a validation error when the user clicks "Afficher les informations" without selecting a convention collective. The implementation is clean and the test coverage is solid. A few issues worth addressing:

File Lines Severity Issue
ContributionGenericAgreementSearch.tsx 155–165 IMPORTANT event.preventDefault() called after router.push() — dead code in the valid-agreement branch
ContributionGenericAgreementSearch.tsx 148–149 IMPORTANT setShowMissingAgreementError(false) is redundant after the early-return guard
ContributionGenericAgreementSearch.tsx 133–145 MINOR Error alert rendered above the button it describes — consider placing it after for better reading order
contributions.test.tsx 127–148 MINOR New tests marked async but contain no await — misleading signature

Comment on lines +159 to +169
setShowMissingAgreementError(false);
onDisplayClick(isValid && !!selectedAgreement);
if (isValid && selectedAgreement) {
router.push(
slug === "les-conges-pour-evenements-familiaux"
? `/contribution/${slug}/${selectedAgreement?.slug || selectedAgreement?.num}`
: `/contribution/${selectedAgreement?.num}-${slug}`
);
} else {
event.preventDefault();
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMPORTANT] event.preventDefault() is unreachable dead code in the valid-agreement branch

  • After the early-return guard on line 148 (if (!selectedAgreement) { … return; }), selectedAgreement is guaranteed to be truthy for the rest of the handler.
  • Therefore the else { event.preventDefault() } branch (when isValid is false but selectedAgreement is set) is still reachable — but calling event.preventDefault() on a type="button" has no effect anyway, since buttons don't have a default browser action.
  • More importantly, setShowMissingAgreementError(false) on line 149 is now redundant: the only way to reach it is when selectedAgreement is truthy, and the useEffect already resets the flag whenever selectedAgreement changes. Keeping it creates a false impression that it is needed here.
- setShowMissingAgreementError(false);
  onDisplayClick(isValid && !!selectedAgreement);
  if (isValid && selectedAgreement) {
    router.push(
      slug === "les-conges-pour-evenements-familiaux"
        ? `/contribution/${slug}/${selectedAgreement?.slug || selectedAgreement?.num}`
        : `/contribution/${selectedAgreement?.num}-${slug}`
    );
- } else {
-   event.preventDefault();
  }

Suggested clean-up:

Comment on lines +133 to +145
{showMissingAgreementError && (
<AccessibleAlert
title="Veuillez sélectionner une convention collective"
description={
<p>
Pour afficher des informations personnalisées, vous devez
d’abord sélectionner une convention collective. Si vous ne
souhaitez pas en sélectionner, vous pouvez cliquer sur
«&nbsp;Afficher les informations sans sélectionner une
convention collective&nbsp;» ci-dessous.
</p>
}
severity="error"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMPORTANT] Error alert is rendered above the button it describes — reading order concern

  • Screen readers and keyboard users encounter the error message before the button that triggered it. This is counter-intuitive: the user activates the button, then has to scroll/tab back up to read the error.
  • DSFR convention for inline form errors is to place the alert immediately after the triggering control, not before it.
  • Moving the <AccessibleAlert> below the <Button> keeps the DOM order consistent with the visual interaction flow and improves the experience for assistive-technology users.
Suggested change
{showMissingAgreementError && (
<AccessibleAlert
title="Veuillez sélectionner une convention collective"
description={
<p>
Pour afficher des informations personnalisées, vous devez
d’abord sélectionner une convention collective. Si vous ne
souhaitez pas en sélectionner, vous pouvez cliquer sur
«&nbsp;Afficher les informations sans sélectionner une
convention collective&nbsp;» ci-dessous.
</p>
}
severity="error"
<Button
className={fr.cx("fr-mt-2w")}
type="button"
onClick={(event) => {
if (!selectedAgreement) {
event.preventDefault();
setShowMissingAgreementError(true);
return;
}
onDisplayClick(isValid && !!selectedAgreement);
if (isValid) {
router.push(
slug === "les-conges-pour-evenements-familiaux"
? `/contribution/${slug}/${selectedAgreement.slug || selectedAgreement.num}`
: `/contribution/${selectedAgreement.num}-${slug}`
);
}
}}
>
Afficher les informations
</Button>
{showMissingAgreementError && (
<AccessibleAlert
title="Veuillez sélectionner une convention collective"
description={
<p>
Pour afficher des informations personnalisées, vous devez
d'abord sélectionner une convention collective. Si vous ne
souhaitez pas en sélectionner, vous pouvez cliquer sur
«&nbsp;Afficher les informations sans sélectionner une
convention collective&nbsp;» ci-dessous.
</p>
}
severity="error"
className={["fr-mt-2w"]}
data-testid="missing-agreement-error"
/>
)}

expect(rendering.getByText("my content")).toBeInTheDocument();
});

it("should display an error and not navigate when clicking 'Afficher les informations' without selecting any agreement", async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MINOR] New tests are declared async but contain no await — misleading signature

  • async functions that never await anything are functionally synchronous. This is misleading to future maintainers who may assume there is asynchronous work happening.
  • Either remove async from the two purely synchronous tests, or add the missing await if async assertions were intended.

Affected tests:

  • "should display an error and not navigate when clicking 'Afficher les informations' without selecting any agreement" (line 127)
  • "should still allow displaying generic content via the fallback link when no agreement is selected" (line 163)
Suggested change
it("should display an error and not navigate when clicking 'Afficher les informations' without selecting any agreement", async () => {
it("should display an error and not navigate when clicking 'Afficher les informations' without selecting any agreement", () => {

@maxgfr maxgfr requested a review from m-maillot April 11, 2026 08:58
@maxgfr maxgfr assigned maxgfr and unassigned maxgfr Apr 11, 2026
…ns CC

Le test «afficher les infos - sans CC» vérifiait l'ancien comportement
buggé où cliquer sur le bouton principal sans convention collective
émettait l'évènement de tracking «click_afficher_les_informations_sans_CC».
Désormais, ce clic est bloqué et un message d'erreur est affiché : le
test vérifie l'absence d'évènement et la présence du message d'erreur.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@maxgfr maxgfr temporarily deployed to build-preproduction April 11, 2026 09:02 — with GitHub Actions Inactive
@maxgfr maxgfr temporarily deployed to build-review-auto April 11, 2026 09:02 — with GitHub Actions Inactive
@maxgfr maxgfr temporarily deployed to build-review-auto April 16, 2026 14:16 — with GitHub Actions Inactive
@maxgfr maxgfr temporarily deployed to build-preproduction April 16, 2026 14:16 — with GitHub Actions Inactive
L'ancien bouton « Afficher les informations sans sélectionner une
convention collective » a été remplacé par un radio « Je ne souhaite
pas renseigner ma convention collective. » suivi du bouton « Afficher
les informations ». Le test e2e suit désormais ce parcours.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@maxgfr maxgfr temporarily deployed to build-review-auto April 16, 2026 16:01 — with GitHub Actions Inactive
@maxgfr maxgfr temporarily deployed to build-preproduction April 16, 2026 16:01 — with GitHub Actions Inactive
…d'information

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@maxgfr maxgfr temporarily deployed to build-review-auto April 17, 2026 10:22 — with GitHub Actions Inactive
@maxgfr maxgfr temporarily deployed to build-preproduction April 17, 2026 10:22 — with GitHub Actions Inactive
@sonarqubecloud
Copy link
Copy Markdown

@tokenbureau
Copy link
Copy Markdown

tokenbureau bot commented Apr 17, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contributions : afficher un message d'erreur si l'utilisateur clique sur "Afficher les informations" sans sélectionner de convention collective

2 participants