2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Global search', :js, feature_category: :global_search do
|
2021-02-22 17:27:13 +05:30
|
|
|
include AfterNextHelpers
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: user.namespace) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
describe 'when new_header_search feature is disabled' do
|
|
|
|
before do
|
|
|
|
# TODO: Remove this along with feature flag #339348
|
|
|
|
stub_feature_flags(new_header_search: false)
|
|
|
|
visit dashboard_projects_path
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it 'increases usage ping searches counter' do
|
|
|
|
expect(Gitlab::UsageDataCounters::SearchCounter).to receive(:count).with(:navbar_searches)
|
|
|
|
expect(Gitlab::UsageDataCounters::SearchCounter).to receive(:count).with(:all_searches)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
submit_search('foobar')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
describe 'I search through the issues and I see pagination' do
|
|
|
|
before do
|
|
|
|
allow_next(SearchService).to receive(:per_page).and_return(1)
|
|
|
|
create_list(:issue, 2, project: project, title: 'initial')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a pagination" do
|
|
|
|
submit_search('initial')
|
|
|
|
select_search_scope('Issues')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(page).to have_selector('.gl-pagination .next')
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
it 'closes the dropdown on blur' do
|
2021-11-11 11:23:49 +05:30
|
|
|
find('#search').click
|
|
|
|
fill_in 'search', with: "a"
|
|
|
|
|
|
|
|
expect(page).to have_selector("div[data-testid='dashboard-search-options'].show")
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
find('#search').send_keys(:backspace)
|
|
|
|
find('body').click
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(page).to have_no_selector("div[data-testid='dashboard-search-options'].show")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders legacy search bar' do
|
|
|
|
expect(page).to have_selector('.search-form')
|
|
|
|
expect(page).to have_no_selector('#js-header-search')
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
it 'focuses search input when shortcut "s" is pressed' do
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(page).not_to have_selector('#search:focus')
|
|
|
|
|
|
|
|
find('body').native.send_key('s')
|
|
|
|
|
|
|
|
expect(page).to have_selector('#search:focus')
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
describe 'when new_header_search feature is enabled' do
|
|
|
|
before do
|
|
|
|
# TODO: Remove this along with feature flag #339348
|
|
|
|
stub_feature_flags(new_header_search: true)
|
|
|
|
visit dashboard_projects_path
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
# initialize javascript loaded input search input field
|
2022-05-07 20:08:51 +05:30
|
|
|
find('#search').click
|
|
|
|
find('body').click
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders updated search bar' do
|
|
|
|
expect(page).to have_no_selector('.search-form')
|
|
|
|
expect(page).to have_selector('#js-header-search')
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
it 'focuses search input when shortcut "s" is pressed' do
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(page).not_to have_selector('#search:focus')
|
|
|
|
|
|
|
|
find('body').native.send_key('s')
|
|
|
|
|
|
|
|
expect(page).to have_selector('#search:focus')
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|