Skip to content

Commit

Permalink
[FEATURE] Afficher la carte d'intro dans les flashcards Modulix (PIX-…
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Oct 10, 2024
2 parents 66ebfd6 + 910cebc commit 6e892be
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"element": {
"id": "47823e8f-a4af-44d6-96f7-5b6fc7bc6b51",
"type": "flashcards",
"title": "Introduction à l'adresse e-mail",
"title": "Introduction à la poésie",
"instruction": "<p>...</p>",
"introImage": {
"url": "https://example.org/image.jpeg"
"url": "https://images.pix.fr/modulix/didacticiel/intro-flashcards.png"
},
"cards": [
{
Expand All @@ -59,7 +59,7 @@
"image": {
"url": "https://images.pix.fr/modulix/didacticiel/icon.svg"
},
"text": "Qui a écrit le Dormeur du Val ?"
"text": "Qui a écrit « Le Dormeur du Val ? »"
},
"verso": {
"image": {
Expand All @@ -71,7 +71,7 @@
{
"id": "48d0cd29-1e08-4b18-b15a-411ab83e5d3c",
"recto": {
"text": "Comment s'appelait la fille de Victor Hugo, évoquée dans le poème 'Demain dès l'aube' ?"
"text": "Comment s'appelait la fille de Victor Hugo, évoquée dans le poème « Demain dès l'aube » ?"
},
"verso": {
"text": "<p>Léopoldine</p>"
Expand All @@ -83,13 +83,13 @@
"image": {
"url": "https://images.pix.fr/modulix/didacticiel/icon.svg"
},
"text": "Quel animal a des yeux 'mêlés de métal et d'agathe' selon Charles Baudelaire ?"
"text": "Quel animal a des yeux « mêlés de métal et d'agathe » selon Charles Baudelaire ?"
},
"verso": {
"image": {
"url": "https://images.pix.fr/modulix/didacticiel/chaton.jpg"
},
"text": "<p>Un chat</p>"
"text": "<p>Le chat</p>"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion mon-pix/app/components/module/element.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Component from '@glimmer/component';
import { eq } from 'ember-truth-helpers';
import DownloadElement from 'mon-pix/components/module/element/download';
import EmbedElement from 'mon-pix/components/module/element/embed';
import FlashcardsElement from 'mon-pix/components/module/element/flashcards';
import FlashcardsElement from 'mon-pix/components/module/element/flashcards/flashcards';
import ImageElement from 'mon-pix/components/module/element/image';
import QcmElement from 'mon-pix/components/module/element/qcm';
import QcuElement from 'mon-pix/components/module/element/qcu';
Expand Down
72 changes: 0 additions & 72 deletions mon-pix/app/components/module/element/flashcards.gjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PixButton from '@1024pix/pix-ui/components/pix-button';
import { t } from 'ember-intl';

<template>
<div class="element-flashcards__intro-card">
{{#if @introImage}}
<div class="element-flashcards__intro-card__image">
<img src={{@introImage.url}} alt="" />
</div>
{{/if}}

<div class="element-flashcards__intro-card__text">
<p class="element-flashcards__intro-card__title">{{@title}}</p>
</div>

<div class="element-flashcards__intro-card__footer">
<PixButton @triggerAction={{@onStart}} @variant="primary" @size="small">
{{t "pages.modulix.buttons.flashcards.start"}}
</PixButton>
</div>
</div>
</template>
97 changes: 97 additions & 0 deletions mon-pix/app/components/module/element/flashcards/flashcards.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';
import { eq } from 'ember-truth-helpers';
import ModulixFlashcardsCard from 'mon-pix/components/module/element/flashcards/flashcards-card';
import ModulixFlashcardsIntroCard from 'mon-pix/components/module/element/flashcards/flashcards-intro-card';

export default class ModulixFlashcards extends Component {
@tracked
/**
* Displayed side of the card on the screen
* @type {"intro"|"cards"|"outro"}
*/
currentStep = 'intro';

@tracked
/**
* Displayed side of the card on the screen
* @type {"recto"|"verso"}
*/
displayedSideName = 'recto';

@tracked
/**
* Index of the displayed card in the deck
* @type {number}
*/
currentCardIndex = 0;

get currentCard() {
return this.args.flashcards.cards[this.currentCardIndex];
}

get currentCardNumber() {
return this.currentCardIndex + 1;
}

get numberOfCards() {
return this.args.flashcards.cards.length;
}

@action
start() {
this.currentStep = 'cards';
}

@action
flipCard() {
this.displayedSideName = this.displayedSideName === 'recto' ? 'verso' : 'recto';
}

@action
goToNextCard() {
this.currentCardIndex++;
this.displayedSideName = 'recto';
}

<template>
<div class="element-flashcards">

{{#if (eq this.currentStep "intro")}}
<ModulixFlashcardsIntroCard
@title={{@flashcards.title}}
@introImage={{@flashcards.introImage}}
@onStart={{this.start}}
/>
{{/if}}

{{#if (eq this.currentStep "cards")}}
<ModulixFlashcardsCard
@card={{this.currentCard}}
@displayedSideName={{this.displayedSideName}}
@onCardFlip={{this.flipCard}}
/>

<div class="element-flashcards__footer">
{{#if (eq this.displayedSideName "recto")}}
<p class="element-flashcards-footer__direction">{{t "pages.modulix.flashcards.direction"}}</p>
<p class="element-flashcards-footer__position">{{t
"pages.modulix.flashcards.position"
currentCardPosition=this.currentCardNumber
totalCards=this.numberOfCards
}}</p>
{{/if}}
{{#if (eq this.displayedSideName "verso")}}
<button type="button" {{on "click" this.goToNextCard}}>{{t
"pages.modulix.buttons.flashcards.nextCard"
}}</button>
{{/if}}
</div>
{{/if}}

</div>
</template>
}
14 changes: 13 additions & 1 deletion mon-pix/app/styles/components/module/_flashcards.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.element-flashcards {
&__card {
&__card,
&__intro-card {
display: flex;
flex-direction: column;
justify-content: space-between;
Expand All @@ -13,6 +14,17 @@
box-shadow: 0 12px 24px 0 rgb(7 20 46 / 12%);
}

&__intro-card {
align-items: center;
padding: var(--pix-spacing-2x);
padding-bottom: var(--pix-spacing-6x);
border: 0;
}

&__intro-card__title {
@extend %pix-title-s;
}

&__footer {
display: flex;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,6 @@ module('Integration | Component | Module | Element', function (hooks) {
);

// then
assert.dom(screen.getByRole('button', { name: 'Voir la réponse' })).exists();
assert.dom(screen.getByRole('button', { name: 'Commencer' })).exists();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { clickByName, render } from '@1024pix/ember-testing-library';
import { t } from 'ember-intl/test-support';
import ModulixFlashcardsCard from 'mon-pix/components/module/element/flashcards-card';
import ModulixFlashcardsCard from 'mon-pix/components/module/element/flashcards/flashcards-card';
// eslint-disable-next-line no-restricted-imports
import { module, test } from 'qunit';
import sinon from 'sinon';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { clickByName, render } from '@1024pix/ember-testing-library';
import { t } from 'ember-intl/test-support';
import ModulixFlashcardsIntroCard from 'mon-pix/components/module/element/flashcards/flashcards-intro-card';
// eslint-disable-next-line no-restricted-imports
import { module, test } from 'qunit';
import sinon from 'sinon';

import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering';

module('Integration | Component | Module | Flashcards Intro Card', function (hooks) {
setupIntlRenderingTest(hooks);

test('should display an intro card', async function (assert) {
// given
const introImage = {
url: 'https://images.pix.fr/modulix/bien-ecrire-son-adresse-mail-explication-les-parties-dune-adresse-mail.svg',
};
const title = 'Introduction à la poésie';

// when
const screen = await render(
<template><ModulixFlashcardsIntroCard @introImage={{introImage}} @title={{title}} /></template>,
);

// then
assert.ok(screen.getByText('Introduction à la poésie'));
assert.strictEqual(
screen.getByRole('presentation').getAttribute('src'),
'https://images.pix.fr/modulix/bien-ecrire-son-adresse-mail-explication-les-parties-dune-adresse-mail.svg',
);
assert.dom(screen.getByRole('button', { name: t('pages.modulix.buttons.flashcards.start') })).exists();
});

test('should not display image if not provided', async function (assert) {
// given
const introImage = undefined;
const title = 'Introduction à la poésie';

// when
const screen = await render(
<template><ModulixFlashcardsIntroCard @introImage={{introImage}} @title={{title}} /></template>,
);

// then
assert.dom(screen.queryByRole('img')).doesNotExist();
});

module('when we click on "Commencer"', function () {
test('should call the onStart method', async function (assert) {
// given
const introImage = undefined;
const title = 'Introduction à la poésie';
const onStartStub = sinon.stub();

await render(
<template>
<ModulixFlashcardsIntroCard @introImage={{introImage}} @title={{title}} @onStart={{onStartStub}} />
</template>,
);

// when
await clickByName(t('pages.modulix.buttons.flashcards.start'));

// then
assert.true(onStartStub.calledOnce);
});
});
});
Loading

0 comments on commit 6e892be

Please sign in to comment.