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

feat(ressources): ajout ressources sur la page résultats #32

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
193 changes: 193 additions & 0 deletions __tests__/components/results/resources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import { getResourcesByScore } from "../../../src/components/results/Resources"

describe("Component Resources", () => {
describe("Renvoie les ressources en fonction d'un score", () => {
test("Aucune ressource => undefined", () => {
const ressources_configs = []
expect(getResourcesByScore(ressources_configs, 10)).toEqual(undefined)
})

test("Aucune des ressources ne correspond au score => undefined", () => {
const ressources_configs = [
{
texte_1: "<p>Vous allez bien</p>",
texte_2: null,
score_min: 0,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
]
expect(getResourcesByScore(ressources_configs, 12)).toEqual(undefined)
})

test("Pas de score_min/max dans la config des ressources => renvoie la ressource", () => {
const ressources_configs = [
{
texte_1: "<p>test</p>",
texte_2: null,
score_min: null,
score_max: null,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
]

const result = {
texte_1: "<p>test</p>",
texte_2: null,
score_min: null,
score_max: null,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
}

expect(getResourcesByScore(ressources_configs, 10)).toEqual(result)
})

test("Le score_min est null et le score est < score_max dans la config des ressources => renvoie la ressource", () => {
const ressources_configs = [
{
texte_1: "<p>test</p>",
texte_2: null,
score_min: null,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
]

const result = {
texte_1: "<p>test</p>",
texte_2: null,
score_min: null,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
}

expect(getResourcesByScore(ressources_configs, 5)).toEqual(result)
})

test("Le score_min est null et le score est > score_max dans la config des ressources => undefined", () => {
const ressources_configs = [
{
texte_1: "<p>test</p>",
texte_2: null,
score_min: null,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
]

expect(getResourcesByScore(ressources_configs, 15)).toEqual(undefined)
})

test("Plusieurs ressources dont une correspondant au score => renvoie la ressource", () => {
const ressources_configs = [
{
texte_1: "<p>Vous allez bien</p>",
texte_2: null,
score_min: 0,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
{
texte_1: "<p>test</p>",
texte_2: null,
score_min: 11,
score_max: 15,
ressources: [],
},
]

const result = {
texte_1: "<p>test</p>",
texte_2: null,
score_min: 11,
score_max: 15,
ressources: [],
}

expect(getResourcesByScore(ressources_configs, 12)).toEqual(result)
})

test("Plusieurs ressources pour un score => prend la 1ère ressource de la liste", () => {
const ressources_configs = [
{
texte_1: "<p>Vous allez bien</p>",
texte_2: null,
score_min: 0,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
},
{
texte_1: "<p>test</p>",
texte_2: null,
score_min: 8,
score_max: 15,
ressources: [],
},
]

const result = {
texte_1: "<p>Vous allez bien</p>",
texte_2: null,
score_min: 0,
score_max: 10,
ressources: [
{
type: "tels",
titre: "Les ressources téléphoniques",
contenu: "<h1>Hello world</h1>",
},
],
}

expect(getResourcesByScore(ressources_configs, 9)).toEqual(result)
})
})
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"@apollo/client": "^3.5.7",
"@dataesr/react-dsfr": "^0.9.7",
"@socialgouv/matomo-next": "^1.2.2",
"@socialgouv/nos1000jours-lib": "^1.4.0",
"@socialgouv/nos1000jours-lib": "^1.5.0",
"bootstrap": "^5.1.3",
"cross-fetch": "^3.1.4",
"graphql": "^16.2.0",
"html-react-parser": "^1.4.8",
"moment": "^2.29.1",
"next": "12.1.0",
"react": "17.0.2",
Expand Down Expand Up @@ -46,4 +47,4 @@
]
},
"version": "1.12.1"
}
}
2 changes: 2 additions & 0 deletions pages/epds-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SurveyProgressBar } from "../src/components/survey/SurveyProgressBar"
import {
EpdsGender,
EPDS_SOURCE,
STORAGE_SCORE,
STORAGE_SCORE_LEVEL_MACARON,
STORAGE_SCORE_LEVEL_MOOD,
STORAGE_SCORE_LEVEL_TEXTS,
Expand Down Expand Up @@ -84,6 +85,7 @@ export default function EpdsSurvey() {
scoreLevelForMacaron(totalScore, resultsBoard[9].points)
)

localStorage.setItem(STORAGE_SCORE, totalScore)
goToResults()
},
})
Expand Down
3 changes: 3 additions & 0 deletions pages/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getInLocalStorage,
getLocaleInLocalStorage,
} from "../src/utils/main.utils"
import { Resources } from "../src/components/results/Resources"

export default function Results() {
const router = useRouter()
Expand Down Expand Up @@ -57,6 +58,8 @@ export default function Results() {
<button className="fr-btn result-return-bt" onClick={goToSurvey}>
Recommencer le questionnaire
</button>

<Resources />
</ContentLayout>
)
}
Expand Down
32 changes: 32 additions & 0 deletions public/img/pro-sante.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions public/img/telephone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading