filter_issues_spec.rb 27.8 KB
Newer Older
1 2
require 'rails_helper'

Clement Ho's avatar
Clement Ho committed
3
describe 'Filter issues', js: true, feature: true do
Clement Ho's avatar
Clement Ho committed
4
  include FilteredSearchHelpers
5
  include WaitForAjax
6

Clement Ho's avatar
Clement Ho committed
7 8 9 10
  let!(:group) { create(:group) }
  let!(:project) { create(:project, group: group) }
  let!(:user) { create(:user) }
  let!(:user2) { create(:user) }
Arinde Eniola's avatar
Arinde Eniola committed
11
  let!(:milestone) { create(:milestone, project: project) }
Clement Ho's avatar
Clement Ho committed
12 13
  let!(:label) { create(:label, project: project) }
  let!(:wontfix) { create(:label, project: project, title: "Won't fix") }
14

Clement Ho's avatar
Clement Ho committed
15 16 17
  let!(:bug_label) { create(:label, project: project, title: 'bug') }
  let!(:caps_sensitive_label) { create(:label, project: project, title: 'CAPS_sensitive') }
  let!(:milestone) { create(:milestone, title: "8", project: project) }
Clement Ho's avatar
Clement Ho committed
18
  let!(:multiple_words_label) { create(:label, project: project, title: "Two words") }
Clement Ho's avatar
Clement Ho committed
19

Clement Ho's avatar
Clement Ho committed
20
  let!(:closed_issue) { create(:issue, title: 'bug that is closed', project: project, state: :closed) }
Clement Ho's avatar
Clement Ho committed
21

Clement Ho's avatar
Clement Ho committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  def expect_no_issues_list
    page.within '.issues-list' do
      expect(page).not_to have_selector('.issue')
    end
  end

  def expect_issues_list_count(open_count, closed_count = 0)
    all_count = open_count + closed_count

    expect(page).to have_issuable_counts(open: open_count, closed: closed_count, all: all_count)
    page.within '.issues-list' do
      expect(page).to have_selector('.issue', count: open_count)
    end
  end

Phil Hughes's avatar
Phil Hughes committed
37 38 39 40
  def select_search_at_index(pos)
    evaluate_script("el = document.querySelector('.filtered-search'); el.focus(); el.setSelectionRange(#{pos}, #{pos});")
  end

41 42
  before do
    project.team << [user, :master]
Clement Ho's avatar
Clement Ho committed
43
    project.team << [user2, :master]
44
    group.add_developer(user)
Clement Ho's avatar
Clement Ho committed
45
    group.add_developer(user2)
46
    login_as(user)
47
    create(:issue, project: project)
48

Clement Ho's avatar
Clement Ho committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    create(:issue, title: "Bug report 1", project: project)
    create(:issue, title: "Bug report 2", project: project)
    create(:issue, title: "issue with 'single quotes'", project: project)
    create(:issue, title: "issue with \"double quotes\"", project: project)
    create(:issue, title: "issue with !@\#{$%^&*()-+", project: project)
    create(:issue, title: "issue by assignee", project: project, milestone: milestone, author: user, assignee: user)
    create(:issue, title: "issue by assignee with searchTerm", project: project, milestone: milestone, author: user, assignee: user)

    issue = create(:issue,
      title: "Bug 2",
      project: project,
      milestone: milestone,
      author: user,
      assignee: user)
    issue.labels << bug_label

Clement Ho's avatar
Clement Ho committed
65 66 67 68 69
    issue_with_caps_label = create(:issue,
      title: "issue by assignee with searchTerm and label",
      project: project,
      milestone: milestone,
      author: user,
Clement Ho's avatar
Clement Ho committed
70 71 72
      assignee: user)
    issue_with_caps_label.labels << caps_sensitive_label

Clement Ho's avatar
Clement Ho committed
73 74 75 76 77
    issue_with_everything = create(:issue,
      title: "Bug report with everything you thought was possible",
      project: project,
      milestone: milestone,
      author: user,
Clement Ho's avatar
Clement Ho committed
78 79 80 81
      assignee: user)
    issue_with_everything.labels << bug_label
    issue_with_everything.labels << caps_sensitive_label

Clement Ho's avatar
Clement Ho committed
82 83 84
    multiple_words_label_issue = create(:issue, title: "Issue with multiple words label", project: project)
    multiple_words_label_issue.labels << multiple_words_label

85
    future_milestone = create(:milestone, title: "future", project: project, due_date: Time.now + 1.month)
Clement Ho's avatar
Clement Ho committed
86 87

    create(:issue,
88 89 90 91
      title: "Issue with future milestone",
      milestone: future_milestone,
      project: project)

Clement Ho's avatar
Clement Ho committed
92 93
    visit namespace_project_issues_path(project.namespace, project)
  end
94

Clement Ho's avatar
Clement Ho committed
95
  describe 'filter issues by author' do
Clement Ho's avatar
Clement Ho committed
96
    context 'only author' do
Clement Ho's avatar
Clement Ho committed
97
      it 'filters issues by searched author' do
98
        input_filtered_search("author:@#{user.username}")
Clement Ho's avatar
Clement Ho committed
99

Clement Ho's avatar
Clement Ho committed
100 101
        expect_issues_list_count(5)
      end
102

Clement Ho's avatar
Clement Ho committed
103
      it 'filters issues by invalid author' do
104
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
105
      end
106

Clement Ho's avatar
Clement Ho committed
107
      it 'filters issues by multiple authors' do
108
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
109
      end
110 111
    end

Clement Ho's avatar
Clement Ho committed
112
    context 'author with other filters' do
Clement Ho's avatar
Clement Ho committed
113
      it 'filters issues by searched author and text' do
Clement Ho's avatar
Clement Ho committed
114 115
        search = "author:@#{user.username} issue"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
116

Clement Ho's avatar
Clement Ho committed
117
        expect_issues_list_count(3)
Clement Ho's avatar
Clement Ho committed
118
        expect_filtered_search_input(search)
119 120
      end

Clement Ho's avatar
Clement Ho committed
121
      it 'filters issues by searched author, assignee and text' do
Clement Ho's avatar
Clement Ho committed
122 123
        search = "author:@#{user.username} assignee:@#{user.username} issue"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
124

Clement Ho's avatar
Clement Ho committed
125
        expect_issues_list_count(3)
Clement Ho's avatar
Clement Ho committed
126
        expect_filtered_search_input(search)
127 128
      end

Clement Ho's avatar
Clement Ho committed
129
      it 'filters issues by searched author, assignee, label, and text' do
Clement Ho's avatar
Clement Ho committed
130 131
        search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} issue"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
132

Clement Ho's avatar
Clement Ho committed
133
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
134
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
135
      end
136

Clement Ho's avatar
Clement Ho committed
137
      it 'filters issues by searched author, assignee, label, milestone and text' do
Clement Ho's avatar
Clement Ho committed
138 139
        search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} issue"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
140

Clement Ho's avatar
Clement Ho committed
141
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
142
        expect_filtered_search_input(search)
143 144
      end
    end
Clement Ho's avatar
Clement Ho committed
145

Clement Ho's avatar
Clement Ho committed
146
    it 'sorting' do
147
      skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
148
    end
149
  end
Arinde Eniola's avatar
Arinde Eniola committed
150

Clement Ho's avatar
Clement Ho committed
151
  describe 'filter issues by assignee' do
Clement Ho's avatar
Clement Ho committed
152
    context 'only assignee' do
Clement Ho's avatar
Clement Ho committed
153
      it 'filters issues by searched assignee' do
Clement Ho's avatar
Clement Ho committed
154 155
        search = "assignee:@#{user.username}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
156

Clement Ho's avatar
Clement Ho committed
157
        expect_issues_list_count(5)
