Commit 3608a1e8 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'move-admin-groups-spinach-test-to-rspec' into 'master'

Move admin groups spinach tests to rspec

See merge request !8313
parents f1bd9f05 cec230bd
@admin
Feature: Admin Groups
Background:
Given I sign in as an admin
And I have group with projects
And User "John Doe" exists
And I visit admin groups page
Scenario: See group list
Then I should be all groups
Scenario: Create a group
When I click new group link
And submit form with new group info
Then I should be redirected to group page
And I should see newly created group
@javascript
Scenario: Add user into projects in group
When I visit admin group page
When I select user "John Doe" from user list as "Reporter"
Then I should see "John Doe" in team list in every project as "Reporter"
Scenario: Shared projects
Given group has shared projects
When I visit group page
Then I should see project shared with group
@javascript
Scenario: Invite user to a group by e-mail
When I visit admin group page
When I select user "johndoe@gitlab.com" from user list as "Reporter"
Then I should see "johndoe@gitlab.com" in team list in every project as "Reporter"
@javascript
Scenario: Signed in admin should be able to add himself to a group
Given "John Doe" is owner of group "Owned"
When I visit group "Owned" members page
When I select current user as "Developer"
Then I should see current user as "Developer"
@javascript
Scenario: Signed in admin should be able to remove himself from group
Given current user is developer of group "Owned"
When I visit group "Owned" members page
Then I should see current user as "Developer"
When I click on the "Remove User From Group" button for current user
When I visit group "Owned" members page
Then I should not see current user as "Developer"
class Spinach::Features::AdminGroups < Spinach::FeatureSteps
include SharedAuthentication
include SharedGroup
include SharedPaths
include SharedUser
include SharedActiveTab
include Select2Helper
When 'I visit admin group page' do
visit admin_group_path(current_group)
end
When 'I click new group link' do
click_link "New Group"
end
step 'I have group with projects' do
@group = create(:group)
@project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project)
@project.team << [current_user, :master]
end
step 'submit form with new group info' do
fill_in 'group_path', with: 'gitlab'
fill_in 'group_description', with: 'Group description'
click_button "Create group"
end
step 'I should see newly created group' do
expect(page).to have_content "Group: gitlab"
expect(page).to have_content "Group description"
end
step 'I should be redirected to group page' do
expect(current_path).to eq admin_group_path(Group.find_by(path: 'gitlab'))
end
When 'I select user "John Doe" from user list as "Reporter"' do
select2(user_john.id, from: "#user_ids", multiple: true)
page.within "#new_project_member" do
select "Reporter", from: "access_level"
end
click_button "Add users to group"
end
When 'I select user "johndoe@gitlab.com" from user list as "Reporter"' do
select2('johndoe@gitlab.com', from: "#user_ids", multiple: true)
page.within "#new_project_member" do
select "Reporter", from: "access_level"
end
click_button "Add users to group"
end
step 'I should see "John Doe" in team list in every project as "Reporter"' do
page.within ".group-users-list" do
expect(page).to have_content "John Doe"
expect(page).to have_content "Reporter"
end
end
step 'I should see "johndoe@gitlab.com" in team list in every project as "Reporter"' do
page.within ".group-users-list" do
expect(page).to have_content "johndoe@gitlab.com"
expect(page).to have_content "Invited by"
expect(page).to have_content "Reporter"
end
end
step 'I should be all groups' do
Group.all.each do |group|
expect(page).to have_content group.name
end
end
step 'group has shared projects' do
share_link = shared_project.project_group_links.new(group_access: Gitlab::Access::MASTER)
share_link.group_id = current_group.id
share_link.save!
end
step 'I visit group page' do
visit admin_group_path(current_group)
end
step 'I should see project shared with group' do
expect(page).to have_content(shared_project.name_with_namespace)
expect(page).to have_content "Projects shared with"
end
step 'we have user "John Doe" in group' do
current_group.add_reporter(user_john)
end
step 'I should not see "John Doe" in team list' do
page.within ".group-users-list" do
expect(page).not_to have_content "John Doe"
end
end
step 'I select current user as "Developer"' do
page.within ".users-group-form" do
select2(current_user.id, from: "#user_ids", multiple: true)
select "Developer", from: "access_level"
end
click_button "Add to group"
end
step 'I should see current user as "Developer"' do
page.within '.content-list' do
expect(page).to have_content(current_user.name)
expect(page).to have_content('Developer')
end
end
step 'I click on the "Remove User From Group" button for current user' do
find(:css, 'li', text: current_user.name).find(:css, 'a.btn-remove').click
# poltergeist always confirms popups.
end
step 'I should not see current user as "Developer"' do
page.within '.content-list' do
expect(page).not_to have_content(current_user.name)
expect(page).not_to have_content('Developer')
end
end
protected
def current_group
@group ||= Group.first
end
def shared_project
@shared_project ||= create(:empty_project)
end
def user_john
@user_john ||= User.find_by(name: "John Doe")
end
end
...@@ -191,10 +191,6 @@ module SharedPaths ...@@ -191,10 +191,6 @@ module SharedPaths
visit admin_background_jobs_path visit admin_background_jobs_path
end end
step 'I visit admin groups page' do
visit admin_groups_path
end
step 'I visit admin teams page' do step 'I visit admin teams page' do
visit admin_teams_path visit admin_teams_path
end end
......
require 'spec_helper' require 'spec_helper'
feature 'Admin Groups', feature: true do feature 'Admin Groups', feature: true do
include Select2Helper
let(:internal) { Gitlab::VisibilityLevel::INTERNAL } let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
let(:user) { create :user }
let!(:group) { create :group }
let!(:current_user) { login_as :admin }
before do before do
login_as(:admin)
stub_application_setting(default_group_visibility: internal) stub_application_setting(default_group_visibility: internal)
end end
describe 'list' do
it 'renders groups' do
visit admin_groups_path
expect(page).to have_content(group.name)
end
end
describe 'create a group' do describe 'create a group' do
it 'creates new group' do
visit admin_groups_path
click_link "New Group"
fill_in 'group_path', with: 'gitlab'
fill_in 'group_description', with: 'Group description'
click_button "Create group"
expect(current_path).to eq admin_group_path(Group.find_by(path: 'gitlab'))
expect(page).to have_content('Group: gitlab')
expect(page).to have_content('Group description')
end
scenario 'shows the visibility level radio populated with the default value' do scenario 'shows the visibility level radio populated with the default value' do
visit new_admin_group_path visit new_admin_group_path
...@@ -37,6 +61,91 @@ feature 'Admin Groups', feature: true do ...@@ -37,6 +61,91 @@ feature 'Admin Groups', feature: true do
end end
end end
describe 'add user into a group', js: true do
shared_context 'adds user into a group' do
it do
visit admin_group_path(group)
select2(user_selector, from: '#user_ids', multiple: true)
page.within '#new_project_member' do
select2(Gitlab::Access::REPORTER, from: '#access_level')
end
click_button "Add users to group"
page.within ".group-users-list" do
expect(page).to have_content(user.name)
expect(page).to have_content('Reporter')
end
end
end
it_behaves_like 'adds user into a group' do
let(:user_selector) { user.id }
end
it_behaves_like 'adds user into a group' do
let(:user_selector) { user.email }
end
end
describe 'add admin himself to a group' do
before do
group.add_user(:user, Gitlab::Access::OWNER)
end
it 'adds admin a to a group as developer', js: true do
visit group_group_members_path(group)
page.within '.users-group-form' do
select2(current_user.id, from: '#user_ids', multiple: true)
select 'Developer', from: 'access_level'
end
click_button 'Add to group'
page.within '.content-list' do
expect(page).to have_content(current_user.name)
expect(page).to have_content('Developer')
end
end
end
describe 'admin remove himself from a group', js: true do
it 'removes admin from the group' do
group.add_user(current_user, Gitlab::Access::DEVELOPER)
visit group_group_members_path(group)
page.within '.content-list' do
expect(page).to have_content(current_user.name)
expect(page).to have_content('Developer')
end
find(:css, 'li', text: current_user.name).find(:css, 'a.btn-remove').click
visit group_group_members_path(group)
page.within '.content-list' do
expect(page).not_to have_content(current_user.name)
expect(page).not_to have_content('Developer')
end
end
end
describe 'shared projects' do
it 'renders shared project' do
empty_project = create(:empty_project)
empty_project.project_group_links.create!(
group_access: Gitlab::Access::MASTER,
group: group
)
visit admin_group_path(group)
expect(page).to have_content(empty_project.name_with_namespace)
expect(page).to have_content('Projects shared with')
end
end
def expect_selected_visibility(level) def expect_selected_visibility(level)
selector = "#group_visibility_level_#{level}[checked=checked]" selector = "#group_visibility_level_#{level}[checked=checked]"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment