From 1a8b88b4999f79968f574eca33ce39cb44770232 Mon Sep 17 00:00:00 2001 From: Geoffroy Begouaussel Date: Tue, 19 Nov 2024 16:46:53 +0100 Subject: [PATCH] fix(mon-pix): display reward tab only if there is at least an acquired or an always visible badge --- .../results/evaluation-results-tabs/index.gjs | 4 +- .../evaluation-results-tabs/index-test.js | 88 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 mon-pix/tests/unit/components/campaigns/assessment/results/evaluation-results-tabs/index-test.js diff --git a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/index.gjs b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/index.gjs index afd62cc69db..13673ddddb9 100644 --- a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/index.gjs +++ b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/index.gjs @@ -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() { diff --git a/mon-pix/tests/unit/components/campaigns/assessment/results/evaluation-results-tabs/index-test.js b/mon-pix/tests/unit/components/campaigns/assessment/results/evaluation-results-tabs/index-test.js new file mode 100644 index 00000000000..4f053675178 --- /dev/null +++ b/mon-pix/tests/unit/components/campaigns/assessment/results/evaluation-results-tabs/index-test.js @@ -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); + }); + }); + }); + }); + }, +);