Clement Ho's avatar
Clement Ho committed
158
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
159
      end
Arinde Eniola's avatar
Arinde Eniola committed
160

Clement Ho's avatar
Clement Ho committed
161
      it 'filters issues by no assignee' do
Clement Ho's avatar
Clement Ho committed
162 163
        search = "assignee:none"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
164

Clement Ho's avatar
Clement Ho committed
165
        expect_issues_list_count(8, 1)
Clement Ho's avatar
Clement Ho committed
166
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
167
      end
Arinde Eniola's avatar
Arinde Eniola committed
168

Clement Ho's avatar
Clement Ho committed
169
      it 'filters issues by invalid assignee' do
170
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
171
      end
Arinde Eniola's avatar
Arinde Eniola committed
172

Clement Ho's avatar
Clement Ho committed
173
      it 'filters issues by multiple assignees' do
174
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
175
      end
Arinde Eniola's avatar
Arinde Eniola committed
176 177
    end

Clement Ho's avatar
Clement Ho committed
178
    context 'assignee with other filters' do
Clement Ho's avatar
Clement Ho committed
179
      it 'filters issues by searched assignee and text' do
Clement Ho's avatar
Clement Ho committed
180 181
        search = "assignee:@#{user.username} searchTerm"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
182

Clement Ho's avatar
Clement Ho committed
183
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
184
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
185
      end
Arinde Eniola's avatar
Arinde Eniola committed
186

Clement Ho's avatar
Clement Ho committed
187
      it 'filters issues by searched assignee, author and text' do
Clement Ho's avatar
Clement Ho committed
188 189
        search = "assignee:@#{user.username} author:@#{user.username} searchTerm"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
190

Clement Ho's avatar
Clement Ho committed
191
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
192
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
193
      end
Arinde Eniola's avatar
Arinde Eniola committed
194

Clement Ho's avatar
Clement Ho committed
195
      it 'filters issues by searched assignee, author, label, text' do
Clement Ho's avatar
Clement Ho committed
196 197
        search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} searchTerm"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
198

Clement Ho's avatar
Clement Ho committed
199
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
200
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
201
      end
Arinde Eniola's avatar
Arinde Eniola committed
202

Clement Ho's avatar
Clement Ho committed
203
      it 'filters issues by searched assignee, author, label, milestone and text' do
Clement Ho's avatar
Clement Ho committed
204 205
        search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} searchTerm"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
206

Clement Ho's avatar
Clement Ho committed
207
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
208
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
209 210
      end
    end
Phil Hughes's avatar
Phil Hughes committed
211

Clement Ho's avatar
Clement Ho committed
212
    context 'sorting' do
Clement Ho's avatar
Clement Ho committed
213
      it 'sorts' do
214
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
215
      end
Phil Hughes's avatar
Phil Hughes committed
216
    end
Clement Ho's avatar
Clement Ho committed
217
  end
Phil Hughes's avatar
Phil Hughes committed
218

Clement Ho's avatar
Clement Ho committed
219
  describe 'filter issues by label' do
Clement Ho's avatar
Clement Ho committed
220
    context 'only label' do
Clement Ho's avatar
Clement Ho committed
221
      it 'filters issues by searched label' do
Clement Ho's avatar
Clement Ho committed
222 223
        search = "label:~#{bug_label.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
224

Clement Ho's avatar
Clement Ho committed
225
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
226
        expect_filtered_search_input(search)
227
      end
Phil Hughes's avatar
Phil Hughes committed
228

Clement Ho's avatar
Clement Ho committed
229
      it 'filters issues by no label' do
Clement Ho's avatar
Clement Ho committed
230 231
        search = "label:none"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
232

Clement Ho's avatar
Clement Ho committed
233
        expect_issues_list_count(9, 1)
Clement Ho's avatar
Clement Ho committed
234
        expect_filtered_search_input(search)
235
      end
236

Clement Ho's avatar
Clement Ho committed
237
      it 'filters issues by invalid label' do
