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 5
  include WaitForAjax

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

  before do
11 12 13
    project.create_board
    project.board.lists.create(list_type: :backlog)
    project.board.lists.create(list_type: :done)
14

P
Phil Hughes 已提交
15
    project.team << [user, :master]
P
Phil Hughes 已提交
16
    project.team << [user2, :master]
17

P
Phil Hughes 已提交
18 19 20
    login_as(user)
  end

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

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

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

P
Phil Hughes 已提交
39 40
    it 'creates default lists' do
      lists = ['Backlog', 'Development', 'Testing', 'Production', 'Ready', 'Done']
P
Phil Hughes 已提交
41

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

P
Phil Hughes 已提交
47 48 49 50 51 52
      expect(page).to have_selector('.board', count: 6)

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

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

P
Phil Hughes 已提交
58 59 60
    let(:planning)    { create(:label, project: project, name: 'Planning') }
    let(:development) { create(:label, project: project, name: 'Development') }
    let(:testing)     { create(:label, project: project, name: 'Testing') }
P
Phil Hughes 已提交
61
    let(:bug)         { create(:label, project: project, name: 'Bug') }
62 63
    let!(:backlog)    { create(:label, project: project, name: 'Backlog') }
    let!(:done)       { create(:label, project: project, name: 'Done') }
P
Phil Hughes 已提交
64 65 66 67

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

68 69 70 71 72
    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 已提交
73
    let!(:issue5) { create(:labeled_issue, project: project, labels: [planning], milestone: milestone) }
74 75
    let!(:issue6) { create(:labeled_issue, project: project, labels: [planning, development]) }
    let!(:issue7) { create(:labeled_issue, project: project, labels: [development]) }
76
    let!(:issue8) { create(:closed_issue, project: project) }
77
    let!(:issue9) { create(:labeled_issue, project: project, labels: [testing, bug]) }
P
Phil Hughes 已提交
78 79 80 81

    before do
      visit namespace_project_board_path(project.namespace, project)

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

      expect(page).to have_selector('.board', count: 4)
85 86 87 88
      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 已提交
89 90 91 92 93 94 95
    end

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

    it 'shows issues in lists' do
P
Phil Hughes 已提交
96
      page.within(find('.board:nth-child(2)')) do
97 98
        expect(page.find('.board-header')).to have_content('2')
        expect(page).to have_selector('.card', count: 2)
P
Phil Hughes 已提交
99
      end
P
Phil Hughes 已提交
100

P
Phil Hughes 已提交
101
      page.within(find('.board:nth-child(3)')) do
P
Phil Hughes 已提交
102 103 104 105
        expect(page.find('.board-header')).to have_content('2')
        expect(page).to have_selector('.card', count: 2)
      end
    end
P
Phil Hughes 已提交
106

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

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
    it 'search backlog list' do
      page.within('#js-boards-seach') do
        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
      page.within('#js-boards-seach') do
        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
      page.within('#js-boards-seach') do
        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 已提交
152
    it 'allows user to delete board' do
P
Phil Hughes 已提交
153
      page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
154
        find('.board-delete').click
P
Phil Hughes 已提交
155
      end
P
Phil Hughes 已提交
156 157 158

      wait_for_vue_resource

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

162 163 164 165
    it 'removes checkmark in new list dropdown after deleting' do
      click_button 'Create new list'
      wait_for_ajax

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

P
Phil Hughes 已提交
170
      wait_for_vue_resource
171

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

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

      visit namespace_project_board_path(project.namespace, project)
P
Phil Hughes 已提交
182
      wait_for_vue_resource
183

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

        evaluate_script("document.querySelectorAll('.board .board-list')[0].scrollTop = document.querySelectorAll('.board .board-list')[0].scrollHeight")
190
        wait_for_vue_resource(spinner: false)
191 192

        expect(page).to have_selector('.card', count: 40)
P
Phil Hughes 已提交
193 194 195 196 197 198 199
        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")
        wait_for_vue_resource(spinner: false)

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

P
Phil Hughes 已提交
203 204
    context 'backlog' do
      it 'shows issues in backlog with no labels' do
P
Phil Hughes 已提交
205
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
206 207
          expect(page.find('.board-header')).to have_content('6')
          expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
208 209 210 211 212
        end
      end

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

P
Phil Hughes 已提交
214
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
215 216
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
217
        end
P
Phil Hughes 已提交
218

219 220
        wait_for_vue_resource

P
Phil Hughes 已提交
221
        page.within(find('.board:nth-child(2)')) do
222 223
          expect(page.find('.board-header')).to have_content('3')
          expect(page).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
224
        end
P
Phil Hughes 已提交
225 226 227
      end
    end

P
Phil Hughes 已提交
228 229
    context 'done' do
      it 'shows list of done issues' do
P
Phil Hughes 已提交
230
        expect(find('.board:nth-child(4)')).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
231 232 233 234 235
      end

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

P
Phil Hughes 已提交
236 237 238
        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 已提交
239 240 241 242 243
      end

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

