debian-mirror-gitlab/spec/helpers/search_helper_spec.rb

225 lines
7.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe SearchHelper do
# Override simple_sanitize for our testing purposes
def simple_sanitize(str)
str
end
describe 'search_autocomplete_source' do
context "with no current user" do
before do
allow(self).to receive(:current_user).and_return(nil)
end
2019-07-07 11:18:12 +05:30
it "returns nil" do
2015-04-26 12:48:37 +05:30
expect(search_autocomplete_opts("q")).to be_nil
2014-09-02 18:07:02 +05:30
end
end
2018-03-17 18:26:18 +05:30
context "with a standard user" do
2019-03-02 22:35:43 +05:30
let(:user) { create(:user) }
2014-09-02 18:07:02 +05:30
before do
allow(self).to receive(:current_user).and_return(user)
end
it "includes Help sections" do
2015-04-26 12:48:37 +05:30
expect(search_autocomplete_opts("hel").size).to eq(9)
2014-09-02 18:07:02 +05:30
end
it "includes default sections" do
2018-03-17 18:26:18 +05:30
expect(search_autocomplete_opts("dash").size).to eq(1)
end
it "does not include admin sections" do
expect(search_autocomplete_opts("admin").size).to eq(0)
2014-09-02 18:07:02 +05:30
end
2016-09-29 09:46:39 +05:30
it "does not allow regular expression in search term" do
expect(search_autocomplete_opts("(webhooks|api)").size).to eq(0)
end
2014-09-02 18:07:02 +05:30
it "includes the user's groups" do
create(:group).add_owner(user)
2015-04-26 12:48:37 +05:30
expect(search_autocomplete_opts("gro").size).to eq(1)
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
it "includes nested group" do
create(:group, :nested, name: 'foo').add_owner(user)
expect(search_autocomplete_opts('foo').size).to eq(1)
end
2014-09-02 18:07:02 +05:30
it "includes the user's projects" do
2017-09-10 17:25:29 +05:30
project = create(:project, namespace: create(:namespace, owner: user))
2015-04-26 12:48:37 +05:30
expect(search_autocomplete_opts(project.name).size).to eq(1)
2014-09-02 18:07:02 +05:30
end
2018-11-18 11:00:15 +05:30
it "includes the required project attrs" do
project = create(:project, namespace: create(:namespace, owner: user))
result = search_autocomplete_opts(project.name).first
expect(result.keys).to match_array(%i[category id value label url avatar_url])
end
it "includes the required group attrs" do
create(:group).add_owner(user)
result = search_autocomplete_opts("gro").first
expect(result.keys).to match_array(%i[category id label url avatar_url])
end
2016-09-13 17:45:13 +05:30
it "does not include the public group" do
group = create(:group)
2016-04-02 18:10:28 +05:30
expect(search_autocomplete_opts(group.name).size).to eq(0)
2015-11-26 14:37:03 +05:30
end
2014-09-02 18:07:02 +05:30
context "with a current project" do
2017-08-17 22:00:37 +05:30
before do
@project = create(:project, :repository)
end
2014-09-02 18:07:02 +05:30
it "includes project-specific sections" do
2015-04-26 12:48:37 +05:30
expect(search_autocomplete_opts("Files").size).to eq(1)
expect(search_autocomplete_opts("Commits").size).to eq(1)
2014-09-02 18:07:02 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
context 'with an admin user' do
let(:admin) { create(:admin) }
before do
allow(self).to receive(:current_user).and_return(admin)
end
it "includes admin sections" do
expect(search_autocomplete_opts("admin").size).to eq(1)
end
end
2014-09-02 18:07:02 +05:30
end
2017-09-10 17:25:29 +05:30
describe 'search_filter_input_options' do
context 'project' do
before do
@project = create(:project, :repository)
end
it 'includes id with type' do
expect(search_filter_input_options('type')[:id]).to eq('filtered-search-type')
end
it 'includes project-id' do
expect(search_filter_input_options('')[:data]['project-id']).to eq(@project.id)
end
2019-09-04 21:01:54 +05:30
it 'includes project endpoints' do
2019-09-30 21:07:59 +05:30
expect(search_filter_input_options('')[:data]['runner-tags-endpoint']).to eq(tag_list_admin_runners_path)
2019-09-04 21:01:54 +05:30
expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(project_labels_path(@project))
expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(project_milestones_path(@project))
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
it 'includes autocomplete=off flag' do
expect(search_filter_input_options('')[:autocomplete]).to eq('off')
end
2017-09-10 17:25:29 +05:30
end
context 'group' do
before do
@group = create(:group, name: 'group')
end
it 'does not includes project-id' do
expect(search_filter_input_options('')[:data]['project-id']).to eq(nil)
end
2019-09-04 21:01:54 +05:30
it 'includes group endpoints' do
2019-09-30 21:07:59 +05:30
expect(search_filter_input_options('')[:data]['runner-tags-endpoint']).to eq(tag_list_admin_runners_path)
2019-09-04 21:01:54 +05:30
expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(group_labels_path(@group))
expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(group_milestones_path(@group))
2017-09-10 17:25:29 +05:30
end
end
2019-02-15 15:39:39 +05:30
context 'dashboard' do
it 'does not include group-id and project-id' do
expect(search_filter_input_options('')[:data]['project-id']).to eq(nil)
expect(search_filter_input_options('')[:data]['group-id']).to eq(nil)
end
2019-09-04 21:01:54 +05:30
it 'includes dashboard endpoints' do
2019-09-30 21:07:59 +05:30
expect(search_filter_input_options('')[:data]['runner-tags-endpoint']).to eq(tag_list_admin_runners_path)
2019-09-04 21:01:54 +05:30
expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(dashboard_labels_path)
expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(dashboard_milestones_path)
2019-02-15 15:39:39 +05:30
end
end
end
describe 'search_history_storage_prefix' do
context 'project' do
it 'returns project full_path' do
@project = create(:project, :repository)
expect(search_history_storage_prefix).to eq(@project.full_path)
end
end
context 'group' do
it 'returns group full_path' do
@group = create(:group, :nested, name: 'group-name')
expect(search_history_storage_prefix).to eq(@group.full_path)
end
end
context 'dashboard' do
it 'returns dashboard' do
expect(search_history_storage_prefix).to eq("dashboard")
end
end
2017-09-10 17:25:29 +05:30
end
2019-10-12 21:52:04 +05:30
describe 'search_filter_link' do
it 'renders a search filter link for the current scope' do
@scope = 'projects'
@search_results = double
expect(@search_results).to receive(:formatted_count).with('projects').and_return('23')
link = search_filter_link('projects', 'Projects')
expect(link).to have_css('li.active')
expect(link).to have_link('Projects', href: search_path(scope: 'projects'))
expect(link).to have_css('span.badge.badge-pill:not(.js-search-count):not(.hidden):not([data-url])', text: '23')
end
it 'renders a search filter link for another scope' do
link = search_filter_link('projects', 'Projects')
count_path = search_count_path(scope: 'projects')
expect(link).to have_css('li:not([class="active"])')
expect(link).to have_link('Projects', href: search_path(scope: 'projects'))
expect(link).to have_css("span.badge.badge-pill.js-search-count.hidden[data-url='#{count_path}']", text: '')
end
it 'merges in the current search params and given params' do
expect(self).to receive(:params).and_return(
ActionController::Parameters.new(
search: 'hello',
scope: 'ignored',
other_param: 'ignored'
)
)
link = search_filter_link('projects', 'Projects', search: { project_id: 23 })
expect(link).to have_link('Projects', href: search_path(scope: 'projects', search: 'hello', project_id: 23))
end
it 'assigns given data attributes on the list container' do
link = search_filter_link('projects', 'Projects', data: { foo: 'bar' })
expect(link).to have_css('li[data-foo="bar"]')
end
end
2014-09-02 18:07:02 +05:30
end