diff options
author | Sean McGivern <sean@gitlab.com> | 2018-11-01 11:07:09 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-11-01 11:07:09 +0000 |
commit | c49f57fe430edeac9a5f2423dac7afb80ff72576 (patch) | |
tree | 23c8e45711083748f18d81a9f40f3b464e4b62cb /spec | |
parent | f7c0a18b8a061bfea650897b22dce24d712c6439 (diff) | |
parent | 8df7e6021b0da30e3b7550ca83cd9ab3f991c235 (diff) | |
download | gitlab-ce-c49f57fe430edeac9a5f2423dac7afb80ff72576.tar.gz |
Merge branch 'engwan/gitlab-ce-44012-filter-reactions-none-any'
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/issues/filtered_search/dropdown_emoji_spec.rb | 20 | ||||
-rw-r--r-- | spec/finders/issues_finder_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/concerns/awardable_spec.rb | 18 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 20 | ||||
-rw-r--r-- | spec/support/helpers/filtered_search_helpers.rb | 8 |
5 files changed, 72 insertions, 10 deletions
diff --git a/spec/features/issues/filtered_search/dropdown_emoji_spec.rb b/spec/features/issues/filtered_search/dropdown_emoji_spec.rb index be229e8aa7d..c42fcd92a36 100644 --- a/spec/features/issues/filtered_search/dropdown_emoji_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_emoji_spec.rb @@ -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 @@ -121,13 +121,29 @@ describe 'Dropdown emoji', :js do send_keys_to_filtered_search(':') end + it 'selects `None`' do + find('#js-dropdown-my-reaction .filter-dropdown-item', text: 'None').click + + expect(page).to have_css(js_dropdown_emoji, visible: false) + expect_tokens([reaction_token('none', false)]) + expect_filtered_search_input_empty + end + + it 'selects `Any`' do + find('#js-dropdown-my-reaction .filter-dropdown-item', text: 'Any').click + + expect(page).to have_css(js_dropdown_emoji, visible: false) + expect_tokens([reaction_token('any', false)]) + expect_filtered_search_input_empty + end + it 'fills in the my-reaction name' do click_emoji('thumbsup') 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 diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 0b3e2709ade..c0488c83bd8 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -372,6 +372,22 @@ describe IssuesFinder do end context 'filtering by reaction name' do + context 'user searches by no reaction' do + let(:params) { { my_reaction_emoji: 'None' } } + + it 'returns issues that the user did not react to' do + expect(issues).to contain_exactly(issue2, issue4) + end + end + + context 'user searches by any reaction' do + let(:params) { { my_reaction_emoji: 'Any' } } + + it 'returns issues that the user reacted to' do + expect(issues).to contain_exactly(issue1, issue3) + end + end + context 'user searches by "thumbsup" reaction' do let(:params) { { my_reaction_emoji: 'thumbsup' } } diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb index 69083bdc125..debc02fa51f 100644 --- a/spec/models/concerns/awardable_spec.rb +++ b/spec/models/concerns/awardable_spec.rb @@ -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 diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index 7813f6bc550..5dbe967e4fe 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -196,14 +196,24 @@ describe API::Issues do expect_paginated_array_response(size: 3) end - it 'returns issues reacted by the authenticated user by the given emoji' 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') - get api('/issues', user2), my_reaction_emoji: award_emoji.name, scope: 'all' + create(:award_emoji, awardable: issue, user: user2, name: 'thumbsup') - expect_paginated_array_response(size: 1) - expect(first_issue['id']).to eq(issue2.id) + get api('/issues', user2), my_reaction_emoji: 'Any', scope: 'all' + + expect_paginated_array_response(size: 2) + end + + it 'returns issues not reacted by the authenticated user' do + issue2 = create(:issue, project: project, author: user, assignees: [user]) + create(:award_emoji, awardable: issue2, user: user2, name: 'star') + + get api('/issues', user2), my_reaction_emoji: 'None', scope: 'all' + + expect_paginated_array_response(size: 2) end it 'returns issues matching given search string for title' do diff --git a/spec/support/helpers/filtered_search_helpers.rb b/spec/support/helpers/filtered_search_helpers.rb index 5f42ff77fb2..6569feec39b 100644 --- a/spec/support/helpers/filtered_search_helpers.rb +++ b/spec/support/helpers/filtered_search_helpers.rb @@ -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 |