238
        skip('to be tested, issue #26546')
239
      end
240

Clement Ho's avatar
Clement Ho committed
241
      it 'filters issues by multiple labels' do
Clement Ho's avatar
Clement Ho committed
242 243
        search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
244

Clement Ho's avatar
Clement Ho committed
245
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
246
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
247
      end
Clement Ho's avatar
Clement Ho committed
248 249 250 251 252

      it 'filters issues by label containing special characters' do
        special_label = create(:label, project: project, title: '!@#{$%^&*()-+[]<>?/:{}|\}')
        special_issue = create(:issue, title: "Issue with special character label", project: project)
        special_issue.labels << special_label
Clement Ho's avatar
Clement Ho committed
253 254 255

        search = "label:~#{special_label.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
256

Clement Ho's avatar
Clement Ho committed
257
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
258
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
259 260 261 262
      end

      it 'does not show issues' do
        new_label = create(:label, project: project, title: "new_label")
Clement Ho's avatar
Clement Ho committed
263 264 265

        search = "label:~#{new_label.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
266

Clement Ho's avatar
Clement Ho committed
267
        expect_no_issues_list()
Clement Ho's avatar
Clement Ho committed
268
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
269 270 271
      end
    end

Clement Ho's avatar
Clement Ho committed
272
    context 'label with multiple words' do
Clement Ho's avatar
Clement Ho committed
273 274 275 276 277
      it 'special characters' do
        special_multiple_label = create(:label, project: project, title: "Utmost |mp0rt@nce")
        special_multiple_issue = create(:issue, title: "Issue with special character multiple words label", project: project)
        special_multiple_issue.labels << special_multiple_label

Clement Ho's avatar
Clement Ho committed
278 279
        search = "label:~'#{special_multiple_label.title}'"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
280

Clement Ho's avatar
Clement Ho committed
281
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
282 283 284

        # filtered search defaults quotations to double quotes
        expect_filtered_search_input("label:~\"#{special_multiple_label.title}\"")
Clement Ho's avatar
Clement Ho committed
285 286 287
      end

      it 'single quotes' do
Clement Ho's avatar
Clement Ho committed
288 289 290
        search = "label:~'#{multiple_words_label.title}'"
        input_filtered_search(search)

Clement Ho's avatar
Clement Ho committed
291
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
292
        expect_filtered_search_input("label:~\"#{multiple_words_label.title}\"")
Clement Ho's avatar
Clement Ho committed
293 294 295
      end

      it 'double quotes' do
Clement Ho's avatar
Clement Ho committed
296 297
        search = "label:~\"#{multiple_words_label.title}\""
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
298

Clement Ho's avatar
Clement Ho committed
299
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
300
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
301 302 303
      end

      it 'single quotes containing double quotes' do
304 305 306
        double_quotes_label = create(:label, project: project, title: 'won"t fix')
        double_quotes_label_issue = create(:issue, title: "Issue with double quotes label", project: project)
        double_quotes_label_issue.labels << double_quotes_label
Clement Ho's avatar
Clement Ho committed
307

Clement Ho's avatar
Clement Ho committed
308 309
        search = "label:~'#{double_quotes_label.title}'"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
310

311
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
312
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
313 314 315 316 317 318 319
      end

      it 'double quotes containing single quotes' do
        single_quotes_label = create(:label, project: project, title: "won't fix")
        single_quotes_label_issue = create(:issue, title: "Issue with single quotes label", project: project)
        single_quotes_label_issue.labels << single_quotes_label

Clement Ho's avatar
Clement Ho committed
320 321
        search = "label:~\"#{single_quotes_label.title}\""
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
322

Clement Ho's avatar
Clement Ho committed
323
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
324
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
325
      end
326
    end
327

Clement Ho's avatar
Clement Ho committed
328
    context 'label with other filters' do
Clement Ho's avatar
Clement Ho committed
329
      it 'filters issues by searched label and text' do
