Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Améliorer les affichages conditionnels de l'en-tête de fin de parcours (PIX-15274). #10543

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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
Expand Down Expand Up @@ -124,76 +123,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 +206,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 @@ -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 });
Expand All @@ -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 });
Expand Down Expand Up @@ -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`<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 @@ -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`<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