Skip to content

Commit

Permalink
✨ Attribue le scoreMax dans l'evenement réponse depuis les composants…
Browse files Browse the repository at this point in the history
… Defi
  • Loading branch information
cprodhomme authored and marouria committed Jul 5, 2024
1 parent 9ba68a4 commit b546237
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default {
const reponse = lien.textContent.trim();
const succes = this.question.reponse.texte === reponse;
const score = succes ? this.question.score : 0;
this.$emit('reponse', { reponse, succes, score } );
const scoreMax = this.question.score;
this.$emit('reponse', { reponse, succes, score, scoreMax } );
},
envoiReponseMultiple(listeLiens) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default {
} else {
const succes = estSucces(reponse, this.question.reponse.bonne_reponse);
const score = succes ? this.question.score : 0;
this.$emit('reponse', { score, succes, reponse });
const scoreMax = this.question.score;
this.$emit('reponse', { reponse, succes, score, scoreMax });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/situations/cafe_de_la_place/vues/components/puzzle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export default {
const reponse = this.fragmentsClasses.map((fragment) => fragment.position);
const succes = this.succes(reponse);
const score = succes ? this.calculeScore(reponse) : 0;
const scoreMax = this.nombreFragment + 1;
this.affichePuzzleDroite = reponse.length < this.nombreFragment;
this.$emit('reponse', { score, succes, reponse });
this.$emit('reponse', { reponse, succes, score, scoreMax });
},
calculeScore(reponse) {
Expand Down
45 changes: 0 additions & 45 deletions src/situations/commun/vues/defi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ export default {
this.$emit('reponse', {
question: this.question.id,
intitule: this.question.intitule ?? this.question.retranscription_audio,
scoreMax: this.scoreMax(),
metacompetence: this.question.metacompetence,
reponseIntitule: this.reponseIntitule(),
...this.reponse
});
},
Expand All @@ -175,49 +173,6 @@ export default {
this.$refs.questionEntete.demarreSon();
}
},
scoreMax () {
let scoreMax = undefined;
if (this.question.choix) {
scoreMax = this.question.score;
}
if (this.question.reponse) {
scoreMax = this.scoreMaxDepuisReponse();
}
return scoreMax;
},
scoreMaxDepuisReponse() {
let scoreMax = undefined;
const scores = this.question.reponse.scores;
const score = this.question.score;
if (score) {
scoreMax = score;
}
if (scores) {
scoreMax = scores.reduce((max, score) => {
if (!max) return score;
return (score > max) ? score : max;
}, undefined);
}
return scoreMax;
},
reponseIntitule () {
const reponseId = this.reponse.reponse;
if (this.question.choix) {
const reponse = this.question.choix.find(choix => choix.id === reponseId);
if (reponse) return (reponse.intitule ?? reponse.retranscription_audio);
}
return undefined;
},
}
};
</script>
12 changes: 10 additions & 2 deletions src/situations/commun/vues/defi/champ_saisie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,20 @@ export default {
const reponse = valeur.trim();
let succes;
let score;
let scoreMax;
if(this.question.reponse) {
const indexReponse = this.question.reponse.textes.indexOf(reponse.toLowerCase());
succes = indexReponse != -1;
score = this.question.reponse.scores && this.question.reponse.scores[indexReponse];
const scores = this.question.reponse.scores;
if (scores) {
score = scores[indexReponse] ?? 0;
scoreMax = scores.reduce((max, score) => {
if (!max) return score;
return (score > max) ? score : max;
});
}
}
this.$emit('reponse', { reponse, succes, score });
this.$emit('reponse', { reponse, succes, score, scoreMax });
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/situations/commun/vues/defi/jauge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default ({
emetSelection () {
const reponseChoisie = this.question.choix[this.choixFait];
this.$emit('reponse', { reponse: reponseChoisie.id });
this.$emit('reponse', { reponse: reponseChoisie.id, reponseIntitule: reponseChoisie.intitule });
},
afficheLectureReponse (nomTechnique) {
Expand Down
15 changes: 13 additions & 2 deletions src/situations/commun/vues/defi/qcm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ export default {
selectReponse (valeur) {
this.reponse = valeur;
const choix = this.question.choix.find((choix) => choix.id === this.reponse);
const score = choix.bonneReponse ? this.question.score : 0;
this.$emit('reponse', { reponse: choix.id, succes: choix.bonneReponse, score: score });
let reponseIntitule;
if (choix) reponseIntitule = choix.intitule ?? choix.retranscription_audio;
let reponseData;
if (this.question.score) {
const score = choix.bonneReponse ? this.question.score : 0;
const scoreMax = this.question.score;
reponseData = { reponse: choix.id, succes: choix.bonneReponse, reponseIntitule: reponseIntitule, score: score, scoreMax: scoreMax };
} else {
reponseData = { reponse: choix.id, succes: choix.bonneReponse, reponseIntitule: reponseIntitule };
}
this.$emit('reponse', reponseData);
}
}
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Le composant Clic Sur Mots', function () {
const lien = wrapper.findAll('.mot-cliquable').at(1);
wrapper.vm.envoiReponse(lien.element);
expect(wrapper.emitted().reponse.length).toEqual(1);
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: 'exercice', succes: true, score: 1 });
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: 'exercice', succes: true, score: 1, scoreMax: 1 });
});
});

