diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 03:08:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-09 03:08:54 +0300 |
commit | bded2fb7888ecf5af057a1d879ea9d85c2fea060 (patch) | |
tree | 5e9506e3f962290f727a7fad1ccb1fb759a3461f | |
parent | 6869f07304d5bcea12ec61ca6362259f3c72fdf8 (diff) |
Add latest changes from gitlab-org/gitlab@master
18 files changed, 140 insertions, 74 deletions
diff --git a/app/assets/javascripts/search/index.js b/app/assets/javascripts/search/index.js index 1e4b1e36514..f5684cebbf9 100644 --- a/app/assets/javascripts/search/index.js +++ b/app/assets/javascripts/search/index.js @@ -15,7 +15,7 @@ export const initSearchApp = () => { const store = createStore({ query, navigation, - useNewNavigation: gon.use_new_navigation, + useSidebarNavigation: gon.use_new_navigation, }); initTopbar(store); diff --git a/app/assets/javascripts/search/sidebar/components/app.vue b/app/assets/javascripts/search/sidebar/components/app.vue index af4d93dc033..cd289be4c05 100644 --- a/app/assets/javascripts/search/sidebar/components/app.vue +++ b/app/assets/javascripts/search/sidebar/components/app.vue @@ -1,7 +1,7 @@ <script> import { mapState, mapGetters } from 'vuex'; -import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue'; -import ScopeNewNavigation from '~/search/sidebar/components/scope_new_navigation.vue'; +import ScopeLegacyNavigation from '~/search/sidebar/components/scope_legacy_navigation.vue'; +import ScopeSidebarNavigation from '~/search/sidebar/components/scope_sidebar_navigation.vue'; import SidebarPortal from '~/super_sidebar/components/sidebar_portal.vue'; import { SCOPE_ISSUES, SCOPE_MERGE_REQUESTS, SCOPE_BLOB } from '../constants'; import IssuesFilters from './issues_filters.vue'; @@ -11,13 +11,14 @@ export default { name: 'GlobalSearchSidebar', components: { IssuesFilters, - ScopeNavigation, - ScopeNewNavigation, + ScopeLegacyNavigation, + ScopeSidebarNavigation, LanguageFilter, SidebarPortal, }, computed: { - ...mapState(['urlQuery', 'useNewNavigation']), + // useSidebarNavigation refers to whether the new left sidebar navigation is enabled + ...mapState(['useSidebarNavigation']), ...mapGetters(['currentScope']), showIssueAndMergeFilters() { return this.currentScope === SCOPE_ISSUES || this.currentScope === SCOPE_MERGE_REQUESTS; @@ -28,7 +29,9 @@ export default { showLabelFilter() { return this.currentScope === SCOPE_ISSUES; }, - showOldNavigation() { + showScopeNavigation() { + // showScopeNavigation refers to whether the scope navigation should be shown + // while the legacy navigation is being used and there are no search results the scope navigation has to be hidden return Boolean(this.currentScope); }, }, @@ -36,18 +39,18 @@ export default { </script> <template> - <section v-if="useNewNavigation"> + <section v-if="useSidebarNavigation"> <sidebar-portal> - <scope-new-navigation /> + <scope-sidebar-navigation /> <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </sidebar-portal> </section> <section - v-else + v-else-if="showScopeNavigation" class="search-sidebar gl-display-flex gl-flex-direction-column gl-md-mr-5 gl-mb-6 gl-mt-5" > - <scope-navigation /> + <scope-legacy-navigation /> <issues-filters v-if="showIssueAndMergeFilters" /> <language-filter v-if="showBlobFilter" /> </section> diff --git a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue b/app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue index b29a8d13425..e682369d60b 100644 --- a/app/assets/javascripts/search/sidebar/components/scope_navigation.vue +++ b/app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue @@ -8,7 +8,7 @@ import { NAV_LINK_DEFAULT_CLASSES, NAV_LINK_COUNT_DEFAULT_CLASSES } from '../con import { slugifyWithUnderscore } from '../../../lib/utils/text_utility'; export default { - name: 'ScopeNavigation', + name: 'ScopeLegacyNavigation', i18n: { countOverLimitLabel: s__('GlobalSearch|Result count is over limit.'), }, @@ -80,6 +80,6 @@ export default { </span> </gl-nav-item> </gl-nav> - <hr class="gl-mt-3 gl-mb-5 gl-border-gray-100 gl-md-display-none" /> + <hr class="gl-mt-5 gl-mx-5 gl-mb-0 gl-border-gray-100 gl-md-display-none" /> </nav> </template> diff --git a/app/assets/javascripts/search/sidebar/components/scope_new_navigation.vue b/app/assets/javascripts/search/sidebar/components/scope_sidebar_navigation.vue index 86b7cc577a6..3707e152e47 100644 --- a/app/assets/javascripts/search/sidebar/components/scope_new_navigation.vue +++ b/app/assets/javascripts/search/sidebar/components/scope_sidebar_navigation.vue @@ -6,7 +6,7 @@ import NavItem from '~/super_sidebar/components/nav_item.vue'; import { NAV_LINK_DEFAULT_CLASSES, NAV_LINK_COUNT_DEFAULT_CLASSES } from '../constants'; export default { - name: 'ScopeNewNavigation', + name: 'ScopeSidebarNavigation', i18n: { countOverLimitLabel: s__('GlobalSearch|Result count is over limit.'), }, diff --git a/app/assets/javascripts/search/store/index.js b/app/assets/javascripts/search/store/index.js index 634f8f7a7fa..2478518c157 100644 --- a/app/assets/javascripts/search/store/index.js +++ b/app/assets/javascripts/search/store/index.js @@ -7,11 +7,11 @@ import createState from './state'; Vue.use(Vuex); -export const getStoreConfig = ({ query, navigation, useNewNavigation }) => ({ +export const getStoreConfig = (storeInitValues) => ({ actions, getters, mutations, - state: createState({ query, navigation, useNewNavigation }), + state: createState(storeInitValues), }); const createStore = (config) => new Vuex.Store(getStoreConfig(config)); diff --git a/app/assets/javascripts/search/store/state.js b/app/assets/javascripts/search/store/state.js index a62b6728819..c897d4108a8 100644 --- a/app/assets/javascripts/search/store/state.js +++ b/app/assets/javascripts/search/store/state.js @@ -1,7 +1,7 @@ import { cloneDeep } from 'lodash'; import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from './constants'; -const createState = ({ query, navigation, useNewNavigation }) => ({ +const createState = ({ query, navigation, useSidebarNavigation }) => ({ urlQuery: cloneDeep(query), query, groups: [], @@ -14,7 +14,7 @@ const createState = ({ query, navigation, useNewNavigation }) => ({ }, sidebarDirty: false, navigation, - useNewNavigation, + useSidebarNavigation, aggregations: { error: false, fetching: false, diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 6f675e1120c..9415e7d4dc3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -177,7 +177,11 @@ module ProjectsHelper abilities = Array(search_tab_ability_map[tab]) - abilities.any? { |ability| can?(current_user, ability, @project) } + if @project.respond_to?(:each) # support multi-project select + @project.any? { |project| abilities.any? { |ability| can?(current_user, ability, project) } } + else + abilities.any? { |ability| can?(current_user, ability, @project) } + end end def can_change_visibility_level?(project, current_user) @@ -616,7 +620,8 @@ module ProjectsHelper commits: :read_code, merge_requests: :read_merge_request, notes: [:read_merge_request, :read_code, :read_issue, :read_snippet], - members: :read_project_member + users: :read_project_member, + wiki_blobs: :read_wiki ) end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 7f0916ca316..1d58239aea9 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -457,35 +457,53 @@ module SearchHelper result end - def code_tab_condition + def show_code_search_tab? return true if project_search_tabs?(:blobs) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_code_tab) end - def wiki_tab_condition - return true if project_search_tabs?(:wiki) + def show_wiki_search_tab? + return true if project_search_tabs?(:wiki_blobs) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_wiki_tab) end - def commits_tab_condition + def show_commits_search_tab? return true if project_search_tabs?(:commits) @project.nil? && search_service.show_elasticsearch_tabs? && feature_flag_tab_enabled?(:global_search_commits_tab) end + def show_issues_search_tab? + return true if project_search_tabs?(:issues) + + @project.nil? && feature_flag_tab_enabled?(:global_search_issues_tab) + end + + def show_merge_requests_search_tab? + return true if project_search_tabs?(:merge_requests) + + @project.nil? && feature_flag_tab_enabled?(:global_search_merge_requests_tab) + end + + def show_comments_search_tab? + return true if project_search_tabs?(:notes) + + @project.nil? && search_service.show_elasticsearch_tabs? + end + # search page scope navigation def search_navigation { projects: { sort: 1, label: _("Projects"), data: { qa_selector: 'projects_tab' }, condition: @project.nil? }, - blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: code_tab_condition }, + blobs: { sort: 2, label: _("Code"), data: { qa_selector: 'code_tab' }, condition: show_code_search_tab? }, # sort: 3 is reserved for EE items - issues: { sort: 4, label: _("Issues"), condition: project_search_tabs?(:issues) || feature_flag_tab_enabled?(:global_search_issues_tab) }, - merge_requests: { sort: 5, label: _("Merge requests"), condition: project_search_tabs?(:merge_requests) || feature_flag_tab_enabled?(:global_search_merge_requests_tab) }, - wiki_blobs: { sort: 6, label: _("Wiki"), condition: wiki_tab_condition }, - commits: { sort: 7, label: _("Commits"), condition: commits_tab_condition }, - notes: { sort: 8, label: _("Comments"), condition: project_search_tabs?(:notes) || search_service.show_elasticsearch_tabs? }, + issues: { sort: 4, label: _("Issues"), condition: show_issues_search_tab? }, + merge_requests: { sort: 5, label: _("Merge requests"), condition: show_merge_requests_search_tab? }, + wiki_blobs: { sort: 6, label: _("Wiki"), condition: show_wiki_search_tab? }, + commits: { sort: 7, label: _("Commits"), condition: show_commits_search_tab? }, + notes: { sort: 8, label: _("Comments"), condition: show_comments_search_tab? }, milestones: { sort: 9, label: _("Milestones"), condition: project_search_tabs?(:milestones) || @project.nil? }, users: { sort: 10, label: _("Users"), condition: show_user_search_tab? }, snippet_titles: { sort: 11, label: _("Titles and Descriptions"), search: { snippets: true, group_id: nil, project_id: nil }, condition: search_service.show_snippets? && @project.nil? } @@ -576,7 +594,7 @@ module SearchHelper end def show_user_search_tab? - return project_search_tabs?(:members) if @project + return project_search_tabs?(:users) if @project return false unless can?(current_user, :read_users_list) return true if @group diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index 85ca0b850f5..f4c0a743ef0 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -5,7 +5,8 @@ module Search include Search::Filter include Gitlab::Utils::StrongMemoize - ALLOWED_SCOPES = %w(issues merge_requests milestones users).freeze + DEFAULT_SCOPE = 'projects' + ALLOWED_SCOPES = %w(projects issues merge_requests milestones users).freeze attr_accessor :current_user, :params @@ -34,7 +35,7 @@ module Search def scope strong_memoize(:scope) do - allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects' + allowed_scopes.include?(params[:scope]) ? params[:scope] : DEFAULT_SCOPE end end end diff --git a/app/services/search/project_service.rb b/app/services/search/project_service.rb index d30c500df14..71314f85984 100644 --- a/app/services/search/project_service.rb +++ b/app/services/search/project_service.rb @@ -4,7 +4,9 @@ module Search class ProjectService include Search::Filter include Gitlab::Utils::StrongMemoize - ALLOWED_SCOPES = %w(notes issues merge_requests milestones wiki_blobs commits users).freeze + include ProjectsHelper + + ALLOWED_SCOPES = %w(blobs issues merge_requests wiki_blobs commits notes milestones users).freeze attr_accessor :project, :current_user, :params @@ -31,7 +33,11 @@ module Search def scope strong_memoize(:scope) do - allowed_scopes.include?(params[:scope]) ? params[:scope] : 'blobs' + next params[:scope] if allowed_scopes.include?(params[:scope]) && project_search_tabs?(params[:scope].to_sym) + + allowed_scopes.find do |scope| + project_search_tabs?(scope.to_sym) + end end end end diff --git a/doc/development/ee_features.md b/doc/development/ee_features.md index bc997c37e66..f81486d17a8 100644 --- a/doc/development/ee_features.md +++ b/doc/development/ee_features.md @@ -548,6 +548,9 @@ EE-specific models should `extend EE::Model`. For example, if EE has a specific `Tanuki` model, you would place it in `ee/app/models/ee/tanuki.rb`. +ActiveRecord `enums` should be entirely +[defined in FOSS](database/creating_enums.md#all-of-the-keyvalue-pairs-should-be-defined-in-foss). + ### Code in `app/views/` It's a very frequent problem that EE is adding some specific view code in a CE diff --git a/qa/qa/page/search/results.rb b/qa/qa/page/search/results.rb index 769f8accfca..a04fd9092d1 100644 --- a/qa/qa/page/search/results.rb +++ b/qa/qa/page/search/results.rb @@ -4,7 +4,7 @@ module QA module Page module Search class Results < QA::Page::Base - view 'app/assets/javascripts/search/sidebar/components/scope_navigation.vue' do + view 'app/assets/javascripts/search/sidebar/components/scope_legacy_navigation.vue' do element :code_tab, ':data-qa-selector="qaSelectorValue(item)"' # rubocop:disable QA/ElementWithPattern element :projects_tab, ':data-qa-selector="qaSelectorValue(item)"' # rubocop:disable QA/ElementWithPattern end diff --git a/spec/frontend/branches/components/delete_merged_branches_spec.js b/spec/frontend/branches/components/delete_merged_branches_spec.js index 4d8b887efd3..3e47e76622d 100644 --- a/spec/frontend/branches/components/delete_merged_branches_spec.js +++ b/spec/frontend/branches/components/delete_merged_branches_spec.js @@ -44,7 +44,7 @@ const findConfirmationButton = () => const findCancelButton = () => wrapper.findByTestId('delete-merged-branches-cancel-button'); const findFormInput = () => wrapper.findComponent(GlFormInput); const findForm = () => wrapper.find('form'); -const submitFormSpy = () => jest.spyOn(wrapper.vm.$refs.form, 'submit'); +const submitFormSpy = () => jest.spyOn(findForm().element, 'submit'); describe('Delete merged branches component', () => { beforeEach(() => { diff --git a/spec/frontend/search/sidebar/components/app_spec.js b/spec/frontend/search/sidebar/components/app_spec.js index e1911534928..ba492833ec4 100644 --- a/spec/frontend/search/sidebar/components/app_spec.js +++ b/spec/frontend/search/sidebar/components/app_spec.js @@ -4,7 +4,8 @@ import Vuex from 'vuex'; import { MOCK_QUERY } from 'jest/search/mock_data'; import GlobalSearchSidebar from '~/search/sidebar/components/app.vue'; import IssuesFilters from '~/search/sidebar/components/issues_filters.vue'; -import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue'; +import ScopeLegacyNavigation from '~/search/sidebar/components/scope_legacy_navigation.vue'; +import ScopeSidebarNavigation from '~/search/sidebar/components/scope_sidebar_navigation.vue'; import LanguageFilter from '~/search/sidebar/components/language_filter/index.vue'; Vue.use(Vuex); @@ -12,22 +13,16 @@ Vue.use(Vuex); describe('GlobalSearchSidebar', () => { let wrapper; - const actionSpies = { - applyQuery: jest.fn(), - resetQuery: jest.fn(), - }; - const getterSpies = { currentScope: jest.fn(() => 'issues'), }; - const createComponent = (initialState, featureFlags) => { + const createComponent = (initialState = {}, featureFlags = {}) => { const store = new Vuex.Store({ state: { urlQuery: MOCK_QUERY, ...initialState, }, - actions: actionSpies, getters: getterSpies, }); @@ -43,13 +38,14 @@ describe('GlobalSearchSidebar', () => { const findSidebarSection = () => wrapper.find('section'); const findFilters = () => wrapper.findComponent(IssuesFilters); - const findSidebarNavigation = () => wrapper.findComponent(ScopeNavigation); + const findScopeLegacyNavigation = () => wrapper.findComponent(ScopeLegacyNavigation); + const findScopeSidebarNavigation = () => wrapper.findComponent(ScopeSidebarNavigation); const findLanguageAggregation = () => wrapper.findComponent(LanguageFilter); describe('renders properly', () => { describe('always', () => { beforeEach(() => { - createComponent({}); + createComponent(); }); it(`shows section`, () => { expect(findSidebarSection().exists()).toBe(true); @@ -77,12 +73,24 @@ describe('GlobalSearchSidebar', () => { }); }); - describe('renders navigation', () => { + describe.each` + currentScope | sidebarNavShown | legacyNavShown + ${'issues'} | ${false} | ${true} + ${''} | ${false} | ${false} + ${'issues'} | ${true} | ${false} + ${''} | ${true} | ${false} + `('renders navigation', ({ currentScope, sidebarNavShown, legacyNavShown }) => { beforeEach(() => { - createComponent({}); + getterSpies.currentScope = jest.fn(() => currentScope); + createComponent({ useSidebarNavigation: sidebarNavShown }); }); - it('shows the vertical navigation', () => { - expect(findSidebarNavigation().exists()).toBe(true); + + it(`${!legacyNavShown ? 'hides' : 'shows'} the legacy navigation`, () => { + expect(findScopeLegacyNavigation().exists()).toBe(legacyNavShown); + }); + + it(`${!sidebarNavShown ? 'hides' : 'shows'} the sidebar navigation`, () => { + expect(findScopeSidebarNavigation().exists()).toBe(sidebarNavShown); }); }); }); diff --git a/spec/frontend/search/sidebar/components/scope_navigation_spec.js b/spec/frontend/search/sidebar/components/scope_legacy_navigation_spec.js index e8737384f27..6a94da31a1b 100644 --- a/spec/frontend/search/sidebar/components/scope_navigation_spec.js +++ b/spec/frontend/search/sidebar/components/scope_legacy_navigation_spec.js @@ -3,11 +3,11 @@ import { shallowMount } from '@vue/test-utils'; import Vue from 'vue'; import Vuex from 'vuex'; import { MOCK_QUERY, MOCK_NAVIGATION } from 'jest/search/mock_data'; -import ScopeNavigation from '~/search/sidebar/components/scope_navigation.vue'; +import ScopeLegacyNavigation from '~/search/sidebar/components/scope_legacy_navigation.vue'; Vue.use(Vuex); -describe('ScopeNavigation', () => { +describe('ScopeLegacyNavigation', () => { let wrapper; const actionSpies = { @@ -29,7 +29,7 @@ describe('ScopeNavigation', () => { getters: getterSpies, }); - wrapper = shallowMount(ScopeNavigation, { + wrapper = shallowMount(ScopeLegacyNavigation, { store, }); }; diff --git a/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js b/spec/frontend/search/sidebar/components/scope_sidebar_navigation_spec.js index 5207665f883..f31a7c8fa5d 100644 --- a/spec/frontend/search/sidebar/components/scope_new_navigation_spec.js +++ b/spec/frontend/search/sidebar/components/scope_sidebar_navigation_spec.js @@ -1,13 +1,13 @@ import { mount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; -import ScopeNewNavigation from '~/search/sidebar/components/scope_new_navigation.vue'; +import ScopeSidebarNavigation from '~/search/sidebar/components/scope_sidebar_navigation.vue'; import NavItem from '~/super_sidebar/components/nav_item.vue'; import { MOCK_QUERY, MOCK_NAVIGATION, MOCK_NAVIGATION_ITEMS } from '../../mock_data'; Vue.use(Vuex); -describe('ScopeNewNavigation', () => { +describe('ScopeSidebarNavigation', () => { let wrapper; const actionSpies = { @@ -30,7 +30,7 @@ describe('ScopeNewNavigation', () => { getters: getterSpies, }); - wrapper = mount(ScopeNewNavigation, { + wrapper = mount(ScopeSidebarNavigation, { store, stubs: { NavItem, diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index bbc07e91728..99ef8a8de08 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -682,7 +682,7 @@ RSpec.describe SearchHelper, feature_category: :global_search do @project = :some_project expect(self).to receive(:project_search_tabs?) - .with(:members) + .with(:users) .and_return(:value) end @@ -1109,15 +1109,20 @@ RSpec.describe SearchHelper, feature_category: :global_search do end context 'issues' do - where(:project_search_tabs, :global_search_issues_tab, :condition) do - false | false | false - false | true | true - true | false | true - true | true | true + where(:project_search_tabs, :global_search_issues_tab, :global_project, :condition) do + false | false | nil | false + false | true | nil | true + false | true | ref(:project) | false + false | false | ref(:project) | false + true | false | nil | true + true | true | nil | true + true | false | ref(:project) | true + true | true | ref(:project) | true end with_them do it 'data item condition is set correctly' do + @project = global_project allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_issues_tab).and_return(global_search_issues_tab) allow(self).to receive(:project_search_tabs?).with(:issues).and_return(project_search_tabs) @@ -1127,15 +1132,20 @@ RSpec.describe SearchHelper, feature_category: :global_search do end context 'merge requests' do - where(:project_search_tabs, :feature_flag_tab_enabled, :condition) do - false | false | false - true | false | true - false | true | true - true | true | true + where(:project_search_tabs, :feature_flag_tab_enabled, :global_project, :condition) do + false | false | nil | false + true | false | nil | true + false | false | ref(:project) | false + true | false | ref(:project) | true + false | true | nil | true + true | true | nil | true + false | true | ref(:project) | false + true | true | ref(:project) | true end with_them do it 'data item condition is set correctly' do + @project = global_project 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) @@ -1148,7 +1158,9 @@ RSpec.describe SearchHelper, feature_category: :global_search do where(:global_search_wiki_tab, :show_elasticsearch_tabs, :global_project, :project_search_tabs, :condition) do false | false | nil | true | true false | false | nil | false | false + false | false | ref(:project) | false | false false | true | nil | false | false + false | true | ref(:project) | false | false true | false | nil | false | false true | true | ref(:project) | false | false end @@ -1158,7 +1170,7 @@ RSpec.describe SearchHelper, feature_category: :global_search do @project = global_project allow(search_service).to receive(:show_elasticsearch_tabs?).and_return(show_elasticsearch_tabs) allow(self).to receive(:feature_flag_tab_enabled?).with(:global_search_wiki_tab).and_return(global_search_wiki_tab) - allow(self).to receive(:project_search_tabs?).with(:wiki).and_return(project_search_tabs) + allow(self).to receive(:project_search_tabs?).with(:wiki_blobs).and_return(project_search_tabs) expect(search_navigation[:wiki_blobs][:condition]).to eq(condition) end @@ -1168,9 +1180,12 @@ RSpec.describe SearchHelper, feature_category: :global_search do context 'commits' do where(:global_search_commits_tab, :show_elasticsearch_tabs, :global_project, :project_search_tabs, :condition) do false | false | nil | true | true + false | false | ref(:project) | true | true false | false | nil | false | false + false | true | ref(:project) | false | false false | true | nil | false | false true | false | nil | false | false + true | false | ref(:project) | false | false true | true | ref(:project) | false | false true | true | nil | false | true end @@ -1188,15 +1203,20 @@ RSpec.describe SearchHelper, feature_category: :global_search do end context 'comments' do - where(:project_search_tabs, :show_elasticsearch_tabs, :condition) do - true | true | true - false | false | false - false | true | true - true | false | true + where(:project_search_tabs, :show_elasticsearch_tabs, :global_project, :condition) do + true | true | nil | true + true | true | ref(:project) | true + false | false | nil | false + false | false | ref(:project) | false + false | true | nil | true + false | true | ref(:project) | false + true | false | nil | true + true | false | ref(:project) | true end with_them do it 'data item condition is set correctly' do + @project = global_project 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) diff --git a/spec/support/helpers/search_helpers.rb b/spec/support/helpers/search_helpers.rb index 72673648b89..d13703776cd 100644 --- a/spec/support/helpers/search_helpers.rb +++ b/spec/support/helpers/search_helpers.rb @@ -35,6 +35,8 @@ module SearchHelpers end def has_search_scope?(scope) + return false unless page.has_selector?('[data-testid="search-filter"]') + page.within '[data-testid="search-filter"]' do has_link?(scope) end |