diff --git a/__tests__/pages/contact/to-be-contacted.test.js b/__tests__/pages/contact/to-be-contacted.test.js index fc79ed94..738cea80 100644 --- a/__tests__/pages/contact/to-be-contacted.test.js +++ b/__tests__/pages/contact/to-be-contacted.test.js @@ -11,6 +11,14 @@ describe("Demande de contact", () => { expect(result).toEqual(true) }) + test("Sélection du type RDV => choix valide", () => { + const result = isValidButtonEnabled( + RequestContact.type.rendezvous, + undefined + ) + expect(result).toEqual(true) + }) + test("Sélection du type Email => choix valide", () => { const result = isValidButtonEnabled(RequestContact.type.email, undefined) expect(result).toEqual(true) @@ -146,7 +154,9 @@ describe("Demande de contact", () => { }, ] - expect(convertHoursListInString(contactHours)).toEqual(" matin après-midi") + expect(convertHoursListInString(contactHours)).toEqual( + " matin après-midi" + ) }) }) }) diff --git a/__tests__/utils/ab-testing/ab-testing.utils.test.js b/__tests__/utils/ab-testing/ab-testing.utils.test.js index 0705d5ec..8c4557c3 100644 --- a/__tests__/utils/ab-testing/ab-testing.utils.test.js +++ b/__tests__/utils/ab-testing/ab-testing.utils.test.js @@ -24,11 +24,23 @@ describe("Utils", () => { trackerSpy = jest.spyOn(TrackerUtils, "track") }) - test("Should return tracker with label", () => { + test("Should return tracker with test A for test A", () => { localStorage.setItem(STORAGE_TEST_ABC, "A") - AbTestingUtils.trackerForAbTesting("my label") - expect(trackerSpy).toHaveBeenCalledWith("Test_A", "my label") + AbTestingUtils.trackerForAbTesting("test A") + expect(trackerSpy).toHaveBeenCalledWith("Test_A", "test A") + }) + test("Should return tracker with B test for test B", () => { + localStorage.setItem(STORAGE_TEST_ABC, "B") + + AbTestingUtils.trackerForAbTesting("B test") + expect(trackerSpy).toHaveBeenCalledWith("Test_B", "B test") + }) + test("Should return tracker with C super test for test C", () => { + localStorage.setItem(STORAGE_TEST_ABC, "C") + + AbTestingUtils.trackerForAbTesting("C super test") + expect(trackerSpy).toHaveBeenCalledWith("Test_C", "C super test") }) }) }) diff --git a/__tests__/utils/contact.utils.test.js b/__tests__/utils/contact.utils.test.js index b67a8689..d1e18d8b 100644 --- a/__tests__/utils/contact.utils.test.js +++ b/__tests__/utils/contact.utils.test.js @@ -15,6 +15,24 @@ const sendTrackerContactConfirmed = (contactType) => { } describe("Contact Utils", () => { + describe("trackerContactName", () => { + test("Should return confirmation mail if email type is selected", () => { + expect(ContactUtils.trackerContactName("email")).toEqual( + "Confirmation email" + ) + }) + test("Should return confirmation mail if chat type is selected", () => { + expect(ContactUtils.trackerContactName("chat")).toEqual("Ouverture chat") + }) + test("Should return confirmation mail if rendezvous type is selected", () => { + expect(ContactUtils.trackerContactName("rendezvous")).toEqual( + "Confirmation rendezvous" + ) + }) + test("Should return confirmation mail if sms type is selected", () => { + expect(ContactUtils.trackerContactName("sms")).toEqual("Confirmation sms") + }) + }) describe("sendTrackerContactConfirmed", () => { let trackerSpy localStorage.setItem(STORAGE_SOURCE, "1000-premiers-jours") @@ -58,8 +76,15 @@ describe("Contact Utils", () => { expect(ContactUtils.isMamanBluesAvailableHours()).toBeTruthy() }) - test("Should return true with 10h", () => { - const date = new Date("2023-02-13 10:50:05") + test("Should return false with 12h00", () => { + const date = new Date("2023-02-13 12:00:05") + jest.useFakeTimers().setSystemTime(date) + + expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy() + }) + + test("Should return true with 13h00", () => { + const date = new Date("2023-02-13 13:00:05") jest.useFakeTimers().setSystemTime(date) expect(ContactUtils.isMamanBluesAvailableHours()).toBeTruthy() @@ -79,13 +104,6 @@ describe("Contact Utils", () => { expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy() }) - test("Should return false with 18h00", () => { - const date = new Date("2023-02-13 18:00:05") - jest.useFakeTimers().setSystemTime(date) - - expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy() - }) - test("Should return false with sunday", () => { const date = new Date("2023-02-12 14:00:05") jest.useFakeTimers().setSystemTime(date) diff --git a/__tests__/utils/tracker.utils.test.js b/__tests__/utils/tracker.utils.test.js new file mode 100644 index 00000000..d08014e9 --- /dev/null +++ b/__tests__/utils/tracker.utils.test.js @@ -0,0 +1,75 @@ +import { STORAGE_CONTACT_TYPE } from "../../src/constants/constants" +import * as TrackerUtils from "../../src/utils/tracker.utils" + +describe("Trackers utils", () => { + describe("Should return tracker for every category", () => { + let trackerSpy + + beforeEach(() => { + trackerSpy = jest.spyOn(TrackerUtils, "track") + }) + + test("Should return tracker with demographic category", () => { + TrackerUtils.track( + TrackerUtils.CATEG.demography, + TrackerUtils.ACTION.end_demo + ) + expect(trackerSpy).toHaveBeenCalledWith( + "Démographie", + "Terminer le formulaire démographique" + ) + }) + test("Should return tracker with survey category", () => { + TrackerUtils.track( + TrackerUtils.CATEG.survey, + TrackerUtils.ACTION.end_survey + ) + expect(trackerSpy).toHaveBeenCalledWith( + "Questionnaire", + "Terminer le questionnaire" + ) + }) + test("Should return tracker with results category", () => { + const score = 11 + TrackerUtils.track( + TrackerUtils.CATEG.results, + TrackerUtils.seuilScore(score) + ) + expect(trackerSpy).toHaveBeenCalledWith("Résultat", "score >= 11") + }) + test("Should return tracker with intentions category", () => { + TrackerUtils.track( + TrackerUtils.CATEG.intentions, + TrackerUtils.ACTION.download + ) + expect(trackerSpy).toHaveBeenCalledWith( + "Intentions", + "Télécharger mes réponses" + ) + }) + test("Should return tracker with contacts category", () => { + localStorage.setItem(STORAGE_CONTACT_TYPE, "sms") + const typeContact = localStorage.getItem(STORAGE_CONTACT_TYPE) + TrackerUtils.track(TrackerUtils.CATEG.contact, `Choix ${typeContact}`) + expect(trackerSpy).toHaveBeenCalledWith("Contact", "Choix sms") + }) + }) + describe("Should return good value for seuil score", () => { + test("Should return score < 9 if score from EPDS is <9", () => { + const score = 4 + const score2 = 9 + expect(TrackerUtils.seuilScore(score)).toEqual("score < 9") + expect(TrackerUtils.seuilScore(score2)).toEqual("9 >= score < 11") + }) + test("Should return 9 >= score < 11 if score from EPDS is between 9 & 11", () => { + const score = 9 + const score2 = 11 + expect(TrackerUtils.seuilScore(score)).toEqual("9 >= score < 11") + expect(TrackerUtils.seuilScore(score2)).toEqual("score >= 11") + }) + test("Should return score >= 11 if score from EPDS is >11", () => { + const score = 26 + expect(TrackerUtils.seuilScore(score)).toEqual("score >= 11") + }) + }) +}) diff --git a/src/utils/contact.utils.js b/src/utils/contact.utils.js index 03fc32ac..417fb959 100644 --- a/src/utils/contact.utils.js +++ b/src/utils/contact.utils.js @@ -6,6 +6,10 @@ import { STORAGE_SOURCE, } from "../constants/constants" +/** + * Return la confirmation du mode de contact selectionner + * @param {RequestContact.type} typeContact + */ export const trackerContactName = (typeContact) => { switch (typeContact) { case RequestContact.type.email: diff --git a/src/utils/tracker.utils.js b/src/utils/tracker.utils.js index 45c2f035..ea726da9 100644 --- a/src/utils/tracker.utils.js +++ b/src/utils/tracker.utils.js @@ -1,7 +1,6 @@ import { push } from "@socialgouv/matomo-next" import * as StorageUtils from "../utils/storage.utils" import { STORAGE_SOURCE } from "../constants/constants" -export const EVENT_CLICK = "Click" export const CATEG = { home: "Home",