Skip to content

Commit 964c67b

Browse files
[BUGFIX] Corriger la mise à jour trop tôt du rôle d'un membre sur Pix Orga (PIX-11534)
#10686
2 parents 9eff352 + 784f28f commit 964c67b

File tree

3 files changed

+76
-24
lines changed

3 files changed

+76
-24
lines changed

orga/app/components/team/members-list-item.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
@placeholder="{{t 'pages.team-members.actions.select-role.label'}}"
4949
@onChange={{this.setRoleSelection}}
5050
@options={{this.organizationRoles}}
51-
@value={{@membership.organizationRole}}
51+
@value={{this.roleSelection}}
5252
>
5353
<:label>{{t "pages.team-members.actions.select-role.label"}}</:label>
5454
</PixSelect>

orga/app/components/team/members-list-item.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class MembersListItem extends Component {
1616
@tracked isEditionMode = false;
1717
@tracked isRemoveMembershipModalDisplayed = false;
1818
@tracked isLeaveOrganizationModalDisplayed = false;
19+
@tracked roleSelection = null;
1920

2021
adminOption = {
2122
value: 'ADMIN',
@@ -37,6 +38,7 @@ export default class MembersListItem extends Component {
3738
constructor() {
3839
super(...arguments);
3940
this.organizationRoles = [this.adminOption, this.memberOption];
41+
this.roleSelection = this.args.membership.organizationRole;
4042
}
4143

4244
get displayRole() {
@@ -53,7 +55,7 @@ export default class MembersListItem extends Component {
5355

5456
@action
5557
setRoleSelection(value) {
56-
this.args.membership.organizationRole = value;
58+
this.roleSelection = value;
5759
}
5860

5961
@action
@@ -64,7 +66,7 @@ export default class MembersListItem extends Component {
6466
@action
6567
async updateRoleOfMember(membership) {
6668
this.isEditionMode = false;
67-
69+
membership.organizationRole = this.roleSelection;
6870
membership.organization = this.currentUser.organization;
6971

7072
try {
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,69 @@
1-
import { render } from '@1024pix/ember-testing-library';
1+
import { clickByName, render } from '@1024pix/ember-testing-library';
22
import Service from '@ember/service';
3+
import { click } from '@ember/test-helpers';
34
import { hbs } from 'ember-cli-htmlbars';
45
import { t } from 'ember-intl/test-support';
56
import { module, test } from 'qunit';
7+
import sinon from 'sinon';
68

79
import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering';
810

911
module('Integration | Component | Team::MembersList', function (hooks) {
12+
let members;
13+
1014
setupIntlRenderingTest(hooks);
1115

12-
test('it should list the team members', async function (assert) {
13-
//given
16+
hooks.beforeEach(function () {
17+
const store = this.owner.lookup('service:store');
1418
class CurrentUserMemberStub extends Service {
15-
isAdminInOrganization = false;
16-
organization = {
19+
isAdminInOrganization = true;
20+
organization = store.createRecord('organization', {
1721
credit: 10000,
1822
name: 'Super Orga',
23+
});
24+
prescriber = {
25+
id: '111',
26+
firstName: 'Gigi',
27+
lastName: 'La Terreur',
1928
};
2029
}
2130
this.owner.register('service:current-user', CurrentUserMemberStub);
2231

23-
const members = [
24-
{
32+
const [adminUser, memberUser] = [
33+
store.createRecord('user', {
34+
id: '111',
35+
firstName: 'Gigi',
36+
lastName: 'La Terreur',
37+
}),
38+
store.createRecord('user', {
39+
id: '121',
40+
firstName: 'Jojo',
41+
lastName: 'La Panique',
42+
}),
43+
];
44+
45+
members = [
46+
store.createRecord('membership', {
2547
id: '1',
48+
displayRole: t('pages.team-members.actions.select-role.options.admin'),
2649
organizationRole: 'ADMIN',
27-
user: {
28-
id: '111',
29-
firstName: 'Gigi',
30-
lastName: 'La Terreur',
31-
},
32-
},
33-
{
50+
user: adminUser,
51+
save: sinon.stub(),
52+
rollbackAttributes: sinon.stub(),
53+
}),
54+
store.createRecord('membership', {
3455
id: '2',
56+
displayRole: t('pages.team-members.actions.select-role.options.member'),
3557
organizationRole: 'MEMBER',
36-
user: {
37-
id: '121',
38-
firstName: 'Jojo',
39-
lastName: 'La Panique',
40-
},
41-
},
58+
save: sinon.stub(),
59+
rollbackAttributes: sinon.stub(),
60+
user: memberUser,
61+
}),
4262
];
63+
});
64+
65+
test('it lists the team members', async function (assert) {
66+
//given
4367
members.meta = { rowCount: 2 };
4468
this.set('members', members);
4569

@@ -51,7 +75,7 @@ module('Integration | Component | Team::MembersList', function (hooks) {
5175
assert.ok(screen.getByText('Jojo'));
5276
});
5377

54-
test('it should display a message when there are no members', async function (assert) {
78+
test('it displays a message when there are no members', async function (assert) {
5579
//given
5680
this.set('members', []);
5781

@@ -61,4 +85,30 @@ module('Integration | Component | Team::MembersList', function (hooks) {
6185
// then
6286
assert.ok(screen.getByText(t('pages.team-members.table.empty')));
6387
});
88+
89+
module('when updating a team member role to "ADMIN"', function () {
90+
test('it does not display dropdown icon on the admin member before confirming update', async function (assert) {
91+
// given
92+
members.meta = { rowCount: 2 };
93+
this.set('members', members);
94+
95+
// when
96+
const screen = await render(hbs`<Team::MembersList @members={{this.members}} />`);
97+
98+
await clickByName(t('pages.team-members.actions.manage'));
99+
await clickByName(t('pages.team-members.actions.edit-organization-membership-role'));
100+
await clickByName(t('pages.team-members.actions.select-role.label'));
101+
await click(
102+
await screen.findByRole('option', {
103+
name: t('pages.team-members.actions.select-role.options.admin'),
104+
}),
105+
);
106+
107+
// then
108+
assert.notOk(screen.queryByText(t('pages.team-members.actions.manage')));
109+
110+
await clickByName(t('pages.team-members.actions.save'));
111+
assert.strictEqual(screen.queryAllByRole('button', { name: t('pages.team-members.actions.manage') }).length, 2);
112+
});
113+
});
64114
});

0 commit comments

Comments
 (0)