summaryrefslogtreecommitdiff
path: root/spec/features/issues/award_emoji_spec.rb
blob: 81ae54c7a108caf7e548488a7af21b170ca4ae3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
require 'rails_helper'

describe 'Awards Emoji', feature: true do
  let!(:project)   { create(:project, :public) }
  let!(:user)      { create(:user) }
  let(:issue) do
    create(:issue,
           assignees: [user],
           project: project)
  end

  context 'authorized user' do
    before do
      project.team << [user, :master]
      login_as(user)
    end

    describe 'visiting an issue with a legacy award emoji that is not valid anymore' do
      before do
        # The `heart_tip` emoji is not valid anymore so we need to skip validation
        issue.award_emoji.build(user: user, name: 'heart_tip').save!(validate: false)
        visit namespace_project_issue_path(project.namespace, project, issue)
        wait_for_requests
      end

      # Regression test: https://gitlab.com/gitlab-org/gitlab-ce/issues/29529
      it 'does not shows a 500 page', js: true do
        expect(page).to have_text(issue.title)
      end
    end

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

      before do
        visit namespace_project_issue_path(project.namespace, project, issue)
        wait_for_requests
      end

      it 'increments the thumbsdown emoji', js: true do
        find('[data-name="thumbsdown"]').click
        wait_for_requests
        expect(thumbsdown_emoji).to have_text("1")
      end

      context 'click the thumbsup emoji' do
        it 'increments the thumbsup emoji', js: true do
          find('[data-name="thumbsup"]').click
          wait_for_requests
          expect(thumbsup_emoji).to have_text("1")
        end

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

      context 'click the thumbsdown emoji' do
        it 'increments the thumbsdown emoji', js: true do
          find('[data-name="thumbsdown"]').click
          wait_for_requests
          expect(thumbsdown_emoji).to have_text("1")
        end

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

      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)

        within('.note-awards') do
          expect(page).not_to have_selector(emoji_counter)
        end
      end

      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
    end
  end

  context 'unauthorized user', js: true do
    before do
      visit namespace_project_issue_path(project.namespace, project, issue)
    end

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

  def execute_slash_command(cmd)
    within('.js-main-target-form') do
      fill_in 'note[note]', with: cmd
      click_button 'Comment'
    end

    wait_for_requests
  end

  def thumbsup_emoji
    page.all(emoji_counter).first
  end

  def thumbsdown_emoji
    page.all(emoji_counter).last
  end

  def emoji_counter
    'span.js-counter'
  end

  def noteable_award_counter
    ".awards .active"
  end

  def toggle_smiley_emoji(status)
    within('.note') do
      find('.note-emoji-button').click
    end

    unless status
      first('[data-name="smiley"]').click
    else
      find('[data-name="smiley"]').click
    end

    wait_for_requests
  end
end