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
|
require 'rails_helper'
describe 'Filter merge requests' do
include FilteredSearchHelpers
include MergeRequestHelpers
let!(:project) { create(:project, :repository) }
let!(:group) { create(:group) }
let!(:user) { create(:user) }
let!(:milestone) { create(:milestone, project: project) }
let!(:label) { create(:label, project: project) }
let!(:wontfix) { create(:label, project: project, title: "Won't fix") }
before do
project.add_master(user)
group.add_developer(user)
sign_in(user)
create(:merge_request, source_project: project, target_project: project)
visit project_merge_requests_path(project)
end
describe 'for assignee from mr#index' do
let(:search_query) { "assignee:@#{user.username}" }
def expect_assignee_visual_tokens
wait_for_requests
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
before do
input_filtered_search(search_query)
expect_mr_list_count(0)
end
context 'assignee', js: true do
it 'updates to current user' do
expect_assignee_visual_tokens()
end
it 'does not change when closed link is clicked' do
find('.issues-state-filters [data-state="closed"]').click
expect_assignee_visual_tokens()
end
it 'does not change when all link is clicked' do
find('.issues-state-filters [data-state="all"]').click
expect_assignee_visual_tokens()
end
end
end
describe 'for milestone from mr#index' do
let(:search_query) { "milestone:%\"#{milestone.title}\"" }
def expect_milestone_visual_tokens
expect_tokens([milestone_token("\"#{milestone.title}\"")])
expect_filtered_search_input_empty
end
before do
input_filtered_search(search_query)
expect_mr_list_count(0)
end
context 'milestone', js: true do
it 'updates to current milestone' do
expect_milestone_visual_tokens()
end
it 'does not change when closed link is clicked' do
find('.issues-state-filters [data-state="closed"]').click
expect_milestone_visual_tokens()
end
it 'does not change when all link is clicked' do
find('.issues-state-filters [data-state="all"]').click
expect_milestone_visual_tokens()
end
end
end
describe 'for label from mr#index', js: true do
it 'filters by no label' do
input_filtered_search('label:none')
expect_mr_list_count(1)
expect_tokens([label_token('none', false)])
expect_filtered_search_input_empty
end
it 'filters by a label' do
input_filtered_search("label:~#{label.title}")
expect_mr_list_count(0)
expect_tokens([label_token(label.title)])
expect_filtered_search_input_empty
end
it "filters by `won't fix` and another label" do
input_filtered_search("label:~\"#{wontfix.title}\" label:~#{label.title}")
expect_mr_list_count(0)
expect_tokens([label_token("\"#{wontfix.title}\""), label_token(label.title)])
expect_filtered_search_input_empty
end
it "filters by `won't fix` label followed by another label after page load" do
input_filtered_search("label:~\"#{wontfix.title}\"")
expect_mr_list_count(0)
expect_tokens([label_token("\"#{wontfix.title}\"")])
expect_filtered_search_input_empty
input_filtered_search_keys("label:~#{label.title}")
expect_mr_list_count(0)
expect_tokens([label_token("\"#{wontfix.title}\""), label_token(label.title)])
expect_filtered_search_input_empty
end
end
describe 'for assignee and label from mr#index' do
let(:search_query) { "assignee:@#{user.username} label:~#{label.title}" }
before do
input_filtered_search(search_query)
expect_mr_list_count(0)
end
context 'assignee and label', js: true do
def expect_assignee_label_visual_tokens
wait_for_requests
expect_tokens([assignee_token(user.name), label_token(label.title)])
expect_filtered_search_input_empty
end
it 'updates to current assignee and label' do
expect_assignee_label_visual_tokens()
end
it 'does not change when closed link is clicked' do
find('.issues-state-filters [data-state="closed"]').click
expect_assignee_label_visual_tokens()
end
it 'does not change when all link is clicked' do
find('.issues-state-filters [data-state="all"]').click
expect_assignee_label_visual_tokens()
end
end
end
describe 'filter merge requests by text' do
before do
create(:merge_request, title: "Bug", source_project: project, target_project: project, source_branch: "wip")
bug_label = create(:label, project: project, title: 'bug')
milestone = create(:milestone, title: "8", project: project)
mr = create(:merge_request,
title: "Bug 2",
source_project: project,
target_project: project,
source_branch: "fix",
milestone: milestone,
author: user,
assignee: user)
mr.labels << bug_label
visit project_merge_requests_path(project)
end
context 'only text', js: true do
it 'filters merge requests by searched text' do
input_filtered_search('bug')
expect_mr_list_count(2)
end
it 'does not show any merge requests' do
input_filtered_search('testing')
page.within '.mr-list' do
expect(page).not_to have_selector('.merge-request')
end
end
end
context 'filters and searches', js: true do
it 'filters by text and label' do
input_filtered_search('Bug')
expect_mr_list_count(2)
expect_filtered_search_input('Bug')
input_filtered_search_keys(' label:~bug')
expect_mr_list_count(1)
expect_tokens([label_token('bug')])
expect_filtered_search_input('Bug')
end
it 'filters by text and milestone' do
input_filtered_search('Bug')
expect_mr_list_count(2)
expect_filtered_search_input('Bug')
input_filtered_search_keys(' milestone:%8')
expect_mr_list_count(1)
expect_tokens([milestone_token('8')])
expect_filtered_search_input('Bug')
end
it 'filters by text and assignee' do
input_filtered_search('Bug')
expect_mr_list_count(2)
expect_filtered_search_input('Bug')
input_filtered_search_keys(" assignee:@#{user.username}")
expect_mr_list_count(1)
wait_for_requests
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input('Bug')
end
it 'filters by text and author' do
input_filtered_search('Bug')
expect_mr_list_count(2)
expect_filtered_search_input('Bug')
input_filtered_search_keys(" author:@#{user.username}")
wait_for_requests
expect_mr_list_count(1)
expect_tokens([author_token(user.name)])
expect_filtered_search_input('Bug')
end
end
end
describe 'filter merge requests and sort', :js do
before do
bug_label = create(:label, project: project, title: 'bug')
mr1 = create(:merge_request, title: "Frontend", source_project: project, target_project: project, source_branch: "wip")
mr2 = create(:merge_request, title: "Bug 2", source_project: project, target_project: project, source_branch: "fix")
mr1.labels << bug_label
mr2.labels << bug_label
visit project_merge_requests_path(project)
end
it 'is able to filter and sort merge requests' do
input_filtered_search('label:~bug')
expect_mr_list_count(2)
click_button 'Last created'
page.within '.dropdown-menu-sort' do
click_link 'Oldest created'
end
wait_for_requests
page.within '.mr-list' do
expect(page).to have_content('Frontend')
end
end
end
describe 'filter by assignee id', js: true do
it 'filter by current user' do
visit project_merge_requests_path(project, assignee_id: user.id)
wait_for_requests
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'filter by new user' do
new_user = create(:user)
project.add_developer(new_user)
visit project_merge_requests_path(project, assignee_id: new_user.id)
wait_for_requests
expect_tokens([assignee_token(new_user.name)])
expect_filtered_search_input_empty
end
end
describe 'filter by author id', js: true do
it 'filter by current user' do
visit project_merge_requests_path(project, author_id: user.id)
wait_for_requests
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
it 'filter by new user' do
new_user = create(:user)
project.add_developer(new_user)
visit project_merge_requests_path(project, author_id: new_user.id)
wait_for_requests
expect_tokens([author_token(new_user.name)])
expect_filtered_search_input_empty
end
end
end
|