Skip to content

Commit

Permalink
[BUGFIX] Rafraîchir la page lorsque le candidat clique sur le bouton …
Browse files Browse the repository at this point in the history
…lors d'un signalement en certification (PIX-14959).

 #10379
  • Loading branch information
pix-service-auto-merge authored Oct 23, 2024
2 parents 832b315 + b65f3df commit cf4a502
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
9 changes: 6 additions & 3 deletions mon-pix/app/components/assessments/live-alert.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixIcon from '@1024pix/pix-ui/components/pix-icon';
import PixMessage from '@1024pix/pix-ui/components/pix-message';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { t } from 'ember-intl';

export default class LiveAlert extends Component {
@service router;

@action
reloadAssessment() {
this.args.assessment.reload();
refreshPage() {
this.router.refresh();
}

<template>
Expand All @@ -20,7 +23,7 @@ export default class LiveAlert extends Component {
<PixButton
@variant="tertiary"
@loadingColor="grey"
@triggerAction={{this.reloadAssessment}}
@triggerAction={{this.refreshPage}}
class="refresh-information-live-alert__button"
>
<PixIcon @name="refresh" @ariaHidden={{true}} class="refresh-information-live-alert__icon" />
Expand Down
2 changes: 1 addition & 1 deletion mon-pix/app/components/feedback-panel-v3.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{! template-lint-disable require-input-label no-unknown-arguments-for-builtin-components }}
{{#if this.isAssessmentPaused}}
<Assessments::LiveAlert @message={{t "pages.challenge.live-alerts.challenge.message"}} @assessment={{@assessment}} />
<Assessments::LiveAlert @message={{t "pages.challenge.live-alerts.challenge.message"}} />
{{else}}
<div class="feedback-panel-v3">
<h2 class="screen-reader-only">{{t "pages.challenge.parts.feedback-v3"}}</h2>
Expand Down
5 changes: 1 addition & 4 deletions mon-pix/app/templates/assessments/challenge.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@
{{/unless}}

{{#if @model.assessment.hasOngoingCompanionLiveAlert}}
<Assessments::LiveAlert
@message={{t "pages.challenge.live-alerts.companion.message"}}
@assessment={{@model.assessment}}
/>
<Assessments::LiveAlert @message={{t "pages.challenge.live-alerts.companion.message"}} />
{{/if}}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { render } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';
import { t } from 'ember-intl/test-support';
import LiveAlert from 'mon-pix/components/assessments/live-alert';
import { module, test } from 'qunit';
import sinon from 'sinon';

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

Expand All @@ -12,34 +10,14 @@ module('Integration | Component | Assessments | live-alert', function (hooks) {

test('it displays challenge live alert', async function (assert) {
// given
const assessment = {
reload: sinon.stub(),
};
const message = t('pages.challenge.live-alerts.companion.message');

// when
const screen = await render(<template><LiveAlert @assessment={{assessment}} @message={{message}} /></template>);
const screen = await render(<template><LiveAlert @message={{message}} /></template>);

// then
assert.dom(screen.getByText(message)).exists();
assert.dom(screen.getByText(t('pages.challenge.live-alerts.waiting-information'))).exists();
assert.dom(screen.getByRole('button', { name: t('pages.challenge.live-alerts.refresh') })).exists();
});

module('when user clicks refresh button', function () {
test('it should reload assessment', async function (assert) {
// given
const assessment = {
reload: sinon.stub(),
};
const screen = await render(<template><LiveAlert @assessment={{assessment}} /></template>);

// when
await click(screen.getByRole('button', { name: t('pages.challenge.live-alerts.refresh') }));

// then
sinon.assert.calledOnce(assessment.reload);
assert.ok(true);
});
});
});
24 changes: 24 additions & 0 deletions mon-pix/tests/unit/components/assessments/live-alert-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { setupTest } from 'ember-qunit';
import createGlimmerComponent from 'mon-pix/tests/helpers/create-glimmer-component';
import { module, test } from 'qunit';
import sinon from 'sinon';

module('Unit | Component | Assessments | Live alert', function (hooks) {
setupTest(hooks);

module('#refreshPage', function () {
test('should refresh page', async function (assert) {
// given
const routerService = this.owner.lookup('service:router');
sinon.stub(routerService, 'refresh');
const component = createGlimmerComponent('assessments/live-alert');

// when
await component.refreshPage();

// then
sinon.assert.calledOnce(component.router.refresh);
assert.ok(true);
});
});
});

0 comments on commit cf4a502

Please sign in to comment.