Clement Ho's avatar
Clement Ho committed
330 331
        search = "label:~#{caps_sensitive_label.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
332

Clement Ho's avatar
Clement Ho committed
333
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
334
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
335 336
      end

Clement Ho's avatar
Clement Ho committed
337
      it 'filters issues by searched label, author and text' do
Clement Ho's avatar
Clement Ho committed
338 339
        search = "label:~#{caps_sensitive_label.title} author:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
340

Clement Ho's avatar
Clement Ho committed
341
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
342
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
343
      end
Phil Hughes's avatar
Phil Hughes committed
344

Clement Ho's avatar
Clement Ho committed
345
      it 'filters issues by searched label, author, assignee and text' do
Clement Ho's avatar
Clement Ho committed
346 347
        search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
348

Clement Ho's avatar
Clement Ho committed
349
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
350
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
351
      end
352

Clement Ho's avatar
Clement Ho committed
353
      it 'filters issues by searched label, author, assignee, milestone and text' do
Clement Ho's avatar
Clement Ho committed
354 355
        search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
356

Clement Ho's avatar
Clement Ho committed
357
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
358
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
359 360
      end
    end
Phil Hughes's avatar
Phil Hughes committed
361

Clement Ho's avatar
Clement Ho committed
362
    context 'multiple labels with other filters' do
Clement Ho's avatar
Clement Ho committed
363
      it 'filters issues by searched label, label2, and text' do
Clement Ho's avatar
Clement Ho committed
364 365
        search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
366

Clement Ho's avatar
Clement Ho committed
367
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
368
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
369
      end
Phil Hughes's avatar
Phil Hughes committed
370

Clement Ho's avatar
Clement Ho committed
371
      it 'filters issues by searched label, label2, author and text' do
Clement Ho's avatar
Clement Ho committed
372 373
        search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
374

Clement Ho's avatar
Clement Ho committed
375
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
376
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
377
      end
378

Clement Ho's avatar
Clement Ho committed
379
      it 'filters issues by searched label, label2, author, assignee and text' do
Clement Ho's avatar
Clement Ho committed
380 381
        search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
382

Clement Ho's avatar
Clement Ho committed
383
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
384
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
385
      end
Phil Hughes's avatar
Phil Hughes committed
386

Clement Ho's avatar
Clement Ho committed
387
      it 'filters issues by searched label, label2, author, assignee, milestone and text' do
Clement Ho's avatar
Clement Ho committed
388 389
        search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
390

Clement Ho's avatar
Clement Ho committed
391
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
392
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
393
      end
394 395
    end

Clement Ho's avatar
Clement Ho committed
396
    context 'issue label clicked' do
Clement Ho's avatar
Clement Ho committed
397 398 399 400 401 402 403 404 405 406 407 408 409
      before do
        find('.issues-list .issue .issue-info a .label', text: multiple_words_label.title).click
        sleep 1
      end

      it 'filters' do
        expect_issues_list_count(1)
      end

      it 'displays in search bar' do
        expect(find('.filtered-search').value).to eq("label:~\"#{multiple_words_label.title}\"")
      end
    end
410

Clement Ho's avatar
Clement Ho committed
411
    context 'sorting' do
Clement Ho's avatar
Clement Ho committed
412
      it 'sorts' do
413
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
414
      end
415
    end
Phil Hughes's avatar
Phil Hughes committed
416 417
  end

Clement Ho's avatar
Clement Ho committed
418
  describe 'filter issues by milestone' do
Clement Ho's avatar
Clement Ho committed
419
    context 'only milestone' do
Clement Ho's avatar
Clement Ho committed
420
      it 'filters issues by searched milestone' do
421
        input_filtered_search("milestone:%#{milestone.title}")
Clement Ho's avatar
Clement Ho committed
422

Clement Ho's avatar
Clement Ho committed
423 424
        expect_issues_list_count(5)
      end
Arinde Eniola's avatar
Arinde Eniola committed
425

