Skip to content

Commit

Permalink
[BUGFIX] Réparer l'affichage du contenu spécifique de l'écran de fin …
Browse files Browse the repository at this point in the history
…de parcours (PIX-15109). (#10472)
  • Loading branch information
Jeyffrey authored Nov 6, 2024
1 parent 2b6b3f4 commit 4ba3c2e
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 61 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 { or } from 'ember-truth-helpers';
import ENV from 'mon-pix/config/environment';

import MarkdownToHtml from '../../../../markdown-to-html';
Expand Down Expand Up @@ -47,6 +46,11 @@ export default class EvaluationResultsHero extends Component {
};
}

get showCustomOrganizationBlock() {
const hasCustomContent = this.args.campaign.customResultPageText || this.args.campaign.hasCustomResultPageButton;
return hasCustomContent && this.args.campaignParticipationResult.isShared;
}

@action
handleSeeTrainingsClick() {
this.args.showTrainings();
Expand Down Expand Up @@ -157,15 +161,19 @@ export default class EvaluationResultsHero extends Component {
{{t "pages.skill-review.hero.see-trainings"}}
</PixButton>
{{else}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{/if}}
{{else}}
{{#if this.isAutonomousCourse}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{#unless @campaign.hasCustomResultPageButton}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{/unless}}
{{else}}
<PixButton
@triggerAction={{this.handleShareResultsClick}}
Expand Down Expand Up @@ -200,7 +208,7 @@ export default class EvaluationResultsHero extends Component {
<AcquiredBadges @acquiredBadges={{@campaignParticipationResult.acquiredBadges}} />
{{/if}}
</div>
{{#if (or @campaign.customResultPageText @campaign.hasCustomResultPageButton)}}
{{#if this.showCustomOrganizationBlock}}
<CustomOrganizationBlock
@customResultPageText={{@campaign.customResultPageText}}
@customResultPageButtonText={{@campaign.customResultPageButtonText}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
});

module('when results are shared', function () {
module('when there are no trainings', function () {
module('when there are no trainings and no custom link', function () {
test('it should display a message and a homepage link', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
Expand All @@ -172,6 +172,29 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
});
});

module('when there are no trainings and a custom link', function () {
test('it should display a message but no homepage link', async function (assert) {
// given
this.set('campaign', {
organizationId: 1,
hasCustomResultPageButton: true,
});
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.hero.shared-message'))).exists();
assert.dom(screen.queryByRole('link', { name: t('navigation.back-to-homepage') })).doesNotExist();
});
});

module('when there are trainings', function (hooks) {
let screen, showTrainings;

Expand Down Expand Up @@ -214,25 +237,56 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
});

module('when it is an autonomous course', function () {
test('it should display only a homepage link', async function (assert) {
// given
this.set('campaign', { organizationId: ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID });
this.set('campaignParticipationResult', { masteryRate: 0.75 });
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,
hasCustomResultPageButton: false,
});
this.set('campaignParticipationResult', { masteryRate: 0.75 });

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
// 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();
// 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', {
organizationId: ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID,
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.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();
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();
});
});
});

Expand Down Expand Up @@ -479,14 +533,10 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
});

module('custom organization block', function () {
module('when customResultPageText if defined', function () {
test('displays the organization block with the text', async function (assert) {
module('when results are not shared', function () {
test('it should not display the organization block', async function (assert) {
// given
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', { masteryRate: 0.75 });

// when
Expand All @@ -498,54 +548,80 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
);

// then
assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists();
assert.dom(screen.getByText('My custom result page text')).exists();
assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist();
assert.dom(screen.queryByText('My custom result page text')).doesNotExist();
});
});

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,
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();
});
this.set('campaign', campaign);
this.set('campaignParticipationResult', { masteryRate: 0.75 });
});

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
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();
// 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 });
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
// 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();
// then
assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist();
assert.dom(screen.queryByText('My custom result page text')).doesNotExist();
});
});
});
});
Expand Down

0 comments on commit 4ba3c2e

Please sign in to comment.