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

138 lines
3.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 searches for issues', :js do
2018-03-17 18:26:18 +05:30
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
2021-01-29 00:20:46 +05:30
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) }
2020-11-24 15:15:51 +05:30
def search_for_issue(search)
fill_in('dashboard_search', with: search)
find('.btn-search').click
select_search_scope('Issues')
end
2018-03-17 18:26:18 +05:30
context 'when signed in' do
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
sign_in(user)
visit(search_path)
end
include_examples 'top right search form'
it 'finds an issue' do
2020-11-24 15:15:51 +05:30
search_for_issue(issue1.title)
2018-03-17 18:26:18 +05:30
page.within('.results') do
2019-12-04 20:38:33 +05:30
expect(page).to have_link(issue1.title)
expect(page).not_to have_link(issue2.title)
2018-03-17 18:26:18 +05:30
end
end
2020-11-24 15:15:51 +05:30
it 'hides confidential icon for non-confidential issues' do
search_for_issue(issue1.title)
page.within('.results') do
expect(page).not_to have_css('[data-testid="eye-slash-icon"]')
end
end
it 'shows confidential icon for confidential issues' do
search_for_issue(issue2.title)
page.within('.results') do
expect(page).to have_css('[data-testid="eye-slash-icon"]')
end
end
it 'shows correct badge for open issues' do
search_for_issue(issue1.title)
page.within('.results') do
expect(page).to have_css('.badge-success')
expect(page).not_to have_css('.badge-info')
end
end
it 'shows correct badge for closed issues' do
search_for_issue(issue2.title)
page.within('.results') do
expect(page).not_to have_css('.badge-success')
expect(page).to have_css('.badge-info')
end
end
2021-01-29 00:20:46 +05:30
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
2021-03-11 19:13:27 +05:30
find('[data-testid="sort-highest-icon"]').click
2021-01-29 00:20:46 +05:30
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
2018-03-17 18:26:18 +05:30
context 'when on a project page' do
it 'finds an issue' do
2021-02-22 17:27:13 +05:30
find('[data-testid="project-filter"]').click
wait_for_requests
page.within('[data-testid="project-filter"]') do
click_on(project.full_name)
end
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
search_for_issue(issue1.title)
2018-03-17 18:26:18 +05:30
page.within('.results') do
2019-12-04 20:38:33 +05:30
expect(page).to have_link(issue1.title)
expect(page).not_to have_link(issue2.title)
2018-03-17 18:26:18 +05:30
end
end
end
end
context 'when signed out' do
2020-11-24 15:15:51 +05:30
context 'when block_anonymous_global_searches is disabled' do
let(:project) { create(:project, :public) }
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
before do
stub_feature_flags(block_anonymous_global_searches: false)
visit(search_path)
end
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
include_examples 'top right search form'
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
it 'finds an issue' do
search_for_issue(issue1.title)
2018-03-17 18:26:18 +05:30
2020-11-24 15:15:51 +05:30
page.within('.results') do
expect(page).to have_link(issue1.title)
expect(page).not_to have_link(issue2.title)
end
end
end
context 'when block_anonymous_global_searches is enabled' do
before do
visit(search_path)
end
it 'is redirected to login page' do
expect(page).to have_content('You must be logged in to search across all of GitLab')
2018-03-17 18:26:18 +05:30
end
end
end
end