Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rajouter des tests unitaires sur la nouvelles versions des trackers + les anciennes fonctionnalités #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion __tests__/pages/contact/to-be-contacted.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -146,7 +154,9 @@ describe("Demande de contact", () => {
},
]

expect(convertHoursListInString(contactHours)).toEqual(" matin après-midi")
expect(convertHoursListInString(contactHours)).toEqual(
" matin après-midi"
)
})
})
})
18 changes: 15 additions & 3 deletions __tests__/utils/ab-testing/ab-testing.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
})
36 changes: 27 additions & 9 deletions __tests__/utils/contact.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
75 changes: 75 additions & 0 deletions __tests__/utils/tracker.utils.test.js
Original file line number Diff line number Diff line change
@@ -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")
})
})
})
4 changes: 4 additions & 0 deletions src/utils/contact.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/utils/tracker.utils.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down