Skip to content

Commit

Permalink
feat(mon-pix): add evaluation results hero autonomouse course specifi…
Browse files Browse the repository at this point in the history
…city
  • Loading branch information
Jeyffrey committed Oct 4, 2024
1 parent 6e36d8e commit e979ee1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link';
import PixMessage from '@1024pix/pix-ui/components/pix-message';
import PixStars from '@1024pix/pix-ui/components/pix-stars';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { t } from 'ember-intl';
import ENV from 'mon-pix/config/environment';

import MarkdownToHtml from '../../../../markdown-to-html';
import AcquiredBadges from './acquired-badges';
import CustomOrganizationBlock from './custom-organization-block';
import RetryOrResetBlock from './retry-or-reset-block';

import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link';
import PixMessage from '@1024pix/pix-ui/components/pix-message';
import PixStars from '@1024pix/pix-ui/components/pix-stars';

import MarkdownToHtml from '../../../../markdown-to-html';

export default class EvaluationResultsHero extends Component {
@service currentUser;

get isAutonomousCourse() {
return this.args.campaign.organizationId === ENV.APP.AUTONOMOUS_COURSES_ORGANIZATION_ID;
}

get masteryRatePercentage() {
return Math.round(this.args.campaignParticipationResult.masteryRate * 100);
}
Expand Down Expand Up @@ -81,9 +84,11 @@ export default class EvaluationResultsHero extends Component {
</p>
{{/if}}
{{else}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.send-results"}}
</p>
{{#unless this.isAutonomousCourse}}
<p class="evaluation-results-hero-details__explanations">
{{t "pages.skill-review.hero.explanations.send-results"}}
</p>
{{/unless}}
{{/if}}
{{#if @campaignParticipationResult.canImprove}}
<p class="evaluation-results-hero-details__explanations">
Expand All @@ -100,7 +105,13 @@ export default class EvaluationResultsHero extends Component {
</PixButtonLink>
{{/if}}
{{else}}
<PixButton @size="large">{{t "pages.skill-review.actions.send"}}</PixButton>
{{#if this.isAutonomousCourse}}
<PixButtonLink @route="authentication.login" @size="large">
{{t "navigation.back-to-homepage"}}
</PixButtonLink>
{{else}}
<PixButton @size="large">{{t "pages.skill-review.actions.send"}}</PixButton>
{{/if}}
{{/if}}

{{#if @campaignParticipationResult.canImprove}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render } from '@1024pix/ember-testing-library';
import Service from '@ember/service';
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 setupIntlRenderingTest from '../../../../../../helpers/setup-intl-rendering';
Expand All @@ -22,11 +23,15 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu

this.owner.register('service:currentUser', currentUserService);

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

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

Expand All @@ -53,6 +58,7 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
// given
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

this.set('campaignParticipationResult', {
Expand All @@ -66,9 +72,9 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
// when
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
);

// then
Expand All @@ -79,15 +85,17 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu

module('when results are shared', function () {
module('when there are no trainings', function () {
test('it should display a message and a dashboard link', async function (assert) {
test('it should display a message and a homepage link', 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::SkillReview::EvaluationResultsHero
@campaignParticipationResult={{this.campaignParticipationResult}} />`,
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsHero
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
);

// then
Expand All @@ -100,14 +108,16 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
test('it should display specific explanation and button', async function (assert) {
// given
this.set('hasTrainings', true);
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', { masteryRate: 0.75, isShared: true });

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

// then
Expand All @@ -118,17 +128,42 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
});
});

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 });

// when
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::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();
});
});

module('improve results', function () {
module('when user can improve results', function () {
test('it should display specific explanation and button', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', { masteryRate: 0.75, canImprove: true });

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

// then
Expand All @@ -140,13 +175,15 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when user can not improve results', function () {
test('it should not display specific explanation and button', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', { masteryRate: 0.75, canImprove: false });

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

// then
Expand All @@ -160,6 +197,7 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when there are stages', function () {
test('it should display reached stage stars and message', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', {
hasReachedStage: true,
reachedStage: { reachedStage: 4, totalStage: 5, message: 'lorem ipsum dolor sit amet' },
Expand All @@ -168,8 +206,9 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
// when
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsHero
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
@campaign={{this.campaign}}
@campaignParticipationResult={{this.campaignParticipationResult}}
/>`,
);

// then
Expand All @@ -186,15 +225,17 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when there are not more than 1 stage', function () {
test('it should not display stars and message', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', {
reachedStage: { reachedStage: 1, totalStage: 1, message: 'lorem ipsum dolor sit amet' },
});

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

// then
Expand All @@ -212,15 +253,17 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when there is at least one badge', function () {
test('should display the badges block', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', {
campaignParticipationBadges: [{ isAcquired: true }],
});

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

// then
Expand All @@ -236,16 +279,17 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
//given
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
});

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

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

// then
Expand All @@ -257,11 +301,15 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when the user can retry or reset the campaign', function () {
test('it should display a specific block', async function (assert) {
// given
this.set('campaign', { organizationId: 1 });
this.set('campaignParticipationResult', { masteryRate: 0.1, canRetry: true });

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

// then
Expand Down

0 comments on commit e979ee1

Please sign in to comment.