-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mon-pix): prevent live-alert trigger when the challenge is alrea…
…dy answered refactor(mon-pix): use PixButton for the challenge live-alert trigger
- Loading branch information
Showing
10 changed files
with
236 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { fn } from '@ember/helper'; | ||
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 AssessmentsLiveAlert from '../assessments/live-alert'; | ||
import FeedbackPanel from '../feedback-panel'; | ||
import FeedbackPanelV3 from '../feedback-panel-v3'; | ||
import ChallengeItem from './item'; | ||
|
||
export default class ChallengeContent extends Component { | ||
@tracked isLiveAlertButtonEnabled = true; | ||
|
||
@action | ||
handleChallengeSubmit() { | ||
this.isLiveAlertButtonEnabled = false; | ||
} | ||
|
||
<template> | ||
<div | ||
class="focus-zone-warning | ||
{{if @isFocusedChallengeAndUserHasFocusedOutOfChallenge 'focus-zone-warning--triggered'}}" | ||
data-challenge-id="{{@challenge.id}}" | ||
{{on "mouseenter" @hideOutOfFocusBorder}} | ||
{{on "mouseleave" @showOutOfFocusBorder}} | ||
> | ||
|
||
<ChallengeItem | ||
@challenge={{@challenge}} | ||
@assessment={{@assessment}} | ||
@answer={{@answer}} | ||
@timeoutChallenge={{@timeoutChallenge}} | ||
@resetAllChallengeInfo={{@resetAllChallengeInfo}} | ||
@resetChallengeInfoOnResume={{@resetChallengeInfoOnResume}} | ||
@onFocusIntoChallenge={{fn @setFocusedOutOfChallenge false}} | ||
@onFocusOutOfChallenge={{fn @setFocusedOutOfChallenge true}} | ||
@onFocusOutOfWindow={{@focusedOutOfWindow}} | ||
@hasFocusedOutOfWindow={{@hasFocusedOutOfWindow}} | ||
@isFocusedChallengeAndUserHasFocusedOutOfChallenge={{@isFocusedChallengeAndUserHasFocusedOutOfChallenge}} | ||
@isTextToSpeechActivated={{@isTextToSpeechActivated}} | ||
@onChallengeSubmit={{this.handleChallengeSubmit}} | ||
/> | ||
|
||
{{#unless @assessment.hasOngoingCompanionLiveAlert}} | ||
<div class="challenge__feedback" role="complementary"> | ||
{{#if (eq @assessment.certificationCourse.version 3)}} | ||
<FeedbackPanelV3 | ||
@submitLiveAlert={{@submitLiveAlert}} | ||
@assessment={{@assessment}} | ||
@isEnabled={{this.isLiveAlertButtonEnabled}} | ||
/> | ||
{{else}} | ||
<FeedbackPanel @assessment={{@assessment}} @challenge={{@challenge}} /> | ||
{{/if}} | ||
</div> | ||
{{/unless}} | ||
|
||
{{#if @assessment.hasOngoingCompanionLiveAlert}} | ||
<AssessmentsLiveAlert @message={{t "pages.challenge.live-alerts.companion.message"}} /> | ||
{{/if}} | ||
</div> | ||
|
||
{{#if @isFocusedChallengeAndUserHasFocusedOutOfChallenge}} | ||
<div class="focus-zone-warning__overlay" /> | ||
{{/if}} | ||
</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
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 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
Empty file.
87 changes: 87 additions & 0 deletions
87
mon-pix/tests/integration/components/challenge/content-test.js
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,87 @@ | ||
import { render } from '@1024pix/ember-testing-library'; | ||
import { click, fillIn } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { module, test } from 'qunit'; | ||
import sinon from 'sinon'; | ||
|
||
import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering'; | ||
|
||
module('Integration | Component | Challenge | Content', function (hooks) { | ||
setupIntlRenderingTest(hooks); | ||
|
||
let screen; | ||
|
||
hooks.before(function () { | ||
sinon.stub(window, 'fetch'); | ||
}); | ||
|
||
hooks.beforeEach(async function () { | ||
// given | ||
const router = this.owner.lookup('service:router'); | ||
router.transitionTo = sinon.stub(); | ||
|
||
const store = this.owner.lookup('service:store'); | ||
this.set( | ||
'challenge', | ||
store.createRecord('challenge', { | ||
type: 'QROC', | ||
timer: false, | ||
format: 'phrase', | ||
proposals: '${myInput}', | ||
}), | ||
); | ||
this.set('answer', null); | ||
this.set( | ||
'assessment', | ||
store.createRecord('assessment', { | ||
certificationCourse: store.createRecord('certification-course', { | ||
version: 3, | ||
}), | ||
answers: [], | ||
}), | ||
); | ||
this.set('fakeFunction', () => {}); | ||
|
||
// when | ||
screen = await render( | ||
hbs`<Challenge::Content | ||
@challenge={{this.challenge}} | ||
@answer={{this.answer}} | ||
@assessment={{this.assessment}} | ||
@hideOutOfFocusBorder={{this.fakeFunction}} | ||
@showOutOfFocusBorder={{this.fakeFunction}} | ||
@resetAllChallengeInfo={{this.fakeFunction}} | ||
/>`, | ||
); | ||
}); | ||
|
||
module('on challenge skip', function () { | ||
test('should disable the live alert button', async function (assert) { | ||
// then | ||
await click(screen.getByRole('button', { name: /Signaler un problème avec la question/ })); | ||
assert.dom(screen.getByRole('button', { name: /Oui, je suis/ })).exists(); | ||
|
||
await click(screen.getByRole('button', { name: /Je passe/ })); | ||
assert | ||
.dom(screen.getByRole('button', { name: /Signaler un problème avec la question/ })) | ||
.hasAttribute('disabled'); | ||
assert.dom(screen.queryByRole('button', { name: /Oui, je suis/ })).doesNotExist(); | ||
}); | ||
}); | ||
|
||
module('on challenge answering', function () { | ||
test('should disable the live alert button', async function (assert) { | ||
// then | ||
await click(screen.getByRole('button', { name: /Signaler un problème avec la question/ })); | ||
assert.dom(screen.getByRole('button', { name: /Oui, je suis/ })).exists(); | ||
|
||
await fillIn(screen.getByRole('textbox'), 'answer'); | ||
await click(screen.getByRole('button', { name: /Je valide/ })); | ||
|
||
assert | ||
.dom(screen.getByRole('button', { name: /Signaler un problème avec la question/ })) | ||
.hasAttribute('disabled'); | ||
assert.dom(screen.queryByRole('button', { name: /Oui, je suis/ })).doesNotExist(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.