Clement Ho's avatar
Clement Ho committed
426
      it 'filters issues by no milestone' do
427
        input_filtered_search("milestone:none")
Clement Ho's avatar
Clement Ho committed
428

Clement Ho's avatar
Clement Ho committed
429
        expect_issues_list_count(7, 1)
Clement Ho's avatar
Clement Ho committed
430
      end
Arinde Eniola's avatar
Arinde Eniola committed
431

Clement Ho's avatar
Clement Ho committed
432
      it 'filters issues by upcoming milestones' do
433
        input_filtered_search("milestone:upcoming")
Clement Ho's avatar
Clement Ho committed
434

435
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
436
      end
Arinde Eniola's avatar
Arinde Eniola committed
437

Clement Ho's avatar
Clement Ho committed
438
      it 'filters issues by invalid milestones' do
439
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
440
      end
Arinde Eniola's avatar
Arinde Eniola committed
441

Clement Ho's avatar
Clement Ho committed
442
      it 'filters issues by multiple milestones' do
443
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
444
      end
Clement Ho's avatar
Clement Ho committed
445 446 447 448

      it 'filters issues by milestone containing special characters' do
        special_milestone = create(:milestone, title: '!@\#{$%^&*()}', project: project)
        create(:issue, title: "Issue with special character milestone", project: project, milestone: special_milestone)
Clement Ho's avatar
Clement Ho committed
449 450 451

        search = "milestone:%#{special_milestone.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
452

Clement Ho's avatar
Clement Ho committed
453
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
454
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
455 456 457 458
      end

      it 'does not show issues' do
        new_milestone = create(:milestone, title: "new", project: project)
Clement Ho's avatar
Clement Ho committed
459 460 461

        search = "milestone:%#{new_milestone.title}"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
462

Clement Ho's avatar
Clement Ho committed
463
        expect_no_issues_list()
Clement Ho's avatar
Clement Ho committed
464
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
465
      end
Arinde Eniola's avatar
Arinde Eniola committed
466 467
    end

Clement Ho's avatar
Clement Ho committed
468
    context 'milestone with other filters' do
Clement Ho's avatar
Clement Ho committed
469
      it 'filters issues by searched milestone and text' do
Clement Ho's avatar
Clement Ho committed
470 471
        search = "milestone:%#{milestone.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
472

Clement Ho's avatar
Clement Ho committed
473 474
        expect_issues_list_count(2)
        expect_filtered_search_input(search)
Arinde Eniola's avatar
Arinde Eniola committed
475 476
      end

Clement Ho's avatar
Clement Ho committed
477
      it 'filters issues by searched milestone, author and text' do
Clement Ho's avatar
Clement Ho committed
478 479
        search = "milestone:%#{milestone.title} author:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
480

Clement Ho's avatar
Clement Ho committed
481 482
        expect_issues_list_count(2)
        expect_filtered_search_input(search)
Arinde Eniola's avatar
Arinde Eniola committed
483 484
      end

Clement Ho's avatar
Clement Ho committed
485
      it 'filters issues by searched milestone, author, assignee and text' do
Clement Ho's avatar
Clement Ho committed
486 487
        search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
488

Clement Ho's avatar
Clement Ho committed
489 490
        expect_issues_list_count(2)
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
491
      end
Arinde Eniola's avatar
Arinde Eniola committed
492

Clement Ho's avatar
Clement Ho committed
493
      it 'filters issues by searched milestone, author, assignee, label and text' do
Clement Ho's avatar
Clement Ho committed
494 495
        search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug"
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
496

Clement Ho's avatar
Clement Ho committed
497 498
        expect_issues_list_count(2)
        expect_filtered_search_input(search)
Arinde Eniola's avatar
Arinde Eniola committed
499 500
      end
    end
Phil Hughes's avatar
Phil Hughes committed
501

Clement Ho's avatar
Clement Ho committed
502
    context 'sorting' do
