groups.rb 12.1 KB
Newer Older
1
class Spinach::Features::Groups < Spinach::FeatureSteps
2 3
  include SharedAuthentication
  include SharedPaths
4
  include SharedGroup
5
  include SharedUser
6
  include Select2Helper
7

8
  step 'I should see back to dashboard button' do
9
    expect(page).to have_content 'Go to dashboard'
10 11
  end

12 13 14 15 16 17 18 19
  step 'gitlab user "Mike"' do
    create(:user, name: "Mike")
  end

  step 'I click link "Add members"' do
    find(:css, 'button.btn-new').click
  end

Valery Sizov's avatar
Valery Sizov committed
20 21 22 23 24 25 26 27 28
  step 'I should see group "Owned"' do
    expect(page).to have_content '@owned'
  end

  step 'I am a signed out user' do
    logout
  end

  step 'Group "Owned" has a public project "Public-project"' do
29
    group = owned_group
Valery Sizov's avatar
Valery Sizov committed
30 31 32 33 34 35 36 37 38 39

    @project = create :empty_project, :public,
                 group: group,
                 name: "Public-project"
  end

  step 'I should see project "Public-project"' do
    expect(page).to have_content 'Public-project'
  end

40 41 42
  step 'I select "Mike" as "Reporter"' do
    user = User.find_by(name: "Mike")

43
    page.within ".users-group-form" do
44 45 46 47 48 49 50
      select2(user.id, from: "#user_ids", multiple: true)
      select "Reporter", from: "access_level"
    end

    click_button "Add users to group"
  end

51 52 53 54 55 56 57 58 59 60 61
  step 'I select "Mike" as "Master"' do
    user = User.find_by(name: "Mike")

    page.within ".users-group-form" do
      select2(user.id, from: "#user_ids", multiple: true)
      select "Master", from: "access_level"
    end

    click_button "Add users to group"
  end

62
  step 'I should see "Mike" in team list as "Reporter"' do
63
    page.within '.well-list' do
64 65
      expect(page).to have_content('Mike')
      expect(page).to have_content('Reporter')
66 67 68
    end
  end

69 70 71 72 73 74 75
  step 'I should see "Mike" in team list as "Owner"' do
    page.within '.well-list' do
      expect(page).to have_content('Mike')
      expect(page).to have_content('Owner')
    end
  end

76
  step 'I select "sjobs@apple.com" as "Reporter"' do
77
    page.within ".users-group-form" do
78 79 80 81 82 83 84 85
      select2("sjobs@apple.com", from: "#user_ids", multiple: true)
      select "Reporter", from: "access_level"
    end

    click_button "Add users to group"
  end

  step 'I should see "sjobs@apple.com" in team list as invited "Reporter"' do
86
    page.within '.well-list' do
87 88 89
      expect(page).to have_content('sjobs@apple.com')
      expect(page).to have_content('invited')
      expect(page).to have_content('Reporter')
90 91 92
    end
  end

93
  step 'I should see group "Owned" projects list' do
94
    owned_group.projects.each do |project|
95
      expect(page).to have_link project.name
96 97 98
    end
  end

99
  step 'I should see projects activity feed' do
100
    expect(page).to have_content 'closed issue'
101 102
  end

103
  step 'I should see issues from group "Owned" assigned to me' do
randx's avatar
randx committed
104
    assigned_to_me(:issues).each do |issue|
105
      expect(page).to have_content issue.title
randx's avatar
randx committed
106 107 108
    end
  end

109
  step 'I should see merge requests from group "Owned" assigned to me' do
randx's avatar
randx committed
110
    assigned_to_me(:merge_requests).each do |issue|
111
      expect(page).to have_content issue.title[0..80]
randx's avatar
randx committed
112 113 114
    end
  end

115
  step 'I select user "Mary Jane" from list with role "Reporter"' do
116
    user = User.find_by(name: "Mary Jane") || create(:user, name: "Mary Jane")
117
    click_button 'Add members'
118
    page.within ".users-group-form" do
119
      select2(user.id, from: "#user_ids", multiple: true)
120
      select "Reporter", from: "access_level"
121
    end
122
    click_button "Add users to group"
123 124
  end

125
  step 'I should see user "John Doe" in team list' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
126
    projects_with_access = find(".panel .well-list")
127
    expect(projects_with_access).to have_content("John Doe")
128 129
  end

130
  step 'I should not see user "John Doe" in team list' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
131
    projects_with_access = find(".panel .well-list")
132
    expect(projects_with_access).not_to have_content("John Doe")
133 134
  end

135
  step 'I should see user "Mary Jane" in team list' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
136
    projects_with_access = find(".panel .well-list")
137
    expect(projects_with_access).to have_content("Mary Jane")
