Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_searches_for_issues_spec.rb « search « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ebbe86d1a9c1be4ef1bd6fe34484039b8d6a58f (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User searches for issues', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do
  using RSpec::Parameterized::TableSyntax

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, namespace: user.namespace) }

  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) }

  def search_for_issue(search)
    fill_in('dashboard_search', with: search)
    find('.gl-search-box-by-click-search-button').click
    select_search_scope('Issues')
  end

  where(search_page_vertical_nav_enabled: [true, false])

  with_them do
    context 'when signed in' do
      before do
        stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled)

        project.add_maintainer(user)
        sign_in(user)

        visit(search_path)
      end

      include_examples 'top right search form'
      include_examples 'search timeouts', 'issues'

      it 'finds an issue' do
        search_for_issue(issue1.title)

        page.within('.results') do
          expect(page).to have_link(issue1.title)
          expect(page).not_to have_link(issue2.title)
        end
      end

      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

      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

        find('[data-testid="sort-highest-icon"]').click

        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

      context 'when on a project page' do
        it 'finds an issue' do
          find('[data-testid="project-filter"]').click

          wait_for_requests

          page.within('[data-testid="project-filter"]') do
            click_on(project.name)
          end

          search_for_issue(issue1.title)

          page.within('.results') do
            expect(page).to have_link(issue1.title)
            expect(page).not_to have_link(issue2.title)
          end
        end
      end
    end

    context 'when signed out' do
      before do
        stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled)
      end

      context 'when block_anonymous_global_searches is disabled' do
        let_it_be(:project) { create(:project, :public) }

        before do
          stub_feature_flags(block_anonymous_global_searches: false)

          visit(search_path)
        end

        include_examples 'top right search form'

        it 'finds an issue' do
          search_for_issue(issue1.title)

          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
        it 'is redirected to login page' do
          visit(search_path)

          expect(page).to have_content('You must be logged in to search across all of GitLab')
        end
      end
    end
  end
end