summaryrefslogtreecommitdiff
path: root/spec/features/search/user_searches_for_issues_spec.rb
blob: 4bff269f89e87cfcb18bb4ad1650e3e4d1a5da44 (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
require 'spec_helper'

describe 'User searches for issues', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project, namespace: user.namespace) }
  let!(:issue1) { create(:issue, title: 'Foo', project: project) }
  let!(:issue2) { create(:issue, title: 'Bar', project: project) }

  context 'when signed in' do
    before do
      project.add_maintainer(user)
      sign_in(user)

      visit(search_path)
    end

    include_examples 'top right search form'

    it 'finds an issue' do
      fill_in('dashboard_search', with: issue1.title)
      find('.btn-search').click

      page.within('.search-filter') do
        click_link('Issues')
      end

      page.within('.results') do
        expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
      end
    end

    context 'when on a project page' do
      it 'finds an issue' do
        find('.js-search-project-dropdown').click

        page.within('.project-filter') do
          click_link(project.full_name)
        end

        fill_in('dashboard_search', with: issue1.title)
        find('.btn-search').click

        page.within('.search-filter') do
          click_link('Issues')
        end

        page.within('.results') do
          expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
        end
      end
    end
  end

  context 'when signed out' do
    let(:project) { create(:project, :public) }

    before do
      visit(search_path)
    end

    include_examples 'top right search form'

    it 'finds an issue' do
      fill_in('dashboard_search', with: issue1.title)
      find('.btn-search').click

      page.within('.search-filter') do
        click_link('Issues')
      end

      page.within('.results') do
        expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
      end
    end
  end
end