Commit 3a700aa6 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'cuddyz-support-tree-ref' into 'master'

Global Search - Fix Branch Ref Based Searches

See merge request gitlab-org/gitlab!80857
parents 18ea2573 08e0800e
...@@ -21,6 +21,8 @@ export const searchQuery = (state) => { ...@@ -21,6 +21,8 @@ export const searchQuery = (state) => {
group_id: state.searchContext?.group?.id, group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope, scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null, snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
}, },
isNil, isNil,
); );
...@@ -98,6 +100,8 @@ export const projectUrl = (state) => { ...@@ -98,6 +100,8 @@ export const projectUrl = (state) => {
group_id: state.searchContext?.group?.id, group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope, scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null, snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
}, },
isNil, isNil,
); );
...@@ -113,6 +117,8 @@ export const groupUrl = (state) => { ...@@ -113,6 +117,8 @@ export const groupUrl = (state) => {
group_id: state.searchContext?.group?.id, group_id: state.searchContext?.group?.id,
scope: state.searchContext?.scope, scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null, snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
}, },
isNil, isNil,
); );
...@@ -127,6 +133,8 @@ export const allUrl = (state) => { ...@@ -127,6 +133,8 @@ export const allUrl = (state) => {
nav_source: 'navbar', nav_source: 'navbar',
scope: state.searchContext?.scope, scope: state.searchContext?.scope,
snippets: state.searchContext?.for_snippets ? true : null, snippets: state.searchContext?.for_snippets ? true : null,
search_code: state.searchContext?.code_search ? true : null,
repository_ref: state.searchContext?.ref,
}, },
isNil, isNil,
); );
...@@ -140,7 +148,7 @@ export const scopedSearchOptions = (state, getters) => { ...@@ -140,7 +148,7 @@ export const scopedSearchOptions = (state, getters) => {
if (state.searchContext?.project) { if (state.searchContext?.project) {
options.push({ options.push({
html_id: 'scoped-in-project', html_id: 'scoped-in-project',
scope: state.searchContext?.project.name, scope: state.searchContext.project?.name || '',
description: MSG_IN_PROJECT, description: MSG_IN_PROJECT,
url: getters.projectUrl, url: getters.projectUrl,
}); });
...@@ -149,7 +157,7 @@ export const scopedSearchOptions = (state, getters) => { ...@@ -149,7 +157,7 @@ export const scopedSearchOptions = (state, getters) => {
if (state.searchContext?.group) { if (state.searchContext?.group) {
options.push({ options.push({
html_id: 'scoped-in-group', html_id: 'scoped-in-group',
scope: state.searchContext?.group.name, scope: state.searchContext.group?.name || '',
description: MSG_IN_GROUP, description: MSG_IN_GROUP,
url: getters.groupUrl, url: getters.groupUrl,
}); });
......
...@@ -80,46 +80,103 @@ RSpec.describe 'User searches for code' do ...@@ -80,46 +80,103 @@ RSpec.describe 'User searches for code' do
end end
end end
context 'search code within refs', :js do context 'when :new_header_search is true' do
let(:ref_name) { 'v1.0.0' } 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')
select_search_scope('Code')
end
before do it 'shows ref switcher in code result summary' do
visit(project_tree_path(project, ref_name)) expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end
submit_search('gitlab-grack') it 'persists branch name across search' do
select_search_scope('Code') find('.gl-search-box-by-click-search-button').click
end expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
end
it 'shows ref switcher in code result summary' do # this example is use to test the desgine that the refs is not
expect(find('.js-project-refs-dropdown')).to have_text(ref_name) # only repersent the branch as well as the tags.
end it 'ref swither list all the branchs and tags' do
it 'persists branch name across search' do find('.js-project-refs-dropdown').click
find('.gl-search-box-by-click-search-button').click expect(find('.dropdown-page-one .dropdown-content')).to have_link('sha-starting-with-large-number')
expect(find('.js-project-refs-dropdown')).to have_text(ref_name) expect(find('.dropdown-page-one .dropdown-content')).to have_link('v1.0.0')
end end
# this example is use to test the desgine that the refs is not it 'search result changes when refs switched' do
# only repersent the branch as well as the tags. expect(find('.results')).not_to have_content('path = gitlab-grack')
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 find('.js-project-refs-dropdown').click
expect(find('.results')).not_to have_content('path = gitlab-grack') find('.dropdown-page-one .dropdown-content').click_link('master')
find('.js-project-refs-dropdown').click expect(page).to have_selector('.results', text: 'path = gitlab-grack')
find('.dropdown-page-one .dropdown-content').click_link('master') end
expect(page).to have_selector('.results', text: 'path = gitlab-grack') 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
end
it 'persist refs over browser tabs' do context 'when :new_header_search is false' do
ref = 'feature' context 'search code within refs', :js do
find('.js-project-refs-dropdown').click let(:ref_name) { 'v1.0.0' }
link = find_link(ref)[:href]
expect(link.include?("repository_ref=" + ref)).to be(true) 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
end end
......
...@@ -37,15 +37,20 @@ describe('Header Search Store Getters', () => { ...@@ -37,15 +37,20 @@ describe('Header Search Store Getters', () => {
}); });
describe.each` describe.each`
group | project | scope | forSnippets | expectedPath group | project | scope | forSnippets | codeSearch | ref | expectedPath
${null} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
${null} | ${null} | ${null} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`} ${null} | ${null} | ${null} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`}
${MOCK_GROUP} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`} ${null} | ${null} | ${null} | ${false} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&search_code=true`}
${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}`} ${null} | ${null} | ${null} | ${false} | ${false} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&repository_ref=test-branch`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}`} ${MOCK_GROUP} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`} ${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}`}
`('searchQuery', ({ group, project, scope, forSnippets, expectedPath }) => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}`}
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, and for_snippets is ${forSnippets}`, () => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true&repository_ref=test-branch`}
`('searchQuery', ({ group, project, scope, forSnippets, codeSearch, ref, expectedPath }) => {
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, for_snippets is ${forSnippets}, code_search is ${codeSearch}, and ref is ${ref}`, () => {
beforeEach(() => { beforeEach(() => {
createState({ createState({
searchContext: { searchContext: {
...@@ -53,6 +58,8 @@ describe('Header Search Store Getters', () => { ...@@ -53,6 +58,8 @@ describe('Header Search Store Getters', () => {
project, project,
scope, scope,
for_snippets: forSnippets, for_snippets: forSnippets,
code_search: codeSearch,
ref,
}, },
}); });
state.search = MOCK_SEARCH; state.search = MOCK_SEARCH;
...@@ -137,15 +144,20 @@ describe('Header Search Store Getters', () => { ...@@ -137,15 +144,20 @@ describe('Header Search Store Getters', () => {
}); });
describe.each` describe.each`
group | project | scope | forSnippets | expectedPath group | project | scope | forSnippets | codeSearch | ref | expectedPath
${null} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
${null} | ${null} | ${null} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`} ${null} | ${null} | ${null} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`}
${MOCK_GROUP} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`} ${null} | ${null} | ${null} | ${false} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&search_code=true`}
${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}`} ${null} | ${null} | ${null} | ${false} | ${false} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&repository_ref=test-branch`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}`} ${MOCK_GROUP} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`} ${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}`}
`('projectUrl', ({ group, project, scope, forSnippets, expectedPath }) => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}`}
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, and for_snippets is ${forSnippets}`, () => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&project_id=${MOCK_PROJECT.id}&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true&repository_ref=test-branch`}
`('projectUrl', ({ group, project, scope, forSnippets, codeSearch, ref, expectedPath }) => {
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, for_snippets is ${forSnippets}, code_search is ${codeSearch}, and ref is ${ref}`, () => {
beforeEach(() => { beforeEach(() => {
createState({ createState({
searchContext: { searchContext: {
...@@ -153,6 +165,8 @@ describe('Header Search Store Getters', () => { ...@@ -153,6 +165,8 @@ describe('Header Search Store Getters', () => {
project, project,
scope, scope,
for_snippets: forSnippets, for_snippets: forSnippets,
code_search: codeSearch,
ref,
}, },
}); });
state.search = MOCK_SEARCH; state.search = MOCK_SEARCH;
...@@ -165,15 +179,20 @@ describe('Header Search Store Getters', () => { ...@@ -165,15 +179,20 @@ describe('Header Search Store Getters', () => {
}); });
describe.each` describe.each`
group | project | scope | forSnippets | expectedPath group | project | scope | forSnippets | codeSearch | ref | expectedPath
${null} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
${null} | ${null} | ${null} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`} ${null} | ${null} | ${null} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`}
${MOCK_GROUP} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`} ${null} | ${null} | ${null} | ${false} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&search_code=true`}
${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&repository_ref=test-branch`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`} ${MOCK_GROUP} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`} ${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
`('groupUrl', ({ group, project, scope, forSnippets, expectedPath }) => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}`}
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, and for_snippets is ${forSnippets}`, () => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}&scope=issues`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&group_id=${MOCK_GROUP.id}&scope=issues&snippets=true&search_code=true&repository_ref=test-branch`}
`('groupUrl', ({ group, project, scope, forSnippets, codeSearch, ref, expectedPath }) => {
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, for_snippets is ${forSnippets}, code_search is ${codeSearch}, and ref is ${ref}`, () => {
beforeEach(() => { beforeEach(() => {
createState({ createState({
searchContext: { searchContext: {
...@@ -181,6 +200,8 @@ describe('Header Search Store Getters', () => { ...@@ -181,6 +200,8 @@ describe('Header Search Store Getters', () => {
project, project,
scope, scope,
for_snippets: forSnippets, for_snippets: forSnippets,
code_search: codeSearch,
ref,
}, },
}); });
state.search = MOCK_SEARCH; state.search = MOCK_SEARCH;
...@@ -193,15 +214,20 @@ describe('Header Search Store Getters', () => { ...@@ -193,15 +214,20 @@ describe('Header Search Store Getters', () => {
}); });
describe.each` describe.each`
group | project | scope | forSnippets | expectedPath group | project | scope | forSnippets | codeSearch | ref | expectedPath
${null} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
${null} | ${null} | ${null} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`} ${null} | ${null} | ${null} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&snippets=true`}
${MOCK_GROUP} | ${null} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&search_code=true`}
${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${null} | ${null} | ${null} | ${false} | ${false} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&repository_ref=test-branch`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`} ${MOCK_GROUP} | ${null} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&scope=issues&snippets=true`} ${null} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
`('allUrl', ({ group, project, scope, forSnippets, expectedPath }) => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${null} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar`}
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, and for_snippets is ${forSnippets}`, () => { ${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${false} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&scope=issues`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${false} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&scope=issues&snippets=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${null} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&scope=issues&snippets=true&search_code=true`}
${MOCK_GROUP} | ${MOCK_PROJECT} | ${'issues'} | ${true} | ${true} | ${'test-branch'} | ${`${MOCK_SEARCH_PATH}?search=${MOCK_SEARCH}&nav_source=navbar&scope=issues&snippets=true&search_code=true&repository_ref=test-branch`}
`('allUrl', ({ group, project, scope, forSnippets, codeSearch, ref, expectedPath }) => {
describe(`when group is ${group?.name}, project is ${project?.name}, scope is ${scope}, for_snippets is ${forSnippets}, code_search is ${codeSearch}, and ref is ${ref}`, () => {
beforeEach(() => { beforeEach(() => {
createState({ createState({
searchContext: { searchContext: {
...@@ -209,6 +235,8 @@ describe('Header Search Store Getters', () => { ...@@ -209,6 +235,8 @@ describe('Header Search Store Getters', () => {
project, project,
scope, scope,
for_snippets: forSnippets, for_snippets: forSnippets,
code_search: codeSearch,
ref,
}, },
}); });
state.search = MOCK_SEARCH; state.search = MOCK_SEARCH;
......
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