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

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

P
Phil Hughes 已提交
6 7
  let(:project)   { create(:project) }
  let(:user)      { create(:user) }
P
Phil Hughes 已提交
8
  let!(:user2)    { create(:user) }
P
Phil Hughes 已提交
9
  let!(:board)    { Boards::CreateService.new(project, user).execute }
P
Phil Hughes 已提交
10 11 12

  before do
    project.team << [user, :master]
P
Phil Hughes 已提交
13
    project.team << [user2, :master]
P
Phil Hughes 已提交
14 15 16
    login_as(user)
  end

P
Phil Hughes 已提交
17 18 19 20
  context 'no lists' do
    before do
      visit namespace_project_board_path(project.namespace, project)
    end
P
Phil Hughes 已提交
21

P
Phil Hughes 已提交
22 23 24
    it 'shows blank state' do
      expect(page).to have_selector('.board', count: 3)
      expect(page).to have_content('Welcome to your Issue Board!')
P
Phil Hughes 已提交
25 26
    end

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

P
Phil Hughes 已提交
34 35
    it 'creates default lists' do
      lists = ['Backlog', 'Development', 'Testing', 'Production', 'Ready', 'Done']
P
Phil Hughes 已提交
36

P
Phil Hughes 已提交
37 38 39 40 41 42 43 44 45
      page.within('.board-blank-state') do
        click_button('Add default lists')
      end
      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 已提交
46 47
  end

P
Phil Hughes 已提交
48
  context 'with lists' do
49
    let(:milestone)           { create(:milestone, project: project) }
P
Phil Hughes 已提交
50

P
Phil Hughes 已提交
51 52 53
    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 已提交
54
    let(:bug)         { create(:label, project: project, name: 'Bug') }
55 56
    let!(:backlog)    { create(:label, project: project, name: 'Backlog') }
    let!(:done)       { create(:label, project: project, name: 'Done') }
P
Phil Hughes 已提交
57 58 59 60

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

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

    before do
      visit namespace_project_board_path(project.namespace, project)

      sleep 1
    end

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

    it 'shows issues in lists' do
      page.within(all('.board')[1]) do
84 85
        expect(page.find('.board-header')).to have_content('2')
        expect(page).to have_selector('.card', count: 2)
P
Phil Hughes 已提交
86
      end
P
Phil Hughes 已提交
87

P
Phil Hughes 已提交
88 89 90 91 92
      page.within(all('.board')[2]) do
        expect(page.find('.board-header')).to have_content('2')
        expect(page).to have_selector('.card', count: 2)
      end
    end
P
Phil Hughes 已提交
93

P
Phil Hughes 已提交
94 95 96 97 98 99
    it 'shows confidential issues with icon' do
      page.within(first('.board')) do
        expect(page).to have_selector('.confidential-icon', count: 1)
      end
    end

P
Phil Hughes 已提交
100 101 102
    it 'allows user to delete board' do
      page.within(all('.board')[1]) do
        find('.board-delete').click
P
Phil Hughes 已提交
103
      end
P
Phil Hughes 已提交
104
      expect(page).to have_selector('.board', count: 3)
P
Phil Hughes 已提交
105 106
    end

107 108 109 110 111 112 113 114 115 116 117 118
    it 'removes checkmark in new list dropdown after deleting' do
      click_button 'Create new list'
      wait_for_ajax

      page.within(all('.board')[1]) do
        find('.board-delete').click
      end
      expect(page).to have_selector('.board', count: 3)

      expect(find(".js-board-list-#{planning.id}", visible: false)).not_to have_css('.is-active')
    end

119 120
    it 'infinite scrolls list' do
      50.times do
121
        create(:issue, project: project)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      end

      visit namespace_project_board_path(project.namespace, project)
      sleep 1

      page.within(first('.board')) do
        expect(page.find('.board-header')).to have_content('20')
        expect(page).to have_selector('.card', count: 20)

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

        expect(page.find('.board-header')).to have_content('40')
        expect(page).to have_selector('.card', count: 40)
      end
    end

P
Phil Hughes 已提交
138 139 140
    context 'backlog' do
      it 'shows issues in backlog with no labels' do
        page.within(first('.board')) do
P
Phil Hughes 已提交
141 142
          expect(page.find('.board-header')).to have_content('6')
          expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        end
      end

      it 'is searchable' do
        page.within(first('.board')) do
          find('.form-control').set issue1.title

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

      it 'clears search' do
        page.within(first('.board')) do
          find('.form-control').set issue1.title

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

          find('.board-search-clear-btn').click

P
Phil Hughes 已提交
162
          expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
163 164 165 166 167
        end
      end

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

P
Phil Hughes 已提交
169
        page.within(first('.board')) do
P
Phil Hughes 已提交
170 171
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
172
        end
P
Phil Hughes 已提交
173

P
Phil Hughes 已提交
174
        page.within(all('.board')[1]) do
175 176
          expect(page.find('.board-header')).to have_content('3')
          expect(page).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
177
        end
P
Phil Hughes 已提交
178 179 180
      end
    end

P
Phil Hughes 已提交
181 182 183 184 185 186 187 188 189
    context 'done' do
      it 'shows list of done issues' do
        expect(all('.board').last).to have_selector('.card', count: 1)
      end

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

        expect(all('.board').last).to have_selector('.card', count: 2)
P
Phil Hughes 已提交
190
        expect(all('.board').last).to have_content(issue9.title)
P
Phil Hughes 已提交
191 192 193 194 195 196
        expect(all('.board').last).not_to have_content(planning.title)
      end

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

197
        expect(all('.board')[1]).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
198 199 200 201 202 203 204
        expect(all('.board')[2]).to have_selector('.card', count: 1)
        expect(all('.board').last).to have_content(issue6.title)
        expect(all('.board').last).not_to have_content(planning.title)
      end
    end

    context 'lists' do
P
Phil Hughes 已提交
205 206 207 208 209 210 211
      it 'changes position of list' do
        drag_to(list_from_index: 1, list_to_index: 2, selector: '.js-board-handle')

        expect(all('.board')[1]).to have_content(development.title)
        expect(all('.board')[1]).to have_content(planning.title)
      end

P
Phil Hughes 已提交
212
      it 'moves between lists' do
213
        drag_to(list_from_index: 1, card_index: 1, list_to_index: 2)
P
Phil Hughes 已提交
214

