Skip to content

Commit

Permalink
đŸ—ƒïž RĂ©cupĂ©re les questions serveur de cafĂ© de la place et place du mar

Browse files Browse the repository at this point in the history

ché dans le store commun
  • Loading branch information
marouria committed Nov 8, 2024
1 parent c3da422 commit 0117cf3
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/situations/cafe_de_la_place/modeles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function creeStore () {

tousLesParcours(state) {
return Object.keys(state.configuration);
}
},
},

mutations: {
Expand Down
24 changes: 19 additions & 5 deletions src/situations/cafe_de_la_place/vues/cafe_de_la_place.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<transition-fade>
<defi
v-if="carteActive.id"
:key="carteActive.id"
:question="carteActive"
v-if="question.id"
:key="question.id"
:question="question"
@reponse="reponse"
>
<pagination
Expand All @@ -26,9 +26,19 @@ import Pagination from 'commun/vues/components/pagination';
export default {
components: { Defi, TransitionFade, Pagination },
data () {
return {
question: {}
};
},
mounted () {
this.$store.commit('recupereQuestionsServeur', this.$depotRessources.questions());
},
computed: {
...mapState(['indexCarte', 'carteActive', 'termine']),
...mapGetters(['nombreCartes', 'acteEnCours']),
...mapGetters(['questionServeur', 'nombreCartes', 'acteEnCours']),
affichePagination () {
return this.carteActive.type !== 'sous-consigne';
Expand All @@ -44,7 +54,11 @@ export default {
termine () {
this.$emit('terminer');
}
},
carteActive() {
this.question = this.questionServeur(this.carteActive) ?? this.carteActive;
},
},
methods: {
Expand Down
24 changes: 23 additions & 1 deletion src/situations/commun/infra/depot_ressources_communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ import calculatrice from 'commun/assets/calculatrice.svg';
import iconeDeconnexion from 'commun/assets/sign_out.svg';
import son from 'commun/assets/son.svg';
import sonConsigneBlanche from 'commun/assets/consigne_blanche.mp3';
import RegistreCampagne from 'commun/infra/registre_campagne';
import { extraitQuestionsReponsesAudios } from 'commun/infra/depot_ressources';

export default class DepotRessourcesCommunes extends DepotRessources {
constructor (chargeurs, messagesVideos, messagesAudios, fondConsigne, sonConsigneDemarrage, sonConsigneTransition = sonConsigneBlanche) {
const questionsServeur = new RegistreCampagne().questions(['cafe_de_la_place', 'place_du_marche']);
const messagesAudiosServeur = extraitQuestionsReponsesAudios(questionsServeur);
super(chargeurs);
this.charge([casque, son, calculatrice, sonConsigneDemarrage, sonConsigneTransition, iconeDeconnexion]);
this.charge(Object.values(messagesVideos));
this.charge(Object.values(messagesAudios));
this.charge(Object.values(messagesAudiosServeur));
if (fondConsigne) {
this.charge([fondConsigne]);
this.imgFondConsigne = fondConsigne;
}
this.sonConsigneDemarrage = sonConsigneDemarrage;
this.sonConsigneTransition = sonConsigneTransition;
this.messagesVideos = messagesVideos;
this.messagesAudios = messagesAudios;
this.messagesAudios = { ...messagesAudios, ...messagesAudiosServeur };
this.questionsServeur = questionsServeur;
}

fondConsigne () {
Expand Down Expand Up @@ -98,4 +104,20 @@ export default class DepotRessourcesCommunes extends DepotRessources {
illustrationQuestion(question) {
return { src: question.illustration };
}

questions () {
this.questionsServeur?.forEach(question => {
if (question.choix) {
question.choix.forEach(choix => {
choix.bonneReponse = choix.type_choix === 'bon';
delete choix.type_choix;
});
}
if(question.type === 'clic-dans-image' || question.type === 'glisser-deposer') {
question.extensionVue = question.type;
delete question.type;
}
});
return this.questionsServeur;
}
}
14 changes: 11 additions & 3 deletions src/situations/commun/infra/registre_campagne.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ export default class RegistreCampagne extends BaseRegistre {
return campagne.situations.find(situation => situation.nom_technique === identifiantSituation);
}

questions (identifiantSituation) {
const situation = this.situation(identifiantSituation);
return situation && situation.questions ? situation.questions : [];
questions (identifiantsSituation) {
if (!Array.isArray(identifiantsSituation)) {
identifiantsSituation = [identifiantsSituation];
}
return identifiantsSituation.reduce((acc, identifiantSituation) => {
const situation = this.situation(identifiantSituation);
if (situation && situation.questions) {
acc.push(...situation.questions);
}
return acc;
}, []);
}

questionsEntrainement (identifiantSituation) {
Expand Down
20 changes: 20 additions & 0 deletions src/situations/commun/modeles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function creeStore ({ state, mutations, getters, actions } = {}) {
state: {
etat: CHARGEMENT,
aide: false,
questions: [],
...state
},
mutations: {
Expand All @@ -36,12 +37,31 @@ export function creeStore ({ state, mutations, getters, actions } = {}) {
activeAide (state) {
state.aide = true;
},

recupereQuestionsServeur(state, questions) {
state.questions = questions;
},
...mutations
},
getters: {
acteEnCours: (state) => {
return state.etat === DEMARRE || state.etat === ENTRAINEMENT_DEMARRE;
},

questionServeur: (state) => (questionActive) => {
const question = state.questions.find(q => q.nom_technique.startsWith(questionActive.nom_technique));

if (!question) return undefined;

const { nom_technique, score, metacompetence } = questionActive;
Object.assign(question, {
id: nom_technique,
score,
metacompetence,
});

return question;
},
...getters
},
actions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import DepotRessourcesCommunes from 'commun/infra/depot_ressources_communes';
import sonConsigne from 'place_du_marche/assets/consigne_place_du_marche.mp3';
import fondSituation from 'bienvenue/assets/bienvenue_background.jpg';
import RegistreCampagne from 'commun/infra/registre_campagne';
import { extraitQuestionsReponsesAudios } from 'commun/infra/depot_ressources';

const messagesVideos = {};
const messagesAudios = {};

export default class DepotRessourcesPlaceDuMarche extends DepotRessourcesCommunes {
constructor (chargeurs, registreCampagne = new RegistreCampagne()) {
const questionsServeur = registreCampagne.questions('place_du_marche');
const messagesAudios = extraitQuestionsReponsesAudios(questionsServeur);
constructor (chargeurs) {
super(chargeurs, messagesVideos, messagesAudios, null, sonConsigne);
this.questionsServeur = questionsServeur;
this.consigneEnCours = null;
this.charge([fondSituation]);
}
Expand All @@ -30,20 +26,4 @@ export default class DepotRessourcesPlaceDuMarche extends DepotRessourcesCommune
fondSituation () {
return this.ressource(fondSituation);
}

questions () {
this.questionsServeur?.forEach(question => {
if (question.choix) {
question.choix.forEach(choix => {
choix.bonneReponse = choix.type_choix === 'bon';
delete choix.type_choix;
});
}
if(question.type === 'clic-dans-image' || question.type === 'glisser-deposer') {
question.extensionVue = question.type;
delete question.type;
}
});
return this.questionsServeur;
}
}
19 changes: 0 additions & 19 deletions src/situations/place_du_marche/modeles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ export function creeStore () {
return state.questionActive.nom_technique === getters.derniereQuestionRattrapage;
},

questionServeur(state) {
const question = state.questions.find(q => q.nom_technique.startsWith(state.questionActive.nom_technique));

if (!question) return undefined;

const { nom_technique, score, metacompetence } = state.questionActive;
Object.assign(question, {
id: nom_technique,
score,
metacompetence,
});

return question;
},

estCarteActive(state) {
return (idCarte) => state.questionActive.nom_technique == idCarte;
},
Expand Down Expand Up @@ -228,10 +213,6 @@ export function creeStore () {

state.pourcentageDeReussiteGlobal = calculPourcentage(scoreTotal, state.maxScoreNiveauEnCours);
},

recupereQuestionsServeur(state, questions) {
state.questions = questions;
},
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/situations/place_du_marche/vues/place_du_marche.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
this.$emit('terminer');
},
questionActive() {
this.question = this.questionServeur ?? this.questionActive;
this.question = this.questionServeur(this.questionActive) ?? this.questionActive;
this.enregistreConsigneEnCours();
},
acteEnCours (acteEnCours) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DEMARRE } from 'commun/modeles/situation';
describe('La vue café de la place', function () {
let wrapper;
let store;
let depotRessources;
let journal;
const sousConsigne = { id: 'sous-consigne', type: 'sous-consigne' };
const question = { id: 'question1' };
Expand All @@ -24,11 +25,15 @@ describe('La vue café de la place', function () {
beforeEach(function () {
store = creeStore();
journal = { enregistre () {} };
depotRessources = {
questions: () => { return []; },
};
wrapper = shallowMount(CafeDeLaPlace, {
global: {
plugins: [store],
mocks: {
$journal: journal
$journal: journal,
$depotRessources: depotRessources,
},
stubs: {
TransitionFade: false
Expand Down
76 changes: 65 additions & 11 deletions tests/situations/commun/modeles/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Situation, {
} from 'commun/modeles/situation';

describe('Le store en commun pour les situations', function () {
let store;

it("initialise l'Ă©tat a CHARGEMENT", function () {
const store = creeStore();
expect(store.state.etat).toEqual(CHARGEMENT);
Expand Down Expand Up @@ -73,25 +75,77 @@ describe('Le store en commun pour les situations', function () {
expect(store.state.aide).toBe(true);
});

describe('#acteEnCours', function () {
let store;

describe('Getters', function () {
beforeEach(function () {
store = creeStore();
});

it("Quand l'acte n'est pas demarré", function () {
expect(store.getters.acteEnCours).toBe(false);
describe('#acteEnCours', function () {
beforeEach(function () {
store = creeStore();
});

it("Quand l'acte n'est pas demarré", function () {
expect(store.getters.acteEnCours).toBe(false);
});

it("Quand l'acte principal est demarré", function () {
store.state.etat = DEMARRE;
expect(store.getters.acteEnCours).toBe(true);
});

it("Quand l'acte d'entrainement est demarré", function () {
store.state.etat = ENTRAINEMENT_DEMARRE;
expect(store.getters.acteEnCours).toBe(true);
});
});

it("Quand l'acte principal est demarré", function () {
store.state.etat = DEMARRE;
expect(store.getters.acteEnCours).toBe(true);
describe('#questionServeur', function() {
beforeEach(function () {
store = creeStore();
store.state.questionActive = { nom_technique: 'N1Prn1', score: 0.5, metacompetence: 'calcul' };
});

describe("si la question active a une question serveur avec le mĂȘme suffixe", function() {
let question;
let questionServeur;

beforeEach(function() {
question = { nom_technique: 'N1Prn1_variant', intitule: 'intitulé serveur' };
store.state.questions = [question];
questionServeur = store.getters.questionServeur(store.state.questionActive);
});

it("retourne la question serveur", function() {
expect(questionServeur.id).toEqual('N1Prn1');
expect(questionServeur.intitule).toEqual('intitulé serveur' );
});

it("recupere les données du client", function() {
expect(questionServeur.score).toEqual(0.5);
expect(questionServeur.metacompetence).toEqual('calcul');
});
});

describe("si la question active n'a pas de question serveur avec le mĂȘme suffixe", function() {
it('ne retourne rien', function() {
store.state.questions = [];
expect(store.getters.questionServeur(store.state.questionActive)).toBeUndefined();
});
});
});

it("Quand l'acte d'entrainement est demarré", function () {
store.state.etat = ENTRAINEMENT_DEMARRE;
expect(store.getters.acteEnCours).toBe(true);
describe('#recupereQuestionsServeur', function() {
beforeEach(function () {
store = creeStore();
});

it('met Ă  jour les questions avec les questions serveur', function() {
const questions = [{ nom_technique: 'N1Pse1' }, { nom_technique: 'N1Pse2' }];
store.commit('recupereQuestionsServeur', questions);

expect(store.state.questions).toEqual(questions);
});
});
});
});
Loading

0 comments on commit 0117cf3

Please sign in to comment.