Skip to content

Commit

Permalink
fix(mon-pix): share results from evaluation results training tab now …
Browse files Browse the repository at this point in the history
…reloads model
  • Loading branch information
Jeyffrey authored Oct 31, 2024
1 parent 98437c0 commit e6dded0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
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 @@ -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 e6dded0

Please sign in to comment.