Skip to content

Commit

Permalink
feat: ajout du tracker pour l'annulation de la prise de contact (#147)
Browse files Browse the repository at this point in the history
* test: rajouter des tests unitaires sur la nouvelles versions des trackers + les anciennes fonctionnalités

* feat: ajout du tracker pour l'annulation de la prise de contact

* fix: test coverage remove duplicate code

* fix: sonar properties exlude test file

* fix: duplicate line

* fix: duplicate line
  • Loading branch information
mbarry-ippon authored Mar 28, 2023
1 parent c33bebf commit 227b36d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 23 deletions.
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")
})
})
})
30 changes: 13 additions & 17 deletions __tests__/utils/contact.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ 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")
})
})
describe("sendTrackerContactConfirmed", () => {
let trackerSpy
localStorage.setItem(STORAGE_SOURCE, "1000-premiers-jours")
Expand Down Expand Up @@ -44,25 +54,18 @@ describe("Contact Utils", () => {
})

describe("isMamanBluesAvailableHours", () => {
test("Should return false with 8h", () => {
const date = new Date("2023-02-13 08:50:05")
jest.useFakeTimers().setSystemTime(date)

expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy()
})

test("Should return true with 9h", () => {
const date = new Date("2023-02-13 09:50:05")
jest.useFakeTimers().setSystemTime(date)

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()).toBeTruthy()
expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy()
})

test("Should return true with 17h30", () => {
Expand All @@ -79,13 +82,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")
})
})
})
1 change: 1 addition & 0 deletions pages/contact/to-be-contacted.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function ToBeContacted() {
}, [itemValueType])

const cancel = () => {
TrackerUtils.trackerForResults(TrackerUtils.ACTION.abandon)
router.back()
}
const [sendContactQuery] = useMutation(SAVE_DEMANDE_DE_CONTACT, {
Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sonar.tests=__tests__
sonar.test.exclusions=__tests__/**/*,**/*.test.js
sonar.coverage.exclusions=__tests__/**/*,**/*.test.js
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.cpd.exclusions=__tests__/**/*,**/*.test.js

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
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
3 changes: 1 addition & 2 deletions 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 All @@ -23,7 +22,7 @@ export const ACTION = {
be_contacted: "Demander à être contacté",
ressource: "Recevoir les ressources par mail",
ressource_mail: "Confirmer recevoir les ressources par mail",

abandon: "Abandon de la prise de contact",
download: "Télécharger mes réponses",

opinion: "Donner son avis",
Expand Down

0 comments on commit 227b36d

Please sign in to comment.