Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda committed Feb 3, 2025
1 parent b9a8c6e commit 2e15898
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { useContributionTracking } from "./tracking";
import { isAgreementSupported, isAgreementValid } from "./contributionUtils";
import { ContributionGenericContent } from "./ContributionGenericContent";
import { Contribution } from "./type";
import { useLocalStorageForAgreementOnPageLoad } from "../common/useLocalStorage";
import {
useLocalStorageForAgreement,
useLocalStorageForAgreementOnPageLoad,
} from "../common/useLocalStorage";
import { ContributionGenericAgreementSearch } from "./ContributionGenericAgreementSearch";

type Props = {
Expand All @@ -17,7 +20,7 @@ export function ContributionGeneric({ contribution }: Props) {

const [displayGeneric, setDisplayGeneric] = useState(false);
const [selectedAgreement, setSelectedAgreement] =
useLocalStorageForAgreementOnPageLoad();
useLocalStorageForAgreement();
const {
emitAgreementTreatedEvent,
emitAgreementUntreatedEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export function ContributionGenericAgreementSearch({
}: Props) {
const { slug } = contribution;

const [selectedAgreement, setSelectedAgreement] =
useState<EnterpriseAgreement>();
const [selectedAgreement, setSelectedAgreement] = useState<
EnterpriseAgreement | undefined
>(defaultAgreement);
const [isValid, setIsValid] = useState(
defaultAgreement ? isAgreementValid(contribution, defaultAgreement) : false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { searchEnterprises } from "../../queries";
import { ui } from "./ui";
import { sendEvent } from "../../../utils";
import { wait } from "@testing-library/user-event/dist/utils";
import { TrackingAgreementSearchAction } from "../../../convention-collective/tracking";

jest.mock("../../../utils", () => ({
sendEvent: jest.fn(),
Expand Down Expand Up @@ -44,7 +45,10 @@ describe("EnterpriseAgreementSearchInput", () => {
describe("Form mode", () => {
beforeEach(async () => {
rendering = render(
<EnterpriseAgreementSearchInput onAgreementSelect={() => {}} />
<EnterpriseAgreementSearchInput
onAgreementSelect={() => {}}
trackingActionName={TrackingAgreementSearchAction.AGREEMENT_SEARCH}
/>
);
});
it("should navigate correctly with one treated agreement on enterprise", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,29 @@ export const useEnterpriseAgreementSearchTracking = () => {
});
};

const emitSelectEnterpriseEvent = (
action: string,
enterprise: {
label: string;
siren: string;
}
) => {
sendEvent({
category: TrackingAgreementSearchCategory.CC_ENTERPRISE_SELECT,
action: action,
name: JSON.stringify(enterprise),
value: generateUUID(),
});
};
const emitSelectEnterpriseEvent = (
action: string,
enterprise: {
label: string;
siren: string;
}
) => {
sendEvent({
category: TrackingAgreementSearchCategory.CC_ENTERPRISE_SELECT,
action: action,
name: JSON.stringify(enterprise),
value: generateUUID(),
});
};

const emitSelectEnterpriseAgreementEvent = (
idcc: string,
action: string
) => {
sendEvent({
category: TrackingAgreementSearchCategory.CC_SELECT_P2,
action: action,
name: idcc,
value: generateUUID(),
});
};
const emitSelectEnterpriseAgreementEvent = (idcc: string, action: string) => {
sendEvent({
category: TrackingAgreementSearchCategory.CC_SELECT_P2,
action: action,
name: idcc,
value: generateUUID(),
});
};

const emitPreviousEvent = () => {
sendEvent({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { RadioButtons } from "@codegouvfr/react-dsfr/RadioButtons";
import { ReactNode, useState } from "react";
import { ReactNode, useEffect, useState } from "react";
import { AgreementSearchInput } from "./AgreementSearchInput";
import {
EnterpriseAgreement,
Expand All @@ -24,7 +24,11 @@ export const AgreementSearchForm = ({
}: Props) => {
const [mode, setMode] = useState<
"agreementSearch" | "enterpriseSearch" | "noSearch" | undefined
>(!!defaultAgreement ? "agreementSearch" : undefined);
>();

useEffect(() => {
setMode(!!defaultAgreement ? "agreementSearch" : undefined);
}, [defaultAgreement]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { render, screen } from "@testing-library/react";
import React, { useRef } from "react";
import React from "react";
import { wait } from "@testing-library/user-event/dist/utils";
import { searchEnterprises } from "../../enterprise/queries";
import { sendEvent } from "../../../common/utils";
import { ui } from "./ui";
import { ui as enterpriseUi } from "../../enterprise/EnterpriseAgreementSearch/__tests__/ui";
import { AgreementSearchForm } from "../AgreementSearchForm";
import { searchEnterprises } from "../../../enterprise";
import { UserAction } from "../../../../common";
import { AgreementSearchForm } from "../../common/AgreementSearchForm/AgreementSearchForm";
import { TrackingAgreementSearchAction } from "../../../convention-collective/tracking";
import { ui } from "../../../convention-collective/__tests__/ui";
import { ui as enterpriseUi } from "../../../enterprise/EnterpriseAgreementSearch/__tests__/ui";
import { sendEvent } from "../../../utils";

jest.mock("../../../common/utils", () => ({
sendEvent: jest.fn(),
Expand Down Expand Up @@ -101,7 +102,11 @@ const enterpriseMoreCC = {
describe("<PageContribution />", () => {
let userAction: UserAction;
it("should track when searching by enterprise name", async () => {
render(<AgreementSearchForm />);
render(
<AgreementSearchForm
trackingActionName={TrackingAgreementSearchAction.AGREEMENT_SEARCH}
/>
);
(searchEnterprises as jest.Mock).mockImplementation(() =>
Promise.resolve([enterprise1CC])
);
Expand Down Expand Up @@ -142,7 +147,11 @@ describe("<PageContribution />", () => {
});
});
it("should track when searching by enterprise with multiple agreements", async () => {
render(<AgreementSearchForm />);
render(
<AgreementSearchForm
trackingActionName={TrackingAgreementSearchAction.AGREEMENT_SEARCH}
/>
);
(searchEnterprises as jest.Mock).mockImplementation(() =>
Promise.resolve([enterpriseMoreCC])
);
Expand Down Expand Up @@ -196,7 +205,11 @@ describe("<PageContribution />", () => {
});

it("should track when selecting agreement 3239", () => {
render(<AgreementSearchForm />);
render(
<AgreementSearchForm
trackingActionName={TrackingAgreementSearchAction.AGREEMENT_SEARCH}
/>
);
userAction = new UserAction();
userAction.click(ui.radio.enterpriseSearchOption.get());
screen.debug();
Expand Down

0 comments on commit 2e15898

Please sign in to comment.