summaryrefslogtreecommitdiff
path: root/spec/features/issues/filtered_search/dropdown_author_spec.rb
blob: 91c85825a175592d9dff4a331198546a20db18bb (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Dropdown author', :js do
  include FilteredSearchHelpers

  let!(:project) { create(:project) }
  let!(:user) { create(:user, name: 'administrator', username: 'root') }
  let(:js_dropdown_author) { '#js-dropdown-author' }
  let(:filter_dropdown) { find("#{js_dropdown_author} .filter-dropdown") }

  before do
    project.add_maintainer(user)
    sign_in(user)
    create(:issue, project: project)

    visit project_issues_path(project)
  end

  describe 'behavior' do
    it 'loads all the authors when opened' do
      input_filtered_search('author:=', submit: false, extra_space: false)

      expect_filtered_search_dropdown_results(filter_dropdown, 2)
    end

    it 'shows current user at top of dropdown' do
      input_filtered_search('author:=', submit: false, extra_space: false)

      expect(filter_dropdown.first('.filter-dropdown-item')).to have_content(user.name)
    end
  end

  describe 'selecting from dropdown without Ajax call' do
    before do
      Gitlab::Testing::RequestBlockerMiddleware.block_requests!
      input_filtered_search('author:=', submit: false, extra_space: false)
    end

    after do
      Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
    end

    it 'selects current user' do
      find("#{js_dropdown_author} .filter-dropdown-item", text: user.username).click

      expect(page).to have_css(js_dropdown_author, visible: false)
      expect_tokens([author_token(user.username)])
      expect_filtered_search_input_empty
    end
  end
end