debian-mirror-gitlab/spec/views/search/_results.html.haml_spec.rb

156 lines
5.3 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe 'search/_results' do
2021-02-22 17:27:13 +05:30
let(:user) { create(:user) }
2020-11-24 15:15:51 +05:30
let(:search_objects) { Issue.page(1).per(2) }
let(:scope) { 'issues' }
2021-02-22 17:27:13 +05:30
let(:term) { 'foo' }
2020-11-24 15:15:51 +05:30
2019-12-04 20:38:33 +05:30
before do
controller.params[:action] = 'show'
2021-02-22 17:27:13 +05:30
controller.params[:search] = term
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
create_list(:issue, 3)
2019-12-04 20:38:33 +05:30
2020-11-24 15:15:51 +05:30
@search_objects = search_objects
@scope = scope
2021-02-22 17:27:13 +05:30
@search_term = term
@search_service = SearchServicePresenter.new(SearchService.new(user, search: term, scope: scope))
allow(@search_service).to receive(:search_objects).and_return(search_objects)
2019-12-04 20:38:33 +05:30
end
it 'displays the page size' do
render
2020-01-01 13:55:28 +05:30
expect(rendered).to have_content('Showing 1 - 2 of 3 issues for foo')
2019-12-04 20:38:33 +05:30
end
2021-04-29 21:17:54 +05:30
context 'when searching notes which contain quotes in markdown' do
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project, title: '*') }
let_it_be(:note) { create(:discussion_note_on_issue, noteable: issue, project: issue.project, note: '```"helloworld"```') }
2021-09-30 23:02:18 +05:30
2021-04-29 21:17:54 +05:30
let(:scope) { 'notes' }
let(:search_objects) { Note.page(1).per(2) }
let(:term) { 'helloworld' }
it 'renders plain quotes' do
render
expect(rendered).to include('"<mark>helloworld</mark>"')
end
end
2019-12-04 20:38:33 +05:30
context 'when search results do not have a count' do
before do
@search_objects = @search_objects.without_count
end
it 'does not display the page size' do
render
expect(rendered).not_to have_content(/Showing .* of .*/)
end
end
2020-11-24 15:15:51 +05:30
context 'rendering all types of search results' do
let_it_be(:project) { create(:project, :repository, :wiki_repo) }
2022-05-07 20:08:51 +05:30
let_it_be(:issue) { create(:issue, project: project, title: 'testing') }
let_it_be(:merge_request) { create(:merge_request, title: 'testing', source_project: project, target_project: project) }
let_it_be(:milestone) { create(:milestone, title: 'testing', project: project) }
let_it_be(:note) { create(:discussion_note_on_issue, project: project, note: 'testing') }
let_it_be(:wiki_blob) { create(:wiki_page, wiki: project.wiki, content: 'testing') }
2020-11-24 15:15:51 +05:30
let_it_be(:user) { create(:admin) }
2021-01-29 00:20:46 +05:30
%w[issues merge_requests].each do |search_scope|
2020-11-24 15:15:51 +05:30
context "when scope is #{search_scope}" do
let(:scope) { search_scope }
2022-05-07 20:08:51 +05:30
let(:search_objects) { Gitlab::ProjectSearchResults.new(user, 'testing', project: project).objects(scope) }
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
context 'when admin mode is enabled', :enable_admin_mode do
it 'renders the click text event tracking attributes' do
render
2021-11-11 11:23:49 +05:30
expect(rendered).to have_selector('[data-track-action=click_text]')
2021-02-22 17:27:13 +05:30
expect(rendered).to have_selector('[data-track-property=search_result]')
end
end
context 'when admin mode is disabled' do
it 'does not render the click text event tracking attributes' do
render
2020-11-24 15:15:51 +05:30
2021-11-11 11:23:49 +05:30
expect(rendered).not_to have_selector('[data-track-action=click_text]')
2021-02-22 17:27:13 +05:30
expect(rendered).not_to have_selector('[data-track-property=search_result]')
end
2020-11-24 15:15:51 +05:30
end
2021-01-29 00:20:46 +05:30
it 'does render the sidebar' do
2020-11-24 15:15:51 +05:30
render
2021-01-29 00:20:46 +05:30
expect(rendered).to have_selector('#js-search-sidebar')
2020-11-24 15:15:51 +05:30
end
2021-01-29 00:20:46 +05:30
end
end
2021-01-03 14:25:43 +05:30
2022-05-07 20:08:51 +05:30
describe 'git blame click tracking' do
let(:scope) { 'blobs' }
let(:search_objects) { Gitlab::ProjectSearchResults.new(user, 'testing', project: project).objects(scope) }
context 'when admin mode is enabled', :enable_admin_mode do
it 'renders the click link event tracking attributes' do
render
expect(rendered).to have_selector('[data-track-action=click_link]')
expect(rendered).to have_selector('[data-track-label=git_blame]')
expect(rendered).to have_selector('[data-track-property=search_result]')
end
end
context 'when admin mode is disabled' do
it 'does not render the click link event tracking attributes' do
render
expect(rendered).not_to have_selector('[data-track-action=click_link]')
expect(rendered).not_to have_selector('[data-track-label=git_blame]')
expect(rendered).not_to have_selector('[data-track-property=search_result]')
end
end
end
2021-01-29 00:20:46 +05:30
%w[blobs notes wiki_blobs milestones].each do |search_scope|
context "when scope is #{search_scope}" do
let(:scope) { search_scope }
2022-05-07 20:08:51 +05:30
let(:search_objects) { Gitlab::ProjectSearchResults.new(user, 'testing', project: project).objects(scope) }
2021-01-03 14:25:43 +05:30
2021-02-22 17:27:13 +05:30
context 'when admin mode is enabled', :enable_admin_mode do
it 'renders the click text event tracking attributes' do
render
2021-11-11 11:23:49 +05:30
expect(rendered).to have_selector('[data-track-action=click_text]')
2021-02-22 17:27:13 +05:30
expect(rendered).to have_selector('[data-track-property=search_result]')
end
end
context 'when admin mode is disabled' do
it 'does not render the click text event tracking attributes' do
render
2021-01-03 14:25:43 +05:30
2021-11-11 11:23:49 +05:30
expect(rendered).not_to have_selector('[data-track-action=click_text]')
2021-02-22 17:27:13 +05:30
expect(rendered).not_to have_selector('[data-track-property=search_result]')
end
2021-01-29 00:20:46 +05:30
end
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
it 'does not render the sidebar' do
render
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
expect(rendered).not_to have_selector('#js-search-sidebar')
2021-01-03 14:25:43 +05:30
end
2020-11-24 15:15:51 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
end