Skip to content

Commit

Permalink
refactor(mon-pix): improve evaluation results hero conditionnal displays
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeyffrey committed Nov 15, 2024
1 parent bd43f7a commit 23492ca
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -124,76 +124,79 @@ export default class EvaluationResultsHero extends Component {
</div>
{{/if}}
</div>

<div class="evaluation-results-hero__details">
<h2 class="evaluation-results-hero-details__title">
{{t "pages.skill-review.hero.bravo" name=this.currentUser.user.firstName}}
</h2>

{{#if @campaignParticipationResult.hasReachedStage}}
<div class="evaluation-results-hero-details__stage-message" data-testid="stage-message">
<MarkdownToHtml @isInline={{true}} @markdown={{@campaignParticipationResult.reachedStage.message}} />
</div>
{{/if}}
{{#if @campaignParticipationResult.isShared}}
<PixMessage class="evaluation-results-hero-results__shared-message" @type="success" @withIcon={{true}}>
{{t "pages.skill-review.hero.shared-message"}}
</PixMessage>
{{#if @hasTrainings}}

{{#if this.isSharableCampaign}}
{{#if @campaignParticipationResult.isShared}}
<PixMessage class="evaluation-results-hero-results__shared-message" @type="success" @withIcon={{true}}>
{{t "pages.skill-review.hero.shared-message"}}
</PixMessage>
{{#if @hasTrainings}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.trainings"}}
</p>
{{/if}}
{{else}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.trainings"}}
{{t "pages.skill-review.hero.explanations.send-results"}}
</p>
{{/if}}
{{else}}
{{#unless this.isAutonomousCourse}}
{{#if @campaignParticipationResult.canImprove}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.send-results"}}
{{t "pages.skill-review.hero.explanations.improve"}}
</p>
{{/unless}}
{{/if}}
{{#if @campaignParticipationResult.canImprove}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.improve"}}
</p>
{{/if}}
{{/if}}

<div class="evaluation-results-hero-details__actions">
{{#if @campaignParticipationResult.isShared}}
{{#if @hasTrainings}}
<PixButton @triggerAction={{this.handleSeeTrainingsClick}} @size="large">
{{t "pages.skill-review.hero.see-trainings"}}
</PixButton>
{{else}}
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{/if}}
{{else}}
{{#if this.isAutonomousCourse}}
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{else}}
{{#if this.isSharableCampaign}}
{{#unless @campaignParticipationResult.isShared}}
<PixButton
@triggerAction={{this.handleShareResultsClick}}
@size="large"
@isLoading={{this.isShareResultsLoading}}
>
{{t "pages.skill-review.actions.send"}}
</PixButton>
{{else}}
{{#if @hasTrainings}}
<PixButton @triggerAction={{this.handleSeeTrainingsClick}} @size="large">
{{t "pages.skill-review.hero.see-trainings"}}
</PixButton>
{{else}}
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{/if}}
{{/unless}}
{{#if @campaignParticipationResult.canImprove}}
<PixButton
@variant="tertiary"
@size="large"
@triggerAction={{this.improveResults}}
@isLoading={{this.isImproveButtonLoading}}
>
{{t "pages.skill-review.actions.improve"}}
</PixButton>
{{/if}}
{{/if}}

{{#if @campaignParticipationResult.canImprove}}
<PixButton
@variant="tertiary"
@size="large"
@triggerAction={{this.improveResults}}
@isLoading={{this.isImproveButtonLoading}}
>
{{t "pages.skill-review.actions.improve"}}
</PixButton>
{{else}}
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{/if}}

{{#if this.hasGlobalError}}
Expand All @@ -204,16 +207,19 @@ export default class EvaluationResultsHero extends Component {
</div>
{{/if}}
</div>

{{#if @campaignParticipationResult.acquiredBadges.length}}
<AcquiredBadges @acquiredBadges={{@campaignParticipationResult.acquiredBadges}} />
{{/if}}
</div>

{{#if this.showCustomOrganizationBlock}}
<CustomOrganizationBlock
@campaign={{@campaign}}
@campaignParticipationResult={{@campaignParticipationResult}}
/>
{{/if}}

{{#if @campaignParticipationResult.canRetry}}
<RetryOrResetBlock @campaign={{@campaign}} @campaignParticipationResult={{@campaignParticipationResult}} />
{{/if}}
Expand Down
5 changes: 5 additions & 0 deletions mon-pix/app/models/campaign.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
);

// 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`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
);

// 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) {
Expand Down

0 comments on commit 23492ca

Please sign in to comment.