Commit 08e0800e authored by Tomas Bulva's avatar Tomas Bulva

Global Search - Fix ref based searches

This change fixes a bug with the new
header search. Currenlty the ref property
of the search_context is not properly
being shared with the header search.

With this change it will now properly
be added to the search when needed.

Changelog: fixed
parent 8ea4b646
......@@ -21,6 +21,8 @@ export const searchQuery = (state) => {
group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
},
isNil,
);
......@@ -98,6 +100,8 @@ export const projectUrl = (state) => {
group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
},
isNil,
);
......@@ -113,6 +117,8 @@ export const groupUrl = (state) => {
group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
},
isNil,
);
......@@ -127,6 +133,8 @@ export const allUrl = (state) => {
nav_source: 'navbar',
scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
},
isNil,
);
......@@ -140,7 +148,7 @@ export const scopedSearchOptions = (state, getters) => {
if (state.searchContext?.project) {
options.push({
html_id: 'scoped-in-project',
scope: state.searchContext?.project.name,
scope: state.searchContext.project?.name || '',
description: MSG_IN_PROJECT,
url: getters.projectUrl,
});
......@@ -149,7 +157,7 @@ export const scopedSearchOptions = (state, getters) => {
if (state.searchContext?.group) {
options.push({
html_id: 'scoped-in-group',
scope: state.searchContext?.group.name,
scope: state.searchContext.group?.name || '',
description: MSG_IN_GROUP,
url: getters.groupUrl,
});
......
......@@ -80,10 +80,15 @@ RSpec.describe 'User searches for code' do
end
end
context 'when :new_header_search is true' do
context 'search code within refs', :js do
let(:ref_name) { 'v1.0.0' }
before do
# This feature is diabled by default in spec_helper.rb.
# We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec.
# This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348.
stub_feature_flags(new_header_search: true)
visit(project_tree_path(project, ref_name))
submit_search('gitlab-grack')
......@@ -93,6 +98,7 @@ RSpec.describe 'User searches for code' do
it 'shows ref switcher in code result summary' do
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end
it 'persists branch name across search' do
find('.gl-search-box-by-click-search-button').click
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
......@@ -122,6 +128,57 @@ RSpec.describe 'User searches for code' do
expect(link.include?("repository_ref=" + ref)).to be(true)
end
end
end
context 'when :new_header_search is false' do
context 'search code within refs', :js do
let(:ref_name) { 'v1.0.0' }
before do
# This feature is diabled by default in spec_helper.rb.
# We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec.
# This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348.
stub_feature_flags(new_header_search: false)
visit(project_tree_path(project, ref_name))
submit_search('gitlab-grack')
select_search_scope('Code')
end
it 'shows ref switcher in code result summary' do
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end
it 'persists branch name across search' do
find('.gl-search-box-by-click-search-button').click
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end
# this example is use to test the desgine that the refs is not
# only repersent the branch as well as the tags.
it 'ref swither list all the branchs and tags' do
find('.js-project-refs-dropdown').click
expect(find('.dropdown-page-one .dropdown-content')).to have_link('sha-starting-with-large-number')
expect(find('.dropdown-page-one .dropdown-content')).to have_link('v1.0.0')
end
it 'search result changes when refs switched' do
expect(find('.results')).not_to have_content('path = gitlab-grack')
find('.js-project-refs-dropdown').click
find('.dropdown-page-one .dropdown-content').click_link('master')
expect(page).to have_selector('.results', text: 'path = gitlab-grack')
end
it 'persist refs over browser tabs' do
ref = 'feature'
find('.js-project-refs-dropdown').click
link = find_link(ref)[:href]
expect(link.include?("repository_ref=" + ref)).to be(true)
end
end
end
it 'no ref switcher shown in issue result summary', :js do
issue = create(:issue, title: 'test', project: project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment