summaryrefslogtreecommitdiff
path: root/spec/views/search/show.html.haml_spec.rb
blob: 26ec2c6ae745084f274a0cb6dc60223d3b950ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'search/show', feature_category: :global_search do
  let(:search_term) { nil }
  let(:user) { build(:user) }
  let(:search_service_presenter) do
    instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false)
  end

  before do
    stub_template "search/_category.html.haml" => 'Category Partial'
    stub_template "search/_results.html.haml" => 'Results Partial'

    assign(:search_service, search_service_presenter)
  end

  context 'search_page_vertical_nav feature flag enabled' do
    before do
      allow(view).to receive(:current_user) { user }
      assign(:search_term, search_term)
    end

    context 'when search term is supplied' do
      let(:search_term) { 'Search Foo' }

      it 'will not render category partial' do
        render

        expect(rendered).not_to render_template('search/_category')
        expect(rendered).to render_template('search/_results')
      end
    end
  end

  context 'search_page_vertical_nav feature flag disabled' do
    before do
      stub_feature_flags(search_page_vertical_nav: false)

      assign(:search_term, search_term)
    end

    context 'when the search page is opened' do
      it 'displays the title' do
        render

        expect(rendered).to have_selector('h1.page-title', text: 'Search')
        expect(rendered).not_to have_selector('h1.page-title code')
      end

      it 'does not render partials' do
        render

        expect(rendered).not_to render_template('search/_category')
        expect(rendered).not_to render_template('search/_results')
      end
    end

    context 'when search term is supplied' do
      let(:search_term) { 'Search Foo' }

      it 'renders partials' do
        render

        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

        before do
          assign(:search_results, search_results)
          assign(:scope, 'issues')
          assign(:group, group)
        end

        context 'search with full count' do
          let(:search_service_presenter) do
            instance_double(SearchServicePresenter, without_count?: false, advanced_search_enabled?: false)
          end

          it 'renders meta tags for a group' do
            render

            expect(view.page_description).to match(/\d+ issues for term '#{search_term}'/)
            expect(view.page_card_attributes).to eq("Namespace" => group.full_path)
          end

          it 'renders meta tags for both group and project' do
            project = build(:project, group: group)
            assign(:project, project)

            render

            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
        end

        context 'search without full count' do
          let(:search_service_presenter) do
            instance_double(SearchServicePresenter, without_count?: true, advanced_search_enabled?: false)
          end

          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

          it 'renders meta tags for both group and project' do
            project = build(:project, group: group)
            assign(:project, project)

            render

            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
        end
      end
    end
  end
end