new_issue_spec.rb 2.41 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1 2
require 'rails_helper'

3
describe 'Issue Boards new issue', js: true do
4 5
  let(:project) { create(:empty_project, :public) }
  let(:board)   { create(:board, project: project) }
6
  let!(:list)   { create(:list, board: board, position: 0) }
Phil Hughes's avatar
Phil Hughes committed
7 8 9 10 11 12
  let(:user)    { create(:user) }

  context 'authorized user' do
    before do
      project.team << [user, :master]

13
      sign_in(user)
Phil Hughes's avatar
Phil Hughes committed
14

15
      visit project_board_path(project, board)
16
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
17

Phil Hughes's avatar
Phil Hughes committed
18
      expect(page).to have_selector('.board', count: 3)
Phil Hughes's avatar
Phil Hughes committed
19 20 21
    end

    it 'displays new issue button' do
22
      expect(first('.board')).to have_selector('.issue-count-badge-add-button', count: 1)
Phil Hughes's avatar
Phil Hughes committed
23 24
    end

25
    it 'does not display new issue button in closed list' do
Phil Hughes's avatar
Phil Hughes committed
26
      page.within('.board:nth-child(3)') do
27
        expect(page).not_to have_selector('.issue-count-badge-add-button')
Phil Hughes's avatar
Phil Hughes committed
28 29 30 31 32
      end
    end

    it 'shows form when clicking button' do
      page.within(first('.board')) do
33
        find('.issue-count-badge-add-button').click
Phil Hughes's avatar
Phil Hughes committed
34 35 36 37 38 39 40

        expect(page).to have_selector('.board-new-issue-form')
      end
    end

    it 'hides form when clicking cancel' do
      page.within(first('.board')) do
41
        find('.issue-count-badge-add-button').click
Phil Hughes's avatar
Phil Hughes committed
42 43 44 45 46

        expect(page).to have_selector('.board-new-issue-form')

        click_button 'Cancel'

Phil Hughes's avatar
Phil Hughes committed
47
        expect(page).not_to have_selector('.board-new-issue-form')
Phil Hughes's avatar
Phil Hughes committed
48 49 50 51 52
      end
    end

    it 'creates new issue' do
      page.within(first('.board')) do
53
        find('.issue-count-badge-add-button').click
Phil Hughes's avatar
Phil Hughes committed
54 55 56 57 58 59 60
      end

      page.within(first('.board-new-issue-form')) do
        find('.form-control').set('bug')
        click_button 'Submit issue'
      end

61
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
62

63
      page.within(first('.board .issue-count-badge-count')) do
Phil Hughes's avatar
Phil Hughes committed
64 65 66
        expect(page).to have_content('1')
      end
    end
67 68 69

    it 'shows sidebar when creating new issue' do
      page.within(first('.board')) do
70
        find('.issue-count-badge-add-button').click
71 72 73 74 75 76 77
      end

      page.within(first('.board-new-issue-form')) do
        find('.form-control').set('bug')
        click_button 'Submit issue'
      end

78
      wait_for_requests
79 80 81

      expect(page).to have_selector('.issue-boards-sidebar')
    end
Phil Hughes's avatar
Phil Hughes committed
82 83 84 85
  end

  context 'unauthorized user' do
    before do
86
      visit project_board_path(project, board)
87
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
88 89 90
    end

    it 'does not display new issue button' do
91
      expect(page).to have_selector('.issue-count-badge-add-button', count: 0)
Phil Hughes's avatar
Phil Hughes committed
92 93 94
    end
  end
end