215 216
        expect(all('.board')[1]).to have_selector('.card', count: 1)
        expect(all('.board')[2]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
217 218
        expect(all('.board')[2]).to have_content(issue6.title)
        expect(all('.board')[2].all('.card').last).not_to have_content(development.title)
P
Phil Hughes 已提交
219 220 221 222 223
      end

      it 'moves between lists' do
        drag_to(list_from_index: 2, list_to_index: 1)

224
        expect(all('.board')[1]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
225 226
        expect(all('.board')[2]).to have_selector('.card', count: 1)
        expect(all('.board')[1]).to have_content(issue7.title)
P
Phil Hughes 已提交
227
        expect(all('.board')[1].all('.card').first).not_to have_content(planning.title)
P
Phil Hughes 已提交
228 229 230 231 232
      end

      it 'moves from done' do
        drag_to(list_from_index: 3, list_to_index: 1)

233
        expect(all('.board')[1]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
234 235 236 237 238 239
        expect(all('.board')[1]).to have_content(issue8.title)
      end

      context 'issue card' do
        it 'shows assignee' do
          page.within(first('.board')) do
P
Phil Hughes 已提交
240
            expect(page).to have_selector('.avatar', count: 1)
P
Phil Hughes 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
          end
        end
      end

      context 'new list' do
        it 'shows all labels in new list dropdown' do
          click_button 'Create new list'

          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'

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

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

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
        it 'creates new list for Backlog label' do
          click_button 'Create new list'

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

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

        it 'creates new list for Done label' do
          click_button 'Create new list'

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

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

P
Phil Hughes 已提交
286 287
        it 'moves issues from backlog into new list' do
          page.within(first('.board')) do
P
Phil Hughes 已提交
288 289
            expect(page.find('.board-header')).to have_content('6')
            expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
290 291 292 293 294 295 296 297 298
          end

          click_button 'Create new list'

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

          page.within(first('.board')) do
P
Phil Hughes 已提交
299 300
            expect(page.find('.board-header')).to have_content('5')
            expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
301 302 303 304 305 306
          end
        end
      end
    end

    context 'filtering' do
P
Phil Hughes 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      it 'filters by author' do
        page.within '.issues-filters' do
          click_button('Author')

          page.within '.dropdown-menu-author' do
            click_link(user2.name)
          end

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

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

        page.within(all('.board')[1]) do
          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')

          page.within '.dropdown-menu-assignee' do
            click_link(user.name)
          end

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

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

        page.within(all('.board')[1]) do
          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
353
          click_button('Milestone')
P
Phil Hughes 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

          page.within '.milestone-filter' do
            click_link(milestone.title)
          end

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

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end

        page.within(all('.board')[1]) do
          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')

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
            find('.dropdown-menu-close').click
          end
        end

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

        page.within(all('.board')[1]) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end

394 395
      it 'infinite scrolls list with label filter' do
        50.times do
396
          create(:labeled_issue, project: project, labels: [testing])
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
        end

        page.within '.issues-filters' do
          click_button('Label')

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
            find('.dropdown-menu-close').click
          end
        end

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('20')
          expect(page).to have_selector('.card', count: 20)

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

          expect(page.find('.board-header')).to have_content('40')
          expect(page).to have_selector('.card', count: 40)
        end
      end

P
Phil Hughes 已提交
419 420 421 422 423 424 425 426 427 428 429 430
      it 'filters by multiple labels' do
        page.within '.issues-filters' do
          click_button('Label')

          page.within '.dropdown-menu-labels' do
            click_link(testing.title)
            click_link(bug.title)
            find('.dropdown-menu-close').click
          end
        end

        page.within(first('.board')) do
P
Phil Hughes 已提交
431 432
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
433 434 435 436 437 438 439 440 441 442 443
        end

        page.within(all('.board')[1]) do
          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')
P
Phil Hughes 已提交
444

P
Phil Hughes 已提交
445 446 447 448 449 450 451
          page.within '.dropdown-menu-labels' do
            click_link("No Label")
            find('.dropdown-menu-close').click
          end
        end

        page.within(first('.board')) do
P
Phil Hughes 已提交
452 453
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
454 455 456 457 458 459 460
        end

        page.within(all('.board')[1]) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end
      end
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482

      it 'filters by clicking label button on issue' do
        page.within '.issues-filters' do
          click_button('Label')

          page.within '.dropdown-menu-labels' do
            click_link(bug.title)
            find('.dropdown-menu-close').click
          end
        end

        page.within(first('.board')) do
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
        end

        page.within(all('.board')[1]) do
          expect(page.find('.board-header')).to have_content('0')
          expect(page).to have_selector('.card', count: 0)
        end

        page.within(first('.board')) do
P
Phil Hughes 已提交
483
          click_button(bug.title)
484

P
Phil Hughes 已提交
485
          expect(page).to have_selector('.card', count: 6)
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
        end

        page.within('.labels-filter') do
          expect(find('.dropdown-toggle-text')).not_to have_content(bug.title)
        end
      end

      it 'removes label filter by clicking label button on issue' do
        page.within(first('.board')) do
          page.within(first('.card')) do
            click_button(bug.title)
          end

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

        page.within('.labels-filter') do
          expect(find('.dropdown-toggle-text')).to have_content(bug.title)
        end
      end
P
Phil Hughes 已提交
506 507 508
    end
  end

P
Phil Hughes 已提交
509 510
  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}}});")
P
Phil Hughes 已提交
511 512 513
    sleep 1
  end
end