summaryrefslogtreecommitdiff
path: root/spec/views/search/_results.html.haml_spec.rb
blob: 033b2304e3357ff39b7b3671ec8857a65e4f0746 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'search/_results' do
  let(:search_objects) { Issue.page(1).per(2) }
  let(:scope) { 'issues' }

  before do
    controller.params[:action] = 'show'

    create_list(:issue, 3)

    @search_objects = search_objects
    @scope = scope
    @search_term = 'foo'
  end

  it 'displays the page size' do
    render

    expect(rendered).to have_content('Showing 1 - 2 of 3 issues for foo')
  end

  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

  context 'rendering all types of search results' do
    let_it_be(:project) { create(:project, :repository, :wiki_repo) }
    let_it_be(:issue) { create(:issue, project: project, title: '*') }
    let_it_be(:merge_request) { create(:merge_request, title: '*', source_project: project, target_project: project) }
    let_it_be(:milestone) { create(:milestone, title: '*', project: project) }
    let_it_be(:note) { create(:discussion_note_on_issue, project: project, note: '*') }
    let_it_be(:wiki_blob) { create(:wiki_page, project: project, content: '*') }
    let_it_be(:user) { create(:admin) }

    %w[issues blobs notes wiki_blobs merge_requests milestones].each do |search_scope|
      context "when scope is #{search_scope}" do
        let(:scope) { search_scope }
        let(:search_objects) { Gitlab::ProjectSearchResults.new(user, '*', project: project).objects(scope) }

        it 'renders the click text event tracking attributes' do
          render

          expect(rendered).to have_selector('[data-track-event=click_text]')
          expect(rendered).to have_selector('[data-track-property=search_result]')
        end

        it 'renders the state filter drop down' do
          render

          expect(rendered).to have_selector('#js-search-filter-by-state')
        end

        context 'Feature search_filter_by_confidential' do
          context 'when disabled' do
            before do
              stub_feature_flags(search_filter_by_confidential: false)
            end

            it 'does not render the confidential drop down' do
              render

              expect(rendered).not_to have_selector('#js-search-filter-by-confidential')
            end
          end

          context 'when enabled' do
            it 'renders the confidential drop down' do
              render

              expect(rendered).to have_selector('#js-search-filter-by-confidential')
            end
          end
        end
      end
    end
  end
end