boards_spec.rb 21.6 KB
Newer Older
P
Phil Hughes 已提交
1 2 3
require 'rails_helper'

describe 'Issue Boards', feature: true, js: true do
4
  include WaitForAjax
P
Phil Hughes 已提交
5
  include WaitForVueResource
6

7 8
  let(:project) { create(:empty_project, :public) }
  let(:board)   { create(:board, project: project) }
9 10
  let(:user)    { create(:user) }
  let!(:user2)  { create(:user) }
P
Phil Hughes 已提交
11 12 13

  before do
    project.team << [user, :master]
P
Phil Hughes 已提交
14
    project.team << [user2, :master]
15

P
Phil Hughes 已提交
16 17 18
    login_as(user)
  end

P
Phil Hughes 已提交
19 20
  context 'no lists' do
    before do
21
      visit namespace_project_board_path(project.namespace, project, board)
P
Phil Hughes 已提交
22 23
      wait_for_vue_resource
      expect(page).to have_selector('.board', count: 3)
P
Phil Hughes 已提交
24
    end
P
Phil Hughes 已提交
25

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

30
    it 'hides the blank state when clicking nevermind button' do
P
Phil Hughes 已提交
31
      page.within(find('.board-blank-state')) do
P
Phil Hughes 已提交
32
        click_button("Nevermind, I'll use my own")
P
Phil Hughes 已提交
33 34
      end
      expect(page).to have_selector('.board', count: 2)
P
Phil Hughes 已提交
35 36
    end

P
Phil Hughes 已提交
37
    it 'creates default lists' do
A
Annabel Dunstone Gray 已提交
38
      lists = ['Backlog', 'To Do', 'Doing', 'Done']
P
Phil Hughes 已提交
39

P
Phil Hughes 已提交
40
      page.within(find('.board-blank-state')) do
P
Phil Hughes 已提交
41 42
        click_button('Add default lists')
      end
P
Phil Hughes 已提交
43 44
      wait_for_vue_resource

A
Annabel Dunstone Gray 已提交
45
      expect(page).to have_selector('.board', count: 4)
P
Phil Hughes 已提交
46 47 48 49 50

      page.all('.board').each_with_index do |list, i|
        expect(list.find('.board-title')).to have_content(lists[i])
      end
    end
P
Phil Hughes 已提交
51 52
  end

P
Phil Hughes 已提交
53
  context 'with lists' do
54
    let(:milestone) { create(:milestone, project: project) }
P
Phil Hughes 已提交
55

56
    let(:planning)    { create(:label, project: project, name: 'Planning', description: 'Test') }
P
Phil Hughes 已提交
57 58
    let(:development) { create(:label, project: project, name: 'Development') }
    let(:testing)     { create(:label, project: project, name: 'Testing') }
P
Phil Hughes 已提交
59
    let(:bug)         { create(:label, project: project, name: 'Bug') }
60 61
    let!(:backlog)    { create(:label, project: project, name: 'Backlog') }
    let!(:done)       { create(:label, project: project, name: 'Done') }
62
    let!(:accepting)  { create(:label, project: project, name: 'Accepting Merge Requests') }
P
Phil Hughes 已提交
63

64 65
    let!(:list1) { create(:list, board: board, label: planning, position: 0) }
    let!(:list2) { create(:list, board: board, label: development, position: 1) }
P
Phil Hughes 已提交
66

67 68 69 70 71
    let!(:confidential_issue) { create(:issue, :confidential, project: project, author: user) }
    let!(:issue1) { create(:issue, project: project, assignee: user) }
    let!(:issue2) { create(:issue, project: project, author: user2) }
    let!(:issue3) { create(:issue, project: project) }
    let!(:issue4) { create(:issue, project: project) }
P
Phil Hughes 已提交
72
    let!(:issue5) { create(:labeled_issue, project: project, labels: [planning], milestone: milestone) }
73 74
    let!(:issue6) { create(:labeled_issue, project: project, labels: [planning, development]) }
    let!(:issue7) { create(:labeled_issue, project: project, labels: [development]) }
