BigW Consortium Gitlab

boards_spec.rb 18.1 KB
Newer Older
1 2 3
require 'rails_helper'

describe 'Issue Boards', feature: true, js: true do
4
  include DragTo
5

6 7
  let(:group) { create(:group, :nested) }
  let(:project) { create(:empty_project, :public, namespace: group) }
8
  let(:board)   { create(:board, project: project) }
9 10
  let(:user)    { create(:user) }
  let!(:user2)  { create(:user) }
11 12 13

  before do
    project.team << [user, :master]
Phil Hughes committed
14
    project.team << [user2, :master]
15

16
    sign_in(user)
17 18
  end

Phil Hughes committed
19 20
  context 'no lists' do
    before do
21
      visit project_board_path(project, board)
22
      wait_for_requests
Phil Hughes committed
23
      expect(page).to have_selector('.board', count: 3)
Phil Hughes committed
24
    end
25

Phil Hughes committed
26 27
    it 'shows blank state' do
      expect(page).to have_content('Welcome to your Issue Board!')
28 29
    end

Phil Hughes committed
30
    it 'shows tooltip on add issues button' do
31
      button = page.find('.filter-dropdown-container button', text: 'Add issues')
32

Phil Hughes committed
33
      expect(button[:"data-original-title"]).to eq("Please add a list to your board first")
34 35
    end

36
    it 'hides the blank state when clicking nevermind button' do
Phil Hughes committed
37
      page.within(find('.board-blank-state')) do
38
        click_button("Nevermind, I'll use my own")
Phil Hughes committed
39
      end
Phil Hughes committed
40
      expect(page).to have_selector('.board', count: 2)
41 42
    end

Phil Hughes committed
43
    it 'creates default lists' do
Phil Hughes committed
44
      lists = ['Backlog', 'To Do', 'Doing', 'Closed']
45

Phil Hughes committed
46
      page.within(find('.board-blank-state')) do
Phil Hughes committed
47 48
        click_button('Add default lists')
      end
49
      wait_for_requests
Phil Hughes committed
50

Phil Hughes committed
51
      expect(page).to have_selector('.board', count: 4)
Phil Hughes committed
52 53 54 55 56

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

Phil Hughes committed
59
  context 'with lists' do
60
    let(:milestone) { create(:milestone, project: project) }
Phil Hughes committed
61

62
    let(:planning)    { create(:label, project: project, name: 'Planning', description: 'Test') }
Phil Hughes committed
63 64
    let(:development) { create(:label, project: project, name: 'Development') }
    let(:testing)     { create(:label, project: project, name: 'Testing') }
Phil Hughes committed
65
    let(:bug)         { create(:label, project: project, name: 'Bug') }
66
    let!(:backlog)    { create(:label, project: project, name: 'Backlog') }
67
    let!(:closed)       { create(:label, project: project, name: 'Closed') }
68
    let!(:accepting)  { create(:label, project: project, name: 'Accepting Merge Requests') }
Phil Hughes committed
69

70 71
    let!(:list1) { create(:list, board: board, label: planning, position: 0) }
    let!(:list2) { create(:list, board: board, label: development, position: 1) }
Phil Hughes committed
72

Phil Hughes committed
73
    let!(:confidential_issue) { create(:labeled_issue, :confidential, project: project, author: user, labels: [planning], relative_position: 9) }
74
    let!(:issue1) { create(:labeled_issue, project: project, assignees: [user], labels: [planning], relative_position: 8) }
Phil Hughes committed
75 76 77 78 79 80
    let!(:issue2) { create(:labeled_issue, project: project, author: user2, labels: [planning], relative_position: 7) }
    let!(:issue3) { create(:labeled_issue, project: project, labels: [planning], relative_position: 6) }
    let!(:issue4) { create(:labeled_issue, project: project, labels: [planning], relative_position: 5) }
    let!(:issue5) { create(:labeled_issue, project: project, labels: [planning], milestone: milestone, relative_position: 4) }
    let!(:issue6) { create(:labeled_issue, project: project, labels: [planning, development], relative_position: 3) }
    let!(:issue7) { create(:labeled_issue, project: project, labels: [development], relative_position: 2) }
81
    let!(:issue8) { create(:closed_issue, project: project) }
Phil Hughes committed
82
    let!(:issue9) { create(:labeled_issue, project: project, labels: [planning, testing, bug, accepting], relative_position: 1) }
Phil Hughes committed
83 84

    before do
85
      visit project_board_path(project, board)
Phil Hughes committed
86

87
      wait_for_requests
Phil Hughes committed
88