Clement Ho's avatar
Clement Ho committed
503
      it 'sorts' do
504
        skip('to be tested, issue #26546')
Clement Ho's avatar
Clement Ho committed
505
      end
Phil Hughes's avatar
Phil Hughes committed
506
    end
Clement Ho's avatar
Clement Ho committed
507
  end
Phil Hughes's avatar
Phil Hughes committed
508

Phil Hughes's avatar
Phil Hughes committed
509 510 511 512 513 514 515 516 517 518
  describe 'overwrites selected filter' do
    it 'changes author' do
      input_filtered_search("author:@#{user.username}", submit: false)

      select_search_at_index(3)

      page.within '#js-dropdown-author' do
        click_button user2.username
      end

519
      expect(filtered_search.value).to eq("author:@#{user2.username} ")
Phil Hughes's avatar
Phil Hughes committed
520 521 522 523 524 525 526 527 528 529 530
    end

    it 'changes label' do
      input_filtered_search("author:@#{user.username} label:~#{bug_label.title}", submit: false)

      select_search_at_index(27)

      page.within '#js-dropdown-label' do
        click_button label.name
      end

531
      expect(filtered_search.value).to eq("author:@#{user.username} label:~#{label.name} ")
Phil Hughes's avatar
Phil Hughes committed
532
    end
533 534 535 536 537 538 539 540 541 542

    it 'changes label correctly space is in previous label' do
      input_filtered_search("label:~\"#{multiple_words_label.title}\"", submit: false)

      select_search_at_index(0)

      page.within '#js-dropdown-label' do
        click_button label.name
      end

543
      expect(filtered_search.value).to eq("label:~#{label.name} ")
544
    end
Phil Hughes's avatar
Phil Hughes committed
545 546
  end

Clement Ho's avatar
Clement Ho committed
547
  describe 'filter issues by text' do
Clement Ho's avatar
Clement Ho committed
548
    context 'only text' do
549
      it 'filters issues by searched text' do
Clement Ho's avatar
Clement Ho committed
550 551
        search = 'Bug'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
552

Clement Ho's avatar
Clement Ho committed
553
        expect_issues_list_count(4, 1)
Clement Ho's avatar
Clement Ho committed
554
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
555 556
      end

Clement Ho's avatar
Clement Ho committed
557
      it 'filters issues by multiple searched text' do
Clement Ho's avatar
Clement Ho committed
558 559
        search = 'Bug report'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
560

Clement Ho's avatar
Clement Ho committed
561
        expect_issues_list_count(3)
Clement Ho's avatar
Clement Ho committed
562
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
563 564
      end

Clement Ho's avatar
Clement Ho committed
565
      it 'filters issues by case insensitive searched text' do
Clement Ho's avatar
Clement Ho committed
566 567
        search = 'bug report'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
568

Clement Ho's avatar
Clement Ho committed
569
        expect_issues_list_count(3)
Clement Ho's avatar
Clement Ho committed
570
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
571 572
      end

Clement Ho's avatar
Clement Ho committed
573
      it 'filters issues by searched text containing single quotes' do
Clement Ho's avatar
Clement Ho committed
574 575
        search = '\'single quotes\''
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
576

Clement Ho's avatar
Clement Ho committed
577
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
578
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
579 580
      end

Clement Ho's avatar
Clement Ho committed
581
      it 'filters issues by searched text containing double quotes' do
Clement Ho's avatar
Clement Ho committed
582 583
        search = '"double quotes"'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
584

Clement Ho's avatar
Clement Ho committed
585
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
586
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
587
      end
Phil Hughes's avatar
Phil Hughes committed
588

Clement Ho's avatar
Clement Ho committed
589
      it 'filters issues by searched text containing special characters' do
Clement Ho's avatar
Clement Ho committed
590 591
        search = '!@#{$%^&*()-+'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
592

Clement Ho's avatar
Clement Ho committed
593
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
594
        expect_filtered_search_input(search)
Clement Ho's avatar
Clement Ho committed
595
      end
