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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
require 'rails_helper'
describe 'Visual tokens', :js do
include FilteredSearchHelpers
let!(:project) { create(:project) }
let!(:user) { create(:user, name: 'administrator', username: 'root') }
let!(:user_rock) { create(:user, name: 'The Rock', username: 'rock') }
let!(:milestone_nine) { create(:milestone, title: '9.0', project: project) }
let!(:milestone_ten) { create(:milestone, title: '10.0', project: project) }
let!(:label) { create(:label, project: project, title: 'abc') }
let!(:cc_label) { create(:label, project: project, title: 'Community Contribution') }
let(:filtered_search) { find('.filtered-search') }
let(:filter_author_dropdown) { find("#js-dropdown-author .filter-dropdown") }
let(:filter_assignee_dropdown) { find("#js-dropdown-assignee .filter-dropdown") }
let(:filter_milestone_dropdown) { find("#js-dropdown-milestone .filter-dropdown") }
let(:filter_label_dropdown) { find("#js-dropdown-label .filter-dropdown") }
def is_input_focused
page.evaluate_script("document.activeElement.classList.contains('filtered-search')")
end
before do
project.add_user(user, :maintainer)
project.add_user(user_rock, :maintainer)
sign_in(user)
create(:issue, project: project)
set_cookie('sidebar_collapsed', 'true')
visit project_issues_path(project)
end
describe 'editing author token' do
before do
input_filtered_search('author:@root assignee:none', submit: false)
first('.tokens-container .filtered-search-token').click
end
it 'opens author dropdown' do
expect(page).to have_css('#js-dropdown-author', visible: true)
end
it 'makes value editable' do
expect_filtered_search_input('@root')
end
it 'filters value' do
filtered_search.send_keys(:backspace)
expect(page).to have_css('#js-dropdown-author .filter-dropdown .filter-dropdown-item', count: 1)
end
it 'ends editing mode when document is clicked' do
find('#content-body').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-author', visible: false)
end
it 'ends editing mode when scroll container is clicked' do
find('.scroll-container').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-author', visible: false)
end
describe 'selecting different author from dropdown' do
before do
filter_author_dropdown.find('.filter-dropdown-item .dropdown-light-content', text: "@#{user_rock.username}").click
end
it 'changes value in visual token' do
wait_for_requests
expect(first('.tokens-container .filtered-search-token .value').text).to eq("#{user_rock.name}")
end
it 'moves input to the right' do
expect(is_input_focused).to eq(true)
end
end
end
describe 'editing assignee token' do
before do
input_filtered_search('assignee:@root author:none', submit: false)
first('.tokens-container .filtered-search-token').double_click
end
it 'opens assignee dropdown' do
expect(page).to have_css('#js-dropdown-assignee', visible: true)
end
it 'makes value editable' do
expect_filtered_search_input('@root')
end
it 'filters value' do
filtered_search.send_keys(:backspace)
expect(page).to have_css('#js-dropdown-assignee .filter-dropdown .filter-dropdown-item', count: 1)
end
it 'ends editing mode when document is clicked' do
find('#content-body').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-assignee', visible: false)
end
it 'ends editing mode when scroll container is clicked' do
find('.scroll-container').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-assignee', visible: false)
end
describe 'selecting static option from dropdown' do
before do
find("#js-dropdown-assignee").find('.filter-dropdown-item', text: 'None').click
end
it 'changes value in visual token' do
expect(first('.tokens-container .filtered-search-token .value').text).to eq('none')
end
it 'moves input to the right' do
expect(is_input_focused).to eq(true)
end
end
end
describe 'editing milestone token' do
before do
input_filtered_search('milestone:%10.0 author:none', submit: false)
first('.tokens-container .filtered-search-token').click
first('#js-dropdown-milestone .filter-dropdown .filter-dropdown-item')
end
it 'opens milestone dropdown' do
expect(filter_milestone_dropdown.find('.filter-dropdown-item', text: milestone_ten.title)).to be_visible
expect(filter_milestone_dropdown.find('.filter-dropdown-item', text: milestone_nine.title)).to be_visible
expect(page).to have_css('#js-dropdown-milestone', visible: true)
end
it 'selects static option from dropdown' do
find("#js-dropdown-milestone").find('.filter-dropdown-item', text: 'Upcoming').click
expect(first('.tokens-container .filtered-search-token .value').text).to eq('upcoming')
expect(is_input_focused).to eq(true)
end
it 'makes value editable' do
expect_filtered_search_input('%10.0')
end
it 'filters value' do
filtered_search.send_keys(:backspace)
expect(page).to have_css('#js-dropdown-milestone .filter-dropdown .filter-dropdown-item', count: 1)
end
it 'ends editing mode when document is clicked' do
find('#content-body').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-milestone', visible: false)
end
it 'ends editing mode when scroll container is clicked' do
find('.scroll-container').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-milestone', visible: false)
end
end
describe 'editing label token' do
before do
input_filtered_search("label:~#{label.title} author:none", submit: false)
first('.tokens-container .filtered-search-token').double_click
first('#js-dropdown-label .filter-dropdown .filter-dropdown-item')
end
it 'opens label dropdown' do
expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
expect(page).to have_css('#js-dropdown-label', visible: true)
end
it 'selects option from dropdown' do
expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
find("#js-dropdown-label").find('.filter-dropdown-item', text: cc_label.title).click
expect(first('.tokens-container .filtered-search-token .value').text).to eq("~\"#{cc_label.title}\"")
expect(is_input_focused).to eq(true)
end
it 'makes value editable' do
expect_filtered_search_input("~#{label.title}")
end
it 'filters value' do
expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
filtered_search.send_keys(:backspace)
filter_label_dropdown.find('.filter-dropdown-item')
expect(page.all('#js-dropdown-label .filter-dropdown .filter-dropdown-item').size).to eq(1)
end
it 'ends editing mode when document is clicked' do
find('#content-body').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-label', visible: false)
end
it 'ends editing mode when scroll container is clicked' do
find('.scroll-container').click
expect_filtered_search_input_empty
expect(page).to have_css('#js-dropdown-label', visible: false)
end
end
describe 'editing multiple tokens' do
before do
input_filtered_search('author:@root assignee:none', submit: false)
first('.tokens-container .filtered-search-token').double_click
end
it 'opens author dropdown' do
expect(page).to have_css('#js-dropdown-author', visible: true)
end
it 'opens assignee dropdown' do
find('.tokens-container .filtered-search-token', text: 'Assignee').double_click
expect(page).to have_css('#js-dropdown-assignee', visible: true)
end
end
describe 'editing a search term while editing another filter token' do
before do
input_filtered_search('author assignee:', submit: false)
first('.tokens-container .filtered-search-term').double_click
end
it 'opens hint dropdown' do
expect(page).to have_css('#js-dropdown-hint', visible: true)
end
it 'opens author dropdown' do
find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'author').click
expect(page).to have_css('#js-dropdown-author', visible: true)
end
end
describe 'add new token after editing existing token' do
before do
input_filtered_search('author:@root assignee:none', submit: false)
first('.tokens-container .filtered-search-token').double_click
filtered_search.send_keys(' ')
end
describe 'opens dropdowns' do
it 'opens hint dropdown' do
expect(page).to have_css('#js-dropdown-hint', visible: true)
end
it 'opens author dropdown' do
filtered_search.send_keys('author:')
expect(page).to have_css('#js-dropdown-author', visible: true)
end
it 'opens assignee dropdown' do
filtered_search.send_keys('assignee:')
expect(page).to have_css('#js-dropdown-assignee', visible: true)
end
it 'opens milestone dropdown' do
filtered_search.send_keys('milestone:')
expect(page).to have_css('#js-dropdown-milestone', visible: true)
end
it 'opens label dropdown' do
filtered_search.send_keys('label:')
expect(page).to have_css('#js-dropdown-label', visible: true)
end
end
describe 'creates visual tokens' do
it 'creates author token' do
filtered_search.send_keys('author:@thomas ')
token = page.all('.tokens-container .filtered-search-token')[1]
expect(token.find('.name').text).to eq('Author')
expect(token.find('.value').text).to eq('@thomas')
end
it 'creates assignee token' do
filtered_search.send_keys('assignee:@thomas ')
token = page.all('.tokens-container .filtered-search-token')[1]
expect(token.find('.name').text).to eq('Assignee')
expect(token.find('.value').text).to eq('@thomas')
end
it 'creates milestone token' do
filtered_search.send_keys('milestone:none ')
token = page.all('.tokens-container .filtered-search-token')[1]
expect(token.find('.name').text).to eq('Milestone')
expect(token.find('.value').text).to eq('none')
end
it 'creates label token' do
filtered_search.send_keys('label:~Backend ')
token = page.all('.tokens-container .filtered-search-token')[1]
expect(token.find('.name').text).to eq('Label')
expect(token.find('.value').text).to eq('~Backend')
end
end
it 'does not tokenize incomplete token' do
filtered_search.send_keys('author:')
find('body').click
token = page.all('.tokens-container .js-visual-token')[1]
expect_filtered_search_input_empty
expect(token.find('.name').text).to eq('Author')
end
end
describe 'search using incomplete visual tokens' do
before do
input_filtered_search('author:@root assignee:none', extra_space: false)
end
it 'tokenizes the search term to complete visual token' do
expect_tokens([
author_token(user.name),
assignee_token('none')
])
end
end
end
|