summaryrefslogtreecommitdiff
path: root/spec/finders/autocomplete
diff options
context:
space:
mode:
authorAlexis Reigel <alexis.reigel.ext@siemens.com>2018-11-15 16:10:10 +0100
committerAlexis Reigel <alexis.reigel.ext@siemens.com>2019-02-27 20:19:49 +0100
commit2e05292562e71deeff9b76bd3c696eca2a65a491 (patch)
tree3cceb216c54d7c55376b53421d273147d03b06ba /spec/finders/autocomplete
parent315361e025f5e490631d611b0f43b1814d1b0edc (diff)
downloadgitlab-ce-2e05292562e71deeff9b76bd3c696eca2a65a491.tar.gz
use lazy ajax filter dropdown for runner tags
the potential number of available runner tags is too large to load it statically to a dropdown. we use the same lazy loaded dropdown as is used for the users dropdown already.
Diffstat (limited to 'spec/finders/autocomplete')
-rw-r--r--spec/finders/autocomplete/acts_as_taggable_on/tags_finder_spec.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/finders/autocomplete/acts_as_taggable_on/tags_finder_spec.rb b/spec/finders/autocomplete/acts_as_taggable_on/tags_finder_spec.rb
new file mode 100644
index 00000000000..9d1fac20362
--- /dev/null
+++ b/spec/finders/autocomplete/acts_as_taggable_on/tags_finder_spec.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Autocomplete::ActsAsTaggableOn::TagsFinder do
+ describe '#execute' do
+ context 'with empty params' do
+ it 'returns all tags' do
+ create :ci_runner, tag_list: ['tag1']
+ create :ci_runner, tag_list: ['tag2']
+
+ tags = described_class.new(taggable_type: Ci::Runner, params: {}).execute.map(&:name)
+
+ expect(tags).to match_array %w(tag1 tag2)
+ end
+ end
+
+ context 'filter by search' do
+ context 'with an empty search term' do
+ it 'returns an empty collection' do
+ create :ci_runner, tag_list: ['tag1']
+ create :ci_runner, tag_list: ['tag2']
+
+ tags = described_class.new(taggable_type: Ci::Runner, params: { search: '' }).execute.map(&:name)
+
+ expect(tags).to be_empty
+ end
+ end
+
+ context 'with a search containing 2 characters' do
+ it 'returns the tag that strictly matches the search term' do
+ create :ci_runner, tag_list: ['t1']
+ create :ci_runner, tag_list: ['t11']
+
+ tags = described_class.new(taggable_type: Ci::Runner, params: { search: 't1' }).execute.map(&:name)
+
+ expect(tags).to match_array ['t1']
+ end
+ end
+
+ context 'with a search containing 3 characters' do
+ it 'returns the tag that partially matches the search term' do
+ create :ci_runner, tag_list: ['tag1']
+ create :ci_runner, tag_list: ['tag11']
+
+ tags = described_class.new(taggable_type: Ci::Runner, params: { search: 'ag1' }).execute.map(&:name)
+
+ expect(tags).to match_array %w(tag1 tag11)
+ end
+ end
+ end
+
+ context 'limit' do
+ it 'limits the result set by the limit constant' do
+ stub_const("#{described_class}::LIMIT", 1)
+
+ create :ci_runner, tag_list: ['tag1']
+ create :ci_runner, tag_list: ['tag2']
+
+ tags = described_class.new(taggable_type: Ci::Runner, params: { search: 'tag' }).execute
+
+ expect(tags.count).to eq 1
+ end
+ end
+ end
+end