Skip to content

Commit

Permalink
[BUGFIX].Rendre réactif le partage de résultat depuis l'onglet format…
Browse files Browse the repository at this point in the history
…ions (PIX-15069)

 #10449
  • Loading branch information
pix-service-auto-merge authored Oct 31, 2024
2 parents 1815b2b + e6dded0 commit dc22dcc
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class EvaluationResultsTabs extends Component {
@service tabManager;

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

get initialTabIndex() {
Expand Down Expand Up @@ -46,26 +46,33 @@ export default class EvaluationResultsTabs extends Component {
<:panels as |Panel|>
{{#if this.showRewardsTab}}
<Panel @index={{0}}>
<Rewards @badges={{@badges}} />
<Rewards @badges={{@campaignParticipationResult.campaignParticipationBadges}} />
</Panel>
{{/if}}
<Panel @index={{1}}>
<ResultsDetails @competenceResults={{@competenceResults}} @totalStage={{@totalStage}} />
<ResultsDetails
@competenceResults={{@campaignParticipationResult.competenceResults}}
@totalStage={{@campaignParticipationResult.reachedStage.totalStage}}
/>
</Panel>
{{#if this.showTrainingsTab}}
<Panel @index={{2}}>
<Trainings
@trainings={{@trainings}}
@isParticipationShared={{@isParticipationShared}}
@campaignParticipationResultId={{@campaignParticipationResultId}}
@isParticipationShared={{@campaignParticipationResult.isShared}}
@campaignParticipationResultId={{@campaignParticipationResult.id}}
@campaignId={{@campaign.id}}
/>
</Panel>
{{/if}}
</:panels>
</Tabs>
{{else}}
<section class="evaluation-results-tabs">
<ResultsDetails @competenceResults={{@competenceResults}} @totalStage={{@totalStage}} />
<ResultsDetails
@competenceResults={{@campaignParticipationResult.competenceResults}}
@totalStage={{@campaignParticipationResult.reachedStage.totalStage}}
/>
</section>
{{/if}}
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import { t } from 'ember-intl';
import TrainingCard from '../../../../training/card';

export default class EvaluationResultsTabsTrainings extends Component {
@service currentUser;
@service store;

@tracked isShareResultsLoading = false;
@tracked isShareResultsError = false;
@tracked isParticipationShared = false;

constructor() {
super(...arguments);

this.isParticipationShared = this.args.isParticipationShared;
}

@action
async shareResults() {
Expand All @@ -31,7 +25,14 @@ export default class EvaluationResultsTabsTrainings extends Component {

await adapter.share(this.args.campaignParticipationResultId);

this.isParticipationShared = true;
await this.store.queryRecord(
'campaign-participation-result',
{
campaignId: this.args.campaignId,
userId: this.currentUser.user.id,
},
{ reload: true },
);
} catch {
this.isShareResultsError = true;
} finally {
Expand All @@ -42,12 +43,12 @@ export default class EvaluationResultsTabsTrainings extends Component {
<template>
<div
class="evaluation-results-tab__trainings
{{unless this.isParticipationShared 'evaluation-results-tab__trainings--with-modal'}}"
{{unless @isParticipationShared 'evaluation-results-tab__trainings--with-modal'}}"
>
<div
class="evaluation-results-tab__trainings-content"
inert={{unless this.isParticipationShared "true"}}
role={{unless this.isParticipationShared "presentation"}}
inert={{unless @isParticipationShared "true"}}
role={{unless @isParticipationShared "presentation"}}
>
<h2 class="evaluation-results-tab__title">{{t "pages.skill-review.tabs.trainings.title"}}</h2>
<p class="evaluation-results-tab__description">{{t "pages.skill-review.tabs.trainings.description"}}</p>
Expand All @@ -61,7 +62,7 @@ export default class EvaluationResultsTabsTrainings extends Component {
</ul>
</div>

{{#unless this.isParticipationShared}}
{{#unless @isParticipationShared}}
<div class="evaluation-results-tab__share-results-modal" role="dialog">
<div class="evaluation-results-tab-share-results-modal__content">
<p>{{t "pages.skill-review.tabs.trainings.modal.content" htmlSafe=true}}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ export default class EvaluationResults extends Component {
@showTrainings={{this.showTrainings}}
/>
<EvaluationResultsTabs
@badges={{@model.campaignParticipationResult.campaignParticipationBadges}}
@campaignParticipationResultId={{@model.campaignParticipationResult.id}}
@competenceResults={{@model.campaignParticipationResult.competenceResults}}
@isParticipationShared={{@model.campaignParticipationResult.isShared}}
@totalStage={{@model.campaignParticipationResult.reachedStage.totalStage}}
@campaign={{@model.campaign}}
@campaignParticipationResult={{@model.campaignParticipationResult}}
@trainings={{@model.trainings}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
const store = this.owner.lookup('service:store');

const acquiredBadge = store.createRecord('badge', { isAcquired: true });
this.set('badges', [acquiredBadge]);
this.set('campaignParticipationResult', {
campaignParticipationBadges: [acquiredBadge],
});

const training = store.createRecord('training', { duration: { days: 2 } });
this.set('trainings', [training]);

// when
screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs @badges={{this.badges}} @trainings={{this.trainings}} />`,
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs
@campaignParticipationResult={{this.campaignParticipationResult}}
@trainings={{this.trainings}}
/>`,
);
});

Expand All @@ -47,16 +52,19 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
// given
const store = this.owner.lookup('service:store');
const acquiredBadge = store.createRecord('badge', { isAcquired: true });
this.set('badges', [acquiredBadge]);

this.set('campaignParticipationResult', {
campaignParticipationBadges: [acquiredBadge],
competenceResults: [],
});

this.set('trainings', []);
this.set('competenceResults', []);

// when
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs
@badges={{this.badges}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@trainings={{this.trainings}}
@competenceResults={{this.competenceResults}}
/>`,
);

Expand All @@ -76,18 +84,19 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
// given
const store = this.owner.lookup('service:store');

this.set('badges', []);
this.set('competenceResults', []);
this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
competenceResults: [],
});

const training = store.createRecord('training', { duration: { days: 2 } });
this.set('trainings', [training]);

// when
screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs
@badges={{this.badges}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@trainings={{this.trainings}}
@competenceResults={{this.competenceResults}}
/>`,
);
});
Expand All @@ -110,16 +119,18 @@ module('Integration | Components | Campaigns | Assessment | Skill Review | Evalu
module('when there are no rewards and no trainings', function () {
test('it should not display the tabs component', async function (assert) {
// given
this.set('badges', []);
this.set('trainings', []);
this.set('competenceResults', []);

this.set('campaignParticipationResult', {
campaignParticipationBadges: [],
competenceResults: [],
});

// when
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs
@badges={{this.badges}}
@campaignParticipationResult={{this.campaignParticipationResult}}
@trainings={{this.trainings}}
@competenceResults={{this.competenceResults}}
/>`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T
module('when participation is already shared', function () {
test('it should display the trainings list', async function (assert) {
// given

const store = this.owner.lookup('service:store');
const training1 = store.createRecord('training', {
title: 'Mon super training',
Expand All @@ -31,7 +32,7 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T
const screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs::Trainings
@trainings={{this.trainings}}
@isParticipationShared='true'
@isParticipationShared={{true}}
/>`,
);

Expand All @@ -53,13 +54,15 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T
hooks.beforeEach(async function () {
// given
this.set('isParticipationShared', false);
this.set('campaignId', 1);
this.set('campaignParticipationResultId', 1);

// when
screen = await render(
hbs`<Campaigns::Assessment::SkillReview::EvaluationResultsTabs::Trainings
@isParticipationShared={{this.isParticipationShared}}
@campaignParticipationResultId={{this.campaignParticipationResultId}}
@campaignId={{this.campaignId}}
/>`,
);
});
Expand All @@ -81,41 +84,37 @@ module('Integration | Components | Campaigns | Assessment | Evaluation Results T
});

module('when clicking on the share results button', function (hooks) {
let adapter;
let adapter, storeService;

hooks.beforeEach(function () {
const store = this.owner.lookup('service:store');
adapter = store.adapterFor('campaign-participation-result');
sinon.stub(this.owner.lookup('service:currentUser'), 'user').value({ id: 1 });

storeService = this.owner.lookup('service:store');
adapter = storeService.adapterFor('campaign-participation-result');
});

test('it should call the share method of the adapter', async function (assert) {
test('it should call the share method of the adapter and reload campaign-participation-result model', async function (assert) {
// given
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.ok(createShareStub.calledOnce);
sinon.assert.calledWithExactly(createShareStub, 1);
});

module('when share action succeeds', function () {
test('it hide the dialog and show the trainings list', async function (assert) {
// given
sinon.stub(adapter, 'share');

// when
await click(screen.queryByRole('button', { name: t('pages.skill-review.actions.send') }));

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

const trainingsListTitle = screen.getByRole('heading', {
name: t('pages.skill-review.tabs.trainings.title'),
});
assert.dom(trainingsListTitle.closest('[role="presentation"]')).doesNotExist();
});
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 () {
Expand Down

0 comments on commit dc22dcc

Please sign in to comment.