boards_spec.rb 15.3 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
P
Phil Hughes 已提交
47 48
    let(:milestone) { create(:milestone, project: project) }

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') }
P
Phil Hughes 已提交
53 54 55 56

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

P
Phil Hughes 已提交
57
    let!(:confidential_issue) { create(:issue, :confidential, project: project, author: user) }
P
Phil Hughes 已提交
58
    let!(:issue1) { create(:issue, project: project, assignee: user) }
P
Phil Hughes 已提交
59
    let!(:issue2) { create(:issue, project: project, author: user2) }
P
Phil Hughes 已提交
60 61
    let!(:issue3) { create(:issue, project: project) }
    let!(:issue4) { create(:issue, project: project) }
P
Phil Hughes 已提交
62
    let!(:issue5) { create(:labeled_issue, project: project, labels: [planning], milestone: milestone) }
P
Phil Hughes 已提交
63 64 65
    let!(:issue6) { create(:labeled_issue, project: project, labels: [planning, development]) }
    let!(:issue7) { create(:labeled_issue, project: project, labels: [development]) }
    let!(:issue8) { create(:closed_issue, project: project) }
P
Phil Hughes 已提交
66
    let!(:issue9) { create(:labeled_issue, project: project, labels: [testing, bug]) }
P
Phil Hughes 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

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

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

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

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

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

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

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

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

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

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

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

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

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

        expect(all('.board')[1]).to have_selector('.card', count: 3)
        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 已提交
224
            expect(page).to have_selector('.avatar', count: 1)
P
Phil Hughes 已提交
225 226 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

        it 'moves issues from backlog into new list' do
          page.within(first('.board')) do
P
Phil Hughes 已提交
252 253
            expect(page.find('.board-header')).to have_content('6')
            expect(page).to have_selector('.card', count: 6)
P
Phil Hughes 已提交
254 255 256 257 258 259 260 261 262
          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 已提交
263 264
            expect(page.find('.board-header')).to have_content('5')
            expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
265 266 267 268 269 270
          end
        end
      end
    end

    context 'filtering' do
P
Phil Hughes 已提交
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
      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
          click_button('Milestone')

          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

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
      it 'infinite scrolls list with label filter' do
        50.times do
          create(:labeled_issue, project: project, labels: [testing])
        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 已提交
383 384 385 386 387 388 389 390 391 392 393 394
      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 已提交
395 396
          expect(page.find('.board-header')).to have_content('1')
          expect(page).to have_selector('.card', count: 1)
P
Phil Hughes 已提交
397 398 399 400 401 402 403 404 405 406 407
        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 已提交
408

P
Phil Hughes 已提交
409 410 411 412 413 414 415
          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 已提交
416 417
          expect(page.find('.board-header')).to have_content('5')
          expect(page).to have_selector('.card', count: 5)
P
Phil Hughes 已提交
418 419 420 421 422 423 424
        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
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446

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

P
Phil Hughes 已提交
449
          expect(page).to have_selector('.card', count: 6)
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
        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 已提交
470 471 472
    end
  end

P
Phil Hughes 已提交
473 474
  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 已提交
475 476 477
    sleep 1
  end
end