P
Phil Hughes 已提交
244 245 246 247
        expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1)
        expect(find('.board:nth-child(3)')).to have_selector('.card', count: 1)
        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 已提交
248 249 250 251
      end
    end

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

P
Phil Hughes 已提交
255 256
        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 已提交
257 258
      end

P
Phil Hughes 已提交
259
      it 'issue moves between lists' do
260
        drag_to(list_from_index: 1, card_index: 1, list_to_index: 2)
P
Phil Hughes 已提交
261

P
Phil Hughes 已提交
262 263 264 265
        expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1)
        expect(find('.board:nth-child(3)')).to have_selector('.card', count: 3)
        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 已提交
266 267
      end

P
Phil Hughes 已提交
268
      it 'issue moves between lists' do
P
Phil Hughes 已提交
269 270
        drag_to(list_from_index: 2, list_to_index: 1)

P
Phil Hughes 已提交
271 272 273 274
        expect(find('.board:nth-child(2)')).to have_selector('.card', count: 3)
        expect(find('.board:nth-child(3)')).to have_selector('.card', count: 1)
        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 已提交
275 276
      end

P
Phil Hughes 已提交
277
      it 'issue moves from done' do
P
Phil Hughes 已提交
278 279
        drag_to(list_from_index: 3, list_to_index: 1)

P
Phil Hughes 已提交
280 281
        expect(find('.board:nth-child(2)')).to have_selector('.card', count: 3)
        expect(find('.board:nth-child(2)')).to have_content(issue8.title)
P
Phil Hughes 已提交
282 283 284 285
      end

      context 'issue card' do
        it 'shows assignee' do
P
Phil Hughes 已提交
286
          page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
287
            expect(page).to have_selector('.avatar', count: 1)
P
Phil Hughes 已提交
288 289 290 291 292 293 294
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
          click_button 'Create new list'
295
          wait_for_ajax
P
Phil Hughes 已提交
296 297 298 299 300 301 302 303 304 305

          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 'Create new list'
306
          wait_for_ajax
P
Phil Hughes 已提交
307 308 309 310 311

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

312 313
          wait_for_vue_resource

P
Phil Hughes 已提交
314 315 316
          expect(page).to have_selector('.board', count: 5)
        end

317 318
        it 'creates new list for Backlog label' do
          click_button 'Create new list'
319
          wait_for_ajax
320 321 322 323 324

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

325 326
          wait_for_vue_resource

327 328 329 330 331
          expect(page).to have_selector('.board', count: 5)
        end

        it 'creates new list for Done label' do
          click_button 'Create new list'
332
          wait_for_ajax
333 334 335 336 337

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

338 339
          wait_for_vue_resource

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

P
Phil Hughes 已提交
343
        it 'moves issues from backlog into new list' do
P
Phil Hughes 已提交
344
          page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
345 346
            expect(page.find('.board-header')).to have_content('6')
            expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
347 348 349
          end

          click_button 'Create new list'
350
          wait_for_ajax
P
Phil Hughes 已提交
351 352 353 354 355

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

356 357
          wait_for_vue_resource

P
Phil Hughes 已提交
358
          page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
359 360
            expect(page.find('.board-header')).to have_content('5')
            expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
361 362 363 364 365 366
          end
        end
      end
    end

    context 'filtering' do
P
Phil Hughes 已提交
367 368 369
      it 'filters by author' do
        page.within '.issues-filters' do
          click_button('Author')
370
          wait_for_ajax
P
Phil Hughes 已提交
371 372 373 374

          page.within '.dropdown-menu-author' do
            click_link(user2.name)
          end
P
Phil Hughes 已提交
375
          wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
376 377 378 379

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

P
Phil Hughes 已提交
380 381
        wait_for_vue_resource

P
Phil Hughes 已提交
382
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
383 384 385 386
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

P
Phil Hughes 已提交
387
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
388 389 390 391 392 393 394 395
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

      it 'filters by assignee' do
        page.within '.issues-filters' do
          click_button('Assignee')
396
          wait_for_ajax
P
Phil Hughes 已提交
397 398 399 400

          page.within '.dropdown-menu-assignee' do
            click_link(user.name)
          end
P
Phil Hughes 已提交
401
          wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
402 403 404 405

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

P
Phil Hughes 已提交
406 407
        wait_for_vue_resource

P
Phil Hughes 已提交
408
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
409 410 411 412
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

P
Phil Hughes 已提交
413
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
414 415 416 417 418 419 420
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

      it 'filters by milestone' do
        page.within '.issues-filters' do
421
          click_button('Milestone')
422
          wait_for_ajax
P
Phil Hughes 已提交
423 424 425 426

          page.within '.milestone-filter' do
            click_link(milestone.title)
          end
P
Phil Hughes 已提交
427
          wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
428 429 430 431

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

P
Phil Hughes 已提交
432 433
        wait_for_vue_resource

P
Phil Hughes 已提交
434
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
435 436 437 438
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end

P
Phil Hughes 已提交
439
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
440 441 442 443 444 445 446 447
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end
      end

      it 'filters by label' do
        page.within '.issues-filters' do
          click_button('Label')