75
    let!(:issue8) { create(:closed_issue, project: project) }
76
    let!(:issue9) { create(:labeled_issue, project: project, labels: [testing, bug, accepting]) }
P
Phil Hughes 已提交
77 78

    before do
79
      visit namespace_project_board_path(project.namespace, project, board)
P
Phil Hughes 已提交
80

P
Phil Hughes 已提交
81
      wait_for_vue_resource
P
Phil Hughes 已提交
82 83

      expect(page).to have_selector('.board', count: 4)
84 85 86 87
      expect(find('.board:nth-child(1)')).to have_selector('.card')
      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')
P
Phil Hughes 已提交
88 89 90 91 92 93
    end

    it 'shows lists' do
      expect(page).to have_selector('.board', count: 4)
    end

94 95 96 97 98 99
    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

P
Phil Hughes 已提交
100
    it 'shows issues in lists' do
101 102
      wait_for_board_cards(2, 2)
      wait_for_board_cards(3, 2)
P
Phil Hughes 已提交
103
    end
P
Phil Hughes 已提交
104

P
Phil Hughes 已提交
105
    it 'shows confidential issues with icon' do
P
Phil Hughes 已提交
106
      page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
107 108 109 110
        expect(page).to have_selector('.confidential-icon', count: 1)
      end
    end

111
    it 'search backlog list' do
V
victorwu 已提交
112
      page.within('#js-boards-search') do
113 114 115 116 117 118 119 120 121 122 123 124
        find('.form-control').set(issue1.title)
      end

      wait_for_vue_resource

      expect(find('.board:nth-child(1)')).to have_selector('.card', count: 1)
      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: 0)
    end

    it 'search done list' do
V
victorwu 已提交
125
      page.within('#js-boards-search') do
126 127 128 129 130 131 132 133 134 135 136 137
        find('.form-control').set(issue8.title)
      end

      wait_for_vue_resource

      expect(find('.board:nth-child(1)')).to have_selector('.card', count: 0)
      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
V
victorwu 已提交
138
      page.within('#js-boards-search') do
139 140 141 142 143 144 145 146 147 148 149
        find('.form-control').set(issue5.title)
      end

      wait_for_vue_resource

      expect(find('.board:nth-child(1)')).to have_selector('.card', count: 0)
      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

P
Phil Hughes 已提交
150
    it 'allows user to delete board' do
P
Phil Hughes 已提交
151
      page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
152
        find('.board-delete').click
P
Phil Hughes 已提交
153
      end
P
Phil Hughes 已提交
154 155 156

      wait_for_vue_resource

P
Phil Hughes 已提交
157
      expect(page).to have_selector('.board', count: 3)
P
Phil Hughes 已提交
158 159
    end

160
    it 'removes checkmark in new list dropdown after deleting' do
161
      click_button 'Add list'
162 163
      wait_for_ajax

P
Phil Hughes 已提交
164
      page.within(find('.board:nth-child(2)')) do
165 166
        find('.board-delete').click
      end
167

P
Phil Hughes 已提交
168
      wait_for_vue_resource
169

170
      expect(page).to have_selector('.board', count: 3)
171 172 173
      expect(find(".js-board-list-#{planning.id}", visible: false)).not_to have_css('.is-active')
    end

174 175
    it 'infinite scrolls list' do
      50.times do
176
        create(:issue, project: project)
177 178
      end

179
      visit namespace_project_board_path(project.namespace, project, board)
P
Phil Hughes 已提交
180
      wait_for_vue_resource
181

P
Phil Hughes 已提交
182
      page.within(find('.board', match: :first)) do
183
        expect(page.find('.board-header')).to have_content('56')
184
        expect(page).to have_selector('.card', count: 20)
P
Phil Hughes 已提交
185
        expect(page).to have_content('Showing 20 of 56 issues')
186 187

        evaluate_script("document.querySelectorAll('.board .board-list')[0].scrollTop = document.querySelectorAll('.board .board-list')[0].scrollHeight")
P
Phil Hughes 已提交
188
        wait_for_vue_resource
189 190

        expect(page).to have_selector('.card', count: 40)
P
Phil Hughes 已提交
191 192 193
        expect(page).to have_content('Showing 40 of 56 issues')

        evaluate_script("document.querySelectorAll('.board .board-list')[0].scrollTop = document.querySelectorAll('.board .board-list')[0].scrollHeight")
P
Phil Hughes 已提交
194
        wait_for_vue_resource
P
Phil Hughes 已提交
195 196 197

        expect(page).to have_selector('.card', count: 56)
        expect(page).to have_content('Showing all issues')
198 199 200
      end
    end

P
Phil Hughes 已提交
201 202
    context 'backlog' do
      it 'shows issues in backlog with no labels' do
203
        wait_for_board_cards(1, 6)
P
Phil Hughes 已提交
204 205 206 207
      end

      it 'moves issue from backlog into list' do
        drag_to(list_to_index: 1)
P
Phil Hughes 已提交
208

209
        wait_for_vue_resource
210 211
        wait_for_board_cards(1, 5)
        wait_for_board_cards(2, 3)
P
Phil Hughes 已提交
212 213 214
      end
    end

P
Phil Hughes 已提交
215 216
    context 'done' do
      it 'shows list of done issues' do
217 218
        wait_for_board_cards(4, 1)
        wait_for_ajax
P
Phil Hughes 已提交
219 220 221 222 223
      end

      it 'moves issue to done' do
        drag_to(list_from_index: 0, list_to_index: 3)

224 225 226 227 228 229
        wait_for_board_cards(1, 5)
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 2)

        expect(find('.board:nth-child(1)')).not_to have_content(issue9.title)
P
Phil Hughes 已提交
230 231 232
        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)
P
Phil Hughes 已提交
233 234 235 236 237
      end

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

238 239 240 241 242 243
        wait_for_board_cards(1, 6)
        wait_for_board_cards(2, 1)
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 2)

        expect(find('.board:nth-child(2)')).not_to have_content(issue6.title)
P
Phil Hughes 已提交
244 245
        expect(find('.board:nth-child(4)')).to have_content(issue6.title)
        expect(find('.board:nth-child(4)')).not_to have_content(planning.title)
P
Phil Hughes 已提交
246 247 248 249
      end
    end

    context 'lists' do
P
Phil Hughes 已提交
250
      it 'changes position of list' do
P
Phil Hughes 已提交
251
        drag_to(list_from_index: 1, list_to_index: 2, selector: '.board-header')
P
Phil Hughes 已提交
252

253 254 255 256 257
        wait_for_board_cards(1, 6)
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 1)

P
Phil Hughes 已提交
258 259
        expect(find('.board:nth-child(2)')).to have_content(development.title)
        expect(find('.board:nth-child(2)')).to have_content(planning.title)
P
Phil Hughes 已提交
260 261
      end

P
Phil Hughes 已提交
262
      it 'issue moves between lists' do
263
        drag_to(list_from_index: 1, card_index: 1, list_to_index: 2)
P
Phil Hughes 已提交
264

265 266 267 268 269
        wait_for_board_cards(1, 6)
        wait_for_board_cards(2, 1)
        wait_for_board_cards(3, 3)
        wait_for_board_cards(4, 1)

P
Phil Hughes 已提交
270 271
        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)
P
Phil Hughes 已提交
272 273
      end

P
Phil Hughes 已提交
274
      it 'issue moves between lists' do
P
Phil Hughes 已提交
275 276
        drag_to(list_from_index: 2, list_to_index: 1)

277 278 279 280 281
        wait_for_board_cards(1, 6)
        wait_for_board_cards(2, 3)
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 1)

P
Phil Hughes 已提交
282 283
        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)
P
Phil Hughes 已提交
284 285
      end

