2013-10-20 01:05:20 -04:00
|
|
|
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
|
2013-12-14 08:43:48 -05:00
|
|
|
before do
|
|
|
|
allow(self).to receive(:current_user).and_return(nil)
|
|
|
|
end
|
2013-10-20 01:05:20 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it "returns nil" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(search_autocomplete_opts("q")).to be_nil
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-03 01:49:19 -04:00
|
|
|
context "with a standard user" do
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:user) { create(:user) }
|
2013-10-20 01:05:20 -04:00
|
|
|
|
|
|
|
before do
|
2013-12-14 08:43:48 -05:00
|
|
|
allow(self).to receive(:current_user).and_return(user)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes Help sections" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(search_autocomplete_opts("hel").size).to eq(9)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes default sections" do
|
2017-09-03 01:49:19 -04:00
|
|
|
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)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
2016-09-07 07:40:14 -04:00
|
|
|
it "does not allow regular expression in search term" do
|
|
|
|
expect(search_autocomplete_opts("(webhooks|api)").size).to eq(0)
|
|
|
|
end
|
|
|
|
|
2013-10-20 01:05:20 -04:00
|
|
|
it "includes the user's groups" do
|
|
|
|
create(:group).add_owner(user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(search_autocomplete_opts("gro").size).to eq(1)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
2017-01-27 08:52:50 -05:00
|
|
|
it "includes nested group" do
|
|
|
|
create(:group, :nested, name: 'foo').add_owner(user)
|
|
|
|
expect(search_autocomplete_opts('foo').size).to eq(1)
|
|
|
|
end
|
|
|
|
|
2013-10-20 01:05:20 -04:00
|
|
|
it "includes the user's projects" do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, namespace: create(:namespace, owner: user))
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(search_autocomplete_opts(project.name).size).to eq(1)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
|
2018-07-17 01:48:39 -04:00
|
|
|
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-07-25 14:16:19 -04:00
|
|
|
it "does not include the public group" do
|
2015-12-28 06:32:18 -05:00
|
|
|
group = create(:group)
|
2016-02-04 11:00:32 -05:00
|
|
|
expect(search_autocomplete_opts(group.name).size).to eq(0)
|
2015-11-05 05:38:00 -05:00
|
|
|
end
|
|
|
|
|
2013-10-20 01:05:20 -04:00
|
|
|
context "with a current project" do
|
2017-01-25 17:10:32 -05:00
|
|
|
before do
|
|
|
|
@project = create(:project, :repository)
|
|
|
|
end
|
2013-10-20 01:05:20 -04:00
|
|
|
|
|
|
|
it "includes project-specific sections" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(search_autocomplete_opts("Files").size).to eq(1)
|
|
|
|
expect(search_autocomplete_opts("Commits").size).to eq(1)
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-03 01:49:19 -04:00
|
|
|
|
|
|
|
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
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|
2017-08-02 05:27:24 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'includes project base-endpoint' do
|
|
|
|
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq(project_path(@project))
|
|
|
|
end
|
2017-11-20 02:49:13 -05:00
|
|
|
|
|
|
|
it 'includes autocomplete=off flag' do
|
|
|
|
expect(search_filter_input_options('')[:autocomplete]).to eq('off')
|
|
|
|
end
|
2017-08-02 05:27:24 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
it 'includes group base-endpoint' do
|
|
|
|
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/groups#{group_path(@group)}")
|
|
|
|
end
|
|
|
|
end
|
2018-11-07 00:25:08 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'includes dashboard base-endpoint' do
|
|
|
|
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/dashboard")
|
|
|
|
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-08-02 05:27:24 -04:00
|
|
|
end
|
2013-10-20 01:05:20 -04:00
|
|
|
end
|