award_emoji_spec.rb 3.2 KB
Newer Older
1 2 3
require 'rails_helper'

describe 'Awards Emoji', feature: true do
4 5
  include WaitForAjax

6
  let!(:project)   { create(:project, :public) }
7
  let!(:user)      { create(:user) }
8 9 10 11
  let(:issue) do
    create(:issue,
           assignee: @user,
           project: project)
12 13
  end

14
  context 'authorized user' do
15
    before do
16 17
      project.team << [user, :master]
      login_as(user)
18 19
    end

20 21
    describe 'Click award emoji from issue#show' do
      let!(:note) {  create(:note_on_issue, noteable: issue, project: issue.project, note: "Hello world") }
22

23 24
      before do
        visit namespace_project_issue_path(project.namespace, project, issue)
25 26
      end

27
      it 'increments the thumbsdown emoji', js: true do
E
Eric Eastwood 已提交
28
        find('[data-name="thumbsdown"]').click
29
        wait_for_ajax
30 31 32
        expect(thumbsdown_emoji).to have_text("1")
      end

33 34
      context 'click the thumbsup emoji' do
        it 'increments the thumbsup emoji', js: true do
E
Eric Eastwood 已提交
35
          find('[data-name="thumbsup"]').click
36 37 38 39 40 41 42
          wait_for_ajax
          expect(thumbsup_emoji).to have_text("1")
        end

        it 'decrements the thumbsdown emoji', js: true do
          expect(thumbsdown_emoji).to have_text("0")
        end
43
      end
44

45 46
      context 'click the thumbsdown emoji' do
        it 'increments the thumbsdown emoji', js: true do
E
Eric Eastwood 已提交
47
          find('[data-name="thumbsdown"]').click
48 49 50
          wait_for_ajax
          expect(thumbsdown_emoji).to have_text("1")
        end
51

52 53 54
        it 'decrements the thumbsup emoji', js: true do
          expect(thumbsup_emoji).to have_text("0")
        end
55 56
      end

57 58 59 60 61 62 63 64
      it 'toggles the smiley emoji on a note', js: true do
        toggle_smiley_emoji(true)

        within('.note-awards') do
          expect(find(emoji_counter)).to have_text("1")
        end

        toggle_smiley_emoji(false)
65

66 67 68
        within('.note-awards') do
          expect(page).not_to have_selector(emoji_counter)
        end
69
      end
M
mhasbini 已提交
70 71 72 73 74 75 76 77 78 79 80 81

      context 'execute /award slash command' do
        it 'toggles the emoji award on noteable', js: true do
          execute_slash_command('/award :100:')

          expect(find(noteable_award_counter)).to have_text("1")

          execute_slash_command('/award :100:')

          expect(page).not_to have_selector(noteable_award_counter)
        end
      end
82
    end
83 84
  end

85 86 87 88 89 90
  context 'unauthorized user', js: true do
    before do
      visit namespace_project_issue_path(project.namespace, project, issue)
    end

    it 'has disabled emoji button' do
91
      expect(first('.award-control')[:class]).to have_text('disabled')
92 93 94
    end
  end

M
mhasbini 已提交
95 96 97 98 99 100 101 102 103
  def execute_slash_command(cmd)
    within('.js-main-target-form') do
      fill_in 'note[note]', with: cmd
      click_button 'Comment'
    end

    wait_for_ajax
  end

104
  def thumbsup_emoji
105
    page.all(emoji_counter).first
106 107 108
  end

  def thumbsdown_emoji
109 110 111 112 113 114 115
    page.all(emoji_counter).last
  end

  def emoji_counter
    'span.js-counter'
  end

M
mhasbini 已提交
116 117 118 119
  def noteable_award_counter
    ".awards .active"
  end

120 121 122 123 124 125
  def toggle_smiley_emoji(status)
    within('.note') do
      find('.note-emoji-button').click
    end

    unless status
E
Eric Eastwood 已提交
126
      first('[data-name="smiley"]').click
127
    else
E
Eric Eastwood 已提交
128
      find('[data-name="smiley"]').click
129 130 131
    end

    wait_for_ajax
132 133
  end
end