boards_spec.rb 18.7 KB
Newer Older
1 2
require 'rails_helper'

3
describe 'Issue Boards', :js do
Phil Hughes's avatar
Phil Hughes committed
4
  include DragTo
5

6
  let(:group) { create(:group, :nested) }
7
  let(:project) { create(: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's avatar
Phil Hughes committed
14
    project.team << [user2, :master]
15

Mike Greiling's avatar
Mike Greiling committed
16
    set_cookie('sidebar_collapsed', 'true')
Phil Hughes's avatar
Phil Hughes committed
17

18
    sign_in(user)
19 20
  end

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

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

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

Phil Hughes's avatar
Phil Hughes committed
35
      expect(button[:"data-original-title"]).to eq("Please add a list to your board first")
Phil Hughes's avatar
Phil Hughes committed
36 37
    end

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

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

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

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

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

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

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

72 73
    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
74

Phil Hughes's avatar
Phil Hughes committed
75
    let!(:confidential_issue) { create(:labeled_issue, :confidential, project: project, author: user, labels: [planning], relative_position: 9) }
Hiroyuki Sato's avatar
Hiroyuki Sato committed
76 77 78 79 80 81 82 83 84
    let!(:issue1) { create(:labeled_issue, project: project, title: 'aaa', description: '111', assignees: [user], labels: [planning], relative_position: 8) }
    let!(:issue2) { create(:labeled_issue, project: project, title: 'bbb', description: '222', author: user2, labels: [planning], relative_position: 7) }
    let!(:issue3) { create(:labeled_issue, project: project, title: 'ccc', description: '333', labels: [planning], relative_position: 6) }
    let!(:issue4) { create(:labeled_issue, project: project, title: 'ddd', description: '444', labels: [planning], relative_position: 5) }
    let!(:issue5) { create(:labeled_issue, project: project, title: 'eee', description: '555', labels: [planning], milestone: milestone, relative_position: 4) }
    let!(:issue6) { create(:labeled_issue, project: project, title: 'fff', description: '666', labels: [planning, development], relative_position: 3) }
    let!(:issue7) { create(:labeled_issue, project: project, title: 'ggg', description: '777', labels: [development], relative_position: 2) }
    let!(:issue8) { create(:closed_issue, project: project, title: 'hhh', description: '888') }
    let!(:issue9) { create(:labeled_issue, project: project, title: 'iii', description: '999', labels: [planning, testing, bug, accepting], relative_position: 1) }
Phil Hughes's avatar
Phil Hughes committed
85 86

    before do
87
      visit project_board_path(project, board)
Phil Hughes's avatar
Phil Hughes committed
88

89
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
90

Phil Hughes's avatar
Phil Hughes committed
91
      expect(page).to have_selector('.board', count: 4)
92 93
      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
      expect(find('.board:nth-child(4)')).to have_selector('.card')
Phil Hughes's avatar
Phil Hughes committed
95 96
    end

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

Phil Hughes's avatar
Phil Hughes committed
103
    it 'shows issues in lists' do
Phil Hughes's avatar
Phil Hughes committed
104 105
      wait_for_board_cards(2, 8)
      wait_for_board_cards(3, 2)
Phil Hughes's avatar
Phil Hughes committed
106
    end
107

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

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

118
      wait_for_requests
119 120

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

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

129
      wait_for_requests
130

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

Phil Hughes's avatar
Phil Hughes committed
136
    it 'allows user to delete board' do
Phil Hughes's avatar
Phil Hughes committed
137
      page.within(find('.board:nth-child(2)')) do
138
        accept_confirm { find('.board-delete').click }
139
      end
Phil Hughes's avatar
Phil Hughes committed
140

141
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
142

Phil Hughes's avatar
Phil Hughes committed
143
      expect(page).to have_selector('.board', count: 3)
144 145
    end

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

Phil Hughes's avatar
Phil Hughes committed
150 151
      find('.dropdown-menu-close').click

Phil Hughes's avatar
Phil Hughes committed
152
      page.within(find('.board:nth-child(2)')) do
153
        accept_confirm { find('.board-delete').click }
154
      end
155

156
      wait_for_requests
157

Phil Hughes's avatar
Phil Hughes committed
158
      expect(page).to have_selector('.board', count: 3)
159 160
    end

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

166
      visit project_board_path(project, board)
167
      wait_for_requests
168

Phil Hughes's avatar
Phil Hughes committed
169
      page.within(find('.board:nth-child(2)')) do
170
        expect(page.find('.board-header')).to have_content('58')
171
        expect(page).to have_selector('.card', count: 20)
172
        expect(page).to have_content('Showing 20 of 58 issues')
173

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

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

181
        find('.board .board-list')
Phil Hughes's avatar
Phil Hughes committed
182
        evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
183
        wait_for_requests
184

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

190 191
    context 'closed' do
      it 'shows list of closed issues' do
Phil Hughes's avatar
Phil Hughes committed
192
        wait_for_board_cards(4, 1)
193
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
194 195
      end

196
      it 'moves issue to closed' do
Phil Hughes's avatar
Phil Hughes committed
197
        drag(list_from_index: 1, list_to_index: 3)
Phil Hughes's avatar
Phil Hughes committed
198

Phil Hughes's avatar
Phil Hughes committed
199
        wait_for_board_cards(2, 7)
200
        wait_for_board_cards(3, 2)
Phil Hughes's avatar
Phil Hughes committed
201
        wait_for_board_cards(4, 2)
202

Phil Hughes's avatar
Phil Hughes committed
203 204 205 206
        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's avatar
Phil Hughes committed
207 208
      end

209
      it 'removes all of the same issue to closed' do
Phil Hughes's avatar
Phil Hughes committed
210
        drag(list_from_index: 1, list_to_index: 3)
Phil Hughes's avatar
Phil Hughes committed
211

Phil Hughes's avatar
Phil Hughes committed
212
        wait_for_board_cards(2, 7)
213
        wait_for_board_cards(3, 2)
Phil Hughes's avatar
Phil Hughes committed
214
        wait_for_board_cards(4, 2)
215

Phil Hughes's avatar
Phil Hughes committed
216 217 218
        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's avatar
Phil Hughes committed
219 220 221 222
      end
    end

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

Phil Hughes's avatar
Phil Hughes committed
226 227 228
        wait_for_board_cards(2, 2)
        wait_for_board_cards(3, 8)
        wait_for_board_cards(4, 1)
229

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

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

Phil Hughes's avatar
Phil Hughes committed
237 238 239
        wait_for_board_cards(2, 7)
        wait_for_board_cards(3, 2)
        wait_for_board_cards(4, 1)
240

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

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

Phil Hughes's avatar
Phil Hughes committed
248
        wait_for_board_cards(2, 9)
249
        wait_for_board_cards(3, 1)
Phil Hughes's avatar
Phil Hughes committed
250
        wait_for_board_cards(4, 1)
251

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

256
      it 'issue moves from closed' do
Phil Hughes's avatar
Phil Hughes committed
257
        drag(list_from_index: 2, list_to_index: 3)
Phil Hughes's avatar
Phil Hughes committed
258

Phil Hughes's avatar
Phil Hughes committed
259
        wait_for_board_cards(2, 8)
Phil Hughes's avatar
Phil Hughes committed
260 261
        wait_for_board_cards(3, 1)
        wait_for_board_cards(4, 2)
262

Phil Hughes's avatar
Phil Hughes committed
263
        expect(find('.board:nth-child(4)')).to have_content(issue8.title)
Phil Hughes's avatar
Phil Hughes committed
264 265 266 267
      end

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

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

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

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

294
          wait_for_requests
295

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

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

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

307
          wait_for_requests
308

Phil Hughes's avatar
Phil Hughes committed
309
          expect(page).to have_selector('.board', count: 5)
310 311
        end

312
        it 'creates new list for Closed label' do
313
          click_button 'Add list'
314
          wait_for_requests
315 316

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

320
          wait_for_requests
321

Phil Hughes's avatar
Phil Hughes committed
322
          expect(page).to have_selector('.board', count: 5)
323 324
        end

325
        it 'keeps dropdown open after adding new list' do
326
          click_button 'Add list'
327
          wait_for_requests
328 329

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

333
          wait_for_requests
334

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

338
        it 'creates new list from a new label' do
339
          click_button 'Add list'
340

341
          wait_for_requests
342 343 344 345 346 347 348 349 350

          click_link 'Create new label'

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

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

          click_button 'Create'

351 352
          wait_for_requests
          wait_for_requests
353

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

    context 'filtering' do
Phil Hughes's avatar
Phil Hughes committed
360
      it 'filters by author' do
Phil Hughes's avatar
Phil Hughes committed
361 362 363
        set_filter("author", user2.username)
        click_filter_link(user2.username)
        submit_filter
Phil Hughes's avatar
Phil Hughes committed
364

365
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
366 367
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes's avatar
Phil Hughes committed
368 369 370
      end

      it 'filters by assignee' do
Phil Hughes's avatar
Phil Hughes committed
371 372 373
        set_filter("assignee", user.username)
        click_filter_link(user.username)
        submit_filter
Phil Hughes's avatar
Phil Hughes committed
374

375
        wait_for_requests
376

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

      it 'filters by milestone' do
382
        set_filter("milestone", "\"#{milestone.title}")
Phil Hughes's avatar
Phil Hughes committed
383 384
        click_filter_link(milestone.title)
        submit_filter
Phil Hughes's avatar
Phil Hughes committed
385

386
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
387
        wait_for_board_cards(2, 1)
388
        wait_for_board_cards(3, 0)
Phil Hughes's avatar
Phil Hughes committed
389
        wait_for_board_cards(4, 0)
Phil Hughes's avatar
Phil Hughes committed
390 391 392
      end

      it 'filters by label' do
Phil Hughes's avatar
Phil Hughes committed
393 394 395
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
Phil Hughes's avatar
Phil Hughes committed
396

397
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
398 399
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes's avatar
Phil Hughes committed
400 401
      end

402
      it 'filters by label with space after reload' do
403
        set_filter("label", "\"#{accepting.title}")
Phil Hughes's avatar
Phil Hughes committed
404 405
        click_filter_link(accepting.title)
        submit_filter
406 407 408

        # Test after reload
        page.evaluate_script 'window.location.reload()'
Phil Hughes's avatar
Phil Hughes committed
409 410
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
411

412
        wait_for_requests
413

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

Phil Hughes's avatar
Phil Hughes committed
419
        page.within(find('.board:nth-child(3)')) do
420 421 422 423 424
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

425
      it 'removes filtered labels' do
Phil Hughes's avatar
Phil Hughes committed
426 427 428
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
429

Phil Hughes's avatar
Phil Hughes committed
430
        wait_for_board_cards(2, 1)
431

Phil Hughes's avatar
Phil Hughes committed
432 433
        find('.clear-search').click
        submit_filter
434

Phil Hughes's avatar
Phil Hughes committed
435
        wait_for_board_cards(2, 8)
436 437
      end

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

Phil Hughes's avatar
Phil Hughes committed
443 444 445
        set_filter("label", testing.title)
        click_filter_link(testing.title)
        submit_filter
446

447
        wait_for_requests
448

Phil Hughes's avatar
Phil Hughes committed
449
        page.within(find('.board:nth-child(2)')) do
450
          expect(page.find('.board-header')).to have_content('51')
451
          expect(page).to have_selector('.card', count: 20)
452
          expect(page).to have_content('Showing 20 of 51 issues')
453

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

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

460
          find('.board .board-list')
Phil Hughes's avatar
Phil Hughes committed
461
          evaluate_script("document.querySelectorAll('.board .board-list')[1].scrollTop = document.querySelectorAll('.board .board-list')[1].scrollHeight")
462 463 464

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

Phil Hughes's avatar
Phil Hughes committed
468
      it 'filters by multiple labels' do
Phil Hughes's avatar
Phil Hughes committed
469 470
        set_filter("label", testing.title)
        click_filter_link(testing.title)
Phil Hughes's avatar
Phil Hughes committed
471

Phil Hughes's avatar
Phil Hughes committed
472 473 474 475
        set_filter("label", bug.title)
        click_filter_link(bug.title)

        submit_filter
Phil Hughes's avatar
Phil Hughes committed
476

477
        wait_for_requests
478

Phil Hughes's avatar
Phil Hughes committed
479 480
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
Phil Hughes's avatar
Phil Hughes committed
481
      end
482 483

      it 'filters by clicking label button on issue' do
Phil Hughes's avatar
Phil Hughes committed
484
        page.within(find('.board:nth-child(2)')) do
485
          expect(page).to have_selector('.card', count: 8)
486
          expect(find('.card', match: :first)).to have_content(bug.title)
Phil Hughes's avatar
Phil Hughes committed
487
          click_button(bug.title)
488
          wait_for_requests
489 490
        end

Phil Hughes's avatar
Phil Hughes committed
491 492 493 494
        page.within('.tokens-container') do
          expect(page).to have_content(bug.title)
        end

495
        wait_for_requests
496

Phil Hughes's avatar
Phil Hughes committed
497 498
        wait_for_board_cards(2, 1)
        wait_for_empty_boards((3..4))
499 500 501
      end

      it 'removes label filter by clicking label button on issue' do
Phil Hughes's avatar
Phil Hughes committed
502
        page.within(find('.board:nth-child(2)')) do
Phil Hughes's avatar
Phil Hughes committed
503
          page.within(find('.card', match: :first)) do
504 505
            click_button(bug.title)
          end
Phil Hughes's avatar
Phil Hughes committed
506

507
          wait_for_requests
508 509 510 511

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

512
        wait_for_requests
513
      end
514 515 516
    end
  end

517 518
  context 'keyboard shortcuts' do
    before do
519
      visit project_board_path(project, board)
520
      wait_for_requests
521 522 523
    end

    it 'allows user to use keyboard shortcuts' do
524
      find('body').native.send_keys('i')
525 526 527 528
      expect(page).to have_content('New Issue')
    end
  end

529 530
  context 'signed out user' do
    before do
531
      sign_out(:user)
532
      visit project_board_path(project, board)
533
      wait_for_requests
534 535
    end

536 537 538 539
    it 'displays lists' do
      expect(page).to have_selector('.board')
    end

540
    it 'does not show create new list' do
Eric Eastwood's avatar
Eric Eastwood committed
541
      expect(page).not_to have_button('.js-new-board-list')
542
    end
543 544 545 546

    it 'does not allow dragging' do
      expect(page).not_to have_selector('.user-can-drag')
    end
547 548 549 550 551 552 553
  end

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

    before do
      project.team << [user_guest, :guest]
554 555
      sign_out(:user)
      sign_in(user_guest)
556
      visit project_board_path(project, board)
557
      wait_for_requests
558 559 560 561 562 563 564
    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
565
  def drag(selector: '.board-list', list_from_index: 0, from_index: 0, to_index: 0, list_to_index: 0)
566 567 568
    # ensure there is enough horizontal space for four boards
    page.current_window.resize_to(2000, 800)

Phil Hughes's avatar
Phil Hughes committed
569 570 571 572 573 574
    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)
575
  end
576 577 578 579 580 581 582 583 584 585 586 587 588

  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's avatar
Phil Hughes committed
589 590 591 592 593 594 595 596 597 598

  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)
599
    page.within('.filtered-search-box') do
Phil Hughes's avatar
Phil Hughes committed
600 601 602 603 604
      expect(page).to have_button(link_text)

      click_button(link_text)
    end
  end
605
end