1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# frozen_string_literal: true
RSpec.shared_examples 'inviting members' do |snowplow_invite_label|
before_all do
group.add_owner(user1)
end
it 'adds user as member', :js, :snowplow, :aggregate_failures do
visit members_page_path
invite_member(user2.name, role: 'Reporter')
page.within find_member_row(user2) do
expect(page).to have_button('Reporter')
end
expect_snowplow_event(
category: 'Members::InviteService',
action: 'create_member',
label: snowplow_invite_label,
property: 'existing_user',
user: user1
)
end
it 'displays the user\'s avatar in the member input token', :js do
visit members_page_path
input_invites(user2.name)
expect(page).to have_selector(member_token_avatar_selector)
end
it 'does not display an avatar in the member input token for an email address', :js do
visit members_page_path
input_invites('test@example.com')
expect(page).not_to have_selector(member_token_avatar_selector)
end
it 'invites user by email', :js, :snowplow, :aggregate_failures do
visit members_page_path
invite_member('test@example.com', role: 'Reporter')
click_link 'Invited'
page.within find_invited_member_row('test@example.com') do
expect(page).to have_button('Reporter')
end
expect_snowplow_event(
category: 'Members::InviteService',
action: 'create_member',
label: snowplow_invite_label,
property: 'net_new_user',
user: user1
)
end
it 'invites user by username and invites user by email', :js, :aggregate_failures do
visit members_page_path
invite_member([user2.name, 'test@example.com'], role: 'Reporter')
page.within find_member_row(user2) do
expect(page).to have_button('Reporter')
end
click_link 'Invited'
page.within find_invited_member_row('test@example.com') do
expect(page).to have_button('Reporter')
end
end
context 'when member is already a member by username' do
it 'updates the member for that user', :js do
visit members_page_path
invite_member(user2.name, role: 'Developer')
invite_member(user2.name, role: 'Reporter')
expect(page).not_to have_selector(invite_modal_selector)
page.refresh
page.within find_invited_member_row(user2.name) do
expect(page).to have_button('Reporter')
end
end
end
context 'when member is already a member by email' do
it 'updates the member for that email', :js do
email = 'test@example.com'
visit members_page_path
invite_member(email, role: 'Developer')
invite_member(email, role: 'Reporter')
expect(page).not_to have_selector(invite_modal_selector)
page.refresh
click_link 'Invited'
page.within find_invited_member_row(email) do
expect(page).to have_button('Reporter')
end
end
end
context 'when inviting a parent group member to the sub-entity' do
before_all do
group.add_owner(user1)
group.add_developer(user2)
end
context 'when role is higher than parent group membership' do
let(:role) { 'Maintainer' }
it 'adds the user as a member on sub-entity with higher access level', :js do
visit subentity_members_page_path
invite_member(user2.name, role: role)
expect(page).not_to have_selector(invite_modal_selector)
page.refresh
page.within find_invited_member_row(user2.name) do
expect(page).to have_button(role)
end
end
end
context 'when role is lower than parent group membership' do
let(:role) { 'Reporter' }
it 'fails with an error', :js do
visit subentity_members_page_path
invite_member(user2.name, role: role)
invite_modal = page.find(invite_modal_selector)
expect(invite_modal).to have_content "#{user2.name}: Access level should be greater than or equal to " \
"Developer inherited membership from group #{group.name}"
page.refresh
page.within find_invited_member_row(user2.name) do
expect(page).to have_content('Developer')
expect(page).not_to have_button('Developer')
end
end
context 'when there are multiple users invited with errors' do
let_it_be(:user3) { create(:user) }
before do
group.add_maintainer(user3)
end
it 'shows the partial user error and success and then removes them from the form', :js do
user4 = create(:user)
user5 = create(:user)
user6 = create(:user)
user7 = create(:user)
group.add_maintainer(user6)
group.add_maintainer(user7)
visit subentity_members_page_path
invite_member([user2.name, user3.name, user4.name, user6.name, user7.name], role: role)
# we have more than 2 errors, so one will be hidden
invite_modal = page.find(invite_modal_selector)
expect(invite_modal).to have_text("The following 4 members couldn't be invited")
expect(invite_modal).to have_selector(limited_invite_error_selector, count: 2, visible: :visible)
expect(invite_modal).to have_selector(expanded_invite_error_selector, count: 2, visible: :hidden)
# unpredictability of return order means we can't rely on message showing in any order here
# so we will not expect on the message
expect_to_have_invalid_invite_indicator(invite_modal, user2, message: false)
expect_to_have_invalid_invite_indicator(invite_modal, user3, message: false)
expect_to_have_invalid_invite_indicator(invite_modal, user6, message: false)
expect_to_have_invalid_invite_indicator(invite_modal, user7, message: false)
expect_to_have_successful_invite_indicator(invite_modal, user4)
expect(invite_modal).to have_button('Show more (2)')
# now we want to test the show more errors count logic
remove_token(user7.id)
# count decreases from 4 to 3 and 2 to 1
expect(invite_modal).to have_text("The following 3 members couldn't be invited")
expect(invite_modal).to have_button('Show more (1)')
# we want to show this error now for user6
invite_modal.find(more_invite_errors_button_selector).click
# now we should see the error for all users and our collapse button text
expect(invite_modal).to have_selector(limited_invite_error_selector, count: 2, visible: :visible)
expect(invite_modal).to have_selector(expanded_invite_error_selector, count: 1, visible: :visible)
expect_to_have_invalid_invite_indicator(invite_modal, user2, message: true)
expect_to_have_invalid_invite_indicator(invite_modal, user3, message: true)
expect_to_have_invalid_invite_indicator(invite_modal, user6, message: true)
expect(invite_modal).to have_button('Show less')
# adds new token, but doesn't submit
select_members(user5.name)
expect_to_have_normal_invite_indicator(invite_modal, user5)
remove_token(user2.id)
expect(invite_modal).to have_text("The following 2 members couldn't be invited")
expect(invite_modal).not_to have_selector(more_invite_errors_button_selector)
expect_to_have_invite_removed(invite_modal, user2)
expect_to_have_invalid_invite_indicator(invite_modal, user3)
expect_to_have_invalid_invite_indicator(invite_modal, user6)
expect_to_have_successful_invite_indicator(invite_modal, user4)
expect_to_have_normal_invite_indicator(invite_modal, user5)
remove_token(user6.id)
expect(invite_modal).to have_text("The following member couldn't be invited")
expect_to_have_invite_removed(invite_modal, user6)
expect_to_have_invalid_invite_indicator(invite_modal, user3)
expect_to_have_successful_invite_indicator(invite_modal, user4)
expect_to_have_normal_invite_indicator(invite_modal, user5)
remove_token(user3.id)
expect(invite_modal).not_to have_text("The following member couldn't be invited")
expect(invite_modal).not_to have_text("Review the invite errors and try again")
expect_to_have_invite_removed(invite_modal, user3)
expect_to_have_successful_invite_indicator(invite_modal, user4)
expect_to_have_normal_invite_indicator(invite_modal, user5)
submit_invites
expect(page).not_to have_selector(invite_modal_selector)
page.refresh
page.within find_invited_member_row(user2.name) do
expect(page).to have_content('Developer')
expect(page).not_to have_button('Developer')
end
page.within find_invited_member_row(user3.name) do
expect(page).to have_content('Maintainer')
expect(page).not_to have_button('Maintainer')
end
page.within find_invited_member_row(user4.name) do
expect(page).to have_button(role)
end
end
it 'only shows the error for an invalid formatted email and does not display other member errors', :js do
visit subentity_members_page_path
invite_member([user2.name, user3.name, 'bad@email'], role: role)
invite_modal = page.find(invite_modal_selector)
expect(invite_modal).to have_text('email contains an invalid email address')
expect(invite_modal).not_to have_text("The following 2 members couldn't be invited")
expect(invite_modal).not_to have_text("Review the invite errors and try again")
expect(invite_modal).not_to have_text("#{user2.name}: Access level should be greater than or equal to")
expect(invite_modal).not_to have_text("#{user3.name}: Access level should be greater than or equal to")
end
end
end
end
end
|