Skip to content

Commit

Permalink
[BUGFIX] Afficher l'onglet Récompenses de fin de parcours uniquement …
Browse files Browse the repository at this point in the history
…sous condition (PIX-15052).

 #10592
  • Loading branch information
pix-service-auto-merge authored Nov 20, 2024
2 parents b409349 + 1a8b88b commit 1a074b6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default class EvaluationResultsTabs extends Component {
@service tabManager;

get showRewardsTab() {
return this.args.campaignParticipationResult.campaignParticipationBadges.length > 0;
const badges = this.args.campaignParticipationResult.campaignParticipationBadges;

return badges.some((badge) => badge.isAcquired || badge.isAlwaysVisible);
}

get initialTabIndex() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

import createGlimmerComponent from '../../../../../../helpers/create-glimmer-component';

module(
'Unit | Component | Campaigns | Assessment | Results | EvaluationResultsTabs | ResultsDetails | CompetenceRow',
function (hooks) {
setupTest(hooks);

module('#showRewardsTab', function () {
module('when there is no badge', function () {
test('should return false', async function (assert) {
// given
const component = createGlimmerComponent('campaigns/assessment/results/evaluation-results-tabs/index');

component.args.campaignParticipationResult = {
campaignParticipationBadges: [],
};

// then
assert.false(component.showRewardsTab);
});
});

module('when there is badges', function () {
module('when there is only not-acquired and no always visible badge', function () {
test('should return false', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const notAlwaysVisibledBadge = store.createRecord('campaign-participation-badge', {
isAcquired: false,
isAlwaysVisible: false,
});

const component = createGlimmerComponent('campaigns/assessment/results/evaluation-results-tabs/index');

component.args.campaignParticipationResult = {
campaignParticipationBadges: [notAlwaysVisibledBadge],
};

// then
assert.false(component.showRewardsTab);
});
});

module('when there is at least a not-acquired but always visible badge', function () {
test('should return true', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const alwaysVisibledBadge = store.createRecord('campaign-participation-badge', {
isAcquired: false,
isAlwaysVisible: true,
});

const component = createGlimmerComponent('campaigns/assessment/results/evaluation-results-tabs/index');

component.args.campaignParticipationResult = {
campaignParticipationBadges: [alwaysVisibledBadge],
};

// then
assert.true(component.showRewardsTab);
});
});

module('when there is at least one acquired badge', function () {
test('should return true', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const acquiredBadge = store.createRecord('campaign-participation-badge', {
isAcquired: true,
});

const component = createGlimmerComponent('campaigns/assessment/results/evaluation-results-tabs/index');

component.args.campaignParticipationResult = {
campaignParticipationBadges: [acquiredBadge],
};

// then
assert.true(component.showRewardsTab);
});
});
});
});
},
);

0 comments on commit 1a074b6

Please sign in to comment.