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

133 lines
4.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'search/show', feature_category: :global_search do
2019-10-12 21:52:04 +05:30
let(:search_term) { nil }
2022-11-25 23:54:43 +05:30
let(:user) { build(:user) }
2023-03-04 22:38:38 +05:30
let(:search_service_presenter) do
instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false)
end
2019-10-12 21:52:04 +05:30
before do
stub_template "search/_category.html.haml" => 'Category Partial'
stub_template "search/_results.html.haml" => 'Results Partial'
2023-03-04 22:38:38 +05:30
2023-03-17 16:20:25 +05:30
assign(:search_service_presenter, search_service_presenter)
2019-10-12 21:52:04 +05:30
end
2023-01-13 00:05:48 +05:30
context 'search_page_vertical_nav feature flag enabled' do
2022-11-25 23:54:43 +05:30
before do
2023-01-13 00:05:48 +05:30
allow(view).to receive(:current_user) { user }
assign(:search_term, search_term)
2019-10-12 21:52:04 +05:30
end
2022-11-25 23:54:43 +05:30
context 'when search term is supplied' do
let(:search_term) { 'Search Foo' }
it 'will not render category partial' do
2023-03-04 22:38:38 +05:30
render
2022-11-25 23:54:43 +05:30
expect(rendered).not_to render_template('search/_category')
expect(rendered).to render_template('search/_results')
end
2019-10-12 21:52:04 +05:30
end
end
2023-01-13 00:05:48 +05:30
context 'search_page_vertical_nav feature flag disabled' do
2022-11-25 23:54:43 +05:30
before do
stub_feature_flags(search_page_vertical_nav: false)
2019-10-12 21:52:04 +05:30
2023-01-13 00:05:48 +05:30
assign(:search_term, search_term)
2019-10-12 21:52:04 +05:30
end
2020-10-24 23:57:45 +05:30
2022-11-25 23:54:43 +05:30
context 'when the search page is opened' do
it 'displays the title' do
2023-03-04 22:38:38 +05:30
render
2022-11-25 23:54:43 +05:30
expect(rendered).to have_selector('h1.page-title', text: 'Search')
expect(rendered).not_to have_selector('h1.page-title code')
2020-10-24 23:57:45 +05:30
end
2022-11-25 23:54:43 +05:30
it 'does not render partials' do
2023-03-04 22:38:38 +05:30
render
2022-11-25 23:54:43 +05:30
expect(rendered).not_to render_template('search/_category')
expect(rendered).not_to render_template('search/_results')
2020-10-24 23:57:45 +05:30
end
2022-11-25 23:54:43 +05:30
end
context 'when search term is supplied' do
let(:search_term) { 'Search Foo' }
it 'renders partials' do
2023-03-04 22:38:38 +05:30
render
2022-11-25 23:54:43 +05:30
expect(rendered).to render_template('search/_category')
expect(rendered).to render_template('search/_results')
end
context 'unfurling support' do
let(:group) { build(:group) }
let(:search_results) do
instance_double(Gitlab::GroupSearchResults).tap do |double|
allow(double).to receive(:formatted_count).and_return(0)
end
end
2020-10-24 23:57:45 +05:30
2021-10-27 15:23:28 +05:30
before do
2022-11-25 23:54:43 +05:30
assign(:search_results, search_results)
assign(:scope, 'issues')
assign(:group, group)
2021-10-27 15:23:28 +05:30
end
2022-11-25 23:54:43 +05:30
context 'search with full count' do
2023-03-04 22:38:38 +05:30
let(:search_service_presenter) do
instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false)
2022-11-25 23:54:43 +05:30
end
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
it 'renders meta tags for a group' do
render
2020-10-24 23:57:45 +05:30
2022-11-25 23:54:43 +05:30
expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/)
expect(view.page_card_attributes).to eq("Namespace" => group.full_path)
end
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
it 'renders meta tags for both group and project' do
project = build(:project, group: group)
assign(:project, project)
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
render
2020-10-24 23:57:45 +05:30
2022-11-25 23:54:43 +05:30
expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/)
expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path)
end
2021-10-27 15:23:28 +05:30
end
2022-11-25 23:54:43 +05:30
context 'search without full count' do
2023-03-04 22:38:38 +05:30
let(:search_service_presenter) do
instance_double(SearchServicePresenter, without_count?: true, advanced_search_enabled?: false)
2022-11-25 23:54:43 +05:30
end
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
it 'renders meta tags for a group' do
render
expect(view.page_description).to match(/issues results for term '#{search_term}'/)
expect(view.page_card_attributes).to eq("Namespace" => group.full_path)
end
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
it 'renders meta tags for both group and project' do
project = build(:project, group: group)
assign(:project, project)
2020-10-24 23:57:45 +05:30
2022-11-25 23:54:43 +05:30
render
2020-10-24 23:57:45 +05:30
2022-11-25 23:54:43 +05:30
expect(view.page_description).to match(/issues results for term '#{search_term}'/)
expect(view.page_card_attributes).to eq("Namespace" => group.full_path, "Project" => project.full_path)
end
2021-10-27 15:23:28 +05:30
end
2020-10-24 23:57:45 +05:30
end
end
2019-10-12 21:52:04 +05:30
end
end