From 50a1f97921d7b4a749bf9c25bc7bd382de536290 Mon Sep 17 00:00:00 2001 From: Geoffroy Begouaussel Date: Thu, 26 Dec 2024 15:35:48 +0100 Subject: [PATCH] fix(mon-pix): always display not sharable campaign trainings --- .../results/evaluation-results-tabs/index.gjs | 1 + .../evaluation-results-tabs/trainings.gjs | 14 +- .../assessment/evaluation-results.gjs | 1 + .../assessment/results/tabs/trainings-test.js | 162 +++++++++++------- 4 files changed, 113 insertions(+), 65 deletions(-) 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 13673ddddb9..f1500cac3c3 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 @@ -62,6 +62,7 @@ export default class EvaluationResultsTabs extends Component { diff --git a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/trainings.gjs b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/trainings.gjs index faeecf98042..9cb6d1eb5cb 100644 --- a/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/trainings.gjs +++ b/mon-pix/app/components/campaigns/assessment/results/evaluation-results-tabs/trainings.gjs @@ -27,6 +27,10 @@ export default class EvaluationResultsTabsTrainings extends Component { }); } + get canShareResults() { + return this.args.isSharableCampaign && !this.args.isParticipationShared; + } + @action async shareResults() { const adapter = this.store.adapterFor('campaign-participation-result'); @@ -62,12 +66,12 @@ export default class EvaluationResultsTabsTrainings extends Component { } diff --git a/mon-pix/app/components/routes/campaigns/assessment/evaluation-results.gjs b/mon-pix/app/components/routes/campaigns/assessment/evaluation-results.gjs index c5ad1eb61a5..b4f082af139 100644 --- a/mon-pix/app/components/routes/campaigns/assessment/evaluation-results.gjs +++ b/mon-pix/app/components/routes/campaigns/assessment/evaluation-results.gjs @@ -57,6 +57,7 @@ export default class EvaluationResults extends Component { diff --git a/mon-pix/tests/integration/components/campaigns/assessment/results/tabs/trainings-test.js b/mon-pix/tests/integration/components/campaigns/assessment/results/tabs/trainings-test.js index d44d132ba8d..9bb0267d138 100644 --- a/mon-pix/tests/integration/components/campaigns/assessment/results/tabs/trainings-test.js +++ b/mon-pix/tests/integration/components/campaigns/assessment/results/tabs/trainings-test.js @@ -11,7 +11,7 @@ import setupIntlRenderingTest from '../../../../../../helpers/setup-intl-renderi module('Integration | Components | Campaigns | Assessment | Evaluation Results Tabs | Trainings', function (hooks) { setupIntlRenderingTest(hooks); - module('when participation is already shared', function () { + module("when participation can't be shared", function () { test('it should display the trainings list', async function (assert) { // given @@ -33,7 +33,7 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T const screen = await render( hbs``, ); @@ -49,86 +49,128 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T }); }); - module('when participation is not already shared', function (hooks) { - let screen; + module('when participation can be shared', function () { + module('when participation is already shared', function () { + test('it should display the trainings list', async function (assert) { + // given - hooks.beforeEach(async function () { - // given - this.set('isParticipationShared', false); - this.set('campaignId', 1); - this.set('campaignParticipationResultId', 1); + const store = this.owner.lookup('service:store'); + const training1 = store.createRecord('training', { + title: 'Mon super training', + link: 'https://exemple.net/', + duration: { days: 2 }, + }); + const training2 = store.createRecord('training', { + title: 'Mon autre super training', + link: 'https://exemple.net/', + duration: { days: 2 }, + }); - // when - screen = await render( - hbs``, - ); - }); + ); - test('it should display a dialog with share results button', async function (assert) { - // then - assert.dom(screen.getByRole('dialog')).isVisible(); - assert.dom(screen.getByText(/Envoyez vos résultats pour permettre/)).isVisible(); - assert.dom(screen.getByRole('button', { name: t('pages.skill-review.actions.send') })).isVisible(); - }); + // then + assert.dom(screen.getByRole('heading', { name: t('pages.skill-review.tabs.trainings.title') })).isVisible(); + assert.dom(screen.getByText(t('pages.skill-review.tabs.trainings.description'))).isVisible(); - test('it should have an inert trainings list', async function (assert) { - // then - const trainingsListTitle = screen.getByRole('heading', { - name: t('pages.skill-review.tabs.trainings.title'), + assert.strictEqual(screen.getAllByRole('link').length, 2); + assert.dom(screen.getByText('Mon super training')).isVisible(); + assert.dom(screen.getByText('Mon autre super training')).isVisible(); + + assert.dom(screen.queryByRole('dialog')).doesNotExist(); }); - assert.dom(trainingsListTitle).isVisible(); - assert.dom(trainingsListTitle.closest('[role="presentation"]')).hasAttribute('inert'); }); - module('when clicking on the share results button', function (hooks) { - let adapter, storeService; + module('when participation is not already shared', function (hooks) { + let screen; - hooks.beforeEach(function () { - stubCurrentUserService(this.owner, { id: 1 }); - - storeService = this.owner.lookup('service:store'); - adapter = storeService.adapterFor('campaign-participation-result'); - }); - - test('it should call the share method of the adapter and reload campaign-participation-result model', async function (assert) { + hooks.beforeEach(async function () { // given - const createShareStub = sinon.stub(adapter, 'share'); - sinon.stub(storeService, 'queryRecord'); + this.set('isParticipationShared', false); + this.set('campaignId', 1); + this.set('campaignParticipationResultId', 1); // when - await click(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') })); + screen = await render( + hbs``, + ); + }); + test('it should display a dialog with share results button', async function (assert) { // then - assert.ok(createShareStub.calledOnce); - sinon.assert.calledWithExactly(createShareStub, 1); - - assert.ok(storeService.queryRecord.calledOnce); - sinon.assert.calledWithExactly( - storeService.queryRecord, - 'campaign-participation-result', - { - campaignId: this.campaignId, - userId: 1, - }, - { reload: true }, - ); + assert.dom(screen.getByRole('dialog')).isVisible(); + assert.dom(screen.getByText(/Envoyez vos résultats pour permettre/)).isVisible(); + assert.dom(screen.getByRole('button', { name: t('pages.skill-review.actions.send') })).isVisible(); + }); + + test('it should have an inert trainings list', async function (assert) { + // then + const trainingsListTitle = screen.getByRole('heading', { + name: t('pages.skill-review.tabs.trainings.title'), + }); + assert.dom(trainingsListTitle).isVisible(); + assert.dom(trainingsListTitle.closest('[role="presentation"]')).hasAttribute('inert'); }); - module('when share action fails', function () { - test('it should display an error message', async function (assert) { + module('when clicking on the share results button', function (hooks) { + let adapter, storeService; + + hooks.beforeEach(function () { + stubCurrentUserService(this.owner, { id: 1 }); + + storeService = this.owner.lookup('service:store'); + adapter = storeService.adapterFor('campaign-participation-result'); + }); + + test('it should call the share method of the adapter and reload campaign-participation-result model', async function (assert) { // given - sinon.stub(adapter, 'share').rejects(); + const createShareStub = sinon.stub(adapter, 'share'); + sinon.stub(storeService, 'queryRecord'); // when await click(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') })); // then - assert.dom(screen.queryByRole('dialog')).exists(); - assert.dom(screen.getByText(t('pages.skill-review.tabs.trainings.modal.share-error'))).exists(); + assert.ok(createShareStub.calledOnce); + sinon.assert.calledWithExactly(createShareStub, 1); + + assert.ok(storeService.queryRecord.calledOnce); + sinon.assert.calledWithExactly( + storeService.queryRecord, + 'campaign-participation-result', + { + campaignId: this.campaignId, + userId: 1, + }, + { reload: true }, + ); + }); + + module('when share action fails', function () { + test('it should display an error message', async function (assert) { + // given + sinon.stub(adapter, 'share').rejects(); + + // when + await click(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') })); + + // then + assert.dom(screen.queryByRole('dialog')).exists(); + assert.dom(screen.getByText(t('pages.skill-review.tabs.trainings.modal.share-error'))).exists(); + }); }); }); });