P
Phil Hughes 已提交
286
      it 'issue moves from done' do
P
Phil Hughes 已提交
287 288
        drag_to(list_from_index: 3, list_to_index: 1)

P
Phil Hughes 已提交
289
        expect(find('.board:nth-child(2)')).to have_content(issue8.title)
290 291 292 293 294

        wait_for_board_cards(1, 6)
        wait_for_board_cards(2, 3)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 0)
P
Phil Hughes 已提交
295 296 297 298
      end

      context 'issue card' do
        it 'shows assignee' do
P
Phil Hughes 已提交
299
          page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
300
            expect(page).to have_selector('.avatar', count: 1)
P
Phil Hughes 已提交
301 302 303 304 305 306
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
307
          click_button 'Add list'
308
          wait_for_ajax
P
Phil Hughes 已提交
309 310 311 312 313 314 315 316 317

          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
318
          click_button 'Add list'
319
          wait_for_ajax
P
Phil Hughes 已提交
320 321 322 323 324

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

325 326
          wait_for_vue_resource

P
Phil Hughes 已提交
327 328 329
          expect(page).to have_selector('.board', count: 5)
        end

330
        it 'creates new list for Backlog label' do
331
          click_button 'Add list'
332
          wait_for_ajax
333 334 335 336 337

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

338 339
          wait_for_vue_resource

340 341 342 343
          expect(page).to have_selector('.board', count: 5)
        end

        it 'creates new list for Done label' do
344
          click_button 'Add list'
345
          wait_for_ajax
346 347 348 349 350

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

351 352
          wait_for_vue_resource

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

356
        it 'keeps dropdown open after adding new list' do
357
          click_button 'Add list'
358 359 360 361 362 363 364 365 366 367 368
          wait_for_ajax

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

          wait_for_vue_resource

          expect(find('.issue-boards-search')).to have_selector('.open')
        end

P
Phil Hughes 已提交
369
        it 'moves issues from backlog into new list' do
370
          wait_for_board_cards(1, 6)
P
Phil Hughes 已提交
371

372
          click_button 'Add list'
373
          wait_for_ajax
P
Phil Hughes 已提交
374 375 376 377 378

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

379 380
          wait_for_vue_resource

381
          wait_for_board_cards(1, 5)
P
Phil Hughes 已提交
382
        end
P
Phil Hughes 已提交
383 384

        it 'creates new list from a new label' do
385
          click_button 'Add list'
P
Phil Hughes 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401

          wait_for_ajax

          click_link 'Create new label'

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

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

          click_button 'Create'

          wait_for_ajax
          wait_for_vue_resource

          expect(page).to have_selector('.board', count: 5)
        end
P
Phil Hughes 已提交
402 403 404 405
      end
    end

    context 'filtering' do
P
Phil Hughes 已提交
406 407 408
      it 'filters by author' do
        page.within '.issues-filters' do
          click_button('Author')
409
          wait_for_ajax
P
Phil Hughes 已提交
410 411 412 413

          page.within '.dropdown-menu-author' do
            click_link(user2.name)
          end
P
Phil Hughes 已提交
414
          wait_for_vue_resource
P
Phil Hughes 已提交
415 416 417 418

          expect(find('.js-author-search')).to have_content(user2.name)
        end

P
Phil Hughes 已提交
419
        wait_for_vue_resource
420 421
        wait_for_board_cards(1, 1)
        wait_for_empty_boards((2..4))
P
Phil Hughes 已提交
422 423 424 425 426
      end

      it 'filters by assignee' do
        page.within '.issues-filters' do
          click_button('Assignee')
427
          wait_for_ajax
P
Phil Hughes 已提交
428 429 430 431

          page.within '.dropdown-menu-assignee' do
            click_link(user.name)
          end
P
Phil Hughes 已提交
432
          wait_for_vue_resource
P
Phil Hughes 已提交
433 434 435 436

          expect(find('.js-assignee-search')).to have_content(user.name)
        end

P
Phil Hughes 已提交
437 438
        wait_for_vue_resource

