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

describe 'Issue Boards', feature: true, js: true do
  let(:project)   { create(:project) }
  let(:user)      { create(:user) }
P
Phil Hughes 已提交
6
  let!(:user2)    { create(:user) }
P
Phil Hughes 已提交
7
  let!(:board)    { Boards::CreateService.new(project, user).execute }
P
Phil Hughes 已提交
8 9 10

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

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

P
Phil Hughes 已提交
20 21 22
    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 已提交
23 24
    end

25
    it 'hides the blank state when clicking nevermind button' do
P
Phil Hughes 已提交
26 27 28 29
      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 已提交
30 31
    end

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

P
Phil Hughes 已提交
35 36 37 38 39 40 41 42 43
      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 已提交
44 45
  end

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

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

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

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

    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
82 83
        expect(page.find('.board-header')).to have_content('2')
        expect(page).to have_selector('.card', count: 2)
P
Phil Hughes 已提交
84
      end
P
Phil Hughes 已提交
85

P
Phil Hughes 已提交
86 87 88 89 90
      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 已提交
91

P
Phil Hughes 已提交
92 93 94 95 96 97
    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 已提交
98 99 100
    it 'allows user to delete board' do
      page.within(all('.board')[1]) do
        find('.board-delete').click
P
Phil Hughes 已提交
101
      end
P
Phil Hughes 已提交
102
      expect(page).to have_selector('.board', count: 3)
P
Phil Hughes 已提交
103 104
    end

105 106
    it 'infinite scrolls list' do
      50.times do
107
        create(:issue, project: project)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
      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 已提交
124 125 126
    context 'backlog' do
      it 'shows issues in backlog with no labels' do
        page.within(first('.board')) do
P
Phil Hughes 已提交
127 128
          expect(page.find('.board-header')).to have_content('6')
          expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        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 已提交
148
          expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
149 150 151 152 153
        end
      end

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

P
Phil Hughes 已提交
155
        page.within(first('.board')) do
P
Phil Hughes 已提交
156 157
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
158
        end
P
Phil Hughes 已提交
159

P
Phil Hughes 已提交
160
        page.within(all('.board')[1]) do
161 162
          expect(page.find('.board-header')).to have_content('3')
          expect(page).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
163
        end
P
Phil Hughes 已提交
164 165 166
      end
    end

P
Phil Hughes 已提交
167 168 169 170 171 172 173 174 175
    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 已提交
176
        expect(all('.board').last).to have_content(issue9.title)
P
Phil Hughes 已提交
177 178 179 180 181 182
        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)

183
        expect(all('.board')[1]).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
184 185 186 187 188 189 190
        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 已提交
191 192 193 194 195 196 197
      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 已提交
198
      it 'moves between lists' do
199
        drag_to(list_from_index: 1, card_index: 1, list_to_index: 2)
P
Phil Hughes 已提交
200

201 202
        expect(all('.board')[1]).to have_selector('.card', count: 1)
        expect(all('.board')[2]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
203 204
        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 已提交
205 206 207 208 209
      end

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

210
        expect(all('.board')[1]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
211 212
        expect(all('.board')[2]).to have_selector('.card', count: 1)
        expect(all('.board')[1]).to have_content(issue7.title)
P
Phil Hughes 已提交
213
        expect(all('.board')[1].all('.card').first).not_to have_content(planning.title)
P
Phil Hughes 已提交
214 215 216 217 218
      end

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

219
        expect(all('.board')[1]).to have_selector('.card', count: 3)
P
Phil Hughes 已提交
220 221 222 223 224 225
        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 已提交
226
            expect(page).to have_selector('.avatar', count: 1)
P
Phil Hughes 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
          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

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
        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 已提交
272 273
        it 'moves issues from backlog into new list' do
          page.within(first('.board')) do
P
Phil Hughes 已提交
274 275
            expect(page.find('.board-header')).to have_content('6')
            expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
276 277 278 279 280 281 282 283 284
          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 已提交
285 286
            expect(page.find('.board-header')).to have_content('5')
            expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
287 288 289 290 291 292
          end
        end
      end
    end

    context 'filtering' do
P
Phil Hughes 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305 306 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
      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
339
          click_button('Milestone')
P
Phil Hughes 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 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

          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

380 381
      it 'infinite scrolls list with label filter' do
        50.times do
382
          create(:labeled_issue, project: project, labels: [testing])
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
        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 已提交
405 406 407 408 409 410 411 412 413 414 415 416
      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 已提交
417 418
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
419 420 421 422 423 424 425 426 427 428 429
        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 已提交
430

P
Phil Hughes 已提交
431 432 433 434 435 436 437
          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 已提交
438 439
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
440 441 442 443 444 445 446
        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
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

      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 已提交
469
          click_button(bug.title)
470

P
Phil Hughes 已提交
471
          expect(page).to have_selector('.card', count: 6)
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
        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 已提交
492 493 494
    end
  end

P
Phil Hughes 已提交
495 496
  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 已提交
497 498 499
    sleep 1
  end
end