Skip to content

Commit aff36d9

Browse files
clemlatzdianeCdrPixer-lim
committed
feat(mon-pix): increment self-assessment counters
Co-authored-by: Diane Cordier <[email protected]> Co-authored-by: Eric Lim <[email protected]>
1 parent 8276cc5 commit aff36d9

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

mon-pix/app/components/module/element/flashcards/flashcards.gjs

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import ModulixFlashcardsCard from 'mon-pix/components/module/element/flashcards/
99
import ModulixFlashcardsIntroCard from 'mon-pix/components/module/element/flashcards/flashcards-intro-card';
1010
import ModulixFlashcardsOutroCard from 'mon-pix/components/module/element/flashcards/flashcards-outro-card';
1111

12+
const INITIAL_COUNTERS_VALUE = { yes: 0, almost: 0, no: 0 };
13+
1214
export default class ModulixFlashcards extends Component {
1315
@tracked
1416
/**
@@ -31,6 +33,13 @@ export default class ModulixFlashcards extends Component {
3133
*/
3234
currentCardIndex = 0;
3335

36+
@tracked
37+
/**
38+
* Stores the number of times an answer has been chosen
39+
* @type {object}
40+
*/
41+
counters = { ...INITIAL_COUNTERS_VALUE };
42+
3443
get currentCard() {
3544
return this.args.flashcards.cards[this.currentCardIndex];
3645
}
@@ -52,6 +61,7 @@ export default class ModulixFlashcards extends Component {
5261
this.currentStep = 'intro';
5362
this.currentCardIndex = 0;
5463
this.displayedSideName = 'recto';
64+
this.counters = { ...INITIAL_COUNTERS_VALUE };
5565
}
5666

5767
@action
@@ -64,6 +74,10 @@ export default class ModulixFlashcards extends Component {
6474
this.displayedSideName = this.displayedSideName === 'recto' ? 'verso' : 'recto';
6575
}
6676

77+
incrementCounterFor(userAssessment) {
78+
this.counters[userAssessment]++;
79+
}
80+
6781
goToNextCard() {
6882
if (this.currentCardIndex < this.numberOfCards - 1) {
6983
this.currentCardIndex++;
@@ -80,6 +94,7 @@ export default class ModulixFlashcards extends Component {
8094
cardId: this.currentCard.id,
8195
};
8296
this.args.onSelfAssessment(selfAssessmentData);
97+
this.incrementCounterFor(userAssessment);
8398
this.goToNextCard();
8499
}
85100

@@ -103,7 +118,7 @@ export default class ModulixFlashcards extends Component {
103118
{{/if}}
104119

105120
{{#if (eq this.currentStep "outro")}}
106-
<ModulixFlashcardsOutroCard @title={{@flashcards.title}} @onRetry={{this.retry}} />
121+
<ModulixFlashcardsOutroCard @title={{@flashcards.title}} @onRetry={{this.retry}} @counters={{this.counters}} />
107122
{{/if}}
108123

109124
<div class="element-flashcards__footer {{if this.footerIsEmpty 'element-flashcards__footer--empty'}}">

mon-pix/tests/integration/components/module/flashcards_test.gjs

+60
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,66 @@ module('Integration | Component | Module | Flashcards', function (hooks) {
283283
});
284284
});
285285

286+
module('when users reaches the end of the deck', function () {
287+
test('should display the counters for each answer', async function (assert) {
288+
// given
289+
const firstCard = {
290+
id: 'e1de6394-ff88-4de3-8834-a40057a50ff4',
291+
recto: {
292+
image: {
293+
url: 'https://images.pix.fr/modulix/bien-ecrire-son-adresse-mail-explication-les-parties-dune-adresse-mail.svg',
294+
},
295+
text: "A quoi sert l'arobase dans mon adresse email ?",
296+
},
297+
verso: {
298+
image: { url: 'https://images.pix.fr/modulix/didacticiel/ordi-spatial.svg' },
299+
text: "Parce que c'est joli",
300+
},
301+
};
302+
const secondCard = {
303+
id: 'e1de6394-ff88-4de3-8834-a40057a50ff4',
304+
recto: {
305+
image: {
306+
url: 'https://images.pix.fr/modulix/didacticiel/icon.svg',
307+
},
308+
text: 'Qui a écrit le Dormeur du Val ?',
309+
},
310+
verso: {
311+
image: {
312+
url: 'https://images.pix.fr/modulix/didacticiel/chaton.jpg',
313+
},
314+
text: '<p>Arthur Rimbaud</p>',
315+
},
316+
};
317+
318+
const flashcards = {
319+
id: '71de6394-ff88-4de3-8834-a40057a50ff4',
320+
type: 'flashcards',
321+
title: "Introduction à l'adresse e-mail",
322+
instruction: '<p>...</p>',
323+
introImage: { url: 'https://images.pix.fr/modulix/placeholder-details.svg' },
324+
cards: [firstCard, secondCard],
325+
};
326+
327+
const onSelfAssessment = sinon.stub();
328+
329+
// when
330+
const screen = await render(
331+
<template><ModulixFlashcards @flashcards={{flashcards}} @onSelfAssessment={{onSelfAssessment}} /></template>,
332+
);
333+
await clickByName(t(I18N_KEYS.introStartButton));
334+
await clickByName(t('pages.modulix.buttons.flashcards.seeAnswer'));
335+
await clickByName(t('pages.modulix.buttons.flashcards.answers.yes'));
336+
await clickByName(t('pages.modulix.buttons.flashcards.seeAnswer'));
337+
await clickByName(t('pages.modulix.buttons.flashcards.answers.notAtAll'));
338+
339+
// then
340+
assert.ok(screen.getByText('Oui ! : 1'));
341+
assert.ok(screen.getByText('Presque : 0'));
342+
assert.ok(screen.getByText('Pas du tout : 1'));
343+
});
344+
});
345+
286346
module('when user clicks on the "Retry" button', function () {
287347
test('should display intro card', async function (assert) {
288348
// given

0 commit comments

Comments
 (0)