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

describe 'Issue Boards', feature: true, js: true do
4
  include WaitForAjax
Phil Hughes's avatar
Phil Hughes committed
5
  include WaitForVueResource
Phil Hughes's avatar
Phil Hughes committed
6
  include DragTo
7

8 9
  let(:project) { create(:empty_project, :public) }
  let(:board)   { create(:board, project: project) }
10 11
  let(:user)    { create(:user) }
  let!(:user2)  { create(:user) }
12 13 14

  before do
    project.team << [user, :master]
Phil Hughes's avatar
Phil Hughes committed
15
    project.team << [user2, :master]
16

17 18 19
    login_as(user)
  end

Phil Hughes's avatar
Phil Hughes committed
20 21
  context 'no lists' do
    before do
22
      visit namespace_project_board_path(project.namespace, project, board)
Phil Hughes's avatar
Phil Hughes committed
23
      wait_for_vue_resource
24
      expect(page).to have_selector('.board', count: 2)
Phil Hughes's avatar
Phil Hughes committed
25
    end
26

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

Phil Hughes's avatar
Phil Hughes committed
31 32 33 34 35 36
    it 'disables add issues button by default' do
      button = page.find('.issue-boards-search button', text: 'Add issues')

      expect(button[:disabled]).to eq true
    end

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

Phil Hughes's avatar
Phil Hughes committed
44
    it 'creates default lists' do
45
      lists = ['To Do', 'Doing', 'Done']
46

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

52
      expect(page).to have_selector('.board', count: 3)
Phil Hughes's avatar
Phil Hughes committed
53 54 55 56 57

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

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

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

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

74 75 76 77 78
    let!(:confidential_issue) { create(:labeled_issue, :confidential, project: project, author: user, labels: [planning]) }
    let!(:issue1) { create(:labeled_issue, project: project, assignee: user, labels: [planning]) }
    let!(:issue2) { create(:labeled_issue, project: project, author: user2, labels: [planning]) }
    let!(:issue3) { create(:labeled_issue, project: project, labels: [planning]) }
    let!(:issue4) { create(:labeled_issue, project: project, labels: [planning]) }
Phil Hughes's avatar
Phil Hughes committed
79
    let!(:issue5) { create(:labeled_issue, project: project, labels: [planning], milestone: milestone) }
80 81
    let!(:issue6) { create(:labeled_issue, project: project, labels: [planning, development]) }
    let!(:issue7) { create(:labeled_issue, project: project, labels: [development]) }
82
    let!(:issue8) { create(:closed_issue, project: project) }
83
    let!(:issue9) { create(:labeled_issue, project: project, labels: [planning, testing, bug, accepting]) }
Phil Hughes's avatar
Phil Hughes committed
84 85

    before do
86
      visit namespace_project_board_path(project.namespace, project, board)
Phil Hughes's avatar
Phil Hughes committed
87

88
      wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
89

90
      expect(page).to have_selector('.board', count: 3)
91 92 93
      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')
Phil Hughes's avatar
Phil Hughes committed
94 95 96
    end

    it 'shows lists' do
97
      expect(page).to have_selector('.board', count: 3)
Phil Hughes's avatar
Phil Hughes committed
98 99
    end

100
    it 'shows description tooltip on list title' do
101
      page.within('.board:nth-child(1)') do
102 103 104 105
        expect(find('.board-title span.has-tooltip')[:title]).to eq('Test')
      end
    end

Phil Hughes's avatar
Phil Hughes committed
106
    it 'shows issues in lists' do
107
      wait_for_board_cards(1, 8)
108
      wait_for_board_cards(2, 2)
Phil Hughes's avatar
Phil Hughes committed
109
    end
110

Phil Hughes's avatar
Phil Hughes committed
111
    it 'shows confidential issues with icon' do
Phil Hughes's avatar
Phil Hughes committed
112
      page.within(find('.board', match: :first)) do
Phil Hughes's avatar
Phil Hughes committed
113 114 115 116
        expect(page).to have_selector('.confidential-icon', count: 1)
      end
    end

117
    it 'search done list' do
victorwu's avatar
victorwu committed
118
      page.within('#js-boards-search') do
119 120 121 122 123 124 125
        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)
126
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 1)
127 128 129
    end

    it 'search list' do
victorwu's avatar
victorwu committed
130
      page.within('#js-boards-search') do
131 132 133 134 135
        find('.form-control').set(issue5.title)
      end

      wait_for_vue_resource

136 137
      expect(find('.board:nth-child(1)')).to have_selector('.card', count: 1)
      expect(find('.board:nth-child(2)')).to have_selector('.card', count: 0)
138 139 140
      expect(find('.board:nth-child(3)')).to have_selector('.card', count: 0)
    end

Phil Hughes's avatar
Phil Hughes committed
141
    it 'allows user to delete board' do
