Commit 964bccda authored by Igor Drozdov's avatar Igor Drozdov

Merge branch...

Merge branch '219575-add-feature-tests-to-search-bar-dropdown-scoped-search-shortcuts' into 'master'

Add feature tests to search bar dropdown scoped search shortcuts

See merge request gitlab-org/gitlab!37084
parents 00b75ff4 86cc91aa
......@@ -104,6 +104,14 @@ RSpec.describe 'User uses header search field', :js do
let(:scope_name) { 'All GitLab' }
end
it 'displays search options' do
page.within('.search-input-wrap') do
fill_in('search', with: 'test')
end
expect(page).to have_selector(scoped_search_link('test'))
end
context 'when searching through the search field' do
before do
create(:issue, project: project, title: 'project issue')
......@@ -122,9 +130,41 @@ RSpec.describe 'User uses header search field', :js do
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 }
context 'and it belongs to a group' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
include_examples 'search field examples' do
let(:url) { project_path(project) }
let(:scope_name) { project.name }
end
it 'displays search options' do
page.within('.search-input-wrap') do
fill_in('search', with: 'test')
end
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', project_id: project.id, group_id: group.id))
end
end
context 'and it belongs to a user' do
include_examples 'search field examples' do
let(:url) { project_path(project) }
let(:scope_name) { project.name }
end
it 'displays search options' do
page.within('.search-input-wrap') do
fill_in('search', with: 'test')
end
expect(page).to have_selector(scoped_search_link('test'))
expect(page).not_to have_selector(scoped_search_link('test', group_id: project.namespace_id))
expect(page).to have_selector(scoped_search_link('test', project_id: project.id))
end
end
end
......@@ -140,6 +180,16 @@ RSpec.describe 'User uses header search field', :js do
let(:url) { group_path(group) }
let(:scope_name) { group.name }
end
it 'displays search options' do
page.within('.search-input-wrap') do
fill_in('search', with: 'test')
end
expect(page).to have_selector(scoped_search_link('test'))
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))
end
end
context 'when user is in a subgroup scope' do
......@@ -156,5 +206,25 @@ RSpec.describe 'User uses header search field', :js do
let(:url) { group_path(subgroup) }
let(:scope_name) { subgroup.name }
end
it 'displays search options' do
page.within('.search-input-wrap') do
fill_in('search', with: 'test')
end
expect(page).to have_selector(scoped_search_link('test'))
expect(page).to have_selector(scoped_search_link('test', group_id: subgroup.id))
expect(page).not_to have_selector(scoped_search_link('test', project_id: project.id))
end
end
def scoped_search_link(term, project_id: nil, group_id: nil)
# 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
href = search_path(search: term)
href.concat("&project_id=#{project_id}") if project_id
href.concat("&group_id=#{group_id}") if group_id
".dropdown a[href='#{href}']"
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