summaryrefslogtreecommitdiff
path: root/spec/features/search/user_searches_for_projects_spec.rb
blob: 562da56275c4faa1521b44d7c1dbfd2d8888d444 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User searches for projects', :js do
  let!(:project) { create(:project, :public, name: 'Shop') }

  context 'when signed out' do
    context 'when block_anonymous_global_searches is disabled' do
      before do
        allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit).and_return(1000)
        allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(:search_rate_limit_unauthenticated).and_return(1000)
        stub_feature_flags(block_anonymous_global_searches: false)
      end

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

      it 'finds a project' do
        visit(search_path)

        fill_in('dashboard_search', with: project.name[0..3])
        click_button('Search')

        expect(page).to have_link(project.name)
      end

      it 'preserves the group being searched in' do
        visit(search_path(group_id: project.namespace.id))

        submit_search('foo')

        expect(find('#group_id', visible: false).value).to eq(project.namespace.id.to_s)
      end

      it 'preserves the project being searched in' do
        visit(search_path(project_id: project.id))

        submit_search('foo')

        expect(find('#project_id', visible: false).value).to eq(project.id.to_s)
      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