439 440
        wait_for_board_cards(1, 1)
        wait_for_empty_boards((2..4))
P
Phil Hughes 已提交
441 442 443 444
      end

      it 'filters by milestone' do
        page.within '.issues-filters' do
445
          click_button('Milestone')
446
          wait_for_ajax
P
Phil Hughes 已提交
447 448 449 450

          page.within '.milestone-filter' do
            click_link(milestone.title)
          end
P
Phil Hughes 已提交
451
          wait_for_vue_resource
P
Phil Hughes 已提交
452 453 454 455

          expect(find('.js-milestone-select')).to have_content(milestone.title)
        end

P
Phil Hughes 已提交
456
        wait_for_vue_resource
457 458 459 460
        wait_for_board_cards(1, 0)
        wait_for_board_cards(2, 1)
        wait_for_board_cards(3, 0)
        wait_for_board_cards(4, 0)
P
Phil Hughes 已提交
461 462 463 464 465
      end

      it 'filters by label' do
        page.within '.issues-filters' do
          click_button('Label')
466
          wait_for_ajax
P
Phil Hughes 已提交
467 468 469

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
470
            wait_for_vue_resource
P
Phil Hughes 已提交
471 472 473 474
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
475
        wait_for_vue_resource
476 477
        wait_for_board_cards(1, 1)
        wait_for_empty_boards((2..4))
P
Phil Hughes 已提交
478 479
      end

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
      it 'filters by label with space after reload' do
        page.within '.issues-filters' do
          click_button('Label')
          wait_for_ajax

          page.within '.dropdown-menu-labels' do
            click_link(accepting.title)
            wait_for_vue_resource(spinner: false)
            find('.dropdown-menu-close').click
          end
        end

        # Test after reload
        page.evaluate_script 'window.location.reload()'

        wait_for_vue_resource

        page.within(find('.board', match: :first)) 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(2)')) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

508
      it 'removes filtered labels' do
P
Phil Hughes 已提交
509
        wait_for_vue_resource
510

511 512 513 514 515 516
        page.within '.labels-filter' do
          click_button('Label')
          wait_for_ajax

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
517
            wait_for_vue_resource(spinner: false)
518 519 520 521 522 523
          end

          expect(page).to have_css('input[name="label_name[]"]', visible: false)

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
524
            wait_for_vue_resource(spinner: false)
525 526 527 528 529 530
          end

          expect(page).not_to have_css('input[name="label_name[]"]', visible: false)
        end
      end

531 532
      it 'infinite scrolls list with label filter' do
        50.times do
533
          create(:labeled_issue, project: project, labels: [testing])
534 535 536 537
        end

        page.within '.issues-filters' do
          click_button('Label')
538
          wait_for_ajax
539 540 541

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
542
            wait_for_vue_resource
543 544 545 546
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
547 548
        wait_for_vue_resource

P
Phil Hughes 已提交
549
        page.within(find('.board', match: :first)) do
550
          expect(page.find('.board-header')).to have_content('51')
551
          expect(page).to have_selector('.card', count: 20)
P
Phil Hughes 已提交
552
          expect(page).to have_content('Showing 20 of 51 issues')
553 554 555 556

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

          expect(page).to have_selector('.card', count: 40)
P
Phil Hughes 已提交
557 558 559 560 561 562
          expect(page).to have_content('Showing 40 of 51 issues')

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

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

P
Phil Hughes 已提交
566 567 568
      it 'filters by multiple labels' do
        page.within '.issues-filters' do
          click_button('Label')
569
          wait_for_ajax
P
Phil Hughes 已提交
570

571
          page.within(find('.dropdown-menu-labels')) do
P
Phil Hughes 已提交
572
            click_link(testing.title)
P
Phil Hughes 已提交
573
            wait_for_vue_resource
P
Phil Hughes 已提交
574
            click_link(bug.title)
P
Phil Hughes 已提交
575
            wait_for_vue_resource
