1
- import { render } from '@1024pix/ember-testing-library' ;
1
+ import { clickByName , render } from '@1024pix/ember-testing-library' ;
2
2
import Service from '@ember/service' ;
3
+ import { click } from '@ember/test-helpers' ;
3
4
import { hbs } from 'ember-cli-htmlbars' ;
4
5
import { t } from 'ember-intl/test-support' ;
5
6
import { module , test } from 'qunit' ;
7
+ import sinon from 'sinon' ;
6
8
7
9
import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering' ;
8
10
9
11
module ( 'Integration | Component | Team::MembersList' , function ( hooks ) {
12
+ let members ;
13
+
10
14
setupIntlRenderingTest ( hooks ) ;
11
15
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' ) ;
14
18
class CurrentUserMemberStub extends Service {
15
- isAdminInOrganization = false ;
16
- organization = {
19
+ isAdminInOrganization = true ;
20
+ organization = store . createRecord ( 'organization' , {
17
21
credit : 10000 ,
18
22
name : 'Super Orga' ,
23
+ } ) ;
24
+ prescriber = {
25
+ id : '111' ,
26
+ firstName : 'Gigi' ,
27
+ lastName : 'La Terreur' ,
19
28
} ;
20
29
}
21
30
this . owner . register ( 'service:current-user' , CurrentUserMemberStub ) ;
22
31
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' , {
25
47
id : '1' ,
48
+ displayRole : t ( 'pages.team-members.actions.select-role.options.admin' ) ,
26
49
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' , {
34
55
id : '2' ,
56
+ displayRole : t ( 'pages.team-members.actions.select-role.options.member' ) ,
35
57
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
+ } ) ,
42
62
] ;
63
+ } ) ;
64
+
65
+ test ( 'it lists the team members' , async function ( assert ) {
66
+ //given
43
67
members . meta = { rowCount : 2 } ;
44
68
this . set ( 'members' , members ) ;
45
69
@@ -51,7 +75,7 @@ module('Integration | Component | Team::MembersList', function (hooks) {
51
75
assert . ok ( screen . getByText ( 'Jojo' ) ) ;
52
76
} ) ;
53
77
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 ) {
55
79
//given
56
80
this . set ( 'members' , [ ] ) ;
57
81
@@ -61,4 +85,30 @@ module('Integration | Component | Team::MembersList', function (hooks) {
61
85
// then
62
86
assert . ok ( screen . getByText ( t ( 'pages.team-members.table.empty' ) ) ) ;
63
87
} ) ;
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
+ } ) ;
64
114
} ) ;
0 commit comments