142
      page.within(find('.board:nth-child(1)')) do
Phil Hughes's avatar
Phil Hughes committed
143
        find('.board-delete').click
144
      end
Phil Hughes's avatar
Phil Hughes committed
145 146 147

      wait_for_vue_resource

148
      expect(page).to have_selector('.board', count: 2)
149 150
    end

151
    it 'removes checkmark in new list dropdown after deleting' do
152
      click_button 'Add list'
153 154
      wait_for_ajax

155
      page.within(find('.board:nth-child(1)')) do
156 157
        find('.board-delete').click
      end
158

Phil Hughes's avatar
Phil Hughes committed
159
      wait_for_vue_resource
160

161
      expect(page).to have_selector('.board', count: 2)
162 163
    end

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

169
      visit namespace_project_board_path(project.namespace, project, board)
170
      wait_for_vue_resource
171

Phil Hughes's avatar
Phil Hughes committed
172
      page.within(find('.board', match: :first)) do
173
        expect(page.find('.board-header')).to have_content('58')
174
        expect(page).to have_selector('.card', count: 20)
175
        expect(page).to have_content('Showing 20 of 58 issues')
176 177

        evaluate_script("document.querySelectorAll('.board .board-list')[0].scrollTop = document.querySelectorAll('.board .board-list')[0].scrollHeight")
Phil Hughes's avatar
Phil Hughes committed
178
        wait_for_vue_resource
179 180

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

        evaluate_script("document.querySelectorAll('.board .board-list')[0].scrollTop = document.querySelectorAll('.board .board-list')[0].scrollHeight")
Phil Hughes's avatar
Phil Hughes committed
184
        wait_for_vue_resource
185

186
        expect(page).to have_selector('.card', count: 58)
187
        expect(page).to have_content('Showing all issues')
188 189 190
      end
    end

Phil Hughes's avatar
Phil Hughes committed
191 192
    context 'done' do
      it 'shows list of done issues' do
193
        wait_for_board_cards(3, 1)
194
        wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
195 196 197
      end

      it 'moves issue to done' do
Phil Hughes's avatar
Phil Hughes committed
198
        drag(list_from_index: 0, list_to_index: 2)
Phil Hughes's avatar
Phil Hughes committed
199

200
        wait_for_board_cards(1, 7)
201 202 203 204
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 2)

        expect(find('.board:nth-child(1)')).not_to have_content(issue9.title)
205 206 207
        expect(find('.board:nth-child(3)')).to have_selector('.card', count: 2)
        expect(find('.board:nth-child(3)')).to have_content(issue9.title)
        expect(find('.board:nth-child(3)')).not_to have_content(planning.title)
Phil Hughes's avatar
Phil Hughes committed
208 209 210
      end

      it 'removes all of the same issue to done' do
Phil Hughes's avatar
Phil Hughes committed
211
        drag(list_from_index: 0, list_to_index: 2)
Phil Hughes's avatar
Phil Hughes committed
212

213 214 215
        wait_for_board_cards(1, 7)
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 2)
216

217 218 219
        expect(find('.board:nth-child(1)')).not_to have_content(issue9.title)
        expect(find('.board:nth-child(3)')).to have_content(issue9.title)
        expect(find('.board:nth-child(3)')).not_to have_content(planning.title)
Phil Hughes's avatar
Phil Hughes committed
220 221 222 223
      end
    end

    context 'lists' do
Phil Hughes's avatar
Phil Hughes committed
224
      it 'changes position of list' do
Phil Hughes's avatar
Phil Hughes committed
225
        drag(list_from_index: 1, list_to_index: 0, selector: '.board-header')
Phil Hughes's avatar
Phil Hughes committed
226

227 228 229
        wait_for_board_cards(1, 2)
        wait_for_board_cards(2, 8)
        wait_for_board_cards(3, 1)
230

231 232
        expect(find('.board:nth-child(1)')).to have_content(development.title)
        expect(find('.board:nth-child(1)')).to have_content(planning.title)
Phil Hughes's avatar
Phil Hughes committed
233 234
      end

Phil Hughes's avatar
Phil Hughes committed
235
      it 'issue moves between lists' do
Phil Hughes's avatar
Phil Hughes committed
236
        drag(list_from_index: 0, from_index: 1, list_to_index: 1)
Phil Hughes's avatar
Phil Hughes committed
237

238 239 240
        wait_for_board_cards(1, 7)
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 1)
241

242 243
        expect(find('.board:nth-child(2)')).to have_content(issue6.title)
        expect(find('.board:nth-child(2)').all('.card').last).not_to have_content(development.title)
Phil Hughes's avatar
Phil Hughes committed
244 245
      end

Phil Hughes's avatar
Phil Hughes committed
246
      it 'issue moves between lists' do
