Commit 44876032 authored by Phil Hughes's avatar Phil Hughes Committed by Fatih Acet

Added tests for issues

parent 797acde0
......@@ -9,13 +9,13 @@
= image_tag avatar_icon(note.author), alt: '', class: 'avatar s40'
.timeline-content
.note-header
- if note_editable?(note)
.note-actions
- if current_user
.award-menu-holder.note-action-award-holder.js-award-holder.js-award-action-btn{ data: { target: "##{dom_id(note)} .js-awards-block" } }
= link_to '#', title: 'Award emoji', class: 'note-award-control js-add-award', data: { award_menu_url: emojis_path } do
= icon('smile-o', {class: "award-control-icon award-control-icon-normal"})
= icon('spinner spin', {class: "award-control-icon award-control-icon-loading"})
- if note_editable?(note)
= link_to '#', title: 'Edit comment', class: 'js-note-edit' do
= icon('pencil-square-o')
......
require 'rails_helper'
feature 'Issue awards', js: true, feature: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
let!(:note) { create(:note_on_issue, project: project, noteable: issue, note: 'Looks good!') }
describe 'logged in' do
before do
login_as(user)
visit namespace_project_issue_path(project.namespace, project, issue)
end
it 'should add award to issue' do
first('.js-emoji-btn').click
expect(page).to have_selector('.js-emoji-btn.active')
expect(first('.js-emoji-btn')).to have_content '1'
end
it 'should remove award from issue' do
first('.js-emoji-btn').click
find('.js-emoji-btn.active').click
expect(first('.js-emoji-btn')).to have_content '0'
end
it 'should show award menu button in notes' do
page.within('.note') do
expect(page).to have_selector('.js-award-action-btn')
end
end
it 'should not show award bar on note if no awards given' do
page.within('.note') do
expect(find('.js-awards-block', visible: false)).not_to be_visible
end
end
it 'should be able to show award menu when clicking add award button in note' do
show_note_award_menu
end
it 'should only have one menu on the page' do
first('.js-add-award').click
expect(page).to have_selector('.emoji-menu')
page.within('.note') do
find('.js-add-award').click
expect(page).to have_selector('.emoji-menu', count: 1)
end
end
it 'should add award to note' do
show_note_award_menu
award_on_note
page.within('.note') do
expect(find('.js-awards-block')).to be_visible
expect(find('.js-awards-block')).to have_selector('.active')
end
end
it 'should remove award from note' do
show_note_award_menu
award_on_note
page.within('.note') do
expect(find('.js-awards-block')).to be_visible
expect(find('.js-awards-block')).to have_selector('.active')
end
remove_award_on_note
sleep 0.5
page.within('.note') do
expect(find('.js-awards-block', visible: false)).not_to be_visible
expect(find('.js-awards-block', visible: false)).not_to have_selector('.active')
end
end
it 'should not hide award bar on notes with more than 1 award' do
show_note_award_menu
award_on_note
show_note_award_menu
award_on_note(2)
page.within('.note') do
expect(find('.js-awards-block')).to be_visible
expect(find('.js-awards-block')).to have_selector('.active')
end
remove_award_on_note
page.within('.note') do
expect(find('.js-awards-block')).to be_visible
end
end
end
describe 'logged out' do
before do
visit namespace_project_issue_path(project.namespace, project, issue)
end
it 'should not see award menu button' do
expect(page).not_to have_selector('.js-award-holder')
end
it 'should not see award menu button in note' do
page.within('.note') do
expect(page).not_to have_selector('.js-award-action-btn')
end
end
end
def show_note_award_menu
page.within('.note') do
find('.js-add-award').click
expect(page).to have_selector('.emoji-menu')
end
end
def award_on_note(index = 1)
page.within('.note') do
page.within('.emoji-menu') do
buttons = all('.js-emoji-btn')
buttons[index].click
end
end
end
def remove_award_on_note
page.within('.note') do
page.within('.js-awards-block') do
first('.js-emoji-btn').click
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment