filter_merge_requests_spec.rb 8.38 KB
Newer Older
1 2 3
require 'rails_helper'

describe 'Filter merge requests', feature: true do
Clement Ho's avatar
Clement Ho committed
4 5
  include FilteredSearchHelpers
  include MergeRequestHelpers
6 7 8 9
  include WaitForAjax

  let!(:project)   { create(:project) }
  let!(:group)     { create(:group) }
Clement Ho's avatar
Clement Ho committed
10
  let!(:user)      { create(:user) }
11 12 13 14 15 16 17 18 19
  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.team << [user, :master]
    group.add_developer(user)
    login_as(user)
    create(:merge_request, source_project: project, target_project: project)
Clement Ho's avatar
Clement Ho committed
20 21

    visit namespace_project_merge_requests_path(project.namespace, project)
22 23 24
  end

  describe 'for assignee from mr#index' do
Clement Ho's avatar
Clement Ho committed
25
    let(:search_query) { "assignee:@#{user.username}" }
26

Clement Ho's avatar
Clement Ho committed
27 28
    before do
      input_filtered_search(search_query)
29

Clement Ho's avatar
Clement Ho committed
30
      expect_mr_list_count(0)
31 32 33 34
    end

    context 'assignee', js: true do
      it 'updates to current user' do
Clement Ho's avatar
Clement Ho committed
35
        expect_filtered_search_input(search_query)
36 37 38 39 40
      end

      it 'does not change when closed link is clicked' do
        find('.issues-state-filters a', text: "Closed").click

Clement Ho's avatar
Clement Ho committed
41
        expect_filtered_search_input(search_query)
42 43 44 45 46
      end

      it 'does not change when all link is clicked' do
        find('.issues-state-filters a', text: "All").click

Clement Ho's avatar
Clement Ho committed
47
        expect_filtered_search_input(search_query)
48 49 50 51 52
      end
    end
  end

  describe 'for milestone from mr#index' do
Clement Ho's avatar
Clement Ho committed
53
    let(:search_query) { "milestone:%#{milestone.title}" }
54

Clement Ho's avatar
Clement Ho committed
55 56
    before do
      input_filtered_search(search_query)
57

Clement Ho's avatar
Clement Ho committed
58
      expect_mr_list_count(0)
59 60 61 62
    end

    context 'milestone', js: true do
      it 'updates to current milestone' do
Clement Ho's avatar
Clement Ho committed
63
        expect_filtered_search_input(search_query)
64 65 66 67 68
      end

      it 'does not change when closed link is clicked' do
        find('.issues-state-filters a', text: "Closed").click

Clement Ho's avatar
Clement Ho committed
69
        expect_filtered_search_input(search_query)
70 71 72 73 74
      end

      it 'does not change when all link is clicked' do
        find('.issues-state-filters a', text: "All").click

Clement Ho's avatar
Clement Ho committed
75
        expect_filtered_search_input(search_query)
76 77 78 79 80 81
      end
    end
  end

  describe 'for label from mr#index', js: true do
    it 'filters by no label' do
Clement Ho's avatar
Clement Ho committed
82
      input_filtered_search('label:none')
83

Clement Ho's avatar
Clement Ho committed
84 85
      expect_mr_list_count(1)
      expect_filtered_search_input('label:none')
86 87 88
    end

    it 'filters by a label' do
Clement Ho's avatar
Clement Ho committed
89 90 91 92
      input_filtered_search("label:~#{label.title}")

      expect_mr_list_count(0)
      expect_filtered_search_input("label:~#{label.title}")
93 94 95
    end

    it "filters by `won't fix` and another label" do
Clement Ho's avatar
Clement Ho committed
96
      input_filtered_search("label:~\"#{wontfix.title}\" label:~#{label.title}")
97

Clement Ho's avatar
Clement Ho committed
98 99
      expect_mr_list_count(0)
      expect_filtered_search_input("label:~\"#{wontfix.title}\" label:~#{label.title}")