Phil Hughes committed
89
      expect(page).to have_selector('.board', count: 4)
90 91
      expect(find('.board:nth-child(2)')).to have_selector('.card')
      expect(find('.board:nth-child(3)')).to have_selector('.card')
Phil Hughes committed
92
      expect(find('.board:nth-child(4)')).to have_selector('.card')
Phil Hughes committed
93 94
    end

95
    it 'shows description tooltip on list title' do
Phil Hughes committed
96
      page.within('.board:nth-child(2)') do
97 98 99 100
        expect(find('.board-title span.has-tooltip')[:title]).to eq('Test')
      end
    end

Phil Hughes committed
101
    it 'shows issues in lists' do
Phil Hughes committed
102 103
      wait_for_board_cards(2, 8)
      wait_for_board_cards(3, 2)
Phil Hughes committed
104
    end
105

106
    it 'shows confidential issues with icon' do
Phil Hughes committed
107
      page.within(find('.board:nth-child(2)')) do
108 109 110 111
        expect(page).to have_selector('.confidential-icon', count: 1)
      end
    end

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

116
      wait_for_requests
117 118

      expect(find('.board:nth-child(2)')).to have_selector('.card', count: 0)
Phil Hughes committed
119 120
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 0)
      expect(find('.board:nth-child(4)')).to have_selector('.card', count: 1)
121 122 123
    end

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

127
      wait_for_requests
128

Phil Hughes committed
129
      expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1)
130
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 0)
Phil Hughes committed
131
      expect(find('.board:nth-child(4)')).to have_selector('.card', count: 0)
132 133
    end

Phil Hughes committed
134
    it 'allows user to delete board' do
Phil Hughes committed
135
      page.within(find('.board:nth-child(2)')) do
Phil Hughes committed
136
        find('.board-delete').click
137
      end
Phil Hughes committed
138

139
      wait_for_requests
Phil Hughes committed
140

Phil Hughes committed
141
      expect(page).to have_selector('.board', count: 3)
142 143
    end

144
    it 'removes checkmark in new list dropdown after deleting' do
145
      click_button 'Add list'
146
      wait_for_requests
147

Phil Hughes committed
148
      page.within(find('.board:nth-child(2)')) do
149 150
        find('.board-delete').click
      end
151

152
      wait_for_requests
153

Phil Hughes committed
154
      expect(page).to have_selector('.board', count: 3)
155 156
    end

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

162
      visit project_board_path(project, board)
163
      wait_for_requests
164

Phil Hughes committed
165
      page.within(find('.board:nth-child(2)')) do
166
        expect(page.find('.board-header')).to have_content('58')
167
        expect(page).to have_selector('.card', count: 20)
168
        expect(page).to have_content('Showing 20 of 58 issues')
169

Phil Hughes committed
170
        evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
171
        wait_for_requests
172 173

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

Phil Hughes committed
176
        evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
177
        wait_for_requests
178

179
        expect(page).to have_selector('.card', count: 58)
180
        expect(page).to have_content('Showing all issues')
181 182 183
      end
    end

184 185
    context 'closed' do
      it 'shows list of closed issues' do
Phil Hughes committed
186
        wait_for_board_cards(4, 1)
187
        wait_for_requests
Phil Hughes committed
188 189
      end

190
      it 'moves issue to closed' do
Phil Hughes committed
191
        drag(list_from_index: 1, list_to_index: 3)
Phil Hughes committed
192

Phil Hughes committed
193
        wait_for_board_cards(2, 7)
194
        wait_for_board_cards(3, 2)
Phil Hughes committed
195
        wait_for_board_cards(4, 2)
196

Phil Hughes committed
197 198 199 200
        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)
Phil Hughes committed
201 202
      end

203
      it 'removes all of the same issue to closed' do
Phil Hughes committed
204
        drag(list_from_index: 1, list_to_index: 3)
Phil Hughes committed
205

Phil Hughes committed
206
        wait_for_board_cards(2, 7)
207
        wait_for_board_cards(3, 2)
Phil Hughes committed
208
        wait_for_board_cards(4, 2)
209

Phil Hughes committed
210 211 212
        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)
Phil Hughes committed
213 214 215 216
      end
    end

    context 'lists' do
Phil Hughes committed
217
      it 'changes position of list' do
Phil Hughes committed
218
        drag(list_from_index: 2, list_to_index: 1, selector: '.board-header')
Phil Hughes committed
219

Phil Hughes committed
220 221 222
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 8)
        wait_for_board_cards(4, 1)
223

