summaryrefslogtreecommitdiff
path: root/spec/features/issues/filtered_search/visual_tokens_spec.rb
blob: 854b88c3f81704c5120775132206697e99cff337 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Visual tokens', :js do
  include FilteredSearchHelpers

  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user, name: 'administrator', username: 'root') }
  let_it_be(:user_rock) { create(:user, name: 'The Rock', username: 'rock') }
  let_it_be(:milestone_nine) { create(:milestone, title: '9.0', project: project) }
  let_it_be(:milestone_ten) { create(:milestone, title: '10.0', project: project) }
  let_it_be(:label) { create(:label, project: project, title: 'abc') }
  let_it_be(:cc_label) { create(:label, project: project, title: 'Community Contribution') }
  let_it_be(:issue) { create(:issue, project: project) }

  before do
    stub_feature_flags(or_issuable_queries: false)
    project.add_member(user, :maintainer)
    project.add_member(user_rock, :maintainer)
    sign_in(user)

    visit project_issues_path(project)
  end

  describe 'editing a single token' do
    before do
      select_tokens 'Author', '=', user.username, 'Assignee', '=', 'None'
      click_token_segment(user.name)
    end

    it 'opens author dropdown' do
      expect_visible_suggestions_list
      expect(page).to have_field('Search', with: 'root')
    end

    it 'filters value' do
      send_keys :backspace

      expect_suggestion_count 1
    end

    it 'ends editing mode when document is clicked' do
      find('.js-navbar').click

      expect_empty_search_term
      expect_hidden_suggestions_list
    end

    describe 'selecting different author from dropdown' do
      before do
        send_keys :backspace, :backspace, :backspace, :backspace
        click_on user_rock.name
      end

      it 'changes value in visual token' do
        expect_author_token(user_rock.name)
      end
    end
  end

  describe 'editing multiple tokens' do
    before do
      select_tokens 'Author', '=', user.username, 'Assignee', '=', 'None'
      click_token_segment(user.name)
    end

    it 'opens author dropdown' do
      expect_visible_suggestions_list
    end

    it 'opens assignee dropdown' do
      click_token_segment 'Assignee'

      expect_visible_suggestions_list
    end
  end

  describe 'editing a search term while editing another filter token' do
    before do
      click_filtered_search_bar
      send_keys 'foo '
      select_tokens 'Assignee', '='
      click_token_segment 'foo'
      send_keys ' '
    end

    it 'opens author dropdown' do
      click_on 'Author'

      expect_suggestion '='
      expect_suggestion '!='

      click_on '= is'

      expect_suggestion(user.name)
      expect_suggestion(user_rock.name)
    end
  end

  describe 'add new token after editing existing token' do
    before do
      select_tokens 'Assignee', '=', user.username, 'Label', '=', 'None'
      click_token_segment(user.name)
      send_keys ' '
    end

    describe 'opens dropdowns' do
      it 'opens hint dropdown' do
        expect_visible_suggestions_list
      end

      it 'opens token dropdown' do
        click_on 'Author'

        expect_visible_suggestions_list
      end
    end

    describe 'visual tokens' do
      it 'creates visual token' do
        click_on 'Author'
        click_on '= is'
        click_on 'The Rock'

        expect_author_token 'The Rock'
      end
    end

    it 'does not tokenize incomplete token' do
      click_on 'Author'
      find('.js-navbar').click

      expect_empty_search_term
      expect_token_segment 'Assignee'
    end
  end

  describe 'search using incomplete visual tokens' do
    before do
      select_tokens 'Author', '=', user.username, 'Assignee', '=', 'None'
    end

    it 'tokenizes the search term to complete visual token' do
      expect_author_token(user.name)
      expect_assignee_token 'None'
    end
  end

  it 'does retain hint token when mix of typing and clicks are performed' do
    select_tokens 'Label'
    click_on '= is'

    expect_token_segment 'Label'
    expect_token_segment '='
  end

  describe 'Any/None option' do
    it 'hidden when NOT operator is selected' do
      select_tokens 'Milestone', '!='

      expect_no_suggestion 'Any'
      expect_no_suggestion 'None'
    end

    it 'shown when EQUAL operator is selected' do
      select_tokens 'Milestone', '='

      expect_suggestion 'Any'
      expect_suggestion 'None'
    end
  end
end