100 101 102
    end

    it "filters by `won't fix` label followed by another label after page load" do
Clement Ho's avatar
Clement Ho committed
103
      input_filtered_search("label:~\"#{wontfix.title}\"")
104

Clement Ho's avatar
Clement Ho committed
105 106
      expect_mr_list_count(0)
      expect_filtered_search_input("label:~\"#{wontfix.title}\"")
107

Clement Ho's avatar
Clement Ho committed
108
      input_filtered_search_keys(" label:~#{label.title}")
109

Clement Ho's avatar
Clement Ho committed
110
      expect_filtered_search_input("label:~\"#{wontfix.title}\" label:~#{label.title}")
111

Clement Ho's avatar
Clement Ho committed
112 113
      expect_mr_list_count(0)
      expect_filtered_search_input("label:~\"#{wontfix.title}\" label:~#{label.title}")
114 115 116 117
    end
  end

  describe 'for assignee and label from issues#index' do
Clement Ho's avatar
Clement Ho committed
118
    let(:search_query) { "assignee:@#{user.username} label:~#{label.title}" }
119

Clement Ho's avatar
Clement Ho committed
120 121
    before do
      input_filtered_search("assignee:@#{user.username}")
122

Clement Ho's avatar
Clement Ho committed
123 124
      expect_mr_list_count(1)
      expect_filtered_search_input("assignee:@#{user.username}")
125

Clement Ho's avatar
Clement Ho committed
126
      input_filtered_search_keys(" label:~#{label.title}")
127

Clement Ho's avatar
Clement Ho committed
128
      expect_mr_list_count(1)
129

Clement Ho's avatar
Clement Ho committed
130
      find("#state-opened[href=\"#{URI.parse(current_url).path}?assignee_username=#{user.username}&label_name%5B%5D=#{label.title}&scope=all&state=opened\"]")
131 132 133 134
    end

    context 'assignee and label', js: true do
      it 'updates to current assignee and label' do
Clement Ho's avatar
Clement Ho committed
135
        expect_filtered_search_input(search_query)
136 137 138 139 140
      end

      it 'does not change when closed link is clicked' do
        find('.issues-state-filters a', text: "Closed").click

Clement Ho's avatar
Clement Ho committed
141
        expect_filtered_search_input(search_query)
142 143 144 145 146
      end

      it 'does not change when all link is clicked' do
        find('.issues-state-filters a', text: "All").click

Clement Ho's avatar
Clement Ho committed
147
        expect_filtered_search_input(search_query)
148 149 150 151 152 153 154 155 156 157 158
      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: "bug")

      bug_label = create(:label, project: project, title: 'bug')
      milestone = create(:milestone, title: "8", project: project)

Clement Ho's avatar
Clement Ho committed
159 160 161 162 163
      mr = create(:merge_request,
        title: "Bug 2",
        source_project: project,
        target_project: project,
        source_branch: "bug2",
164 165 166 167 168 169 170 171 172 173
        milestone: milestone,
        author: user,
        assignee: user)
      mr.labels << bug_label

      visit namespace_project_merge_requests_path(project.namespace, project)
    end

    context 'only text', js: true do
      it 'filters merge requests by searched text' do
Clement Ho's avatar
Clement Ho committed
174
        input_filtered_search('bug')
175

Clement Ho's avatar
Clement Ho committed
176
        expect_mr_list_count(2)
177 178 179
      end

      it 'does not show any merge requests' do
Clement Ho's avatar
Clement Ho committed
180
        input_filtered_search('testing')
181 182 183 184 185 186 187

        page.within '.mr-list' do
          expect(page).not_to have_selector('.merge-request')
        end
      end
    end

Clement Ho's avatar
Clement Ho committed
188
    context 'filters and searches', js: true do
189
      it 'filters by text and label' do
Clement Ho's avatar
Clement Ho committed
190
        input_filtered_search('Bug')
191

Clement Ho's avatar
Clement Ho committed
192 193
        expect_mr_list_count(2)
        expect_filtered_search_input('Bug')
194

Clement Ho's avatar
Clement Ho committed
195
        input_filtered_search_keys(' label:~bug')
196

Clement Ho's avatar
Clement Ho committed
197
        expect_mr_list_count(1)
198 199 200
      end

      it 'filters by text and milestone' do
Clement Ho's avatar
Clement Ho committed
201
        input_filtered_search('Bug')
202

Clement Ho's avatar
Clement Ho committed
203 204
        expect_mr_list_count(2)
        expect_filtered_search_input('Bug')
205

Clement Ho's avatar
Clement Ho committed
206
        input_filtered_search_keys(' milestone:%8')
207

Clement Ho's avatar
Clement Ho committed
208
        expect_mr_list_count(1)
209 210 211
      end

      it 'filters by text and assignee' do
Clement Ho's avatar
Clement Ho committed
212
        input_filtered_search('Bug')
213

Clement Ho's avatar
Clement Ho committed
214 215
        expect_mr_list_count(2)
        expect_filtered_search_input('Bug')
216

Clement Ho's avatar
Clement Ho committed
217
        input_filtered_search_keys(" assignee:@#{user.username}")
218

Clement Ho's avatar
Clement Ho committed
219
        expect_mr_list_count(1)
220 221 222
      end

      it 'filters by text and author' do
Clement Ho's avatar
Clement Ho committed
223
        input_filtered_search('Bug')
224

Clement Ho's avatar
Clement Ho committed
225 226
        expect_mr_list_count(2)
        expect_filtered_search_input('Bug')
227

Clement Ho's avatar
Clement Ho committed
228
        input_filtered_search_keys(" author:@#{user.username}")
229

Clement Ho's avatar
Clement Ho committed
230
        expect_mr_list_count(1)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
      end
    end
  end

  describe 'filter merge requests and sort', js: true 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: "Frontend")
      mr2 = create(:merge_request, title: "Bug 2", source_project: project, target_project: project, source_branch: "bug2")

      mr1.labels << bug_label
      mr2.labels << bug_label

      visit namespace_project_merge_requests_path(project.namespace, project)
    end

    it 'is able to filter and sort merge requests' do
Clement Ho's avatar
Clement Ho committed
249
      input_filtered_search('label:~bug')
250

Clement Ho's avatar
Clement Ho committed
251
      expect_mr_list_count(2)
252 253 254 255 256 257 258 259 260 261 262 263

      click_button 'Last created'
      page.within '.dropdown-menu-sort' do
        click_link 'Oldest created'
      end
      wait_for_ajax

      page.within '.mr-list' do
        expect(page).to have_content('Frontend')
      end
    end
  end
Clement Ho's avatar
Clement Ho committed
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

  describe 'filter by assignee id', js: true do
    it 'filter by current user' do
      visit namespace_project_merge_requests_path(project.namespace, project, assignee_id: user.id)

      expect_filtered_search_input("assignee:@#{user.username}")
    end

    it 'filter by new user' do
      new_user = create(:user)
      project.add_developer(new_user)

      visit namespace_project_merge_requests_path(project.namespace, project, assignee_id: new_user.id)

      expect_filtered_search_input("assignee:@#{new_user.username}")
    end
  end

  describe 'filter by author id', js: true do
    it 'filter by current user' do
      visit namespace_project_merge_requests_path(project.namespace, project, author_id: user.id)

      expect_filtered_search_input("author:@#{user.username}")
    end

    it 'filter by new user' do
      new_user = create(:user)
      project.add_developer(new_user)

      visit namespace_project_merge_requests_path(project.namespace, project, author_id: new_user.id)

      expect_filtered_search_input("author:@#{new_user.username}")
    end
  end
298
end