Phil Hughes's avatar
Phil Hughes committed
247
        drag(list_from_index: 1, list_to_index: 0)
Phil Hughes's avatar
Phil Hughes committed
248

249 250
        wait_for_board_cards(1, 9)
        wait_for_board_cards(2, 1)
251 252
        wait_for_board_cards(3, 1)

253 254
        expect(find('.board:nth-child(1)')).to have_content(issue7.title)
        expect(find('.board:nth-child(1)').all('.card').first).not_to have_content(planning.title)
Phil Hughes's avatar
Phil Hughes committed
255 256
      end

Phil Hughes's avatar
Phil Hughes committed
257
      it 'issue moves from done' do
Phil Hughes's avatar
Phil Hughes committed
258
        drag(list_from_index: 2, list_to_index: 1)
Phil Hughes's avatar
Phil Hughes committed
259

Phil Hughes's avatar
Phil Hughes committed
260
        expect(find('.board:nth-child(2)')).to have_content(issue8.title)
261

262
        wait_for_board_cards(1, 8)
263
        wait_for_board_cards(2, 3)
264
        wait_for_board_cards(3, 0)
Phil Hughes's avatar
Phil Hughes committed
265 266 267 268
      end

      context 'issue card' do
        it 'shows assignee' do
Phil Hughes's avatar
Phil Hughes committed
269
          page.within(find('.board', match: :first)) do
Phil Hughes's avatar
Phil Hughes committed
270
            expect(page).to have_selector('.avatar', count: 1)
Phil Hughes's avatar
Phil Hughes committed
271 272 273 274 275 276
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
277
          click_button 'Add list'
278
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
279 280 281 282 283 284 285 286 287

          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
288
          click_button 'Add list'
289
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
290 291 292 293 294

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

295 296
          wait_for_vue_resource

297
          expect(page).to have_selector('.board', count: 4)
Phil Hughes's avatar
Phil Hughes committed
298 299
        end

300
        it 'creates new list for Backlog label' do
301
          click_button 'Add list'
302
          wait_for_ajax
303 304 305 306 307

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

308 309
          wait_for_vue_resource

310
          expect(page).to have_selector('.board', count: 4)
311 312 313
        end

        it 'creates new list for Done label' do
314
          click_button 'Add list'
315
          wait_for_ajax
316 317 318 319 320

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

321 322
          wait_for_vue_resource

323
          expect(page).to have_selector('.board', count: 4)
324 325
        end

326
        it 'keeps dropdown open after adding new list' do
327
          click_button 'Add list'
328 329 330 331 332 333 334 335 336 337 338
          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

339
        it 'creates new list from a new label' do
340
          click_button 'Add list'
341 342 343 344 345 346 347 348 349 350 351 352 353 354

          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

355
          expect(page).to have_selector('.board', count: 4)
356
        end
Phil Hughes's avatar
Phil Hughes committed
357 358 359 360
      end
    end

    context 'filtering' do
Phil Hughes's avatar
Phil Hughes committed
361 362 363
      it 'filters by author' do
        page.within '.issues-filters' do
          click_button('Author')
364
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
365 366 367 368

          page.within '.dropdown-menu-author' do
            click_link(user2.name)
          end
Phil Hughes's avatar
Phil Hughes committed
369
          wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
370 371 372 373

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

374
        wait_for_vue_resource
375
        wait_for_board_cards(1, 1)
376
        wait_for_empty_boards((2..3))
Phil Hughes's avatar
Phil Hughes committed
377 378 379 380 381
      end

      it 'filters by assignee' do
        page.within '.issues-filters' do
          click_button('Assignee')
382
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
383 384 385 386

          page.within '.dropdown-menu-assignee' do
            click_link(user.name)
          end
Phil Hughes's avatar
Phil Hughes committed
387
          wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
388 389 390 391

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

392 393
        wait_for_vue_resource

394
        wait_for_board_cards(1, 1)
395
        wait_for_empty_boards((2..3))
Phil Hughes's avatar
Phil Hughes committed
396 397 398 399
      end

      it 'filters by milestone' do
        page.within '.issues-filters' do
400
          click_button('Milestone')
401
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
402 403 404 405

          page.within '.milestone-filter' do
            click_link(milestone.title)
          end
Phil Hughes's avatar
Phil Hughes committed
406
          wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
407 408 409 410

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

411
        wait_for_vue_resource
412 413
        wait_for_board_cards(1, 1)
        wait_for_board_cards(2, 0)
414
        wait_for_board_cards(3, 0)
Phil Hughes's avatar
Phil Hughes committed
415 416 417 418 419
      end

      it 'filters by label' do
        page.within '.issues-filters' do
          click_button('Label')
420
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
421 422 423

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
424
            wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
425 426 427 428
            find('.dropdown-menu-close').click
          end
        end

429
        wait_for_vue_resource
