award_spec.rb 1.33 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1 2
require 'rails_helper'

3
describe 'Issue awards', :js do
Phil Hughes's avatar
Phil Hughes committed
4
  let(:user)      { create(:user) }
5
  let(:project)   { create(:project, :public) }
Phil Hughes's avatar
Phil Hughes committed
6 7 8 9
  let(:issue)     { create(:issue, project: project) }

  describe 'logged in' do
    before do
10
      sign_in(user)
11
      visit project_issue_path(project, issue)
12
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
13 14
    end

15
    it 'adds award to issue' do
Phil Hughes's avatar
Phil Hughes committed
16 17 18
      first('.js-emoji-btn').click
      expect(page).to have_selector('.js-emoji-btn.active')
      expect(first('.js-emoji-btn')).to have_content '1'
Z.J. van de Weg's avatar
Z.J. van de Weg committed
19

20
      visit project_issue_path(project, issue)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
21
      expect(first('.js-emoji-btn')).to have_content '1'
Phil Hughes's avatar
Phil Hughes committed
22 23
    end

24
    it 'removes award from issue' do
Phil Hughes's avatar
Phil Hughes committed
25 26 27
      first('.js-emoji-btn').click
      find('.js-emoji-btn.active').click
      expect(first('.js-emoji-btn')).to have_content '0'
Z.J. van de Weg's avatar
Z.J. van de Weg committed
28

29
      visit project_issue_path(project, issue)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
30
      expect(first('.js-emoji-btn')).to have_content '0'
Phil Hughes's avatar
Phil Hughes committed
31 32
    end

33
    it 'only has one menu on the page' do
Phil Hughes's avatar
Phil Hughes committed
34 35 36
      first('.js-add-award').click
      expect(page).to have_selector('.emoji-menu')

37
      expect(page).to have_selector('.emoji-menu', count: 1)
Phil Hughes's avatar
Phil Hughes committed
38 39 40 41 42
    end
  end

  describe 'logged out' do
    before do
43
      visit project_issue_path(project, issue)
44
      wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
45 46
    end

47
    it 'does not see award menu button' do
Phil Hughes's avatar
Phil Hughes committed
48 49 50 51
      expect(page).not_to have_selector('.js-award-holder')
    end
  end
end