summaryrefslogtreecommitdiff
path: root/spec/features/boards/boards_spec.rb
blob: 33aca6cb527b4ff3a3a0ac4745945405bcb54704 (plain)
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
require 'rails_helper'

describe 'Issue Boards', js: true do
  include DragTo

  let(:group) { create(:group, :nested) }
  let(:project) { create(:project, :public, namespace: group) }
  let(:board)   { create(:board, project: project) }
  let(:user)    { create(:user) }
  let!(:user2)  { create(:user) }

  before do
    project.team << [user, :master]
    project.team << [user2, :master]

    page.driver.set_cookie('sidebar_collapsed', 'true')

    sign_in(user)
  end

  context 'no lists' do
    before do
      visit project_board_path(project, board)
      wait_for_requests
      expect(page).to have_selector('.board', count: 3)
    end

    it 'shows blank state' do
      expect(page).to have_content('Welcome to your Issue Board!')
    end

    it 'shows tooltip on add issues button' do
      button = page.find('.filter-dropdown-container button', text: 'Add issues')

      expect(button[:"data-original-title"]).to eq("Please add a list to your board first")
    end

    it 'hides the blank state when clicking nevermind button' do
      page.within(find('.board-blank-state')) do
        click_button("Nevermind, I'll use my own")
      end
      expect(page).to have_selector('.board', count: 2)
    end

    it 'creates default lists' do
      lists = ['Backlog', 'To Do', 'Doing', 'Closed']

      page.within(find('.board-blank-state')) do
        click_button('Add default lists')
      end
      wait_for_requests

      expect(page).to have_selector('.board', count: 4)

      page.all('.board').each_with_index do |list, i|
        expect(list.find('.board-title')).to have_content(lists[i])
      end
    end
  end

  context 'with lists' do
    let(:milestone) { create(:milestone, project: project) }

    let(:planning)    { create(:label, project: project, name: 'Planning', description: 'Test') }
    let(:development) { create(:label, project: project, name: 'Development') }
    let(:testing)     { create(:label, project: project, name: 'Testing') }
    let(:bug)         { create(:label, project: project, name: 'Bug') }
    let!(:backlog)    { create(:label, project: project, name: 'Backlog') }
    let!(:closed)       { create(:label, project: project, name: 'Closed') }
    let!(:accepting)  { create(:label, project: project, name: 'Accepting Merge Requests') }

    let!(:list1) { create(:list, board: board, label: planning, position: 0) }
    let!(:list2) { create(:list, board: board, label: development, position: 1) }

    let!(:confidential_issue) { create(:labeled_issue, :confidential, project: project, author: user, labels: [planning], relative_position: 9) }
    let!(:issue1) { create(:labeled_issue, project: project, title: 'aaa', description: '111', assignees: [user], labels: [planning], relative_position: 8) }
    let!(:issue2) { create(:labeled_issue, project: project, title: 'bbb', description: '222', author: user2, labels: [planning], relative_position: 7) }
    let!(:issue3) { create(:labeled_issue, project: project, title: 'ccc', description: '333', labels: [planning], relative_position: 6) }
    let!(:issue4) { create(:labeled_issue, project: project, title: 'ddd', description: '444', labels: [planning], relative_position: 5) }
    let!(:issue5) { create(:labeled_issue, project: project, title: 'eee', description: '555', labels: [planning], milestone: milestone, relative_position: 4) }
    let!(:issue6) { create(:labeled_issue, project: project, title: 'fff', description: '666', labels: [planning, development], relative_position: 3) }
    let!(:issue7) { create(:labeled_issue, project: project, title: 'ggg', description: '777', labels: [development], relative_position: 2) }
    let!(:issue8) { create(:closed_issue, project: project, title: 'hhh', description: '888') }
    let!(:issue9) { create(:labeled_issue, project: project, title: 'iii', description: '999', labels: [planning, testing, bug, accepting], relative_position: 1) }

    before do
      visit project_board_path(project, board)

      wait_for_requests

      expect(page).to have_selector('.board', count: 4)
      expect(find('.board:nth-child(2)')).to have_selector('.card')
      expect(find('.board:nth-child(3)')).to have_selector('.card')
      expect(find('.board:nth-child(4)')).to have_selector('.card')
    end

    it 'shows description tooltip on list title' do
      page.within('.board:nth-child(2)') do
        expect(find('.board-title span.has-tooltip')[:title]).to eq('Test')
      end
    end

    it 'shows issues in lists' do
      wait_for_board_cards(2, 8)
      wait_for_board_cards(3, 2)
    end

    it 'shows confidential issues with icon' do
      page.within(find('.board:nth-child(2)')) do
        expect(page).to have_selector('.confidential-icon', count: 1)
      end
    end

    it 'search closed list' do
      find('.filtered-search').set(issue8.title)
      find('.filtered-search').native.send_keys(:enter)

      wait_for_requests

      expect(find('.board:nth-child(2)')).to have_selector('.card', count: 0)
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 0)
      expect(find('.board:nth-child(4)')).to have_selector('.card', count: 1)
    end

    it 'search list' do
      find('.filtered-search').set(issue5.title)
      find('.filtered-search').native.send_keys(:enter)

      wait_for_requests

      expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1)
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 0)
      expect(find('.board:nth-child(4)')).to have_selector('.card', count: 0)
    end

    it 'allows user to delete board' do
      page.within(find('.board:nth-child(2)')) do
        find('.board-delete').click
      end

      wait_for_requests

      expect(page).to have_selector('.board', count: 3)
    end

    it 'removes checkmark in new list dropdown after deleting' do
      click_button 'Add list'
      wait_for_requests

      find('.dropdown-menu-close').click

      page.within(find('.board:nth-child(2)')) do
        find('.board-delete').click
      end

      wait_for_requests

      expect(page).to have_selector('.board', count: 3)
    end

    it 'infinite scrolls list' do
      50.times do
        create(:labeled_issue, project: project, labels: [planning])
      end

      visit project_board_path(project, board)
      wait_for_requests

      page.within(find('.board:nth-child(2)')) do
        expect(page.find('.board-header')).to have_content('58')
        expect(page).to have_selector('.card', count: 20)
        expect(page).to have_content('Showing 20 of 58 issues')

        evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
        wait_for_requests

        expect(page).to have_selector('.card', count: 40)
        expect(page).to have_content('Showing 40 of 58 issues')

        evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
        wait_for_requests

        expect(page).to have_selector('.card', count: 58)
        expect(page).to have_content('Showing all issues')
      end
    end

    context 'closed' do
      it 'shows list of closed issues' do
        wait_for_board_cards(4, 1)
        wait_for_requests
      end

      it 'moves issue to closed' do
        drag(list_from_index: 1, list_to_index: 3)

        wait_for_board_cards(2, 7)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 2)

        expect(find('.board:nth-child(2)')).not_to have_content(issue9.title)
        expect(find('.board:nth-child(4)')).to have_selector('.card', count: 2)
        expect(find('.board:nth-child(4)')).to have_content(issue9.title)
        expect(find('.board:nth-child(4)')).not_to have_content(planning.title)
      end

      it 'removes all of the same issue to closed' do
        drag(list_from_index: 1, list_to_index: 3)

        wait_for_board_cards(2, 7)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 2)

        expect(find('.board:nth-child(2)')).not_to have_content(issue9.title)
        expect(find('.board:nth-child(4)')).to have_content(issue9.title)
        expect(find('.board:nth-child(4)')).not_to have_content(planning.title)
      end
    end

    context 'lists' do
      it 'changes position of list' do
        drag(list_from_index: 2, list_to_index: 1, selector: '.board-header')

        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 8)
        wait_for_board_cards(4, 1)

        expect(find('.board:nth-child(2)')).to have_content(development.title)
        expect(find('.board:nth-child(2)')).to have_content(planning.title)
      end

      it 'issue moves between lists' do
        drag(list_from_index: 1, from_index: 1, list_to_index: 2)

        wait_for_board_cards(2, 7)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 1)

        expect(find('.board:nth-child(3)')).to have_content(issue6.title)
        expect(find('.board:nth-child(3)').all('.card').last).to have_content(development.title)
      end

      it 'issue moves between lists' do
        drag(list_from_index: 2, list_to_index: 1)

        wait_for_board_cards(2, 9)
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 1)

        expect(find('.board:nth-child(2)')).to have_content(issue7.title)
        expect(find('.board:nth-child(2)').all('.card').first).to have_content(planning.title)
      end

      it 'issue moves from closed' do
        drag(list_from_index: 2, list_to_index: 3)

        wait_for_board_cards(2, 8)
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 2)

        expect(find('.board:nth-child(4)')).to have_content(issue8.title)
      end

      context 'issue card' do
        it 'shows assignee' do
          page.within(find('.board:nth-child(2)')) do
            expect(page).to have_selector('.avatar', count: 1)
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
          click_button 'Add list'
          wait_for_requests

          page.within('.dropdown-menu-issues-board-new') do
            expect(page).to have_content(planning.title)
            expect(page).to have_content(development.title)
            expect(page).to have_content(testing.title)
          end
        end

        it 'creates new list for label' do
          click_button 'Add list'
          wait_for_requests

          page.within('.dropdown-menu-issues-board-new') do
            click_link testing.title
          end

          wait_for_requests

          expect(page).to have_selector('.board', count: 5)
        end

        it 'creates new list for Backlog label' do
          click_button 'Add list'
          wait_for_requests

          page.within('.dropdown-menu-issues-board-new') do
            click_link backlog.title
          end

          wait_for_requests

          expect(page).to have_selector('.board', count: 5)
        end

        it 'creates new list for Closed label' do
          click_button 'Add list'
          wait_for_requests

          page.within('.dropdown-menu-issues-board-new') do
            click_link closed.title
          end

          wait_for_requests

          expect(page).to have_selector('.board', count: 5)
        end

        it 'keeps dropdown open after adding new list' do
          click_button 'Add list'
          wait_for_requests

          page.within('.dropdown-menu-issues-board-new') do
            click_link closed.title
          end

          wait_for_requests

          expect(page).to have_css('#js-add-list.open')
        end

        it 'creates new list from a new label' do
          click_button 'Add list'

          wait_for_requests

          click_link 'Create new label'

          fill_in('new_label_name', with: 'Testing New Label')

          first('.suggest-colors a').click

          click_button 'Create'

          wait_for_requests
          wait_for_requests

          expect(page).to have_selector('.board', count: 5)
        end
      end
    end

    context 'filtering' do
      it 'filters by author' do
        set_filter("author", user2.username)
        click_filter_link(user2.username)
        submit_filter

        wait_for_requests
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
      end

      it 'filters by assignee' do
        set_filter("assignee", user.username)
        click_filter_link(user.username)
        submit_filter

        wait_for_requests

        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
      end

      it 'filters by milestone' do
        set_filter("milestone", "\"#{milestone.title}\"")
        click_filter_link(milestone.title)
        submit_filter

        wait_for_requests
        wait_for_board_cards(2, 1)
        wait_for_board_cards(3, 0)
        wait_for_board_cards(4, 0)
      end

      it 'filters by label' do
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter

        wait_for_requests
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
      end

      it 'filters by label with space after reload' do
        set_filter("label", "\"#{accepting.title}\"")
        click_filter_link(accepting.title)
        submit_filter

        # Test after reload
        page.evaluate_script 'window.location.reload()'
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))

        wait_for_requests

        page.within(find('.board:nth-child(2)')) do
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

        page.within(find('.board:nth-child(3)')) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

      it 'removes filtered labels' do
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter

        wait_for_board_cards(2, 1)

        find('.clear-search').click
        submit_filter

        wait_for_board_cards(2, 8)
      end

      it 'infinite scrolls list with label filter' do
        50.times do
          create(:labeled_issue, project: project, labels: [planning, testing])
        end

        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter

        wait_for_requests

        page.within(find('.board:nth-child(2)')) do
          expect(page.find('.board-header')).to have_content('51')
          expect(page).to have_selector('.card', count: 20)
          expect(page).to have_content('Showing 20 of 51 issues')

          evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")

          expect(page).to have_selector('.card', count: 40)
          expect(page).to have_content('Showing 40 of 51 issues')

          evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")

          expect(page).to have_selector('.card', count: 51)
          expect(page).to have_content('Showing all issues')
        end
      end

      it 'filters by multiple labels' do
        set_filter("label", testing.title)
        click_filter_link(testing.title)

        set_filter("label", bug.title)
        click_filter_link(bug.title)

        submit_filter

        wait_for_requests

        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
      end

      it 'filters by clicking label button on issue' do
        page.within(find('.board:nth-child(2)')) do
          expect(page).to have_selector('.card', count: 8)
          expect(find('.card', match: :first)).to have_content(bug.title)
          click_button(bug.title)
          wait_for_requests
        end

        page.within('.tokens-container') do
          expect(page).to have_content(bug.title)
        end

        wait_for_requests

        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
      end

      it 'removes label filter by clicking label button on issue' do
        page.within(find('.board:nth-child(2)')) do
          page.within(find('.card', match: :first)) do
            click_button(bug.title)
          end

          wait_for_requests

          expect(page).to have_selector('.card', count: 1)
        end

        wait_for_requests
      end
    end
  end

  context 'keyboard shortcuts' do
    before do
      visit project_board_path(project, board)
      wait_for_requests
    end

    it 'allows user to use keyboard shortcuts' do
      find('.boards-list').native.send_keys('i')
      expect(page).to have_content('New Issue')
    end
  end

  context 'signed out user' do
    before do
      sign_out(:user)
      visit project_board_path(project, board)
      wait_for_requests
    end

    it 'displays lists' do
      expect(page).to have_selector('.board')
    end

    it 'does not show create new list' do
      expect(page).not_to have_selector('.js-new-board-list')
    end

    it 'does not allow dragging' do
      expect(page).not_to have_selector('.user-can-drag')
    end
  end

  context 'as guest user' do
    let(:user_guest) { create(:user) }

    before do
      project.team << [user_guest, :guest]
      sign_out(:user)
      sign_in(user_guest)
      visit project_board_path(project, board)
      wait_for_requests
    end

    it 'does not show create new list' do
      expect(page).not_to have_selector('.js-new-board-list')
    end
  end

  def drag(selector: '.board-list', list_from_index: 0, from_index: 0, to_index: 0, list_to_index: 0)
    drag_to(selector: selector,
            scrollable: '#board-app',
            list_from_index: list_from_index,
            from_index: from_index,
            to_index: to_index,
            list_to_index: list_to_index)
  end

  def wait_for_board_cards(board_number, expected_cards)
    page.within(find(".board:nth-child(#{board_number})")) do
      expect(page.find('.board-header')).to have_content(expected_cards.to_s)
      expect(page).to have_selector('.card', count: expected_cards)
    end
  end

  def wait_for_empty_boards(board_numbers)
    board_numbers.each do |board|
      wait_for_board_cards(board, 0)
    end
  end

  def set_filter(type, text)
    find('.filtered-search').native.send_keys("#{type}:#{text}")
  end

  def submit_filter
    find('.filtered-search').native.send_keys(:enter)
  end

  def click_filter_link(link_text)
    page.within('.filtered-search-box') do
      expect(page).to have_button(link_text)

      click_button(link_text)
    end
  end
end