diff options
Diffstat (limited to 'spec/features/search')
7 files changed, 84 insertions, 38 deletions
diff --git a/spec/features/search/user_searches_for_code_spec.rb b/spec/features/search/user_searches_for_code_spec.rb index a88043c98ac..f761bd30baf 100644 --- a/spec/features/search/user_searches_for_code_spec.rb +++ b/spec/features/search/user_searches_for_code_spec.rb @@ -28,10 +28,7 @@ RSpec.describe 'User searches for code' do before do visit(search_path) find('.js-search-project-dropdown').click - - page.within('.project-filter') do - click_link(project.full_name) - end + find('[data-testid="project-filter"]').click_link(project.full_name) end include_examples 'top right search form' diff --git a/spec/features/search/user_searches_for_issues_spec.rb b/spec/features/search/user_searches_for_issues_spec.rb index 900ed35adea..e2ae2738d2f 100644 --- a/spec/features/search/user_searches_for_issues_spec.rb +++ b/spec/features/search/user_searches_for_issues_spec.rb @@ -5,8 +5,8 @@ require 'spec_helper' RSpec.describe 'User searches for issues', :js do let(:user) { create(:user) } let(:project) { create(:project, namespace: user.namespace) } - let!(:issue1) { create(:issue, title: 'Foo', project: project) } - let!(:issue2) { create(:issue, :closed, :confidential, title: 'Bar', project: project) } + let!(:issue1) { create(:issue, title: 'issue Foo', project: project, created_at: 1.hour.ago) } + let!(:issue2) { create(:issue, :closed, :confidential, title: 'issue Bar', project: project) } def search_for_issue(search) fill_in('dashboard_search', with: search) @@ -67,13 +67,26 @@ RSpec.describe 'User searches for issues', :js do end end + it 'sorts by created date' do + search_for_issue('issue') + + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue2.title) + expect(page.all('.search-result-row').last).to have_link(issue1.title) + end + + find('.reverse-sort-btn').click + + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue1.title) + expect(page.all('.search-result-row').last).to have_link(issue2.title) + end + end + context 'when on a project page' do it 'finds an issue' do find('.js-search-project-dropdown').click - - page.within('.project-filter') do - click_link(project.full_name) - end + find('[data-testid="project-filter"]').click_link(project.full_name) search_for_issue(issue1.title) diff --git a/spec/features/search/user_searches_for_merge_requests_spec.rb b/spec/features/search/user_searches_for_merge_requests_spec.rb index 40583664958..6f8f6303b66 100644 --- a/spec/features/search/user_searches_for_merge_requests_spec.rb +++ b/spec/features/search/user_searches_for_merge_requests_spec.rb @@ -31,10 +31,7 @@ RSpec.describe 'User searches for merge requests', :js do context 'when on a project page' do it 'finds a merge request' do find('.js-search-project-dropdown').click - - page.within('.project-filter') do - click_link(project.full_name) - end + find('[data-testid="project-filter"]').click_link(project.full_name) fill_in('dashboard_search', with: merge_request1.title) find('.btn-search').click diff --git a/spec/features/search/user_searches_for_milestones_spec.rb b/spec/features/search/user_searches_for_milestones_spec.rb index 64e756db180..1a2227db214 100644 --- a/spec/features/search/user_searches_for_milestones_spec.rb +++ b/spec/features/search/user_searches_for_milestones_spec.rb @@ -31,10 +31,7 @@ RSpec.describe 'User searches for milestones', :js do context 'when on a project page' do it 'finds a milestone' do find('.js-search-project-dropdown').click - - page.within('.project-filter') do - click_link(project.full_name) - end + find('[data-testid="project-filter"]').click_link(project.full_name) fill_in('dashboard_search', with: milestone1.title) find('.btn-search').click diff --git a/spec/features/search/user_searches_for_wiki_pages_spec.rb b/spec/features/search/user_searches_for_wiki_pages_spec.rb index fc60b6244d9..6bf1407fd4f 100644 --- a/spec/features/search/user_searches_for_wiki_pages_spec.rb +++ b/spec/features/search/user_searches_for_wiki_pages_spec.rb @@ -19,10 +19,7 @@ RSpec.describe 'User searches for wiki pages', :js do shared_examples 'search wiki blobs' do it 'finds a page' do find('.js-search-project-dropdown').click - - page.within('.project-filter') do - click_link(project.full_name) - end + find('[data-testid="project-filter"]').click_link(project.full_name) fill_in('dashboard_search', with: search_term) find('.btn-search').click diff --git a/spec/features/search/user_uses_header_search_field_spec.rb b/spec/features/search/user_uses_header_search_field_spec.rb index 5cbfacf4e48..9296a3f33d4 100644 --- a/spec/features/search/user_uses_header_search_field_spec.rb +++ b/spec/features/search/user_uses_header_search_field_spec.rb @@ -5,11 +5,18 @@ require 'spec_helper' RSpec.describe 'User uses header search field', :js do include FilteredSearchHelpers - let(:project) { create(:project) } - let(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:reporter) { create(:user) } + let_it_be(:developer) { create(:user) } + + let(:user) { reporter } + + before_all do + project.add_reporter(reporter) + project.add_developer(developer) + end before do - project.add_reporter(user) sign_in(user) end @@ -34,7 +41,7 @@ RSpec.describe 'User uses header search field', :js do wait_for_all_requests end - it 'shows the category search dropdown' do + it 'shows the category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i) end end @@ -44,7 +51,7 @@ RSpec.describe 'User uses header search field', :js do page.find('#search').click end - it 'shows category search dropdown' do + it 'shows category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i) end @@ -104,7 +111,7 @@ RSpec.describe 'User uses header search field', :js do let(:scope_name) { 'All GitLab' } end - it 'displays search options' do + it 'displays search options', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/251076' do fill_in_search('test') expect(page).to have_selector(scoped_search_link('test')) @@ -132,6 +139,10 @@ RSpec.describe 'User uses header search field', :js do let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } + before do + project.add_reporter(user) + end + include_examples 'search field examples' do let(:url) { project_path(project) } let(:scope_name) { project.name } @@ -159,6 +170,35 @@ RSpec.describe 'User uses header search field', :js do 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 + + it 'displays a link to project merge requests' do + fill_in_search('Merge') + + within(dashboard_search_options_popup_menu) do + expect(page).to have_text('Merge Requests') + end + end + + it 'does not display a link to project feature flags' do + fill_in_search('Feature') + + within(dashboard_search_options_popup_menu) do + expect(page).to have_text('"Feature" in all GitLab') + expect(page).to have_no_text('Feature Flags') + end + end + + context 'and user is a developer' do + let(:user) { developer } + + it 'displays a link to project feature flags' do + fill_in_search('Feature') + + within(dashboard_search_options_popup_menu) do + expect(page).to have_text('Feature Flags') + end + end + end end end @@ -217,4 +257,8 @@ RSpec.describe 'User uses header search field', :js do ".dropdown a[href='#{href}']" end + + def dashboard_search_options_popup_menu + "div[data-testid='dashboard-search-options']" + end end diff --git a/spec/features/search/user_uses_search_filters_spec.rb b/spec/features/search/user_uses_search_filters_spec.rb index 080cced21c3..bd77e6003e3 100644 --- a/spec/features/search/user_uses_search_filters_spec.rb +++ b/spec/features/search/user_uses_search_filters_spec.rb @@ -18,17 +18,17 @@ RSpec.describe 'User uses search filters', :js do it 'shows group projects' do visit search_path - find('.js-search-group-dropdown').click + find('[data-testid="group-filter"]').click wait_for_requests - page.within('.search-page-form') do - click_link(group.name) + page.within('[data-testid="group-filter"]') do + click_on(group.name) end - expect(find('.js-search-group-dropdown')).to have_content(group.name) + expect(find('[data-testid="group-filter"]')).to have_content(group.name) - page.within('.project-filter') do + page.within('[data-testid="project-filter"]') do find('.js-search-project-dropdown').click wait_for_requests @@ -44,10 +44,11 @@ RSpec.describe 'User uses search filters', :js do describe 'clear filter button' do it 'removes Group and Project filters' do - link = find('[data-testid="group-filter"] .js-search-clear') - params = CGI.parse(URI.parse(link[:href]).query) + find('[data-testid="group-filter"] [data-testid="clear-icon"]').click + + wait_for_requests - expect(params).not_to include(:group_id, :project_id) + expect(page).to have_current_path(search_path(search: "test")) end end end @@ -57,7 +58,7 @@ RSpec.describe 'User uses search filters', :js do it 'shows a project' do visit search_path - page.within('.project-filter') do + page.within('[data-testid="project-filter"]') do find('.js-search-project-dropdown').click wait_for_requests @@ -77,7 +78,7 @@ RSpec.describe 'User uses search filters', :js do describe 'clear filter button' do it 'removes Project filters' do - link = find('.project-filter .js-search-clear') + link = find('[data-testid="project-filter"] .js-search-clear') params = CGI.parse(URI.parse(link[:href]).query) expect(params).not_to include(:project_id) |