Commit 8df7e602 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix tests

parent 69dcab23
......@@ -480,12 +480,13 @@ class IssuableFinder
def by_my_reaction_emoji(items)
if params[:my_reaction_emoji].present? && current_user
items =
if filter_by_no_reaction?
items = items.not_awarded(current_user)
items.not_awarded(current_user)
elsif filter_by_any_reaction?
items = items.awarded_any(current_user)
items.awarded(current_user)
else
items = items.awarded(current_user, params[:my_reaction_emoji])
items.awarded(current_user, params[:my_reaction_emoji])
end
end
......
......@@ -13,13 +13,13 @@ module Awardable
end
class_methods do
def awarded(user, name)
def awarded(user, name = nil)
sql = <<~EOL
EXISTS (
SELECT TRUE
FROM award_emoji
WHERE user_id = :user_id AND
name = :name AND
#{"name = :name AND" if name.present?}
awardable_type = :awardable_type AND
awardable_id = #{self.arel_table.name}.id
)
......@@ -28,20 +28,6 @@ module Awardable
where(sql, user_id: user.id, name: name, awardable_type: self.name)
end
def awarded_any(user)
sql = <<~EOL
EXISTS (
SELECT TRUE
FROM award_emoji
WHERE user_id = :user_id AND
awardable_type = :awardable_type AND
awardable_id = #{self.arel_table.name}.id
)
EOL
where(sql, user_id: user.id, awardable_type: self.name)
end
def not_awarded(user)
sql = <<~EOL
NOT EXISTS (
......
......@@ -92,7 +92,7 @@ describe 'Dropdown emoji', :js do
it 'shows the most populated emoji at top of dropdown' do
send_keys_to_filtered_search('my-reaction:')
expect(first('#js-dropdown-my-reaction li')).to have_content(award_emoji_star.name)
expect(first('#js-dropdown-my-reaction .filter-dropdown li')).to have_content(award_emoji_star.name)
end
end
......@@ -122,18 +122,18 @@ describe 'Dropdown emoji', :js do
end
it 'selects `None`' do
find('#js-dropdown-assignee .filter-dropdown-item', text: 'None').click
find('#js-dropdown-my-reaction .filter-dropdown-item', text: 'None').click
expect(page).to have_css(js_dropdown_emoji, visible: false)
expect_tokens([emoji_token('none')])
expect_tokens([reaction_token('none', false)])
expect_filtered_search_input_empty
end
it 'selects `Any`' do
find('#js-dropdown-assignee .filter-dropdown-item', text: 'Any').click
find('#js-dropdown-my-reaction .filter-dropdown-item', text: 'Any').click
expect(page).to have_css(js_dropdown_emoji, visible: false)
expect_tokens([emoji_token('any')])
expect_tokens([reaction_token('any', false)])
expect_filtered_search_input_empty
end
......@@ -143,7 +143,7 @@ describe 'Dropdown emoji', :js do
wait_for_requests
expect(page).to have_css(js_dropdown_emoji, visible: false)
expect_tokens([emoji_token('thumbsup')])
expect_tokens([reaction_token('thumbsup')])
expect_filtered_search_input_empty
end
end
......
......@@ -24,13 +24,29 @@ describe Awardable do
end
end
describe ".awarded" do
describe "#awarded" do
it "filters by user and emoji name" do
expect(Issue.awarded(award_emoji.user, "thumbsup")).to be_empty
expect(Issue.awarded(award_emoji.user, "thumbsdown")).to eq [issue]
expect(Issue.awarded(award_emoji2.user, "thumbsup")).to eq [issue2]
expect(Issue.awarded(award_emoji2.user, "thumbsdown")).to be_empty
end
it "filters by user and any emoji" do
issue3 = create(:issue)
create(:award_emoji, awardable: issue3, name: "star", user: award_emoji.user)
create(:award_emoji, awardable: issue3, name: "star", user: award_emoji2.user)
expect(Issue.awarded(award_emoji.user)).to eq [issue, issue3]
expect(Issue.awarded(award_emoji2.user)).to eq [issue2, issue3]
end
end
describe "#not_awarded" do
it "returns issues not awarded by user" do
expect(Issue.not_awarded(award_emoji.user)).to eq [issue2]
expect(Issue.not_awarded(award_emoji2.user)).to eq [issue]
end
end
end
......
......@@ -198,7 +198,7 @@ describe API::Issues do
it 'returns issues reacted by the authenticated user' do
issue2 = create(:issue, project: project, author: user, assignees: [user])
award_emoji = create(:award_emoji, awardable: issue2, user: user2, name: 'star')
create(:award_emoji, awardable: issue2, user: user2, name: 'star')
create(:award_emoji, awardable: issue, user: user2, name: 'thumbsup')
......
......@@ -120,8 +120,12 @@ module FilteredSearchHelpers
create_token('Label', label_name, symbol)
end
def emoji_token(emoji_name = nil)
{ name: 'My-Reaction', emoji_name: emoji_name }
def reaction_token(reaction_name = nil, is_emoji = true)
if is_emoji
{ name: 'My-Reaction', emoji_name: reaction_name }
else
create_token('My-Reaction', reaction_name)
end
end
def default_placeholder
......
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