From 2e05292562e71deeff9b76bd3c696eca2a65a491 Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Thu, 15 Nov 2018 16:10:10 +0100 Subject: 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. --- .../acts_as_taggable_on/tags_finder_spec.rb | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 spec/finders/autocomplete/acts_as_taggable_on/tags_finder_spec.rb (limited to 'spec/finders') 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 -- cgit v1.2.3