debian-mirror-gitlab/spec/features/search/user_uses_header_search_field_spec.rb

161 lines
4.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'User uses header search field', :js do
2018-03-17 18:26:18 +05:30
include FilteredSearchHelpers
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
project.add_reporter(user)
sign_in(user)
end
2019-09-30 21:07:59 +05:30
shared_examples 'search field examples' do
2018-03-17 18:26:18 +05:30
before do
2019-09-30 21:07:59 +05:30
visit(url)
2018-03-17 18:26:18 +05:30
end
2019-09-30 21:07:59 +05:30
it 'starts searching by pressing the enter key' do
2019-12-04 20:38:33 +05:30
submit_search('gitlab')
2018-05-09 12:01:36 +05:30
2019-10-12 21:52:04 +05:30
page.within('.page-title') do
2018-05-09 12:01:36 +05:30
expect(page).to have_content('Search')
2018-03-17 18:26:18 +05:30
end
end
2019-12-26 22:10:19 +05:30
context 'when using the keyboard shortcut' do
before do
find('#search.js-autocomplete-disabled')
find('body').native.send_keys('s')
end
it 'shows the category search dropdown' do
expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i)
end
end
2019-09-30 21:07:59 +05:30
context 'when clicking the search field' do
2018-05-09 12:01:36 +05:30
before do
2019-12-26 22:10:19 +05:30
page.find('#search.js-autocomplete-disabled').click
2018-05-09 12:01:36 +05:30
end
it 'shows category search dropdown' do
2019-09-30 21:07:59 +05:30
expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i)
2018-05-09 12:01:36 +05:30
end
context 'when clicking issues' do
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
it 'shows assigned issues' do
2019-09-30 21:07:59 +05:30
find('.search-input-container .dropdown-menu').click_link('Issues assigned to me')
2018-05-09 12:01:36 +05:30
2019-09-30 21:07:59 +05:30
expect(page).to have_selector('.issues-list .issue')
2018-05-09 12:01:36 +05:30
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'shows created issues' do
2019-09-30 21:07:59 +05:30
find('.search-input-container .dropdown-menu').click_link("Issues I've created")
2018-05-09 12:01:36 +05:30
2019-09-30 21:07:59 +05:30
expect(page).to have_selector('.issues-list .issue')
2018-05-09 12:01:36 +05:30
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
end
context 'when clicking merge requests' do
2019-07-31 22:56:46 +05:30
let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignees: [user]) }
2018-05-09 12:01:36 +05:30
it 'shows assigned merge requests' do
2019-09-30 21:07:59 +05:30
find('.search-input-container .dropdown-menu').click_link('Merge requests assigned to me')
2018-05-09 12:01:36 +05:30
2019-09-30 21:07:59 +05:30
expect(page).to have_selector('.mr-list .merge-request')
2018-05-09 12:01:36 +05:30
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'shows created merge requests' do
2019-09-30 21:07:59 +05:30
find('.search-input-container .dropdown-menu').click_link("Merge requests I've created")
2018-05-09 12:01:36 +05:30
2019-09-30 21:07:59 +05:30
expect(page).to have_selector('.mr-list .merge-request')
2018-05-09 12:01:36 +05:30
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
end
end
2019-09-30 21:07:59 +05:30
context 'when entering text into the search field' do
2019-12-26 22:10:19 +05:30
it 'does not display the category search dropdown' do
2018-05-09 12:01:36 +05:30
page.within('.search-input-wrap') do
2019-09-30 21:07:59 +05:30
fill_in('search', with: scope_name.first(4))
2018-05-09 12:01:36 +05:30
end
2019-09-30 21:07:59 +05:30
expect(page).not_to have_selector('.dropdown-header', text: /#{scope_name}/i)
2018-05-09 12:01:36 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
2019-09-30 21:07:59 +05:30
context 'when user is in a global scope' do
include_examples 'search field examples' do
let(:url) { root_path }
let(:scope_name) { 'All GitLab' }
end
2019-10-12 21:52:04 +05:30
context 'when searching through the search field' do
before do
create(:issue, project: project, title: 'project issue')
2019-12-04 20:38:33 +05:30
submit_search('project')
2019-10-12 21:52:04 +05:30
end
it 'displays result counts for all categories' do
expect(page).to have_content('Projects 1')
expect(page).to have_content('Issues 1')
expect(page).to have_content('Merge requests 0')
expect(page).to have_content('Milestones 0')
expect(page).to have_content('Users 0')
end
end
2019-09-30 21:07:59 +05:30
end
context 'when user is in a project scope' do
include_examples 'search field examples' do
let(:url) { project_path(project) }
let(:scope_name) { project.name }
end
end
context 'when user is in a group scope' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
before do
group.add_maintainer(user)
end
include_examples 'search field examples' do
let(:url) { group_path(group) }
let(:scope_name) { group.name }
end
end
context 'when user is in a subgroup scope' do
let(:group) { create(:group) }
let(:subgroup) { create(:group, :public, parent: group) }
let(:project) { create(:project, namespace: subgroup) }
before do
group.add_owner(user)
subgroup.add_owner(user)
end
include_examples 'search field examples' do
let(:url) { group_path(subgroup) }
let(:scope_name) { subgroup.name }
end
end
2018-03-17 18:26:18 +05:30
end