-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Afficher la carte d'intro dans les flashcards Modulix (PIX-…
- Loading branch information
Showing
16 changed files
with
283 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
mon-pix/app/components/module/element/flashcards/flashcards-intro-card.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
97
mon-pix/app/components/module/element/flashcards/flashcards.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
mon-pix/tests/integration/components/module/flashcards-card_test.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
mon-pix/tests/integration/components/module/flashcards-intro-card_test.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.