Skip to content

Commit

Permalink
fix(mon-pix): display reward tab only if there is at least an acquire…
Browse files Browse the repository at this point in the history
…d or an always visible badge
  • Loading branch information
Jeyffrey authored Nov 20, 2024
1 parent b409349 commit 1a8b88b
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 1a8b88b

Please sign in to comment.