From 23492ca3c509417d974f65a232d949ae56791364 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 | 110 +++++++++--------- mon-pix/app/models/campaign.js | 5 + .../hero/evaluation-results-hero-test.js | 54 +++++++++ 3 files changed, 117 insertions(+), 52 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..428ea06b913 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,14 @@ export default class EvaluationResultsHero extends Component { }; } + get isSharableCampaign() { + const isSimplifiedAccessCampaign = this.args.campaign.isAutonomousCourse || this.args.campaign.isForAbsoluteNovice; + return !isSimplifiedAccessCampaign; + } + 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 +124,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 +207,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/app/models/campaign.js b/mon-pix/app/models/campaign.js index 3ca9db83e9e..2983b6e3e36 100644 --- a/mon-pix/app/models/campaign.js +++ b/mon-pix/app/models/campaign.js @@ -1,4 +1,5 @@ import Model, { attr } from '@ember-data/model'; +import ENV from 'mon-pix/config/environment'; export default class Campaign extends Model { @attr('string') code; @@ -47,6 +48,10 @@ export default class Campaign extends Model { return this.organizationType === 'SUP'; } + get isAutonomousCourse() { + return this.organizationId === ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID; + } + get hasCustomResultPageButton() { return Boolean(this.customResultPageButtonUrl) && Boolean(this.customResultPageButtonText); } 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..3673c515e95 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 @@ -290,6 +290,60 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation }); }); + module('when it is an isForAbsoluteNovice campaign', function () { + module('when there is no custom link', function () { + test('it should display only a homepage link', async function (assert) { + // given + this.set('campaign', { + isForAbsoluteNovice: true, + hasCustomResultPageButton: false, + }); + this.set('campaignParticipationResult', { masteryRate: 0.75 }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.queryByText(t('pages.skill-review.hero.explanations.send-results'))).doesNotExist(); + + assert.dom(screen.getByRole('link', { name: t('navigation.back-to-homepage') })).exists(); + assert.dom(screen.queryByRole('button', { name: t('pages.skill-review.hero.see-trainings') })).doesNotExist(); + assert.dom(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') })).doesNotExist(); + }); + }); + + module('when there is a custom link', function () { + test('it should not display a homepage link', async function (assert) { + // given + this.set('campaign', { + isForAbsoluteNovice: true, + hasCustomResultPageButton: true, + }); + this.set('campaignParticipationResult', { masteryRate: 0.75 }); + + // when + const screen = await render( + hbs``, + ); + + // then + assert.dom(screen.queryByText(t('pages.skill-review.hero.explanations.send-results'))).doesNotExist(); + + assert.dom(screen.queryByRole('link', { name: t('navigation.back-to-homepage') })).doesNotExist(); + assert.dom(screen.queryByRole('button', { name: t('pages.skill-review.hero.see-trainings') })).doesNotExist(); + assert.dom(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') })).doesNotExist(); + }); + }); + }); + module('improve results', function () { module('when user can improve results', function () { test('it should display specific explanation and button', async function (assert) {