Phil Hughes committed
224 225
        expect(find('.board:nth-child(2)')).to have_content(development.title)
        expect(find('.board:nth-child(2)')).to have_content(planning.title)
Phil Hughes committed
226 227
      end

Phil Hughes committed
228
      it 'issue moves between lists' do
Phil Hughes committed
229
        drag(list_from_index: 1, from_index: 1, list_to_index: 2)
Phil Hughes committed
230

Phil Hughes committed
231 232 233
        wait_for_board_cards(2, 7)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 1)
234

Phil Hughes committed
235 236
        expect(find('.board:nth-child(3)')).to have_content(issue6.title)
        expect(find('.board:nth-child(3)').all('.card').last).not_to have_content(development.title)
Phil Hughes committed
237 238
      end

Phil Hughes committed
239
      it 'issue moves between lists' do
Phil Hughes committed
240
        drag(list_from_index: 2, list_to_index: 1)
Phil Hughes committed
241

Phil Hughes committed
242
        wait_for_board_cards(2, 9)
243
        wait_for_board_cards(3, 1)
Phil Hughes committed
244
        wait_for_board_cards(4, 1)
245

Phil Hughes committed
246 247
        expect(find('.board:nth-child(2)')).to have_content(issue7.title)
        expect(find('.board:nth-child(2)').all('.card').first).not_to have_content(planning.title)
Phil Hughes committed
248 249
      end

250
      it 'issue moves from closed' do
251
        drag(list_from_index: 2, list_to_index: 3)
Phil Hughes committed
252

Phil Hughes committed
253
        wait_for_board_cards(2, 8)
254 255
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 2)
256

257
        expect(find('.board:nth-child(4)')).to have_content(issue8.title)
Phil Hughes committed
258 259 260 261
      end

      context 'issue card' do
        it 'shows assignee' do
Phil Hughes committed
262
          page.within(find('.board:nth-child(2)')) do
263
            expect(page).to have_selector('.avatar', count: 1)
Phil Hughes committed
264 265 266 267 268 269
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
270
          click_button 'Add list'
271
          wait_for_requests
Phil Hughes committed
272 273 274 275 276 277 278 279 280

          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
281
          click_button 'Add list'
282
          wait_for_requests
Phil Hughes committed
283 284 285 286 287

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

288
          wait_for_requests
289

Phil Hughes committed
290
          expect(page).to have_selector('.board', count: 5)
Phil Hughes committed
291 292
        end

293
        it 'creates new list for Backlog label' do
294
          click_button 'Add list'
295
          wait_for_requests
296 297 298 299 300

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

301
          wait_for_requests
302

Phil Hughes committed
303
          expect(page).to have_selector('.board', count: 5)
304 305
        end

306
        it 'creates new list for Closed label' do
307
          click_button 'Add list'
308
          wait_for_requests
309 310

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

314
          wait_for_requests
315

Phil Hughes committed
316
          expect(page).to have_selector('.board', count: 5)
317 318
        end

319
        it 'keeps dropdown open after adding new list' do
320
          click_button 'Add list'
321
          wait_for_requests
322 323

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

327
          wait_for_requests
328

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

332
        it 'creates new list from a new label' do
333
          click_button 'Add list'
334

335
          wait_for_requests
336 337 338 339 340 341 342 343 344

          click_link 'Create new label'

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

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

          click_button 'Create'

345 346
          wait_for_requests
          wait_for_requests
347

Phil Hughes committed
348
          expect(page).to have_selector('.board', count: 5)
349
        end
Phil Hughes committed
350 351 352 353
      end
    end

    context 'filtering' do
Phil Hughes committed
354
      it 'filters by author' do
Phil Hughes committed
355 356 357
        set_filter("author", user2.username)
        click_filter_link(user2.username)
        submit_filter
Phil Hughes committed
358

359
        wait_for_requests
Phil Hughes committed
360 361
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes committed
362 363 364
      end

      it 'filters by assignee' do
Phil Hughes committed
365 366 367
        set_filter("assignee", user.username)
        click_filter_link(user.username)
        submit_filter
Phil Hughes committed
368

369
        wait_for_requests
370

Phil Hughes committed
371 372
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes committed
373 374 375
      end

      it 'filters by milestone' do
Phil Hughes committed
376 377 378
        set_filter("milestone", "\"#{milestone.title}\"")
        click_filter_link(milestone.title)
        submit_filter
Phil Hughes committed
379

380
        wait_for_requests
Phil Hughes committed
381
        wait_for_board_cards(2, 1)
382
        wait_for_board_cards(3, 0)