138 139
  end

140
  step 'I should not see user "Mary Jane" in team list' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
141
    projects_with_access = find(".panel .well-list")
142
    expect(projects_with_access).not_to have_content("Mary Jane")
143 144
  end

145
  step 'project from group "Owned" has issues assigned to me' do
randx's avatar
randx committed
146 147 148 149 150 151
    create :issue,
      project: project,
      assignee: current_user,
      author: current_user
  end

152
  step 'project from group "Owned" has merge requests assigned to me' do
randx's avatar
randx committed
153
    create :merge_request,
154 155
      source_project: project,
      target_project: project,
randx's avatar
randx committed
156 157 158 159
      assignee: current_user,
      author: current_user
  end

160
  step 'I change group "Owned" name to "new-name"' do
161
    fill_in 'group_name', with: 'new-name'
162
    fill_in 'group_path', with: 'new-name'
163 164 165
    click_button "Save group"
  end

166
  step 'I should see new group "Owned" name' do
167
    page.within ".navbar-gitlab" do
168
      expect(page).to have_content "new-name"
169 170 171
    end
  end

172
  step 'I change group "Owned" avatar' do
173
    attach_file(:group_avatar, File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif'))
Steven Thonus's avatar
Steven Thonus committed
174
    click_button "Save group"
175
    owned_group.reload
Steven Thonus's avatar
Steven Thonus committed
176 177
  end

178
  step 'I should see new group "Owned" avatar' do
179 180
    expect(owned_group.avatar).to be_instance_of AvatarUploader
    expect(owned_group.avatar.url).to eq "/uploads/group/avatar/#{ Group.find_by(name:"Owned").id }/banana_sample.gif"
Steven Thonus's avatar
Steven Thonus committed
181 182 183
  end

  step 'I should see the "Remove avatar" button' do
184
    expect(page).to have_link("Remove avatar")
Steven Thonus's avatar
Steven Thonus committed
185 186
  end

187
  step 'I have group "Owned" avatar' do
188
    attach_file(:group_avatar, File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif'))
Steven Thonus's avatar
Steven Thonus committed
189
    click_button "Save group"
190
    owned_group.reload
Steven Thonus's avatar
Steven Thonus committed
191 192
  end

193
  step 'I remove group "Owned" avatar' do
Steven Thonus's avatar
Steven Thonus committed
194
    click_link "Remove avatar"
195
    owned_group.reload
Steven Thonus's avatar
Steven Thonus committed
196 197
  end

198
  step 'I should not see group "Owned" avatar' do
199
    expect(owned_group.avatar?).to eq false
Steven Thonus's avatar
Steven Thonus committed
200 201 202
  end

  step 'I should not see the "Remove avatar" button' do
203
    expect(page).not_to have_link("Remove avatar")
Steven Thonus's avatar
Steven Thonus committed
204 205
  end

206 207 208 209
  step 'I click on the "Remove User From Group" button for "John Doe"' do
    find(:css, 'li', text: "John Doe").find(:css, 'a.btn-remove').click
    # poltergeist always confirms popups.
  end
210

211 212 213
  step 'I click on the "Remove User From Group" button for "Mary Jane"' do
    find(:css, 'li', text: "Mary Jane").find(:css, 'a.btn-remove').click
    # poltergeist always confirms popups.
214
  end
randx's avatar
randx committed
215

216
  step 'I should not see the "Remove User From Group" button for "John Doe"' do
217
    expect(find(:css, 'li', text: "John Doe")).not_to have_selector(:css, 'a.btn-remove')
218
    # poltergeist always confirms popups.
randx's avatar
randx committed
219 220
  end

221
  step 'I should not see the "Remove User From Group" button for "Mary Jane"' do
222
    expect(find(:css, 'li', text: "Mary Jane")).not_to have_selector(:css, 'a.btn-remove')
223 224 225
    # poltergeist always confirms popups.
  end

226
  step 'I search for \'Mary\' member' do
227
    page.within '.member-search-form' do
228 229 230 231 232
      fill_in 'search', with: 'Mary'
      click_button 'Search'
    end
  end

233 234 235 236 237
  step 'I click on group milestones' do
    click_link 'Milestones'
  end

  step 'I should see group milestones index page has no milestones' do
238
    expect(page).to have_content('No milestones to show')
239 240 241 242 243 244 245
  end

  step 'Group has projects with milestones' do
    group_milestone
  end

  step 'I should see group milestones index page with milestones' do
246 247 248 249
    expect(page).to have_content('Version 7.2')
    expect(page).to have_content('GL-113')
    expect(page).to have_link('2 Issues', href: issues_group_path("owned", milestone_title: "Version 7.2"))
    expect(page).to have_link('3 Merge Requests', href: merge_requests_group_path("owned", milestone_title: "GL-113"))
250 251 252 253 254 255
  end

  step 'I click on one group milestone' do
    click_link 'GL-113'
  end

256
  step 'I should see group milestone with descriptions and expiry date' do
257
    expect(page).to have_content('expires at Aug 20, 2114')
258 259
  end

260
  step 'I should see group milestone with all issues and MRs assigned to that milestone' do
261 262 263 264
    expect(page).to have_content('Milestone GL-113')
    expect(page).to have_content('Progress: 0 closed – 4 open')
    expect(page).to have_link(@issue1.title, href: namespace_project_issue_path(@project1.namespace, @project1, @issue1))
    expect(page).to have_link(@mr3.title, href: namespace_project_merge_request_path(@project3.namespace, @project3, @mr3))
265 266
  end

Artem Sidorenko's avatar
Artem Sidorenko committed
267 268 269 270 271 272 273 274 275
  step 'Group "Owned" has archived project' do
    group = Group.find_by(name: 'Owned')
    create(:project, namespace: group, archived: true, path: "archived-project")
  end

  step 'I should see "archived" label' do
    expect(page).to have_xpath("//span[@class='label label-warning']", text: 'archived')
  end

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  step 'I fill milestone name' do
    fill_in 'milestone_title', with: 'v2.9.0'
  end

  step 'I click new milestone button' do
    click_link "New Milestone"
  end

  step 'I press create mileston button' do
    click_button "Create Milestone"
  end

  step 'milestone in each project should be created' do
    group = Group.find_by(name: 'Owned')
    expect(page).to have_content "Milestone v2.9.0"
    expect(group.projects).to be_present

    group.projects.each do |project|
      expect(page).to have_content project.name
    end
  end

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
  step 'I change the "Mary Jane" role to "Developer"' do
    member = mary_jane_member

    page.within "#group_member_#{member.id}" do
      find(".js-toggle-button").click
      page.within "#edit_group_member_#{member.id}" do
        select 'Developer', from: 'group_member_access_level'
        click_on 'Save'
      end
    end
  end

  step 'I should see "Mary Jane" as "Developer"' do
    member = mary_jane_member

    page.within "#group_member_#{member.id}" do
      page.within '.member-access-level' do
        expect(page).to have_content "Developer"
      end
    end
  end

320 321
  protected

322 323 324 325 326 327
  def owned_group
    @owned_group ||= Group.find_by(name: "Owned")
  end

  def mary_jane_member
    user = User.find_by(name: "Mary Jane")
328
    owned_group.members.find_by(user_id: user.id)
329 330
  end

331
  def assigned_to_me(key)
randx's avatar
randx committed
332 333
    project.send(key).where(assignee_id: current_user.id)
  end
334 335

  def project
336
    owned_group.projects.first
337
  end
338 339

  def group_milestone
340
    group = owned_group
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

    @project1 = create :project,
                 group: group
    project2 = create :project,
                 path: 'gitlab-ci',
                 group: group
    @project3 = create :project,
                 path: 'cookbook-gitlab',
                 group: group
    milestone1_project1 = create :milestone,
                            title: "Version 7.2",
                            project: @project1
    milestone1_project2 = create :milestone,
                            title: "Version 7.2",
                            project: project2
356 357 358
    create :milestone,
      title: "Version 7.2",
      project: @project3
359 360 361 362 363 364 365 366
    milestone2_project1 = create :milestone,
                            title: "GL-113",
                            project: @project1
    milestone2_project2 = create :milestone,
                            title: "GL-113",
                            project: project2
    milestone2_project3 = create :milestone,
                            title: "GL-113",
367
                            project: @project3,
368
                            due_date: '2114-08-20',
369
                            description: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry'
370 371 372 373 374
    @issue1 = create :issue,
               project: @project1,
               assignee: current_user,
               author: current_user,
               milestone: milestone2_project1
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
    create :issue,
      project: project2,
      assignee: current_user,
      author: current_user,
      milestone: milestone1_project2
    create :issue,
      project: @project3,
      assignee: current_user,
      author: current_user,
      milestone: milestone1_project1
    create :merge_request,
      source_project: @project1,
      target_project: @project1,
      assignee: current_user,
      author: current_user,
      milestone: milestone2_project1
    create :merge_request,
      source_project: project2,
      target_project: project2,
      assignee: current_user,
      author: current_user,
      milestone: milestone2_project2
397 398 399 400 401 402 403
    @mr3 = create :merge_request,
            source_project: @project3,
            target_project: @project3,
            assignee: current_user,
            author: current_user,
            milestone: milestone2_project3
  end
404
end