diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/helpers/search_helper_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/helpers/search_helper_spec.rb')
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 293 |
1 files changed, 292 insertions, 1 deletions
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index ad0705e4fbf..20718ad2f48 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -776,7 +776,7 @@ RSpec.describe SearchHelper do end context 'project data' do - let(:project) { create(:project) } + let_it_be(:project) { create(:project) } let(:project_metadata) { { project_path: project.path, issues_path: "/issues" } } let(:scope) { 'issues' } let(:code_search) { true } @@ -848,4 +848,295 @@ RSpec.describe SearchHelper do end end end + + describe '.search_navigation' do + using RSpec::Parameterized::TableSyntax + let(:user) { build(:user) } + let_it_be(:project) { build(:project) } + + before do + allow(self).to receive(:current_user).and_return(user) + allow(self).to receive(:can?).and_return(true) + allow(self).to receive(:project_search_tabs?).and_return(false) + allow(self).to receive(:feature_flag_tab_enabled?).and_return(false) + end + + context 'projects' do + where(:global_project, :condition) do + nil | true + ref(:project) | false + end + + with_them do + it 'data item condition is set correctly' do + @project = global_project + + expect(search_navigation[:projects][:condition]).to eq(condition) + end + end + end + + context 'code' do + where(:feature_flag_tab_enabled, :show_elasticsearch_tabs, :project_search_tabs, :condition) do + false | false | false | false + true | true | true | true + true | false | false | true + false | true | false | true + false | false | true | true + true | false | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(search_service).to receive(:show_elasticsearch_tabs?).and_return(show_elasticsearch_tabs) + allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_code_tab).and_return(feature_flag_tab_enabled) + allow(self).to receive(:project_search_tabs?).with(:blobs).and_return(project_search_tabs) + + expect(search_navigation[:blobs][:condition]).to eq(condition) + end + end + end + + context 'issues' do + where(:feature_flag_tab_enabled, :project_search_tabs, :condition) do + false | false | false + true | true | true + true | false | true + false | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_issues_tab).and_return(feature_flag_tab_enabled) + allow(self).to receive(:project_search_tabs?).with(:issues).and_return(project_search_tabs) + + expect(search_navigation[:issues][:condition]).to eq(condition) + end + end + end + + context 'merge requests' do + where(:feature_flag_tab_enabled, :project_search_tabs, :condition) do + false | false | false + true | true | true + true | false | true + false | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_merge_requests_tab).and_return(feature_flag_tab_enabled) + allow(self).to receive(:project_search_tabs?).with(:merge_requests).and_return(project_search_tabs) + + expect(search_navigation[:merge_requests][:condition]).to eq(condition) + end + end + end + + context 'wiki' do + where(:project_search_tabs, :show_elasticsearch_tabs, :condition) do + false | false | false + true | true | true + true | false | true + false | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(search_service).to receive(:show_elasticsearch_tabs?).and_return(show_elasticsearch_tabs) + allow(self).to receive(:project_search_tabs?).with(:wiki).and_return(project_search_tabs) + + expect(search_navigation[:wiki_blobs][:condition]).to eq(condition) + end + end + end + + context 'commits' do + where(:feature_flag_tab_enabled, :show_elasticsearch_tabs, :project_search_tabs, :condition) do + false | false | false | false + true | true | true | true + true | false | false | false + false | true | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(search_service).to receive(:show_elasticsearch_tabs?).and_return(show_elasticsearch_tabs) + allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_commits_tab).and_return(feature_flag_tab_enabled) + allow(self).to receive(:project_search_tabs?).with(:commits).and_return(project_search_tabs) + + expect(search_navigation[:commits][:condition]).to eq(condition) + end + end + end + + context 'comments' do + where(:show_elasticsearch_tabs, :project_search_tabs, :condition) do + true | true | true + false | false | false + true | false | true + false | true | true + end + + with_them do + it 'data item condition is set correctly' do + allow(search_service).to receive(:show_elasticsearch_tabs?).and_return(show_elasticsearch_tabs) + allow(self).to receive(:project_search_tabs?).with(:notes).and_return(project_search_tabs) + + expect(search_navigation[:notes][:condition]).to eq(condition) + end + end + end + + context 'milestones' do + where(:global_project, :project_search_tabs, :condition) do + ref(:project) | true | true + nil | false | true + ref(:project) | false | false + nil | true | true + end + + with_them do + it 'data item condition is set correctly' do + @project = global_project + allow(self).to receive(:project_search_tabs?).with(:milestones).and_return(project_search_tabs) + + expect(search_navigation[:milestones][:condition]).to eq(condition) + end + end + end + + context 'users' do + where(:show_user_search_tab, :condition) do + true | true + false | false + end + + with_them do + it 'data item condition is set correctly' do + allow(self).to receive(:show_user_search_tab?).and_return(show_user_search_tab) + + expect(search_navigation[:users][:condition]).to eq(condition) + end + end + end + + context 'snippet_titles' do + where(:global_project, :global_show_snippets, :condition) do + ref(:project) | true | false + nil | false | false + ref(:project) | false | false + nil | true | true + end + + with_them do + it 'data item condition is set correctly' do + @show_snippets = global_show_snippets + @project = global_project + + expect(search_navigation[:snippet_titles][:condition]).to eq(condition) + end + end + end + end + + describe '.search_navigation_json' do + using RSpec::Parameterized::TableSyntax + context 'with data' do + example_data_1 = { + projects: { label: _("Projects"), condition: true }, + blobs: { label: _("Code"), condition: false } + } + + example_data_2 = { + projects: { label: _("Projects"), condition: false }, + blobs: { label: _("Code"), condition: false } + } + + example_data_3 = { + projects: { label: _("Projects"), condition: true }, + blobs: { label: _("Code"), condition: true }, + epics: { label: _("Epics"), condition: true } + } + + where(:data, :matcher) do + example_data_1 | -> { include("projects") } + example_data_2 | -> { eq("{}") } + example_data_3 | -> { include("projects", "blobs", "epics") } + end + + with_them do + it 'converts correctly' do + allow(self).to receive(:search_navigation).with(no_args).and_return(data) + + expect(search_navigation_json).to instance_exec(&matcher) + end + end + end + end + + describe '.search_filter_link_json' do + using RSpec::Parameterized::TableSyntax + + context 'data' do + where(:scope, :label, :data, :search, :active_scope) do + "projects" | "Projects" | { qa_selector: 'projects_tab' } | nil | "projects" + "snippet_titles" | "Titles and Descriptions" | nil | { snippets: "test" } | "code" + "projects" | "Projects" | { qa_selector: 'projects_tab' } | nil | "issue" + "snippet_titles" | "Titles and Descriptions" | nil | { snippets: "test" } | "snippet_titles" + end + + with_them do + it 'converts correctly' do + @timeout = false + @scope = active_scope + @search_results = double + dummy_count = 1000 + allow(self).to receive(:search_path).with(any_args).and_return("link test") + + allow(@search_results).to receive(:formatted_count).with(scope).and_return(dummy_count) + allow(self).to receive(:search_count_path).with(any_args).and_return("test count link") + + current_scope = scope == active_scope + + expected = { + label: label, + scope: scope, + data: data, + link: "link test", + active: current_scope + } + + expected[:count] = dummy_count if current_scope + expected[:count_link] = "test count link" unless current_scope + + expect(search_filter_link_json(scope, label, data, search)).to eq(expected) + end + end + end + end + + describe 'show_elasticsearch_tabs' do + subject { search_service.show_elasticsearch_tabs? } + + let(:user) { build(:user) } + + before do + allow(self).to receive(:current_user).and_return(user) + end + + it { is_expected.to eq(false) } + end + + describe 'show_epics' do + subject { search_service.show_epics? } + + let(:user) { build(:user) } + + before do + allow(self).to receive(:current_user).and_return(user) + end + + it { is_expected.to eq(false) } + end end |