Phil Hughes committed
383
        wait_for_board_cards(4, 0)
Phil Hughes committed
384 385 386
      end

      it 'filters by label' do
Phil Hughes committed
387 388 389
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
Phil Hughes committed
390

391
        wait_for_requests
Phil Hughes committed
392 393
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes committed
394 395
      end

396
      it 'filters by label with space after reload' do
Phil Hughes committed
397 398 399
        set_filter("label", "\"#{accepting.title}\"")
        click_filter_link(accepting.title)
        submit_filter
400 401 402

        # Test after reload
        page.evaluate_script 'window.location.reload()'
Phil Hughes committed
403 404
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
405

406
        wait_for_requests
407

Phil Hughes committed
408
        page.within(find('.board:nth-child(2)')) do
409 410 411 412
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

Phil Hughes committed
413
        page.within(find('.board:nth-child(3)')) do
414 415 416 417 418
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

419
      it 'removes filtered labels' do
Phil Hughes committed
420 421 422
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
423

Phil Hughes committed
424
        wait_for_board_cards(2, 1)
425

Phil Hughes committed
426 427
        find('.clear-search').click
        submit_filter
428

Phil Hughes committed
429
        wait_for_board_cards(2, 8)
430 431
      end

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

Phil Hughes committed
437 438 439
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
440

441
        wait_for_requests
442

Phil Hughes committed
443
        page.within(find('.board:nth-child(2)')) do
444
          expect(page.find('.board-header')).to have_content('51')
445
          expect(page).to have_selector('.card', count: 20)
446
          expect(page).to have_content('Showing 20 of 51 issues')
447

Phil Hughes committed
448
          evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
449 450

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

Phil Hughes committed
453
          evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
454 455 456

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

Phil Hughes committed
460
      it 'filters by multiple labels' do
Phil Hughes committed
461 462
        set_filter("label", testing.title)
        click_filter_link(testing.title)
Phil Hughes committed
463

Phil Hughes committed
464 465 466 467
        set_filter("label", bug.title)
        click_filter_link(bug.title)

        submit_filter
Phil Hughes committed
468

469
        wait_for_requests
470

Phil Hughes committed
471 472
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes committed
473
      end
474 475

      it 'filters by clicking label button on issue' do
Phil Hughes committed
476
        page.within(find('.board:nth-child(2)')) do
477
          expect(page).to have_selector('.card', count: 8)
478
          expect(find('.card', match: :first)).to have_content(bug.title)
Phil Hughes committed
479
          click_button(bug.title)
480
          wait_for_requests
481 482
        end

Phil Hughes committed
483 484 485 486
        page.within('.tokens-container') do
          expect(page).to have_content(bug.title)
        end

487
        wait_for_requests
488

Phil Hughes committed
489 490
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
491 492 493
      end

      it 'removes label filter by clicking label button on issue' do
Phil Hughes committed
494
        page.within(find('.board:nth-child(2)')) do
Phil Hughes committed
495
          page.within(find('.card', match: :first)) do
496 497
            click_button(bug.title)
          end
Phil Hughes committed
498

499
          wait_for_requests
500 501 502 503

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

504
        wait_for_requests
505
      end
506 507 508
    end
  end

509 510
  context 'keyboard shortcuts' do
    before do
511
      visit project_board_path(project, board)
512
      wait_for_requests
513 514 515 516 517 518 519 520
    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

521 522
  context 'signed out user' do
    before do
523
      sign_out(:user)
524
      visit project_board_path(project, board)
525
      wait_for_requests
526 527
    end

528 529 530 531
    it 'displays lists' do
      expect(page).to have_selector('.board')
    end

532 533 534
    it 'does not show create new list' do
      expect(page).not_to have_selector('.js-new-board-list')
    end
535 536 537 538

    it 'does not allow dragging' do
      expect(page).not_to have_selector('.user-can-drag')
    end
539 540 541 542 543 544 545
  end

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

    before do
      project.team << [user_guest, :guest]
546 547
      sign_out(:user)
      sign_in(user_guest)
548
      visit project_board_path(project, board)
549
      wait_for_requests
550 551 552 553 554 555 556
    end

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

557 558 559 560 561 562 563
  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)
564
  end
565 566 567 568 569 570 571 572 573 574 575 576 577

  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
Phil Hughes committed
578 579 580 581 582 583 584 585 586 587

  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)
588
    page.within('.filtered-search-box') do
Phil Hughes committed
589 590 591 592 593
      expect(page).to have_button(link_text)

      click_button(link_text)
    end
  end
594
end