Skip to content

Commit

Permalink
refactor(mon-pix): add hasCustomResultPageButton getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeyffrey committed Oct 8, 2024
1 parent a9bbff5 commit 4067f14
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link';
import Component from '@glimmer/component';
import { t } from 'ember-intl';
import { and } from 'ember-truth-helpers';

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

export default class EvaluationResultsHeroCustomOrganizationBlock extends Component {
get hasCustomOrganizationLink() {
return this.args.customResultPageButtonUrl && this.args.customResultPageButtonText;
}

get showOrganizationContent() {
return this.args.customResultPageText || this.hasCustomOrganizationLink;
}

<template>
{{#if this.showOrganizationContent}}
<div class="evaluation-results-hero__organization-block">
<h3 class="evaluation-results-hero-organization-block__title">
{{t "pages.skill-review.organization-message"}}
</h3>
{{#if @customResultPageText}}
<MarkdownToHtml
class="evaluation-results-hero-organization-block__message"
@isInline={{true}}
@markdown={{@customResultPageText}}
/>
{{/if}}
{{#if this.hasCustomOrganizationLink}}
<PixButtonLink
class="evaluation-results-hero-organization-block__link"
@href={{@customResultPageButtonUrl}}
@variant="secondary"
>
{{@customResultPageButtonText}}
</PixButtonLink>
{{/if}}
</div>
<template>
<div class="evaluation-results-hero__organization-block">
<h3 class="evaluation-results-hero-organization-block__title">
{{t "pages.skill-review.organization-message"}}
</h3>
{{#if @customResultPageText}}
<MarkdownToHtml
class="evaluation-results-hero-organization-block__message"
@isInline={{true}}
@markdown={{@customResultPageText}}
/>
{{/if}}
{{#if (and @customResultPageButtonUrl @customResultPageButtonText)}}
<PixButtonLink
class="evaluation-results-hero-organization-block__link"
@href={{@customResultPageButtonUrl}}
@variant="secondary"
>
{{@customResultPageButtonText}}
</PixButtonLink>
{{/if}}
</template>
}
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 { or } from 'ember-truth-helpers';
import ENV from 'mon-pix/config/environment';

import MarkdownToHtml from '../../../../markdown-to-html';
Expand Down Expand Up @@ -129,11 +130,13 @@ export default class EvaluationResultsHero extends Component {
<AcquiredBadges @acquiredBadges={{@campaignParticipationResult.acquiredBadges}} />
{{/if}}
</div>
<CustomOrganizationBlock
@customResultPageText={{@campaign.customResultPageText}}
@customResultPageButtonText={{@campaign.customResultPageButtonText}}
@customResultPageButtonUrl={{@campaign.customResultPageButtonUrl}}
/>
{{#if (or @campaign.customResultPageText @campaign.hasCustomResultPageButton)}}
<CustomOrganizationBlock
@customResultPageText={{@campaign.customResultPageText}}
@customResultPageButtonText={{@campaign.customResultPageButtonText}}
@customResultPageButtonUrl={{@campaign.customResultPageButtonUrl}}
/>
{{/if}}
{{#if @campaignParticipationResult.canRetry}}
<RetryOrResetBlock @campaign={{@campaign}} @campaignParticipationResult={{@campaignParticipationResult}} />
{{/if}}
Expand Down
4 changes: 4 additions & 0 deletions mon-pix/app/models/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class Campaign extends Model {
return this.organizationType === 'SUP';
}

get hasCustomResultPageButton() {
return Boolean(this.customResultPageButtonUrl) && Boolean(this.customResultPageButtonText);
}

isRestrictedByIdentityProvider(identityProviderCode) {
return this.identityProvider === identityProviderCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,123 @@ module(
function (hooks) {
setupIntlRenderingTest(hooks);

module('when organization custom text is defined', function () {
test('it should display organization custom text', async function (assert) {
// given
this.set('customResultPageText', 'My custom result page text');

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

// then
assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists();
assert.dom(screen.getByText('My custom result page text')).exists();
});
test('displays the block title', async function (assert) {
// when
const screen = await render(
hbs`
<Campaigns::Assessment::SkillReview::EvaluationResultsHero::CustomOrganizationBlock />`,
);

// then
assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists();
});

module('when organization custom link url and label is defined', function () {
test('it should display organization custom link', async function (assert) {
// given
this.set('customResultPageButtonUrl', 'https://pix.org/');
this.set('customResultPageButtonText', 'My custom button');

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

// then
assert.dom(screen.getByText(t('pages.skill-review.organization-message'))).exists();
assert.strictEqual(screen.getByRole('link', { name: 'My custom button' }).href, 'https://pix.org/');
module('custom text', function () {
module('when organization custom text is defined', function () {
test('displays organization custom text', async function (assert) {
// given
const customResultPageText = 'My custom result page text';
this.set('customResultPageText', customResultPageText);

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

// then
assert.dom(screen.getByText(customResultPageText)).exists();
});
});

module('when organization custom text is not defined', function () {
test('not display organization custom text', async function (assert) {
// given
this.set('customResultPageText', null);

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

// then
assert.dom(screen.queryByRole('paragraph')).doesNotExist();
});
});
});

module('when no custom organization content is defined', function () {
test('should not display the block', async function (assert) {
// given
this.set('customResultPageText', null);
this.set('customResultPageButtonUrl', null);
this.set('customResultPageButtonText', null);

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

// then
assert.dom(screen.queryByText(t('pages.skill-review.organization-message'))).doesNotExist();
module('custom button', function () {
module('when organization custom link url and label are defined', function () {
test('displays organization custom link', async function (assert) {
// given
const customResultPageButtonUrl = 'https://pix.org/';
this.set('customResultPageButtonUrl', customResultPageButtonUrl);

const customResultPageButtonText = 'My custom button';
this.set('customResultPageButtonText', customResultPageButtonText);

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

// then
assert.strictEqual(
screen.getByRole('link', { name: customResultPageButtonText }).href,
customResultPageButtonUrl,
);
});
});

module('when organization custom link url is defined but label is not', function () {
test('not display organization custom link', async function (assert) {
// given
const customResultPageButtonUrl = 'https://pix.org/';
this.set('customResultPageButtonUrl', customResultPageButtonUrl);

this.set('customResultPageButtonText', null);

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

// then
assert.dom(screen.queryByRole('link')).doesNotExist();
});
});

module('when organization custom link label is defined but url is not', function () {
test('not display organization custom link', async function (assert) {
// given
this.set('customResultPageButtonUrl', null);
this.set('customResultPageButtonText', 'Some custom button text');

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

// then
assert.dom(screen.queryByRole('link')).doesNotExist();
});
});
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,28 +346,78 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
});
});

module('when there is some custom organization content', function () {
test('it should display the organization block', async function (assert) {
//given
this.set('campaign', {
customResultPageText: 'My custom result page text',
organizationId: 1,
module('custom organization block', 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 });

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

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

// 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.organization-message'))).doesNotExist();
assert.dom(screen.queryByText('My custom result page text')).doesNotExist();
});
});
});

Expand Down
Loading

0 comments on commit 4067f14

Please sign in to comment.