Skip to content

Commit

Permalink
[BUGFIX] Réparer l'envoi des résultats d'une campagne à accès simplif…
Browse files Browse the repository at this point in the history
…ié (PIX-15440).

 #10648
  • Loading branch information
pix-service-auto-merge authored Nov 27, 2024
2 parents cb63b2a + e278ad5 commit 420dccb
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ 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.isSharableCampaign || this.args.campaignParticipationResult.isShared);
return (
hasCustomContent && (this.args.campaign.isSimplifiedAccess || this.args.campaignParticipationResult.isShared)
);
}

get hasQuestResults() {
Expand Down Expand Up @@ -192,7 +190,7 @@ export default class EvaluationResultsHero extends Component {
</div>
{{/if}}

{{#if this.isSharableCampaign}}
{{#if @isSharableCampaign}}
{{#if @campaignParticipationResult.isShared}}
<PixMessage class="evaluation-results-hero-results__shared-message" @type="success" @withIcon={{true}}>
{{t "pages.skill-review.hero.shared-message"}}
Expand All @@ -215,7 +213,7 @@ export default class EvaluationResultsHero extends Component {
{{/if}}

<div class="evaluation-results-hero-details__actions">
{{#if this.isSharableCampaign}}
{{#if @isSharableCampaign}}
{{#if @campaignParticipationResult.isShared}}
{{#if @hasTrainings}}
<PixButton @triggerAction={{this.handleSeeTrainingsClick}} @size="large">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,48 @@ import { t } from 'ember-intl';
export default class QuitResults extends Component {
@tracked showModal = false;

get shouldShareCampaignResults() {
return this.args.isSharableCampaign && !this.args.isCampaignShared;
}

@action
toggleModal() {
this.showModal = !this.showModal;
}

<template>
{{#if @isCampaignShared}}
<LinkTo @route="authenticated" class="evaluation-results-header__back-link">
{{t "common.actions.quit"}}
</LinkTo>
{{else}}
{{#if this.shouldShareCampaignResults}}
<button class="evaluation-results-header__back-link" type="button" {{on "click" this.toggleModal}}>
{{t "common.actions.quit"}}
</button>
{{/if}}
<PixModal
@title={{t "pages.evaluation-results.quit-results.modal.title"}}
@onCloseButtonClick={{this.toggleModal}}
@showModal={{this.showModal}}
>
<:content>
<p class="quit-results__first-paragraph">{{t
"pages.evaluation-results.quit-results.modal.content-information"
}}</p>
<p><strong>{{t "pages.evaluation-results.quit-results.modal.content-instruction"}}</strong></p>
</:content>

<PixModal
@title={{t "pages.evaluation-results.quit-results.modal.title"}}
@onCloseButtonClick={{this.toggleModal}}
@showModal={{this.showModal}}
>
<:content>
<p class="quit-results__first-paragraph">{{t
"pages.evaluation-results.quit-results.modal.content-information"
}}</p>
<p><strong>{{t "pages.evaluation-results.quit-results.modal.content-instruction"}}</strong></p>
</:content>
<:footer>
<div class="quit-results__footer">
<PixButton @variant="secondary" @triggerAction={{this.toggleModal}}>
{{t "pages.evaluation-results.quit-results.modal.actions.cancel-to-share"}}
</PixButton>

<:footer>
<div class="quit-results__footer">
<PixButton @variant="secondary" @triggerAction={{this.toggleModal}}>
{{t "pages.evaluation-results.quit-results.modal.actions.cancel-to-share"}}
</PixButton>

<PixButtonLink @href="authenticated" @variant="primary">
{{t "pages.evaluation-results.quit-results.modal.actions.quit-without-sharing"}}
</PixButtonLink>
</div>
</:footer>
</PixModal>
<PixButtonLink @href="authenticated" @variant="primary">
{{t "pages.evaluation-results.quit-results.modal.actions.quit-without-sharing"}}
</PixButtonLink>
</div>
</:footer>
</PixModal>
{{else}}
<LinkTo @route="authenticated" class="evaluation-results-header__back-link">
{{t "common.actions.quit"}}
</LinkTo>
{{/if}}
</template>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { t } from 'ember-intl';
import ENV from 'mon-pix/config/environment';

import EvaluationResultsHero from '../../../campaigns/assessment/results/evaluation-results-hero';
import EvaluationResultsTabs from '../../../campaigns/assessment/results/evaluation-results-tabs';
Expand All @@ -14,6 +15,11 @@ export default class EvaluationResults extends Component {
return Boolean(this.args.model.trainings.length);
}

get isSharableCampaign() {
const isAutonomousCourse = this.args.model.campaign.organizationId === ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID;
return !isAutonomousCourse && !this.args.model.campaign.isForAbsoluteNovice;
}

@action
showTrainings() {
const tabElement = document.querySelector('[role="tablist"]');
Expand All @@ -35,14 +41,18 @@ export default class EvaluationResults extends Component {
<span>{{@model.campaign.title}}</span>
<span class="sr-only">{{t "pages.skill-review.abstract-title"}}</span>
</h1>
<QuitResults @isCampaignShared={{@model.campaignParticipationResult.isShared}} />
<QuitResults
@isCampaignShared={{@model.campaignParticipationResult.isShared}}
@isSharableCampaign={{this.isSharableCampaign}}
/>
</header>
<EvaluationResultsHero
@campaign={{@model.campaign}}
@campaignParticipationResult={{@model.campaignParticipationResult}}
@questResults={{@model.questResults}}
@hasTrainings={{this.hasTrainings}}
@showTrainings={{this.showTrainings}}
@isSharableCampaign={{this.isSharableCampaign}}
/>
<EvaluationResultsTabs
@campaign={{@model.campaign}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
});
Expand Down Expand Up @@ -75,6 +76,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);

Expand Down Expand Up @@ -112,6 +114,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
});
Expand Down Expand Up @@ -175,6 +178,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
@campaign={{this.campaign}}
@questResults={{this.questResults}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
await click(screen.getByRole('button', { name: t('pages.skill-review.actions.send') }));
Expand All @@ -200,6 +204,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
@campaign={{this.campaign}}
@questResults={{this.questResults}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
await click(screen.getByRole('button', { name: t('pages.skill-review.actions.send') }));
Expand All @@ -221,6 +226,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
await click(screen.getByRole('button', { name: t('pages.skill-review.actions.send') }));
Expand All @@ -244,6 +250,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);

Expand All @@ -267,6 +274,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);

Expand Down Expand Up @@ -296,6 +304,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
@showTrainings={{this.showTrainings}}
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
});
Expand All @@ -317,7 +326,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
});
});

module('when campaign is simplified access', function () {
module('when campaign results should not be shared', function () {
module('when there is no custom link', function () {
module('when user is anonymous', function () {
test('it should display only a connection link', async function (assert) {
Expand All @@ -327,17 +336,15 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
}
this.owner.register('service:current-user', currentUserService);

this.set('campaign', {
isSimplifiedAccess: true,
hasCustomResultPageButton: false,
});
this.set('campaign', { hasCustomResultPageButton: false });
this.set('campaignParticipationResult', { masteryRate: 0.75 });

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{false}}
/>`,
);

Expand All @@ -360,17 +367,15 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
}
this.owner.register('service:currentUser', currentUserService);

this.set('campaign', {
isSimplifiedAccess: true,
hasCustomResultPageButton: false,
});
this.set('campaign', { hasCustomResultPageButton: false });
this.set('campaignParticipationResult', { masteryRate: 0.75 });

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{false}}
/>`,
);

Expand All @@ -387,17 +392,15 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
module('when there is a custom link', function () {
test('it should not display a homepage link', async function (assert) {
// given
this.set('campaign', {
isSimplifiedAccess: true,
hasCustomResultPageButton: true,
});
this.set('campaign', { hasCustomResultPageButton: true });
this.set('campaignParticipationResult', { masteryRate: 0.75 });

// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{false}}
/>`,
);

Expand Down Expand Up @@ -440,6 +443,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);
});
Expand All @@ -454,6 +458,7 @@ module('Integration | Components | Campaigns | Assessment | Results | Evaluation
hbs`<Campaigns::Assessment::Results::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@isSharableCampaign={{true}}
/>`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,31 @@ import setupIntlRenderingTest from '../../../../../helpers/setup-intl-rendering'
module('Integration | Components | Campaigns | Assessment | Results | Quit Results', function (hooks) {
setupIntlRenderingTest(hooks);

module('when the campaign results are not sharable', function () {
test('it should display a quit button link', async function (assert) {
// when
const screen = await render(
hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{true}} @isSharableCampaign={{false}} />`,
);

// then
assert.ok(
screen
.getByRole('link', {
name: 'Quitter',
})
.getAttribute('href')
.includes('/'),
);
});
});

module('when the evaluation results have been shared', function () {
test('it should display a quit button link', async function (assert) {
// when
const screen = await render(hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{true}} />`);
const screen = await render(
hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{true}} @isSharableCampaign={{true}} />`,
);

// then
assert.ok(
Expand All @@ -29,7 +50,9 @@ module('Integration | Components | Campaigns | Assessment | Results | Quit Resul
module('when the evaluation results have not been shared yet', function () {
test('it should display a quit button', async function (assert) {
// when
const screen = await render(hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{false}} />`);
const screen = await render(
hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{false}} @isSharableCampaign={{true}} />`,
);

// then
assert.dom(screen.getByRole('button', { name: 'Quitter' })).exists();
Expand All @@ -38,7 +61,9 @@ module('Integration | Components | Campaigns | Assessment | Results | Quit Resul
module('when the quit button is clicked', function () {
test('it should display a modal', async function (assert) {
// given
const screen = await render(hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{false}} />`);
const screen = await render(
hbs`<Campaigns::Assessment::Results::QuitResults @isCampaignShared={{false}} @isSharableCampaign={{true}} />`,
);

// when
await click(screen.getByRole('button', { name: 'Quitter' }));
Expand Down
Loading

0 comments on commit 420dccb

Please sign in to comment.