debian-mirror-gitlab/spec/features/issues/award_emoji_spec.rb

147 lines
3.6 KiB
Ruby
Raw Normal View History

2016-06-02 11:05:42 +05:30
require 'rails_helper'
2017-09-10 17:25:29 +05:30
describe 'Awards Emoji' do
2017-08-17 22:00:37 +05:30
let!(:project) { create(:project, :public) }
2016-06-02 11:05:42 +05:30
let!(:user) { create(:user) }
2017-08-17 22:00:37 +05:30
let(:issue) do
create(:issue,
assignees: [user],
project: project)
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
context 'authorized user' do
2016-06-02 11:05:42 +05:30
before do
2017-08-17 22:00:37 +05:30
project.team << [user, :master]
2017-09-10 17:25:29 +05:30
sign_in(user)
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
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)
2017-09-10 17:25:29 +05:30
visit project_issue_path(project, issue)
wait_for_requests
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
# 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)
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe 'Click award emoji from issue#show' do
let!(:note) { create(:note_on_issue, noteable: issue, project: issue.project, note: "Hello world") }
before do
2017-09-10 17:25:29 +05:30
visit project_issue_path(project, issue)
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2016-09-13 17:45:13 +05:30
it 'increments the thumbsdown emoji', js: true do
2017-08-17 22:00:37 +05:30
find('[data-name="thumbsdown"]').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-06-02 11:05:42 +05:30
expect(thumbsdown_emoji).to have_text("1")
end
2017-08-17 22:00:37 +05:30
context 'click the thumbsup emoji' do
it 'increments the thumbsup emoji', js: true do
find('[data-name="thumbsup"]').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
expect(thumbsup_emoji).to have_text("1")
end
it 'decrements the thumbsdown emoji', js: true do
expect(thumbsdown_emoji).to have_text("0")
end
2016-06-02 11:05:42 +05:30
end
2016-11-03 12:29:30 +05:30
2017-08-17 22:00:37 +05:30
context 'click the thumbsdown emoji' do
it 'increments the thumbsdown emoji', js: true do
find('[data-name="thumbsdown"]').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
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
2016-11-03 12:29:30 +05:30
2017-08-17 22:00:37 +05:30
toggle_smiley_emoji(false)
within('.note-awards') do
expect(page).not_to have_selector(emoji_counter)
end
2016-11-03 12:29:30 +05:30
end
2017-09-10 17:25:29 +05:30
context 'execute /award quick action' do
2017-08-17 22:00:37 +05:30
it 'toggles the emoji award on noteable', js: true do
2017-09-10 17:25:29 +05:30
execute_quick_action('/award :100:')
2017-08-17 22:00:37 +05:30
expect(find(noteable_award_counter)).to have_text("1")
2017-09-10 17:25:29 +05:30
execute_quick_action('/award :100:')
2016-11-03 12:29:30 +05:30
2017-08-17 22:00:37 +05:30
expect(page).not_to have_selector(noteable_award_counter)
end
2016-11-03 12:29:30 +05:30
end
end
2016-06-02 11:05:42 +05:30
end
2017-08-17 22:00:37 +05:30
context 'unauthorized user', js: true do
before do
2017-09-10 17:25:29 +05:30
visit project_issue_path(project, issue)
2017-08-17 22:00:37 +05:30
end
it 'has disabled emoji button' do
expect(first('.award-control')[:class]).to have_text('disabled')
end
end
2017-09-10 17:25:29 +05:30
def execute_quick_action(cmd)
2017-08-17 22:00:37 +05:30
within('.js-main-target-form') do
fill_in 'note[note]', with: cmd
click_button 'Comment'
end
2017-09-10 17:25:29 +05:30
wait_for_requests
2017-08-17 22:00:37 +05:30
end
2016-06-02 11:05:42 +05:30
def thumbsup_emoji
2016-11-03 12:29:30 +05:30
page.all(emoji_counter).first
2016-06-02 11:05:42 +05:30
end
def thumbsdown_emoji
2016-11-03 12:29:30 +05:30
page.all(emoji_counter).last
end
def emoji_counter
'span.js-counter'
end
2017-08-17 22:00:37 +05:30
def noteable_award_counter
".awards .active"
end
2016-11-03 12:29:30 +05:30
def toggle_smiley_emoji(status)
within('.note') do
find('.note-emoji-button').click
end
unless status
2017-08-17 22:00:37 +05:30
first('[data-name="smiley"]').click
2016-11-03 12:29:30 +05:30
else
2017-08-17 22:00:37 +05:30
find('[data-name="smiley"]').click
2016-11-03 12:29:30 +05:30
end
2017-09-10 17:25:29 +05:30
wait_for_requests
2016-06-02 11:05:42 +05:30
end
end