Skip to content

Commit

Permalink
Merge pull request #98 from SocialGouv/feat-suppr-test-demographie
Browse files Browse the repository at this point in the history
feat(demographie): suppression de l'ab testing
  • Loading branch information
alebret authored Nov 14, 2022
2 parents 95bcad7 + 5e49b8d commit 46e4b9b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 84 deletions.
62 changes: 5 additions & 57 deletions __tests__/utils/ab-testing/demographic-data.utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,78 +93,26 @@ describe("Utils", () => {
const demographicSurveyPath = "/ab-testing/demographic-data-survey"

describe("Ecran pré questionnaire EPDS", () => {
test("Test A", async () => {
mockLocalStorageForTest("A")
test("Rentrer dans le questionnaire", async () => {
await act(async () => render(<BeforeSurvey />))

const nextButton = screen.getByRole("button", {
name: "Commencer le questionnaire",
})
const nextButton = screen.getByRole("button", { name: "Suivant" })

expect(nextButton).toBeInTheDocument()
fireEvent.click(nextButton)
expect(router.push).toHaveBeenCalledWith({
pathname: epdsSurveyPath,
})
})

describe("Test B", () => {

beforeAll(() => mockLocalStorageForTest("B"))

test("Rentrer dans le questionnaire", async () => {
await act(async () => render(<BeforeSurvey />))

const nextButton = screen.getByRole("button", { name: "Suivant" })

expect(nextButton).toBeInTheDocument()
fireEvent.click(nextButton)
expect(router.push).toHaveBeenCalledWith({
pathname: demographicSurveyPath,
})
})
test("Sortir du questionnaire", async () => {
await act(async () => render(<DemographicDataSurvey />))

const nextButton = screen.getByRole("button", {
name: "Envoyer et commencer le questionnaire",
})

expect(nextButton).toBeInTheDocument()
fireEvent.click(nextButton)
expect(router.push).toHaveBeenCalledWith({
pathname: epdsSurveyPath,
})
pathname: demographicSurveyPath,
})
})

test("Test C", async () => {
mockLocalStorageForTest("C")
await act(async () => render(<BeforeSurvey />))

const nextButton = screen.getByRole("button", {
name: "Commencer le questionnaire",
})

expect(nextButton).toBeInTheDocument()
fireEvent.click(nextButton)
expect(router.push).toHaveBeenCalledWith({
pathname: epdsSurveyPath,
})
})
})

describe("Ecran post questionnaire EPDS", () => {
test("Test C", async () => {
mockLocalStorageForTest("C")
test("Sortir du questionnaire", async () => {
await act(async () => render(<DemographicDataSurvey />))

const nextButton = screen.getByRole("button", {
name: "Envoyer et afficher le résultat du questionnaire",
name: "Envoyer et commencer le questionnaire",
})

expect(nextButton).toBeInTheDocument()
fireEvent.click(nextButton)
})
})
})
Expand Down
7 changes: 4 additions & 3 deletions pages/ab-testing/demographic-data-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function DemographicDataSurvey() {
const [jobValue, setJobValue] = useState()

const epdsTestID = StorageUtils.getInLocalStorage(STORAGE_RESULTS_ID)
const demographicData = DemographicDataUtils.uiAdaptationForInfoDemographic()
const demographicData = DemographicDataUtils.getDemographicBeforeEpds()

useEffect(() => {
const isCompleted = checkIsFormCompleted(
Expand Down Expand Up @@ -298,11 +298,12 @@ export const checkIsFormCompleted = (
}

/**
* MAJ de l'ID du questionnaire EPDS dans le questionnaire Démographique
* MAJ de l'ID du questionnaire EPDS dans le questionnaire Démographique.
* Important lorsque le quesitonnaire est réalisé avant l'EPDS.
* @param {*} updateEpdsIdInInfosQuery query UPDATE_REPONSES_EPDS_ID_IN_INFORMATION_DEMOGRAPHIQUES
* @param {String} reponsesEpdsID ID du questionnaire EPDS
*/
export const updateInfoDemographic = (
export const updateDemographicData = (
updateEpdsIdInInfosQuery,
reponsesEpdsID
) => {
Expand Down
2 changes: 1 addition & 1 deletion pages/survey/before-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function BeforeSurvey() {
)

const localeSelected = StorageUtils.getLocaleInLocalStorage()
const demographicData = DemographicDataUtils.uiAdaptationForInfoDemographic()
const demographicData = DemographicDataUtils.getDemographicBeforeEpds()

useEffect(() => {
const resultatsCountQuery = async () => {
Expand Down
26 changes: 6 additions & 20 deletions pages/survey/epds-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "../../apollo-client"
import { ContentLayout } from "../../src/components/Layout"
import { SurveyCarousel } from "../../src/components/survey/SurveyCarousel"
import * as Icon from "react-bootstrap-icons"
import { SurveyProgressBar } from "../../src/components/survey/SurveyProgressBar"
import {
EpdsGender,
Expand All @@ -32,8 +31,7 @@ import {
EPDS_SAVE_RESPONSES_FOR_WIDGET,
EPDS_SURVEY_TRANSLATION_BY_LOCALE,
} from "@socialgouv/nos1000jours-lib"
import { updateInfoDemographic } from "../ab-testing/demographic-data-survey"
import * as DemographicDataUtils from "../../src/utils/ab-testing/demographic-data.utils"
import { updateDemographicData } from "../ab-testing/demographic-data-survey"
import * as StorageUtils from "../../src/utils/storage.utils"

export default function EpdsSurvey() {
Expand All @@ -52,7 +50,6 @@ export default function EpdsSurvey() {
const [isLoading, setLoading] = useState(false)

const source = StorageUtils.getInLocalStorage(STORAGE_SOURCE)
const demographicData = DemographicDataUtils.uiAdaptationForInfoDemographic()

const [getEpdsSurveyQuery] = useLazyQuery(
gql(EPDS_SURVEY_TRANSLATION_BY_LOCALE),
Expand Down Expand Up @@ -94,16 +91,12 @@ export default function EpdsSurvey() {
scoreLevelForMacaron(totalScore, resultsBoard[9].points)
)

if (demographicData?.isAfterEpds)
goToDemographicSurvey(data.createReponsesEpdsWidget.id)
else {
updateInfoDemographic(
updateEpdsIdInInfosQuery,
data.createReponsesEpdsWidget.id
)
updateDemographicData(
updateEpdsIdInInfosQuery,
data.createReponsesEpdsWidget.id
)

goToResults()
}
goToResults()
},
})

Expand All @@ -121,10 +114,6 @@ export default function EpdsSurvey() {
})
}

const goToDemographicSurvey = async (epdsTestID) => {
DemographicDataUtils.goToDemographicSurvey(router, epdsTestID)
}

useEffect(() => {
setLocaleSelected(StorageUtils.getLocaleInLocalStorage())
}, [])
Expand Down Expand Up @@ -231,9 +220,6 @@ export default function EpdsSurvey() {
setSendScore(true)
setLoading(true)
trackerClick(CATEG.survey, EVENT_CLICK, `Terminer - ${source}`)
DemographicDataUtils.trackerForDemographie(
"Questionnaire EPDS - Terminer"
)
}}
disabled={!isEnabledNextButton || isLoading}
>
Expand Down
13 changes: 10 additions & 3 deletions src/utils/ab-testing/demographic-data.utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { STORAGE_TEST_ABC, STORAGE_RESULTS_ID } from "../../constants/constants"
import { TEST } from "./ab-testing.utils"
import { ACTION, CATEG, trackerClick } from "../tracker.utils"
import { CATEG, trackerClick } from "../tracker.utils"
import * as StorageUtils from "../storage.utils"

export const genderValues = [
Expand Down Expand Up @@ -128,13 +128,20 @@ export const uiAdaptationForInfoDemographic = () => {
return null
}

export const getDemographicBeforeEpds = () => {
return {
isBeforeEpds: true,
buttonLabelInBeforeSurvey: "Suivant",
buttonLabelInInfoDemographicSurvey: "Envoyer et commencer le questionnaire",
}
}

export const goToDemographicSurvey = async (router, epdsTestID) => {
if (epdsTestID) localStorage.setItem(STORAGE_RESULTS_ID, epdsTestID)

router.push({ pathname: "/ab-testing/demographic-data-survey" })
}

export const trackerForDemographie = (label) => {
const testId = StorageUtils.getInLocalStorage(STORAGE_TEST_ABC)
trackerClick(CATEG.test, `${ACTION.parcours}${testId}`, label)
trackerClick(CATEG.demography, label)
}
1 change: 1 addition & 0 deletions src/utils/tracker.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const CATEG = {
survey: "Questionnaire",
test: "Test",
intentions: "Intentions",
demography: "Démographie",
results: "Résultats",
}

Expand Down

0 comments on commit 46e4b9b

Please sign in to comment.