Skip to content

Commit

Permalink
feat: ajout cas tests & correction message erreur cc non traité no CDT
Browse files Browse the repository at this point in the history
  • Loading branch information
victor committed Jan 16, 2025
1 parent 47d7035 commit 54eb05a
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const Autocomplete = <K,>({
onSearch?.(inputValue, results);
setSuggestions(results);
} catch (error) {
onError?.(error);
onError?.(error.message);
setSuggestions([]);
} finally {
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,38 @@ export function ContributionGenericAgreementSearch({
const selectedAgreementAlert = (agreement: EnterpriseAgreement) => {
const isSupported = isCCSupported(contribution, agreement);
const isUnextended = isCCUnextended(contribution, agreement);
if (isUnextended)
return (
<>
Les dispositions de cette convention n’ont pas été étendues. Cela
signifie qu&apos;elles ne s&apos;appliquent qu&apos;aux entreprises
adhérentes à l&apos;une des organisations signataires de
l&apos;accord. Dans ce contexte, nous ne sommes pas en mesure
d&apos;identifier si cette règle s&apos;applique ou non au sein de
votre entreprise. Vous pouvez toutefois consulter la convention
collective{" "}
<a target="_blank" href={agreement.url}>
ici
</a>{" "}
dans le cas où elle s&apos;applique à votre situation.
</>
);
if (contribution.isNoCDT) {
if (isUnextended)
return (
<>
Les dispositions de cette convention n’ont pas été étendues. Cela
signifie qu&apos;elles ne s&apos;appliquent qu&apos;aux entreprises
adhérentes à l&apos;une des organisations signataires de
l&apos;accord. Dans ce contexte, nous ne sommes pas en mesure
d&apos;identifier si cette règle s&apos;applique ou non au sein de
votre entreprise. Vous pouvez toutefois consulter la convention
collective{" "}
<a target="_blank" href={agreement.url}>
ici
</a>{" "}
dans le cas où elle s&apos;applique à votre situation.
</>
);
if (!isSupported)
return (
<>
Nous vous invitons à consulter votre convention collective qui peut
prévoir une réponse. Vous pouvez consulter votre convention
collective{" "}
<a target="_blank" href={agreement.url}>
ici
</a>
.
<br />
{contribution.messageBlockGenericNoCDT}
</>
);
}
if (!isSupported)
return <>Vous pouvez consulter les informations générales ci-dessous.</>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ export function ContributionGenericContent({
}, [displayContent]);
return (
<>
<Button
className={fr.cx(
!displayContent ? "fr-unhidden" : "fr-hidden",
"fr-mt-2w",
"fr-mb-6w"
)}
priority="tertiary no outline"
onClick={() => {
setDisplayContent(true);
onDisplayClick();
}}
>
Afficher les informations sans sélectionner une convention collective
</Button>
{!displayContent && (
<Button
className={fr.cx("fr-mt-2w", "fr-mb-6w")}
priority="tertiary no outline"
onClick={() => {
setDisplayContent(true);
onDisplayClick();
}}
>
Afficher les informations sans sélectionner une convention collective
</Button>
)}
<div className={fr.cx("fr-grid-row", "fr-grid-row--gutters")}>
<div
className={fr.cx(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { render } from "@testing-library/react";
import {
fireEvent,
render,
RenderResult,
cleanup,
} from "@testing-library/react";
import React from "react";
import { wait } from "@testing-library/user-event/dist/utils";

import { ContributionLayout } from "../ContributionLayout";
import { ElasticSearchContribution } from "@socialgouv/cdtn-types";
import { ui } from "./ui";
import { ui as ccUi } from "../../convention-collective/__tests__/ui";
import { Contribution } from "../type";
import { searchAgreement } from "../../convention-collective/search";
import { sendEvent } from "../../utils";

const contribution = {
source: "contributions",
linkedContent: [],
references: [],
idcc: "0000",
date: "05/12/2023",
metas: {
title: "SEO Title",
description: "SEO Description",
Expand All @@ -17,9 +28,33 @@ const contribution = {
breadcrumbs: [],
slug: "slug",
ccnShortTitle: "Nom de la CC",
} as Partial<ElasticSearchContribution> as any;
type: "content",
isGeneric: true,
isNoCdt: false,
ccSupported: ["0016"],
ccUnextended: ["0029"],
messageBlockGenericNoCDT: "message No CDT",
} as Partial<Contribution> as any;

describe("<PageContribution />", () => {
jest.mock("../../convention-collective/search", () => ({
searchAgreement: jest.fn(),
}));

jest.mock("../../utils", () => ({
sendEvent: jest.fn(),
}));

jest.mock("uuid", () => ({
v4: jest.fn(() => ""),
}));

jest.mock("next/navigation", () => ({
redirect: jest.fn(),
usePathname: jest.fn(),
}));

describe("<ContributionLayout />", () => {
let rendering: RenderResult;
it("should render title only if generic", () => {
const { getByRole } = render(
<ContributionLayout contribution={contribution} />
Expand All @@ -30,13 +65,209 @@ describe("<PageContribution />", () => {
);
});
it("should render title with cc short name if contribution with CC", () => {
contribution.idcc = "0029";
const { getByRole } = render(
<ContributionLayout contribution={contribution} />
<ContributionLayout
contribution={{ ...contribution, idcc: "0029", isGeneric: false }}
/>
);
const titreH1 = getByRole("heading", { level: 1 });
expect(titreH1.textContent).toBe(
"La période d’essai peut-elle être renouvelée ? Nom de la CC"
);
});
describe("base", () => {
beforeEach(async () => {
window.localStorage.clear();
rendering = render(<ContributionLayout contribution={contribution} />);
});
it("should display correctly when no agreement is selected", async () => {
expect(ccUi.buttonDisplayInfo.query()).toBeInTheDocument();
expect(ui.generic.linkDisplayInfo.query()).toBeInTheDocument();
expect(ui.generic.title.query()).toBeInTheDocument();
fireEvent.click(ui.generic.linkDisplayInfo.get());
expect(ui.generic.linkDisplayInfo.query()).not.toBeInTheDocument();
});

it("should display correctly when a treated agreement is selected", async () => {
(searchAgreement as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
id: "0016",
num: 16,
url: "https://www.legifrance.gouv.fr/affichIDCC.do?idConvention=KALICONT000005635624",
shortTitle:
"Transports routiers et activités auxiliaires du transport",
slug: "16-transports-routiers-et-activites-auxiliaires-du-transport",
title:
"Convention collective nationale des transports routiers et activités auxiliaires du transport du 21 décembre 1950",
},
])
);
expect(ui.generic.linkDisplayInfo.query()).toBeInTheDocument();
fireEvent.change(ccUi.searchByName.input.get(), {
target: { value: "16" },
});
await wait();
fireEvent.click(ccUi.searchByName.autocompleteLines.IDCC16.button.get());
expect(ui.generic.linkDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.buttonDisplayInfo.query()).toHaveAttribute(
"href",
"/contribution/16-slug"
);
expect(ccUi.warning.nonTreatedAgreement.query()).not.toBeInTheDocument();
expect(sendEvent).toHaveBeenLastCalledWith({
action: "cc_select_traitée",
category: "outil",
name: "0016",
});
});

it("should display correctly when a non-treated agreement is selected", async () => {
(searchAgreement as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
num: 1388,
url: "https://www.legifrance.gouv.fr/affichIDCC.do?idConvention=KALICONT000005635267",
effectif: 31273,
shortTitle: "Industrie du pétrole",
cdtnId: "8c50f32b7d",
id: "1388",
slug: "1388-industrie-du-petrole",
title:
"Convention collective nationale deo l'industrie du pétrole du 3 septembre 1985. Etendue par arrêté du 31 juillet 1986 JORF 9 août 1986.",
contributions: false,
},
])
);
fireEvent.change(ccUi.searchByName.input.get(), {
target: { value: "1388" },
});
await wait();
fireEvent.click(
ccUi.searchByName.autocompleteLines.IDCC1388.button.get()
);
expect(ui.generic.linkDisplayInfo.query()).toBeInTheDocument();
expect(ccUi.buttonDisplayInfo.query()).toHaveAttribute("href", "");
expect(ccUi.warning.title.query()).toBeInTheDocument();
expect(ccUi.warning.nonTreatedAgreement.query()).toBeInTheDocument();
expect(sendEvent).toHaveBeenLastCalledWith({
action: "cc_select_non_traitée",
category: "outil",
name: "1388",
});
});
});

describe("no CDT", () => {
beforeEach(() => {
window.localStorage.clear();
rendering = render(
<ContributionLayout contribution={{ ...contribution, isNoCDT: true }} />
);
});
it("should display correctly when no agreement is selected", () => {
expect(ui.generic.linkDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.buttonDisplayInfo.query()).not.toBeInTheDocument();
});

it("should display correctly when a treated agreement is selected", async () => {
(searchAgreement as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
id: "0016",
num: 16,
url: "https://www.legifrance.gouv.fr/affichIDCC.do?idConvention=KALICONT000005635624",
shortTitle:
"Transports routiers et activités auxiliaires du transport",
slug: "16-transports-routiers-et-activites-auxiliaires-du-transport",
title:
"Convention collective nationale des transports routiers et activités auxiliaires du transport du 21 décembre 1950",
},
])
);
expect(ccUi.buttonDisplayInfo.query()).not.toBeInTheDocument();
fireEvent.change(ccUi.searchByName.input.get(), {
target: { value: "16" },
});
await wait();
fireEvent.click(ccUi.searchByName.autocompleteLines.IDCC16.button.get());
expect(ccUi.buttonDisplayInfo.query()).toHaveAttribute(
"href",
"/contribution/16-slug"
);
expect(ccUi.warning.nonTreatedAgreement.query()).not.toBeInTheDocument();
expect(sendEvent).toHaveBeenLastCalledWith({
action: "cc_select_traitée",
category: "outil",
name: "0016",
});
});

it("should display correctly when a non-treated agreement is selected", async () => {
(searchAgreement as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
num: 1388,
url: "https://www.legifrance.gouv.fr/affichIDCC.do?idConvention=KALICONT000005635267",
effectif: 31273,
shortTitle: "Industrie du pétrole",
cdtnId: "8c50f32b7d",
id: "1388",
slug: "1388-industrie-du-petrole",
title:
"Convention collective nationale deo l'industrie du pétrole du 3 septembre 1985. Etendue par arrêté du 31 juillet 1986 JORF 9 août 1986.",
contributions: false,
},
])
);
fireEvent.change(ccUi.searchByName.input.get(), {
target: { value: "1388" },
});
await wait();
fireEvent.click(
ccUi.searchByName.autocompleteLines.IDCC1388.button.get()
);
expect(ui.generic.linkDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.buttonDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.warning.title.query()).toBeInTheDocument();
expect(ccUi.warning.noCdtNonTreatedAgreement.query()).toBeInTheDocument();
expect(
rendering.getByText(new RegExp(contribution.messageBlockGenericNoCDT))
).toBeInTheDocument();
expect(sendEvent).toHaveBeenLastCalledWith({
action: "cc_select_non_traitée",
category: "outil",
name: "1388",
});
});

it("should display correctly when a unextended agreement is selected", async () => {
(searchAgreement as jest.Mock).mockImplementation(() =>
Promise.resolve([
{
num: 29,
url: "https://www.legifrance.gouv.fr/affichIDCC.do?idConvention=KALICONT000005635234",
effectif: 1,
shortTitle:
"Hospitalisation privée : établissements privés d'hospitalisation, de soins, de cure et de garde à but non lucratif (FEHAP)",
cdtnId: "394e29a64d",
id: "0029",
slug: "29-hospitalisation-privee-etablissements-prives-dhospitalisation-de-soins-d",
title:
"Convention collective nationale des etablissements privés d'hospitalisation, de soins, de cure et de garde à but non lucratif du 31 octobre 1951.",
contributions: true,
},
])
);
fireEvent.change(ccUi.searchByName.input.get(), {
target: { value: "29" },
});
await wait();
fireEvent.click(ccUi.searchByName.autocompleteLines.IDCC29.button.get());
expect(ui.generic.linkDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.buttonDisplayInfo.query()).not.toBeInTheDocument();
expect(ccUi.warning.title.query()).toBeInTheDocument();
expect(ccUi.warning.noCdtUnextendedAgreement.query()).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
byText,
byLabelText,
byTestId,
byRole,
} from "testing-library-selector";

export const ui = {
generic: {
linkDisplayInfo: byText(
"Afficher les informations sans sélectionner une convention collective"
),
title: byText("Que dit le code du travail ?"),
},
};
Loading

0 comments on commit 54eb05a

Please sign in to comment.