From 2f148b0510854794ef4b95304d7d272da7e267d4 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 | 114 ++++++++-------- .../hero/evaluation-results-hero-test.js | 126 ++++++++++++++---- 2 files changed, 159 insertions(+), 81 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 8339bab6506..19035c0c0a1 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 @@ -8,7 +8,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'; @@ -25,10 +24,6 @@ export default class EvaluationResultsHero extends Component { @tracked hasGlobalError = false; @tracked isButtonLoading = false; - get isAutonomousCourse() { - return this.args.campaign.organizationId === ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID; - } - get masteryRatePercentage() { return Math.round(this.args.campaignParticipationResult.masteryRate * 100); } @@ -47,9 +42,17 @@ 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); + } + + get hasQuestResults() { + return this.args.questResults && this.args.questResults.length > 0; } @action @@ -57,10 +60,6 @@ export default class EvaluationResultsHero extends Component { this.args.showTrainings(); } - get hasQuestResults() { - return this.args.questResults && this.args.questResults.length > 0; - } - @action async improveResults() { if (this.isButtonLoading) return; @@ -144,52 +143,49 @@ export default class EvaluationResultsHero extends Component {

{{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}} + {{#if this.isSharableCampaign}} + {{#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}} - {{/if}} - - {{#if @campaignParticipationResult.canImprove}} - - {{t "pages.skill-review.actions.improve"}} - + {{#if @campaignParticipationResult.canImprove}} + + {{t "pages.skill-review.actions.improve"}} + + {{/if}} + {{else}} + {{#unless @campaign.hasCustomResultPageButton}} + + {{t "navigation.back-to-homepage"}} + + {{/unless}} {{/if}} {{#if this.hasGlobalError}} @@ -220,16 +221,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 6e8ab7a59a6..b6ae4bd7e17 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 @@ -3,7 +3,6 @@ import Service from '@ember/service'; import { click } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; import { t } from 'ember-intl/test-support'; -import ENV from 'mon-pix/config/environment'; import { module, test } from 'qunit'; import sinon from 'sinon'; @@ -236,12 +235,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 +266,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 }); @@ -557,36 +556,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( @@ -648,6 +628,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 () {