Commit 86cc91aa authored by Terri Chu's avatar Terri Chu Committed by Igor Drozdov

Add feature tests to search bar dropdown scoped search shortcuts

parent 00b75ff4
...@@ -104,6 +104,14 @@ RSpec.describe 'User uses header search field', :js do ...@@ -104,6 +104,14 @@ RSpec.describe 'User uses header search field', :js do
let(:scope_name) { 'All GitLab' } let(:scope_name) { 'All GitLab' }
end 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 context 'when searching through the search field' do
before do before do
create(:issue, project: project, title: 'project issue') create(:issue, project: project, title: 'project issue')
...@@ -122,9 +130,41 @@ RSpec.describe 'User uses header search field', :js do ...@@ -122,9 +130,41 @@ RSpec.describe 'User uses header search field', :js do
end end
context 'when user is in a project scope' do context 'when user is in a project scope' do
include_examples 'search field examples' do context 'and it belongs to a group' do
let(:url) { project_path(project) } let(:group) { create(:group) }
let(:scope_name) { project.name } 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
end end
...@@ -140,6 +180,16 @@ RSpec.describe 'User uses header search field', :js do ...@@ -140,6 +180,16 @@ RSpec.describe 'User uses header search field', :js do
let(:url) { group_path(group) } let(:url) { group_path(group) }
let(:scope_name) { group.name } let(:scope_name) { group.name }
end 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 end
context 'when user is in a subgroup scope' do context 'when user is in a subgroup scope' do
...@@ -156,5 +206,25 @@ RSpec.describe 'User uses header search field', :js do ...@@ -156,5 +206,25 @@ RSpec.describe 'User uses header search field', :js do
let(:url) { group_path(subgroup) } let(:url) { group_path(subgroup) }
let(:scope_name) { subgroup.name } let(:scope_name) { subgroup.name }
end 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
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