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 8f92ae3a83c..5c626cbf7da 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 { or } from 'ember-truth-helpers'; import ENV from 'mon-pix/config/environment'; import MarkdownToHtml from '../../../../markdown-to-html'; @@ -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(); @@ -157,15 +161,19 @@ export default class EvaluationResultsHero extends Component { {{t "pages.skill-review.hero.see-trainings"}} {{else}} - - {{t "navigation.back-to-homepage"}} - + {{#unless @campaign.hasCustomResultPageButton}} + + {{t "navigation.back-to-homepage"}} + + {{/unless}} {{/if}} {{else}} {{#if this.isAutonomousCourse}} - - {{t "navigation.back-to-homepage"}} - + {{#unless @campaign.hasCustomResultPageButton}} + + {{t "navigation.back-to-homepage"}} + + {{/unless}} {{else}} {{/if}} - {{#if (or @campaign.customResultPageText @campaign.hasCustomResultPageButton)}} + {{#if this.showCustomOrganizationBlock}} `, + ); + + // 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; @@ -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``, - ); + ); - // 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``, + ); + + // 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(); + }); }); }); @@ -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 @@ -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``, + ); + + // 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``, - ); + ); - // 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``, - ); + ); - // 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(); + }); }); }); });