P
Phil Hughes 已提交
576 577 578 579
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
580 581
        wait_for_vue_resource

582 583
        wait_for_board_cards(1, 1)
        wait_for_empty_boards((2..4))
P
Phil Hughes 已提交
584 585 586 587 588
      end

      it 'filters by no label' do
        page.within '.issues-filters' do
          click_button('Label')
589
          wait_for_ajax
P
Phil Hughes 已提交
590

P
Phil Hughes 已提交
591 592
          page.within '.dropdown-menu-labels' do
            click_link("No Label")
P
Phil Hughes 已提交
593
            wait_for_vue_resource
P
Phil Hughes 已提交
594 595 596 597
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
598 599
        wait_for_vue_resource

600 601 602 603
        wait_for_board_cards(1, 5)
        wait_for_board_cards(2, 0)
        wait_for_board_cards(3, 0)
        wait_for_board_cards(4, 1)
P
Phil Hughes 已提交
604
      end
605 606

      it 'filters by clicking label button on issue' do
P
Phil Hughes 已提交
607 608
        page.within(find('.board', match: :first)) do
          expect(page).to have_selector('.card', count: 6)
609
          expect(find('.card', match: :first)).to have_content(bug.title)
P
Phil Hughes 已提交
610
          click_button(bug.title)
P
Phil Hughes 已提交
611
          wait_for_vue_resource
612 613
        end

614 615
        wait_for_vue_resource

616 617
        wait_for_board_cards(1, 1)
        wait_for_empty_boards((2..4))
618 619

        page.within('.labels-filter') do
P
Phil Hughes 已提交
620
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
621 622 623 624
        end
      end

      it 'removes label filter by clicking label button on issue' do
P
Phil Hughes 已提交
625 626
        page.within(find('.board', match: :first)) do
          page.within(find('.card', match: :first)) do
627 628
            click_button(bug.title)
          end
P
Phil Hughes 已提交
629
          wait_for_vue_resource
630 631 632 633

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

P
Phil Hughes 已提交
634 635
        wait_for_vue_resource

636 637 638 639
        page.within('.labels-filter') do
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
        end
      end
P
Phil Hughes 已提交
640 641 642
    end
  end

643 644
  context 'keyboard shortcuts' do
    before do
645
      visit namespace_project_board_path(project.namespace, project, board)
646 647 648 649 650 651 652 653 654
      wait_for_vue_resource
    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

655 656 657
  context 'signed out user' do
    before do
      logout
658
      visit namespace_project_board_path(project.namespace, project, board)
659
      wait_for_vue_resource
660 661
    end

662 663 664 665
    it 'displays lists' do
      expect(page).to have_selector('.board')
    end

666 667 668
    it 'does not show create new list' do
      expect(page).not_to have_selector('.js-new-board-list')
    end
669 670 671 672

    it 'does not allow dragging' do
      expect(page).not_to have_selector('.user-can-drag')
    end
673 674 675 676 677 678 679 680 681
  end

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

    before do
      project.team << [user_guest, :guest]
      logout
      login_as(user_guest)
682
      visit namespace_project_board_path(project.namespace, project, board)
683
      wait_for_vue_resource
684 685 686 687 688 689 690
    end

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

P
Phil Hughes 已提交
691 692
  def drag_to(list_from_index: 0, card_index: 0, to_index: 0, list_to_index: 0, selector: '.board-list')
    evaluate_script("simulateDrag({scrollable: document.getElementById('board-app'), from: {el: $('#{selector}').eq(#{list_from_index}).get(0), index: #{card_index}}, to: {el: $('.board-list').eq(#{list_to_index}).get(0), index: #{to_index}}});")
693 694 695 696 697 698

    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until page.evaluate_script('window.SIMULATE_DRAG_ACTIVE').zero?
    end

    wait_for_vue_resource
P
Phil Hughes 已提交
699
  end
700 701 702 703 704 705 706 707 708 709 710 711 712

  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
P
Phil Hughes 已提交
713
end