430
        wait_for_board_cards(1, 1)
431
        wait_for_empty_boards((2..3))
Phil Hughes's avatar
Phil Hughes committed
432 433
      end

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
      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

462
      it 'removes filtered labels' do
Phil Hughes's avatar
Phil Hughes committed
463
        wait_for_vue_resource
464

465 466 467 468 469 470
        page.within '.labels-filter' do
          click_button('Label')
          wait_for_ajax

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
471
            wait_for_vue_resource(spinner: false)
472 473 474 475 476 477
          end

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

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
478
            wait_for_vue_resource(spinner: false)
479 480 481 482 483 484
          end

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

485 486
      it 'infinite scrolls list with label filter' do
        50.times do
487
          create(:labeled_issue, project: project, labels: [planning, testing])
488 489 490 491
        end

        page.within '.issues-filters' do
          click_button('Label')
492
          wait_for_ajax
493 494 495

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
496
            wait_for_vue_resource
497 498 499 500
            find('.dropdown-menu-close').click
          end
        end

501 502
        wait_for_vue_resource

Phil Hughes's avatar
Phil Hughes committed
503
        page.within(find('.board', match: :first)) do
504
          expect(page.find('.board-header')).to have_content('51')
505
          expect(page).to have_selector('.card', count: 20)
506
          expect(page).to have_content('Showing 20 of 51 issues')
507 508 509 510

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

          expect(page).to have_selector('.card', count: 40)
511 512 513 514 515 516
          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')
517 518 519
        end
      end

Phil Hughes's avatar
Phil Hughes committed
520 521 522
      it 'filters by multiple labels' do
        page.within '.issues-filters' do
          click_button('Label')
523
          wait_for_ajax
Phil Hughes's avatar
Phil Hughes committed
524

525
          page.within(find('.dropdown-menu-labels')) do
Phil Hughes's avatar
Phil Hughes committed
526
            click_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
527
            wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
528
            click_link(bug.title)
Phil Hughes's avatar
Phil Hughes committed
529
            wait_for_vue_resource
Phil Hughes's avatar
Phil Hughes committed
530 531 532 533
            find('.dropdown-menu-close').click
          end
        end

534 535
        wait_for_vue_resource

536
        wait_for_board_cards(1, 1)
537
        wait_for_empty_boards((2..3))
Phil Hughes's avatar
Phil Hughes committed
538
      end
539 540

      it 'filters by clicking label button on issue' do
Phil Hughes's avatar
Phil Hughes committed
541
        page.within(find('.board', match: :first)) do
542
          expect(page).to have_selector('.card', count: 8)
543
          expect(find('.card', match: :first)).to have_content(bug.title)
Phil Hughes's avatar
Phil Hughes committed
544
          click_button(bug.title)
Phil Hughes's avatar
Phil Hughes committed
545
          wait_for_vue_resource
546 547
        end

548 549
        wait_for_vue_resource

550
        wait_for_board_cards(1, 1)
551
        wait_for_empty_boards((2..3))
552 553

        page.within('.labels-filter') do
Phil Hughes's avatar
Phil Hughes committed
554
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
555 556 557 558
        end
      end

      it 'removes label filter by clicking label button on issue' do
Phil Hughes's avatar
Phil Hughes committed
559 560
        page.within(find('.board', match: :first)) do
          page.within(find('.card', match: :first)) do
561 562
            click_button(bug.title)
          end
Phil Hughes's avatar
Phil Hughes committed
563
          wait_for_vue_resource
564 565 566 567

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

568 569
        wait_for_vue_resource

570 571 572 573
        page.within('.labels-filter') do
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
        end
      end
574 575 576
    end
  end

577 578
  context 'keyboard shortcuts' do
    before do
579
      visit namespace_project_board_path(project.namespace, project, board)
580 581 582 583 584 585 586 587 588
      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

589 590 591
  context 'signed out user' do
    before do
      logout
592
      visit namespace_project_board_path(project.namespace, project, board)
593
      wait_for_vue_resource
594 595
    end

596 597 598 599
    it 'displays lists' do
      expect(page).to have_selector('.board')
    end

600 601 602
    it 'does not show create new list' do
      expect(page).not_to have_selector('.js-new-board-list')
    end
603 604 605 606

    it 'does not allow dragging' do
      expect(page).not_to have_selector('.user-can-drag')
    end
607 608 609 610 611 612 613 614 615
  end

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

    before do
      project.team << [user_guest, :guest]
      logout
      login_as(user_guest)
616
      visit namespace_project_board_path(project.namespace, project, board)
617
      wait_for_vue_resource
618 619 620 621 622 623 624
    end

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

Phil Hughes's avatar
Phil Hughes committed
625 626 627 628 629 630 631
  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)
632
  end
633 634 635 636 637 638 639 640 641 642 643 644 645

  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
646
end