From fbf94e56b6757c8ccedea5870aab7124cfffcbe7 Mon Sep 17 00:00:00 2001 From: Geoffroy Begouaussel Date: Thu, 14 Nov 2024 11:54:10 +0100 Subject: [PATCH] refactor(mon-pix): improve evaluation results hero conditionnal displays --- .../results/evaluation-results-hero/index.gjs | 109 +++++++-------- .../hero/evaluation-results-hero-test.js | 125 ++++++++++++++---- 2 files changed, 157 insertions(+), 77 deletions(-) diff --git a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-hero/index.gjs b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-hero/index.gjs index 4f72b37fef2..b3418df7406 100644 --- a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-hero/index.gjs +++ b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-hero/index.gjs @@ -7,7 +7,6 @@ import { service } from '@ember/service'; import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { t } from 'ember-intl'; -import ENV from 'mon-pix/config/environment'; import MarkdownToHtml from '../../../../markdown-to-html'; import AcquiredBadges from './acquired-badges'; @@ -24,10 +23,6 @@ export default class EvaluationResultsHero extends Component { @tracked isImproveButtonLoading = false; @tracked isShareResultsLoading = false; - get isAutonomousCourse() { - return this.args.campaign.organizationId === ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID; - } - get masteryRatePercentage() { return Math.round(this.args.campaignParticipationResult.masteryRate * 100); } @@ -46,9 +41,13 @@ export default class EvaluationResultsHero extends Component { }; } + get isSharableCampaign() { + return !this.args.campaign.isSimplifiedAccess; + } + get showCustomOrganizationBlock() { const hasCustomContent = this.args.campaign.customResultPageText || this.args.campaign.hasCustomResultPageButton; - return hasCustomContent && this.args.campaignParticipationResult.isShared; + return hasCustomContent && (!this.isSharableCampaign || this.args.campaignParticipationResult.isShared); } @action @@ -124,57 +123,43 @@ export default class EvaluationResultsHero extends Component { {{/if}} +

{{t "pages.skill-review.hero.bravo" name=this.currentUser.user.firstName}}

+ {{#if @campaignParticipationResult.hasReachedStage}}
{{/if}} - {{#if @campaignParticipationResult.isShared}} - - {{t "pages.skill-review.hero.shared-message"}} - - {{#if @hasTrainings}} + + {{#if this.isSharableCampaign}} + {{#if @campaignParticipationResult.isShared}} + + {{t "pages.skill-review.hero.shared-message"}} + + {{#if @hasTrainings}} +

+ {{t "pages.skill-review.hero.explanations.trainings"}} +

+ {{/if}} + {{else}}

- {{t "pages.skill-review.hero.explanations.trainings"}} + {{t "pages.skill-review.hero.explanations.send-results"}}

{{/if}} - {{else}} - {{#unless this.isAutonomousCourse}} + {{#if @campaignParticipationResult.canImprove}}

- {{t "pages.skill-review.hero.explanations.send-results"}} + {{t "pages.skill-review.hero.explanations.improve"}}

- {{/unless}} - {{/if}} - {{#if @campaignParticipationResult.canImprove}} -

- {{t "pages.skill-review.hero.explanations.improve"}} -

+ {{/if}} {{/if}} +
- {{#if @campaignParticipationResult.isShared}} - {{#if @hasTrainings}} - - {{t "pages.skill-review.hero.see-trainings"}} - - {{else}} - {{#unless @campaign.hasCustomResultPageButton}} - - {{t "navigation.back-to-homepage"}} - - {{/unless}} - {{/if}} - {{else}} - {{#if this.isAutonomousCourse}} - {{#unless @campaign.hasCustomResultPageButton}} - - {{t "navigation.back-to-homepage"}} - - {{/unless}} - {{else}} + {{#if this.isSharableCampaign}} + {{#unless @campaignParticipationResult.isShared}} {{t "pages.skill-review.actions.send"}} + {{else}} + {{#if @hasTrainings}} + + {{t "pages.skill-review.hero.see-trainings"}} + + {{else}} + {{#unless @campaign.hasCustomResultPageButton}} + + {{t "navigation.back-to-homepage"}} + + {{/unless}} + {{/if}} + {{/unless}} + {{#if @campaignParticipationResult.canImprove}} + + {{t "pages.skill-review.actions.improve"}} + {{/if}} - {{/if}} - - {{#if @campaignParticipationResult.canImprove}} - - {{t "pages.skill-review.actions.improve"}} - + {{else}} + {{#unless @campaign.hasCustomResultPageButton}} + + {{t "navigation.back-to-homepage"}} + + {{/unless}} {{/if}} {{#if this.hasGlobalError}} @@ -204,16 +206,19 @@ export default class EvaluationResultsHero extends Component {
{{/if}}
+ {{#if @campaignParticipationResult.acquiredBadges.length}} {{/if}} + {{#if this.showCustomOrganizationBlock}} {{/if}} + {{#if @campaignParticipationResult.canRetry}} {{/if}} diff --git a/mon-pix/tests/integration/components/campaigns/assessment/results/hero/evaluation-results-hero-test.js b/mon-pix/tests/integration/components/campaigns/assessment/results/hero/evaluation-results-hero-test.js index 186e3a68644..c3c7bd70f98 100644 --- a/mon-pix/tests/integration/components/campaigns/assessment/results/hero/evaluation-results-hero-test.js +++ b/mon-pix/tests/integration/components/campaigns/assessment/results/hero/evaluation-results-hero-test.js @@ -236,12 +236,12 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation }); }); - module('when it is an autonomous course', function () { + module('when campaign is simplified access', function () { module('when there is no custom link', function () { test('it should display only a homepage link', async function (assert) { // given this.set('campaign', { - organizationId: ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID, + isSimplifiedAccess: true, hasCustomResultPageButton: false, }); this.set('campaignParticipationResult', { masteryRate: 0.75 }); @@ -267,7 +267,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation test('it should not display a homepage link', async function (assert) { // given this.set('campaign', { - organizationId: ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID, + isSimplifiedAccess: true, hasCustomResultPageButton: true, }); this.set('campaignParticipationResult', { masteryRate: 0.75 }); @@ -533,36 +533,17 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation }); module('custom organization block', function () { - module('when results are not shared', function () { - test('it should not display the organization block', async function (assert) { - // given - this.set('campaign', { organizationId: 1 }); - this.set('campaignParticipationResult', { masteryRate: 0.75 }); - - // when - const screen = await render( - hbs``, - ); - - // then - assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist(); - assert.dom(screen.queryByText('My custom result page text')).doesNotExist(); - }); - }); - - module('when results are shared', function () { + module('when campaign is with simplified access', function () { module('when customResultPageText if defined', function () { test('displays the organization block with the text', async function (assert) { // given this.set('campaign', { customResultPageText: 'My custom result page text', organizationId: 1, + isSimplifiedAccess: true, }); - this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: true }); + this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: false }); // when const screen = await render( @@ -624,6 +605,100 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation }); }); }); + + module('when campaign is sharable', function () { + module('when results are not shared', function () { + test('it should not display the organization block', async function (assert) { + // given + this.set('campaign', { organizationId: 1 }); + this.set('campaignParticipationResult', { masteryRate: 0.75 }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist(); + assert.dom(screen.queryByText('My custom result page text')).doesNotExist(); + }); + }); + + module('when results are shared', function () { + module('when customResultPageText if defined', function () { + test('displays the organization block with the text', async function (assert) { + // given + this.set('campaign', { + customResultPageText: 'My custom result page text', + organizationId: 1, + }); + + this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: true }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists(); + assert.dom(screen.getByText('My custom result page text')).exists(); + }); + }); + + module('when campaign has customResultPageButton', function () { + test('displays the organization block with the custom button', async function (assert) { + // given + const store = this.owner.lookup('service:store'); + const campaign = await store.createRecord('campaign', { + customResultPageButtonUrl: 'https://example.net', + customResultPageButtonText: 'Custom result page button text', + organizationId: 1, + }); + this.set('campaign', campaign); + this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: true }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists(); + assert.dom(screen.getByRole('link', { name: 'Custom result page button text' })).exists(); + }); + }); + + module('when campaign has no custom result page button or text', function () { + test('no display the organization block', async function (assert) { + // given + this.set('campaign', { organizationId: 1 }); + this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: true }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist(); + assert.dom(screen.queryByText('My custom result page text')).doesNotExist(); + }); + }); + }); + }); }); module('retry or reset block', function () {