Expand All @@ -75,7 +75,7 @@ describe('Le composant Clic Sur Mots', function () {
const lien = wrapper.findAll('.mot-cliquable').at(0);
wrapper.vm.envoiReponse(lien.element);
expect(wrapper.emitted().reponse.length).toEqual(1);
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: 'invalide', succes: false, score: 0 });
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: 'invalide', succes: false, score: 0, scoreMax: 1 });
});
});
});
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('Le composant Clic Sur Mots', function () {
liens.at(1).trigger('click');
wrapper.vm.$nextTick(() => {
expect(wrapper.emitted().reponse.length).toEqual(1);
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: ['reponse2'], succes: true, score: 1 });
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: ['reponse2'], succes: true, score: 1, scoreMax: 1 });
done();
});
});
Expand All @@ -136,7 +136,7 @@ describe('Le composant Clic Sur Mots', function () {
liens.at(0).trigger('click');
wrapper.vm.$nextTick(() => {
expect(wrapper.emitted().reponse.length).toEqual(1);
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: ['reponse1'], succes: false, score: 0 });
expect(wrapper.emitted().reponse[0][0]).toEqual({ reponse: ['reponse1'], succes: false, score: 0, scoreMax: 1 });
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('Le mixin multi-select', function () {
expect(wrapper.emitted().reponse[0][0]).toEqual({
reponse: ['allemagne', 'france'],
succes: true,
score: 1
score: 1,
scoreMax: 1
});
});

Expand All @@ -36,16 +37,17 @@ describe('Le mixin multi-select', function () {
expect(wrapper.emitted().reponse[0][0]).toEqual({
reponse: ['france', 'allemagne'],
succes: true,
score: 1
score: 1,
scoreMax: 1
});
});


it("quand la réponse est fausse", function() {
wrapper.vm.emetReponseMultiple(['belgique']);
expect(wrapper.emitted().reponse[0][0]).toEqual({
reponse: ['belgique'],
score: 0,
scoreMax: 1,
succes: false
});
});
Expand All @@ -55,6 +57,7 @@ describe('Le mixin multi-select', function () {
expect(wrapper.emitted().reponse[0][0]).toEqual({
reponse: ['allemagne', 'belgique'],
score: 0,
scoreMax: 1,
succes: false
});
});
Expand All @@ -64,6 +67,7 @@ describe('Le mixin multi-select', function () {
expect(wrapper.emitted().reponse[0][0]).toEqual({
reponse: ['allemagne', 'france', 'belgique'],
score: 0,
scoreMax: 1,
succes: false
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('Le composant Puzzle', function () {
expect(wrapper.emitted('reponse').length).toEqual(1);
expect(wrapper.emitted('reponse')[0][0]).toEqual({
score: 8,
scoreMax: 8,
succes: true,
reponse: bonOrdre
});
Expand Down
129 changes: 0 additions & 129 deletions tests/situations/commun/vues/defi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,133 +368,4 @@ describe("La vue d'un défi", function () {
});
});
});

describe('#scoreMax', function () {
describe('quand la question contient une réponse avec une liste de score', function () {
beforeEach(function () {
question.reponse = {
nom_technique: 'APlc/cuisine',
textes: ['cuisine', 'cuisines'],
scores: [1, 0.75]
};
question.choix = undefined;
});

it("retourne le score le plus élevé", function () {
const vue = composant(question);
expect(vue.vm.scoreMax()).toEqual(1);
});
});

describe('quand la question contient une réponse avec un score', function () {
beforeEach(function () {
question.reponse = {
texte: 'Exercice',
nom_technique: 'ALrd/exercice',
};
question.score = 1;
question.choix = undefined;
});

it("retourne le score", function () {
const vue = composant(question);
expect(vue.vm.scoreMax()).toEqual(1);
});
});

describe('quand la question contient des choix', function () {
beforeEach(function () {
question.reponse = undefined;
question.score = 1;
question.choix = [
{
id: 'bax',
nom_technique: 'ALrd/bax',
bonneReponse: false
},
{
id: 'max',
nom_technique: 'ALrd/max',
bonneReponse: true
}
];
});

it("retourne le score", function () {
const vue = composant(question);
expect(vue.vm.scoreMax()).toEqual(1);
});
});

describe('quand la question contient des choix sans aucun score', function () {
beforeEach(function () {
question.reponse = undefined;
question.choix = [
{
id: 'bax',
nom_technique: 'ALrd/bax',
bonneReponse: false
},
{
id: 'max',
nom_technique: 'ALrd/max',
bonneReponse: true
}
];
});

it("retourne le score", function () {
const vue = composant(question);
expect(vue.vm.scoreMax()).toEqual(undefined);
});
});
});

describe('#reponseIntitule', function() {
let vue;

beforeEach(function () {
question.type = 'saisie';
vue = composant(question);
});

describe("quand il n'y a pas d'intitulé", function () {
it("retourne undefined", function () {
expect(vue.vm.reponseIntitule()).toEqual(undefined);
});
});

describe("quand il y a une retranscription audio", function () {
beforeEach(function () {
question.choix = [
{
id: 'tempsPresent',
nom_technique: 'ACrd/le_temps_present',
bonneReponse: false,
retranscription_audio: 'Le temps présent'
},
{
id: 'tempsFutur',
nom_technique: 'ACrd/le_temps_futur',
bonneReponse: true,
retranscription_audio: 'Le temps futur'
},
{
id: 'tempsPasse',
nom_technique: 'ACrd/le_temps_passe',
bonneReponse: false,
retranscription_audio: 'Le temps passé'
}
];
question.score = 1;
vue = composant(question);
const reponse = { reponse: 'tempsFutur', succes: true, score: undefined };
vue.vm.attribueReponse(reponse);
});

it("retourne l'intitulé Le temps futur »", function () {
expect(vue.vm.reponseIntitule()).toEqual('Le temps futur');
});
});
});
});
Loading

0 comments on commit b546237

Please sign in to comment.