Phil Hughes's avatar
Phil Hughes committed
596

Clement Ho's avatar
Clement Ho committed
597
      it 'does not show any issues' do
Clement Ho's avatar
Clement Ho committed
598 599
        search = 'testing'
        input_filtered_search(search)
Clement Ho's avatar
Clement Ho committed
600

Clement Ho's avatar
Clement Ho committed
601
        expect_no_issues_list()
Clement Ho's avatar
Clement Ho committed
602
        expect_filtered_search_input(search)
Phil Hughes's avatar
Phil Hughes committed
603
      end
Clement Ho's avatar
Clement Ho committed
604
    end
Phil Hughes's avatar
Phil Hughes committed
605

Clement Ho's avatar
Clement Ho committed
606
    context 'searched text with other filters' do
Clement Ho's avatar
Clement Ho committed
607
      it 'filters issues by searched text and author' do
608
        input_filtered_search("bug author:@#{user.username}")
Clement Ho's avatar
Clement Ho committed
609

Clement Ho's avatar
Clement Ho committed
610
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
611
        expect_filtered_search_input("author:@#{user.username} bug")
Clement Ho's avatar
Clement Ho committed
612
      end
Phil Hughes's avatar
Phil Hughes committed
613

Clement Ho's avatar
Clement Ho committed
614
      it 'filters issues by searched text, author and more text' do
615
        input_filtered_search("bug author:@#{user.username} report")
Clement Ho's avatar
Clement Ho committed
616

Clement Ho's avatar
Clement Ho committed
617
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
618
        expect_filtered_search_input("author:@#{user.username} bug report")
Clement Ho's avatar
Clement Ho committed
619
      end
Phil Hughes's avatar
Phil Hughes committed
620

Clement Ho's avatar
Clement Ho committed
621
      it 'filters issues by searched text, author and assignee' do
622
        input_filtered_search("bug author:@#{user.username} assignee:@#{user.username}")
Clement Ho's avatar
Clement Ho committed
623

Clement Ho's avatar
Clement Ho committed
624
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
625
        expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug")
Clement Ho's avatar
Clement Ho committed
626
      end
Phil Hughes's avatar
Phil Hughes committed
627

Clement Ho's avatar
Clement Ho committed
628
      it 'filters issues by searched text, author, more text and assignee' do
629
        input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username}")
Clement Ho's avatar
Clement Ho committed
630

Clement Ho's avatar
Clement Ho committed
631
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
632
        expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report")
Phil Hughes's avatar
Phil Hughes committed
633
      end
634

Clement Ho's avatar
Clement Ho committed
635
      it 'filters issues by searched text, author, more text, assignee and even more text' do
636
        input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with")
Clement Ho's avatar
Clement Ho committed
637

Clement Ho's avatar
Clement Ho committed
638
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
639
        expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report with")
Clement Ho's avatar
Clement Ho committed
640
      end
641

Clement Ho's avatar
Clement Ho committed
642
      it 'filters issues by searched text, author, assignee and label' do
643
        input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title}")
Clement Ho's avatar
Clement Ho committed
644

Clement Ho's avatar
Clement Ho committed
645
        expect_issues_list_count(2)
Clement Ho's avatar
Clement Ho committed
646
        expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug")
Clement Ho's avatar
Clement Ho committed
647
      end
648

Clement Ho's avatar
Clement Ho committed
649
      it 'filters issues by searched text, author, text, assignee, text, label and text' do
650
        input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything")
Clement Ho's avatar
Clement Ho committed
651

Clement Ho's avatar
Clement Ho committed
652
        expect_issues_list_count(1)
Clement Ho's avatar
Clement Ho committed
653
        expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug report with everything")
Clement Ho's avatar
Clement Ho committed
654
      end
655

Clement Ho's avatar
Clement Ho committed
656
      it 'filters issues by searched text, author, assignee, label and milestone' do
657
        input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title}")