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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
# frozen_string_literal: true
RSpec.shared_examples 'work items title' do
let(:title_selector) { '[data-testid="work-item-title"]' }
it 'successfully shows and changes the title of the work item' do
expect(work_item.reload.title).to eq work_item.title
find(title_selector).set("Work item title")
find(title_selector).native.send_keys(:return)
wait_for_requests
expect(work_item.reload.title).to eq 'Work item title'
end
end
RSpec.shared_examples 'work items status' do
let(:state_selector) { '[data-testid="work-item-state-select"]' }
it 'successfully shows and changes the status of the work item' do
expect(find(state_selector)).to have_content 'Open'
find(state_selector).select("Closed")
wait_for_requests
expect(find(state_selector)).to have_content 'Closed'
expect(work_item.reload.state).to eq('closed')
end
end
RSpec.shared_examples 'work items comments' do |type|
let(:form_selector) { '[data-testid="work-item-add-comment"]' }
let(:edit_button) { '[data-testid="edit-work-item-note"]' }
let(:textarea_selector) { '[data-testid="work-item-add-comment"] #work-item-add-or-edit-comment' }
let(:is_mac) { page.evaluate_script('navigator.platform').include?('Mac') }
let(:modifier_key) { is_mac ? :command : :control }
let(:comment) { 'Test comment' }
def set_comment
find(form_selector).fill_in(with: comment)
end
it 'successfully creates and shows comments' do
set_comment
click_button "Comment"
wait_for_requests
page.within(".main-notes-list") do
expect(page).to have_content comment
end
end
it 'successfully updates existing comments' do
set_comment
click_button "Comment"
wait_for_all_requests
find(edit_button).click
send_keys(" updated")
click_button "Save comment"
wait_for_all_requests
page.within(".main-notes-list") do
expect(page).to have_content "Test comment updated"
end
end
context 'for work item note actions signed in user with developer role' do
let_it_be(:owner) { create(:user) }
before do
project.add_owner(owner)
end
it 'shows work item note actions' do
set_comment
send_keys([modifier_key, :enter])
wait_for_requests
page.within(".main-notes-list") do
expect(page).to have_content comment
end
page.within('.timeline-entry.note.note-wrapper.note-comment:last-child') do
expect(page).to have_selector('[data-testid="work-item-note-actions"]')
find('[data-testid="work-item-note-actions"]').click
expect(page).to have_selector('[data-testid="copy-link-action"]')
expect(page).to have_selector('[data-testid="assign-note-action"]')
expect(page).to have_selector('[data-testid="delete-note-action"]')
expect(page).to have_selector('[data-testid="edit-work-item-note"]')
end
end
end
it 'successfully posts comments using shortcut and checks if textarea is blank when reinitiated' do
set_comment
send_keys([modifier_key, :enter])
wait_for_requests
page.within(".main-notes-list") do
expect(page).to have_content comment
end
expect(find(textarea_selector)).to have_content ""
end
context 'when using quick actions' do
it 'autocompletes quick actions common to all work item types', :aggregate_failures do
click_reply_and_enter_slash
page.within('#at-view-commands') do
expect(page).to have_text("/title")
expect(page).to have_text("/shrug")
expect(page).to have_text("/tableflip")
expect(page).to have_text("/close")
expect(page).to have_text("/cc")
end
end
context 'when a widget is enabled' do
before do
WorkItems::Type.default_by_type(type).widget_definitions
.find_by_widget_type(:assignees).update!(disabled: false)
end
it 'autocompletes quick action for the enabled widget' do
click_reply_and_enter_slash
page.within('#at-view-commands') do
expect(page).to have_text("/assign")
end
end
end
context 'when a widget is disabled' do
before do
WorkItems::Type.default_by_type(type).widget_definitions
.find_by_widget_type(:assignees).update!(disabled: true)
end
it 'does not autocomplete quick action for the disabled widget' do
click_reply_and_enter_slash
page.within('#at-view-commands') do
expect(page).not_to have_text("/assign")
end
end
end
def click_reply_and_enter_slash
find(form_selector).fill_in(with: "/")
wait_for_all_requests
end
end
end
RSpec.shared_examples 'work items assignees' do
it 'successfully assigns the current user by searching',
quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/413074' do
# The button is only when the mouse is over the input
find('[data-testid="work-item-assignees-input"]').fill_in(with: user.username)
wait_for_requests
# submit and simulate blur to save
send_keys(:enter)
find("body").click
wait_for_requests
expect(work_item.reload.assignees).to include(user)
end
end
RSpec.shared_examples 'work items labels' do
let(:label_title_selector) { '[data-testid="labels-title"]' }
it 'successfully assigns a label' do
label = create(:label, project: work_item.project, title: "testing-label")
find('[data-testid="work-item-labels-input"]').fill_in(with: label.title)
wait_for_requests
# submit and simulate blur to save
send_keys(:enter)
find(label_title_selector).click
wait_for_requests
expect(work_item.labels).to include(label)
end
end
RSpec.shared_examples 'work items description' do
it 'shows GFM autocomplete', :aggregate_failures do
click_button "Edit description"
find('[aria-label="Description"]').send_keys("@#{user.username}")
wait_for_requests
page.within('.atwho-container') do
expect(page).to have_text(user.name)
end
end
it 'autocompletes available quick actions', :aggregate_failures do
click_button "Edit description"
find('[aria-label="Description"]').send_keys("/")
wait_for_requests
page.within('#at-view-commands') do
expect(page).to have_text("title")
expect(page).to have_text("shrug")
expect(page).to have_text("tableflip")
expect(page).to have_text("close")
expect(page).to have_text("cc")
end
end
context 'on conflict' do
let_it_be(:other_user) { create(:user) }
let(:expected_warning) { 'Someone edited the description at the same time you did.' }
before do
project.add_developer(other_user)
end
it 'shows conflict message when description changes', :aggregate_failures do
click_button "Edit description"
wait_for_requests
::WorkItems::UpdateService.new(
container: work_item.project,
current_user: other_user,
params: { description: "oh no!" }
).execute(work_item)
wait_for_requests
find('[aria-label="Description"]').send_keys("oh yeah!")
expect(page.find('[data-testid="work-item-description-conflicts"]')).to have_text(expected_warning)
click_button "Save and overwrite"
expect(page.find('[data-testid="work-item-description"]')).to have_text("oh yeah!")
end
end
end
RSpec.shared_examples 'work items invite members' do
include Features::InviteMembersModalHelpers
it 'successfully assigns the current user by searching' do
# The button is only when the mouse is over the input
find('[data-testid="work-item-assignees-input"]').fill_in(with: 'Invite members')
wait_for_requests
click_button('Invite members')
page.within invite_modal_selector do
expect(page).to have_content("You're inviting members to the #{work_item.project.name} project")
end
end
end
RSpec.shared_examples 'work items milestone' do
def set_milestone(milestone_dropdown, milestone_text)
milestone_dropdown.click
find('[data-testid="work-item-milestone-dropdown"] .gl-form-input', visible: true).send_keys "\"#{milestone_text}\""
wait_for_requests
click_button(milestone_text)
wait_for_requests
end
let(:milestone_dropdown_selector) { '[data-testid="work-item-milestone-dropdown"]' }
it 'searches and sets or removes milestone for the work item' do
set_milestone(find(milestone_dropdown_selector), milestone.title)
expect(page.find(milestone_dropdown_selector)).to have_text(milestone.title)
set_milestone(find(milestone_dropdown_selector), 'No milestone')
expect(page.find(milestone_dropdown_selector)).to have_text('Add to milestone')
end
end
RSpec.shared_examples 'work items comment actions for guest users' do
context 'for guest user' do
it 'hides other actions other than copy link' do
page.within(".main-notes-list") do
expect(page).to have_selector('[data-testid="work-item-note-actions"]')
find('[data-testid="work-item-note-actions"]', match: :first).click
expect(page).to have_selector('[data-testid="copy-link-action"]')
expect(page).not_to have_selector('[data-testid="assign-note-action"]')
end
end
end
end
RSpec.shared_examples 'work items notifications' do
let(:actions_dropdown_selector) { '[data-testid="work-item-actions-dropdown"]' }
let(:notifications_toggle_selector) { '[data-testid="notifications-toggle-action"] > button' }
it 'displays toast when notification is toggled' do
find(actions_dropdown_selector).click
page.within('[data-testid="notifications-toggle-form"]') do
expect(page).not_to have_css(".is-checked")
find(notifications_toggle_selector).click
wait_for_requests
expect(page).to have_css(".is-checked")
end
page.within('.gl-toast') do
expect(find('.toast-body')).to have_content(_('Notifications turned on.'))
end
end
end
RSpec.shared_examples 'work items todos' do
let(:todos_action_selector) { '[data-testid="work-item-todos-action"]' }
let(:todos_icon_selector) { '[data-testid="work-item-todos-icon"]' }
let(:header_section_selector) { '[data-testid="work-item-body"]' }
def toggle_todo_action
find(todos_action_selector).click
wait_for_requests
end
it 'adds item to the list' do
page.within(header_section_selector) do
expect(find(todos_action_selector)['aria-label']).to eq('Add a to do')
toggle_todo_action
expect(find(todos_action_selector)['aria-label']).to eq('Mark as done')
end
page.within ".header-content span[aria-label='#{_('Todos count')}']" do
expect(page).to have_content '1'
end
end
it 'marks a todo as done' do
page.within(header_section_selector) do
toggle_todo_action
toggle_todo_action
end
expect(find(todos_action_selector)['aria-label']).to eq('Add a to do')
expect(page).to have_selector(".header-content span[aria-label='#{_('Todos count')}']", visible: :hidden)
end
end
RSpec.shared_examples 'work items award emoji' do
let(:award_section_selector) { '.awards' }
let(:award_button_selector) { '[data-testid="award-button"]' }
let(:selected_award_button_selector) { '[data-testid="award-button"].selected' }
let(:emoji_picker_button_selector) { '[data-testid="emoji-picker"]' }
let(:basketball_emoji_selector) { 'gl-emoji[data-name="basketball"]' }
let(:tooltip_selector) { '.gl-tooltip' }
def select_emoji
page.within(award_section_selector) do
page.first(award_button_selector).click
end
wait_for_requests
end
before do
emoji_upvote
end
it 'adds award to the work item for current user' do
select_emoji
within(award_section_selector) do
expect(page).to have_selector(selected_award_button_selector)
# As the user2 has already awarded the `:thumbsup:` emoji, the emoji count will be 2
expect(first(award_button_selector)).to have_content '2'
end
expect(page.find(tooltip_selector)).to have_content("You and John reacted with :thumbsup:")
end
it 'removes award from work item for current user' do
select_emoji
page.within(award_section_selector) do
# As the user2 has already awarded the `:thumbsup:` emoji, the emoji count will be 2
expect(first(award_button_selector)).to have_content '2'
end
select_emoji
page.within(award_section_selector) do
# The emoji count will be back to 1
expect(first(award_button_selector)).to have_content '1'
end
end
it 'add custom award to the work item for current user' do
within(award_section_selector) do
find(emoji_picker_button_selector).click
find(basketball_emoji_selector).click
expect(page).to have_selector(basketball_emoji_selector)
end
end
end
|