Skip to content

Commit

Permalink
[REFACTOR] Améliorer les affichages conditionnels de l'en-tête de fin…
Browse files Browse the repository at this point in the history
… de parcours (PIX-15274).

 #10543
  • Loading branch information
pix-service-auto-merge authored Nov 18, 2024
2 parents d066f32 + 2f148b0 commit f636302
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand All @@ -47,20 +42,24 @@ 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
handleSeeTrainingsClick() {
this.args.showTrainings();
}

get hasQuestResults() {
return this.args.questResults && this.args.questResults.length > 0;
}

@action
async improveResults() {
if (this.isButtonLoading) return;
Expand Down Expand Up @@ -144,52 +143,49 @@ export default class EvaluationResultsHero extends Component {
<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}}
{{#if this.isSharableCampaign}}
{{#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}}
<PixButton
@triggerAction={{this.handleShareResultsClick}}
Expand All @@ -199,17 +195,22 @@ export default class EvaluationResultsHero extends Component {
{{t "pages.skill-review.actions.send"}}
</PixButton>
{{/if}}
{{/if}}

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

{{#if this.hasGlobalError}}
Expand All @@ -220,16 +221,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
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

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

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

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

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

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

0 comments on commit f636302

Please sign in to comment.