user_uses_header_search_field_spec.rb 4.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'spec_helper'

describe 'User uses header search field' do
  include FilteredSearchHelpers

  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    project.add_reporter(user)
    sign_in(user)
  end

14
  context 'when user is in a global scope', :js do
15
    before do
16
      visit(root_path)
17 18 19 20 21
      page.find('#search').click
    end

    context 'when clicking issues' do
      it 'shows assigned issues' do
22
        find('.search-input-container .dropdown-menu').click_link('Issues assigned to me')
23

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
24 25 26
        expect(page).to have_selector('.filtered-search')
        expect_tokens([assignee_token(user.name)])
        expect_filtered_search_input_empty
27 28 29
      end

      it 'shows created issues' do
30
        find('.search-input-container .dropdown-menu').click_link("Issues I've created")
31

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
32 33 34
        expect(page).to have_selector('.filtered-search')
        expect_tokens([author_token(user.name)])
        expect_filtered_search_input_empty
35 36 37 38 39 40 41
      end
    end

    context 'when clicking merge requests' do
      let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignee: user) }

      it 'shows assigned merge requests' do
42
        find('.search-input-container .dropdown-menu').click_link('Merge requests assigned to me')
43

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
44 45 46
        expect(page).to have_selector('.filtered-search')
        expect_tokens([assignee_token(user.name)])
        expect_filtered_search_input_empty
47 48 49
      end

      it 'shows created merge requests' do
50
        find('.search-input-container .dropdown-menu').click_link("Merge requests I've created")
51

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
52 53 54
        expect(page).to have_selector('.filtered-search')
        expect_tokens([author_token(user.name)])
        expect_filtered_search_input_empty
55 56 57 58
      end
    end
  end

59
  context 'when user is in a project scope' do
60
    before do
61 62 63 64 65 66 67 68 69
      visit(project_path(project))
    end

    it 'starts searching by pressing the enter key', :js do
      fill_in('search', with: 'gitlab')
      find('#search').native.send_keys(:enter)

      page.within('.breadcrumbs-sub-title') do
        expect(page).to have_content('Search')
70 71 72
      end
    end

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
    context 'when clicking the search field', :js do
      before do
        page.find('#search').click
      end

      it 'shows category search dropdown' do
        expect(page).to have_selector('.dropdown-header', text: /#{project.name}/i)
      end

      context 'when clicking issues' do
        let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }

        it 'shows assigned issues' do
          find('.dropdown-menu').click_link('Issues assigned to me')

          expect(page).to have_selector('.filtered-search')
          expect_tokens([assignee_token(user.name)])
          expect_filtered_search_input_empty
        end

        it 'shows created issues' do
          find('.dropdown-menu').click_link("Issues I've created")

          expect(page).to have_selector('.filtered-search')
          expect_tokens([author_token(user.name)])
          expect_filtered_search_input_empty
        end
      end

      context 'when clicking merge requests' do
        let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignee: user) }

        it 'shows assigned merge requests' do
          find('.dropdown-menu').click_link('Merge requests assigned to me')

          expect(page).to have_selector('.merge-requests-holder')
          expect_tokens([assignee_token(user.name)])
          expect_filtered_search_input_empty
        end

        it 'shows created merge requests' do
          find('.dropdown-menu').click_link("Merge requests I've created")

          expect(page).to have_selector('.merge-requests-holder')
          expect_tokens([author_token(user.name)])
          expect_filtered_search_input_empty
        end
      end
    end

    context 'when entering text into the search field', :js do
      before do
        page.within('.search-input-wrap') do
          fill_in('search', with: project.name[0..3])
        end
      end

      it 'does not display the category search dropdown' do
        expect(page).not_to have_selector('.dropdown-header', text: /#{project.name}/i)
      end
133 134 135
    end
  end
end