448
          wait_for_ajax
P
Phil Hughes 已提交
449 450 451

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
452
            wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
453 454 455 456
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
457 458
        wait_for_vue_resource

P
Phil Hughes 已提交
459
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
460 461 462 463
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

P
Phil Hughes 已提交
464
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
465 466 467 468 469
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

470 471
      it 'infinite scrolls list with label filter' do
        50.times do
472
          create(:labeled_issue, project: project, labels: [testing])
473 474 475 476
        end

        page.within '.issues-filters' do
          click_button('Label')
477
          wait_for_ajax
478 479 480

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
P
Phil Hughes 已提交
481
            wait_for_vue_resource(spinner: false)
482 483 484 485
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
486 487
        wait_for_vue_resource

P
Phil Hughes 已提交
488
        page.within(find('.board', match: :first)) do
489
          expect(page.find('.board-header')).to have_content('51')
490
          expect(page).to have_selector('.card', count: 20)
P
Phil Hughes 已提交
491
          expect(page).to have_content('Showing 20 of 51 issues')
492 493 494 495

          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 已提交
496 497 498 499 500 501
          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')
502 503 504
        end
      end

P
Phil Hughes 已提交
505 506 507
      it 'filters by multiple labels' do
        page.within '.issues-filters' do
          click_button('Label')
508
          wait_for_ajax
P
Phil Hughes 已提交
509

510
          page.within(find('.dropdown-menu-labels')) do
P
Phil Hughes 已提交
511
            click_link(testing.title)
P
Phil Hughes 已提交
512
            wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
513
            click_link(bug.title)
P
Phil Hughes 已提交
514
            wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
515 516 517 518
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
519 520
        wait_for_vue_resource

P
Phil Hughes 已提交
521
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
522 523
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
524 525
        end

P
Phil Hughes 已提交
526
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
527 528 529 530 531 532 533 534
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

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

P
Phil Hughes 已提交
537 538
          page.within '.dropdown-menu-labels' do
            click_link("No Label")
P
Phil Hughes 已提交
539
            wait_for_vue_resource(spinner: false)
P
Phil Hughes 已提交
540 541 542 543
            find('.dropdown-menu-close').click
          end
        end

P
Phil Hughes 已提交
544 545
        wait_for_vue_resource

P
Phil Hughes 已提交
546
        page.within(find('.board', match: :first)) do
P
Phil Hughes 已提交
547 548
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
549 550
        end

P
Phil Hughes 已提交
551
        page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
552 553 554 555
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end
556 557

      it 'filters by clicking label button on issue' do
P
Phil Hughes 已提交
558 559
        page.within(find('.board', match: :first)) do
          expect(page).to have_selector('.card', count: 6)
560
          expect(find('.card', match: :first)).to have_content(bug.title)
P
Phil Hughes 已提交
561 562
          click_button(bug.title)
          wait_for_vue_resource(spinner: false)
563 564
        end

565 566
        wait_for_vue_resource

P
Phil Hughes 已提交
567
        page.within(find('.board', match: :first)) do
568 569 570 571
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

P
Phil Hughes 已提交
572
        page.within(find('.board:nth-child(2)')) do
573 574 575 576 577
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end

        page.within('.labels-filter') do
P
Phil Hughes 已提交
578
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
579 580 581 582
        end
      end

      it 'removes label filter by clicking label button on issue' do
P
Phil Hughes 已提交
583 584
        page.within(find('.board', match: :first)) do
          page.within(find('.card', match: :first)) do
585 586
            click_button(bug.title)
          end
P
Phil Hughes 已提交
587
          wait_for_vue_resource(spinner: false)
588 589 590 591

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

P
Phil Hughes 已提交
592 593
        wait_for_vue_resource

594 595 596 597
        page.within('.labels-filter') do
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
        end
      end
P
Phil Hughes 已提交
598 599 600
    end
  end

601 602 603 604 605 606 607 608 609 610 611 612
  context 'keyboard shortcuts' do
    before do
      visit namespace_project_board_path(project.namespace, project)
      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

613 614 615 616
  context 'signed out user' do
    before do
      logout
      visit namespace_project_board_path(project.namespace, project)
617
      wait_for_vue_resource
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
    end

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

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

    before do
      project.team << [user_guest, :guest]
      logout
      login_as(user_guest)
      visit namespace_project_board_path(project.namespace, project)
633
      wait_for_vue_resource
634 635 636 637 638 639 640
    end

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

P
Phil Hughes 已提交
641 642
  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}}});")
643 644 645 646 647 648

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

P
Phil Hughes 已提交
651
  def wait_for_vue_resource(spinner: true)
652 653 654 655
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until page.evaluate_script('Vue.activeResources').zero?
    end

P
Phil Hughes 已提交
656 657 658
    if spinner
      expect(find('.boards-list')).not_to have_selector('.fa-spinner')
    end
P
Phil Hughes 已提交
659
  end
P
Phil Hughes 已提交
660
end