Commit b0d8e538 authored by Marc Shaw's avatar Marc Shaw

Merge branch '339348-default-enable-new-header-search' into 'master'

Global Search - Enable Header Search Default

See merge request gitlab-org/gitlab!79993
parents 1d6f5ca0 64d3f362
...@@ -127,7 +127,7 @@ function deferredInitialisation() { ...@@ -127,7 +127,7 @@ function deferredInitialisation() {
// In case the user started searching before we bootstrapped, let's pass the search along. // In case the user started searching before we bootstrapped, let's pass the search along.
const initialSearchValue = searchInputBox.value; const initialSearchValue = searchInputBox.value;
await initHeaderSearchApp(initialSearchValue); await initHeaderSearchApp(initialSearchValue);
searchInputBox.focus(); document.querySelector('#search').focus();
}) })
.catch(() => {}); .catch(() => {});
} else { } else {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
- search_menu_item = top_nav_search_menu_item_attrs - search_menu_item = top_nav_search_menu_item_attrs
%li.nav-item.header-search-new.d-none.d-lg-block.m-auto %li.nav-item.header-search-new.d-none.d-lg-block.m-auto
- unless current_controller?(:search) - unless current_controller?(:search)
- if Feature.enabled?(:new_header_search) - if Feature.enabled?(:new_header_search, default_enabled: :yaml)
= render 'layouts/header_search' = render 'layouts/header_search'
- else - else
= render 'layouts/search' = render 'layouts/search'
......
...@@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339348 ...@@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339348
milestone: '14.3' milestone: '14.3'
type: development type: development
group: group::global search group: group::global search
default_enabled: false default_enabled: true
...@@ -50,7 +50,7 @@ const createMainOutput = ({ outFile, cssKeys, type }) => ({ ...@@ -50,7 +50,7 @@ const createMainOutput = ({ outFile, cssKeys, type }) => ({
htmlPaths: [ htmlPaths: [
path.join(FIXTURES_ROOT, `startup_css/project-${type}.html`), path.join(FIXTURES_ROOT, `startup_css/project-${type}.html`),
path.join(FIXTURES_ROOT, `startup_css/project-${type}-signed-out.html`), path.join(FIXTURES_ROOT, `startup_css/project-${type}-signed-out.html`),
path.join(FIXTURES_ROOT, `startup_css/project-${type}-search-ff-on.html`), path.join(FIXTURES_ROOT, `startup_css/project-${type}-search-ff-off.html`),
], ],
cssKeys, cssKeys,
purgeOptions: { purgeOptions: {
......
...@@ -30,7 +30,7 @@ RSpec.describe 'When a user searches for Sentry errors', :js, :use_clean_rails_m ...@@ -30,7 +30,7 @@ RSpec.describe 'When a user searches for Sentry errors', :js, :use_clean_rails_m
expect(results.count).to be(3) expect(results.count).to be(3)
end end
find('.gl-form-input').set('NotFound').native.send_keys(:return) find('.filtered-search-input-container .gl-form-input').set('NotFound').native.send_keys(:return)
page.within(find('.gl-table')) do page.within(find('.gl-table')) do
results = page.all('.table-row') results = page.all('.table-row')
......
...@@ -8,6 +8,8 @@ RSpec.describe 'User searches for projects', :js do ...@@ -8,6 +8,8 @@ RSpec.describe 'User searches for projects', :js do
context 'when signed out' do context 'when signed out' do
context 'when block_anonymous_global_searches is disabled' do context 'when block_anonymous_global_searches is disabled' do
before do before do
allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit).and_return(1000)
allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit_unauthenticated).and_return(1000)
stub_feature_flags(block_anonymous_global_searches: false) stub_feature_flags(block_anonymous_global_searches: false)
end end
......
...@@ -17,12 +17,15 @@ RSpec.describe 'User uses header search field', :js do ...@@ -17,12 +17,15 @@ RSpec.describe 'User uses header search field', :js do
end end
before do before do
allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit).and_return(1000)
allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit_unauthenticated).and_return(1000)
sign_in(user) sign_in(user)
end end
shared_examples 'search field examples' do shared_examples 'search field examples' do
before do before do
visit(url) visit(url)
wait_for_all_requests
end end
it 'starts searching by pressing the enter key' do it 'starts searching by pressing the enter key' do
...@@ -37,7 +40,6 @@ RSpec.describe 'User uses header search field', :js do ...@@ -37,7 +40,6 @@ RSpec.describe 'User uses header search field', :js do
before do before do
find('#search') find('#search')
find('body').native.send_keys('s') find('body').native.send_keys('s')
wait_for_all_requests wait_for_all_requests
end end
...@@ -49,6 +51,7 @@ RSpec.describe 'User uses header search field', :js do ...@@ -49,6 +51,7 @@ RSpec.describe 'User uses header search field', :js do
context 'when clicking the search field' do context 'when clicking the search field' do
before do before do
page.find('#search').click page.find('#search').click
wait_for_all_requests
end end
it 'shows category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do it 'shows category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do
...@@ -59,7 +62,7 @@ RSpec.describe 'User uses header search field', :js do ...@@ -59,7 +62,7 @@ RSpec.describe 'User uses header search field', :js do
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) } let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
it 'shows assigned issues' do it 'shows assigned issues' do
find('.search-input-container .dropdown-menu').click_link('Issues assigned to me') find('[data-testid="header-search-dropdown-menu"]').click_link('Issues assigned to me')
expect(page).to have_selector('.issues-list .issue') expect(page).to have_selector('.issues-list .issue')
expect_tokens([assignee_token(user.name)]) expect_tokens([assignee_token(user.name)])
...@@ -67,7 +70,7 @@ RSpec.describe 'User uses header search field', :js do ...@@ -67,7 +70,7 @@ RSpec.describe 'User uses header search field', :js do
end end
it 'shows created issues' do it 'shows created issues' do
find('.search-input-container .dropdown-menu').click_link("Issues I've created") find('[data-testid="header-search-dropdown-menu"]').click_link("Issues I've created")
expect(page).to have_selector('.issues-list .issue') expect(page).to have_selector('.issues-list .issue')
expect_tokens([author_token(user.name)]) expect_tokens([author_token(user.name)])
...@@ -79,7 +82,7 @@ RSpec.describe 'User uses header search field', :js do ...@@ -79,7 +82,7 @@ RSpec.describe 'User uses header search field', :js do
let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignees: [user]) } let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignees: [user]) }
it 'shows assigned merge requests' do it 'shows assigned merge requests' do
find('.search-input-container .dropdown-menu').click_link('Merge requests assigned to me') find('[data-testid="header-search-dropdown-menu"]').click_link('Merge requests assigned to me')
expect(page).to have_selector('.mr-list .merge-request') expect(page).to have_selector('.mr-list .merge-request')
expect_tokens([assignee_token(user.name)]) expect_tokens([assignee_token(user.name)])
...@@ -87,7 +90,7 @@ RSpec.describe 'User uses header search field', :js do ...@@ -87,7 +90,7 @@ RSpec.describe 'User uses header search field', :js do
end end
it 'shows created merge requests' do it 'shows created merge requests' do
find('.search-input-container .dropdown-menu').click_link("Merge requests I've created") find('[data-testid="header-search-dropdown-menu"]').click_link("Merge requests I've created")
expect(page).to have_selector('.mr-list .merge-request') expect(page).to have_selector('.mr-list .merge-request')
expect_tokens([author_token(user.name)]) expect_tokens([author_token(user.name)])
...@@ -150,10 +153,9 @@ RSpec.describe 'User uses header search field', :js do ...@@ -150,10 +153,9 @@ RSpec.describe 'User uses header search field', :js do
it 'displays search options' do it 'displays search options' do
fill_in_search('test') fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test', search_code: true))
expect(page).to have_selector(scoped_search_link('test')) expect(page).to have_selector(scoped_search_link('test', group_id: group.id, search_code: true))
expect(page).to have_selector(scoped_search_link('test', group_id: group.id)) expect(page).to have_selector(scoped_search_link('test', project_id: project.id, group_id: group.id, search_code: true))
expect(page).to have_selector(scoped_search_link('test', project_id: project.id, group_id: group.id))
end end
end end
...@@ -165,10 +167,9 @@ RSpec.describe 'User uses header search field', :js do ...@@ -165,10 +167,9 @@ RSpec.describe 'User uses header search field', :js do
it 'displays search options' do it 'displays search options' do
fill_in_search('test') fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test', search_code: true, repository_ref: 'master'))
expect(page).to have_selector(scoped_search_link('test')) expect(page).not_to have_selector(scoped_search_link('test', search_code: true, group_id: project.namespace_id, repository_ref: 'master'))
expect(page).not_to have_selector(scoped_search_link('test', group_id: project.namespace_id)) expect(page).to have_selector(scoped_search_link('test', search_code: true, project_id: project.id, repository_ref: 'master'))
expect(page).to have_selector(scoped_search_link('test', project_id: project.id))
end end
it 'displays a link to project merge requests' do it 'displays a link to project merge requests' do
...@@ -217,7 +218,6 @@ RSpec.describe 'User uses header search field', :js do ...@@ -217,7 +218,6 @@ RSpec.describe 'User uses header search field', :js do
it 'displays search options' do it 'displays search options' do
fill_in_search('test') fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test')) expect(page).to have_selector(scoped_search_link('test'))
expect(page).to have_selector(scoped_search_link('test', group_id: group.id)) expect(page).to have_selector(scoped_search_link('test', group_id: group.id))
expect(page).not_to have_selector(scoped_search_link('test', project_id: project.id)) expect(page).not_to have_selector(scoped_search_link('test', project_id: project.id))
...@@ -248,18 +248,20 @@ RSpec.describe 'User uses header search field', :js do ...@@ -248,18 +248,20 @@ RSpec.describe 'User uses header search field', :js do
end end
end end
def scoped_search_link(term, project_id: nil, group_id: nil) def scoped_search_link(term, project_id: nil, group_id: nil, search_code: nil, repository_ref: nil)
# search_path will accept group_id and project_id but the order does not match # search_path will accept group_id and project_id but the order does not match
# what is expected in the href, so the variable must be built manually # what is expected in the href, so the variable must be built manually
href = search_path(search: term) href = search_path(search: term)
href.concat("&nav_source=navbar")
href.concat("&project_id=#{project_id}") if project_id href.concat("&project_id=#{project_id}") if project_id
href.concat("&group_id=#{group_id}") if group_id href.concat("&group_id=#{group_id}") if group_id
href.concat("&nav_source=navbar") href.concat("&search_code=true") if search_code
href.concat("&repository_ref=#{repository_ref}") if repository_ref
".dropdown a[href='#{href}']" "[data-testid='header-search-dropdown-menu'] a[href='#{href}']"
end end
def dashboard_search_options_popup_menu def dashboard_search_options_popup_menu
"div[data-testid='dashboard-search-options']" "[data-testid='header-search-dropdown-menu'] .header-search-dropdown-content"
end end
end end
...@@ -41,12 +41,12 @@ RSpec.describe 'Startup CSS fixtures', type: :controller do ...@@ -41,12 +41,12 @@ RSpec.describe 'Startup CSS fixtures', type: :controller do
expect(response).to be_successful expect(response).to be_successful
end end
# This Feature Flag is off by default # This Feature Flag is on by default
# This ensures that the correct css is generated # This ensures that the correct css is generated
# When the feature flag is off, the general startup will capture it # When the feature flag is on, the general startup will capture it
# This will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/339348 # This will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/339348
it "startup_css/project-#{type}-search-ff-on.html" do it "startup_css/project-#{type}-search-ff-off.html" do
stub_feature_flags(new_header_search: true) stub_feature_flags(new_header_search: false)
get :show, params: { get :show, params: {
namespace_id: project.namespace.to_param, namespace_id: project.namespace.to_param,
......
...@@ -329,11 +329,6 @@ RSpec.configure do |config| ...@@ -329,11 +329,6 @@ RSpec.configure do |config|
stub_feature_flags(disable_anonymous_search: false) stub_feature_flags(disable_anonymous_search: false)
stub_feature_flags(disable_anonymous_project_search: false) stub_feature_flags(disable_anonymous_project_search: false)
# Disable the refactored top nav search until there is functionality
# Can be removed once all existing functionality has been replicated
# For more information check https://gitlab.com/gitlab-org/gitlab/-/issues/339348
stub_feature_flags(new_header_search: false)
allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged) allow(Gitlab::GitalyClient).to receive(:can_use_disk?).and_return(enable_rugged)
else else
unstub_all_feature_flags unstub_all_feature_flags
......
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
module SearchHelpers module SearchHelpers
def fill_in_search(text) def fill_in_search(text)
page.within('.search-input-wrap') do # Once the `new_header_search` feature flag has been removed
# We can remove the `.search-input-wrap` selector
# https://gitlab.com/gitlab-org/gitlab/-/issues/339348
page.within('.header-search-new') do
find('#search').click find('#search').click
fill_in('search', with: text) fill_in 'search', with: text
end end
wait_for_all_requests wait_for_all_requests
......
...@@ -11,6 +11,7 @@ RSpec.shared_examples 'search timeouts' do |scope| ...@@ -11,6 +11,7 @@ RSpec.shared_examples 'search timeouts' do |scope|
end end
it 'renders timeout information' do it 'renders timeout information' do
# expect(page).to have_content('This endpoint has been requested too many times.')
expect(page).to have_content('Your search timed out') expect(page).to have_content('Your search timed out')
end end
......
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