Commit 23c5473c authored by Valery Sizov's avatar Valery Sizov

added spinach tests

parent 2c7d8678
No related merge requests found
......@@ -75,7 +75,7 @@ class @AwardsHandler
if custom_path
$(".awards-menu li").first().html().replace(/emoji\/.*\.png/, custom_path)
else
$("li[data-emoji='" + emoji + "'").html()
$("li[data-emoji='" + emoji + "']").html()
postEmoji: (emoji, callback) ->
......@@ -88,4 +88,4 @@ class @AwardsHandler
callback.call()
findEmojiIcon: (emoji) ->
$(".icon[data-emoji='" + emoji + "'")
\ No newline at end of file
$(".icon[data-emoji='" + emoji + "']")
\ No newline at end of file
......@@ -105,7 +105,11 @@ module IssuesHelper
end
def note_active_class(notes, current_user)
notes.pluck(:author_id).include?(current_user.id) ? "active" : ""
if current_user && notes.pluck(:author_id).include?(current_user.id)
"active"
else
""
end
end
# Required for Gitlab::Markdown::IssueReferenceFilter
......
......@@ -46,6 +46,7 @@ class Note < ActiveRecord::Base
validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' }
validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' }
validates :author, presence: true, if: ->(n) { n.is_award }
mount_uploader :attachment, AttachmentUploader
......
......@@ -6,6 +6,7 @@
.counter
= note.last.count
- if current_user
.dropdown.awards-controls
%a.add-award{"data-toggle" => "dropdown", "data-target" => "#", "href" => "#"}
= icon('plus-square-o')
......@@ -13,7 +14,8 @@
- emoji_list.each do |emoji|
%li{"data-emoji" => "#{emoji}"}= image_tag url_to_emoji(emoji), height: "20px", width: "20px"
:coffeescript
- if current_user
:coffeescript
post_emoji_url = "#{award_toggle_namespace_project_notes_path(@project.namespace, @project)}"
noteable_type = "#{votable.class}"
noteable_id = "#{votable.id}"
......
Feature: Award Emoji
Background:
Given I sign in as a user
And I own project "Shop"
And project "Shop" has issue "Bugfix"
And I visit "Bugfix" issue page
@javascript
Scenario: I add and remove award in the issue
Given I click to emoji-picker
And I click to emoji in the picker
Then I have award added
And I can remove it by clicking to icon
\ No newline at end of file
class Spinach::Features::AwardEmoji < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
include Select2Helper
step 'I visit "Bugfix" issue page' do
visit namespace_project_issue_path(@project.namespace, @project, @issue)
end
step 'I click to emoji-picker' do
page.within ".awards-controls" do
page.find(".add-award").click
end
end
step 'I click to emoji in the picker' do
page.within ".awards-menu" do
page.first("img").click
end
end
step 'I can remove it by clicking to icon' do
page.within ".awards" do
page.first(".award").click
expect(page).to_not have_selector ".award"
end
end
step 'I have award added' do
page.within ".awards" do
expect(page).to have_selector ".award"
expect(page.find(".award .counter")).to have_content "1"
end
end
step 'project "Shop" has issue "Bugfix"' do
@project = Project.find_by(name: "Shop")
@issue = create(:issue, title: "Bugfix", project: project)
end
end
......@@ -32,77 +32,6 @@ describe Note do
it { is_expected.to validate_presence_of(:project) }
end
describe '#votable?' do
it 'is true for issue notes' do
note = build(:note_on_issue)
expect(note).to be_votable
end
it 'is true for merge request notes' do
note = build(:note_on_merge_request)
expect(note).to be_votable
end
it 'is false for merge request diff notes' do
note = build(:note_on_merge_request_diff)
expect(note).not_to be_votable
end
it 'is false for commit notes' do
note = build(:note_on_commit)
expect(note).not_to be_votable
end
it 'is false for commit diff notes' do
note = build(:note_on_commit_diff)
expect(note).not_to be_votable
end
end
describe 'voting score' do
it 'recognizes a neutral note' do
note = build(:votable_note, note: 'This is not a +1 note')
expect(note).not_to be_upvote
expect(note).not_to be_downvote
end
it 'recognizes a neutral emoji note' do
note = build(:votable_note, note: "I would :+1: this, but I don't want to")
expect(note).not_to be_upvote
expect(note).not_to be_downvote
end
it 'recognizes a +1 note' do
note = build(:votable_note, note: '+1 for this')
expect(note).to be_upvote
end
it 'recognizes a +1 emoji as a vote' do
note = build(:votable_note, note: ':+1: for this')
expect(note).to be_upvote
end
it 'recognizes a thumbsup emoji as a vote' do
note = build(:votable_note, note: ':thumbsup: for this')
expect(note).to be_upvote
end
it 'recognizes a -1 note' do
note = build(:votable_note, note: '-1 for this')
expect(note).to be_downvote
end
it 'recognizes a -1 emoji as a vote' do
note = build(:votable_note, note: ':-1: for this')
expect(note).to be_downvote
end
it 'recognizes a thumbsdown emoji as a vote' do
note = build(:votable_note, note: ':thumbsdown: for this')
expect(note).to be_downvote
end
end
describe "Commit notes" do
let!(:note) { create(:note_on_commit, note: "+1 from me") }
let!(:commit) { note.noteable }
......@@ -139,10 +68,6 @@ describe Note do
it "should be recognized by #for_commit_diff_line?" do
expect(note).to be_for_commit_diff_line
end
it "should not be votable" do
expect(note).not_to be_votable
end
end
describe 'authorization' do
......
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