2016-11-14 08:11:55 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
feature 'Admin Groups', feature: true do
|
2016-12-26 14:36:33 -05:00
|
|
|
include Select2Helper
|
|
|
|
|
2016-11-14 08:11:55 -05:00
|
|
|
let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
|
2016-12-26 14:36:33 -05:00
|
|
|
let(:user) { create :user }
|
|
|
|
let!(:group) { create :group }
|
2017-06-05 14:44:29 -04:00
|
|
|
let!(:current_user) { gitlab_sign_in :admin }
|
2016-11-14 08:11:55 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(default_group_visibility: internal)
|
|
|
|
end
|
|
|
|
|
2016-12-26 14:36:33 -05:00
|
|
|
describe 'list' do
|
|
|
|
it 'renders groups' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
|
|
|
expect(page).to have_content(group.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-14 08:11:55 -05:00
|
|
|
describe 'create a group' do
|
2016-12-26 14:36:33 -05:00
|
|
|
it 'creates new group' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
2017-05-31 11:23:48 -04:00
|
|
|
page.within '#content-body' do
|
|
|
|
click_link "New group"
|
|
|
|
end
|
2017-03-12 11:22:00 -04:00
|
|
|
path_component = 'gitlab'
|
|
|
|
group_name = 'GitLab group name'
|
|
|
|
group_description = 'Description of group for GitLab'
|
|
|
|
fill_in 'group_path', with: path_component
|
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
fill_in 'group_description', with: group_description
|
2016-12-26 14:36:33 -05:00
|
|
|
click_button "Create group"
|
|
|
|
|
2017-03-12 11:22:00 -04:00
|
|
|
expect(current_path).to eq admin_group_path(Group.find_by(path: path_component))
|
|
|
|
content = page.find('div#content-body')
|
|
|
|
h3_texts = content.all('h3').collect(&:text).join("\n")
|
|
|
|
expect(h3_texts).to match group_name
|
|
|
|
li_texts = content.all('li').collect(&:text).join("\n")
|
|
|
|
expect(li_texts).to match group_name
|
|
|
|
expect(li_texts).to match path_component
|
|
|
|
expect(li_texts).to match group_description
|
2016-12-26 14:36:33 -05:00
|
|
|
end
|
|
|
|
|
2016-11-14 08:11:55 -05:00
|
|
|
scenario 'shows the visibility level radio populated with the default value' do
|
|
|
|
visit new_admin_group_path
|
|
|
|
|
|
|
|
expect_selected_visibility(internal)
|
|
|
|
end
|
2017-03-12 11:22:00 -04:00
|
|
|
|
|
|
|
scenario 'when entered in group path, it auto filled the group name', js: true do
|
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
|
|
|
group_path = 'gitlab'
|
|
|
|
fill_in 'group_path', with: group_path
|
|
|
|
name_field = find('input#group_name')
|
|
|
|
expect(name_field.value).to eq group_path
|
|
|
|
end
|
2016-11-14 08:11:55 -05:00
|
|
|
end
|
|
|
|
|
2016-12-28 06:10:34 -05:00
|
|
|
describe 'show a group' do
|
|
|
|
scenario 'shows the group' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_content("Group: #{group.name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-14 08:11:55 -05:00
|
|
|
describe 'group edit' do
|
|
|
|
scenario 'shows the visibility level radio populated with the group visibility_level value' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
|
2016-12-08 13:59:41 -05:00
|
|
|
visit admin_group_edit_path(group)
|
2016-11-14 08:11:55 -05:00
|
|
|
|
|
|
|
expect_selected_visibility(group.visibility_level)
|
|
|
|
end
|
2017-03-12 11:22:00 -04:00
|
|
|
|
|
|
|
scenario 'edit group path does not change group name', js: true do
|
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
name_field = find('input#group_name')
|
|
|
|
original_name = name_field.value
|
|
|
|
fill_in 'group_path', with: 'this-new-path'
|
|
|
|
|
|
|
|
expect(name_field.value).to eq original_name
|
|
|
|
end
|
2016-11-14 08:11:55 -05:00
|
|
|
end
|
|
|
|
|
2016-12-26 14:36:33 -05:00
|
|
|
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
|
|
|
|
|
2016-11-14 08:11:55 -05:00
|
|
|
def expect_selected_visibility(level)
|
|
|
|
selector = "#group_visibility_level_#{level}[checked=checked]"
|
|
|
|
|
|
|
|
expect(page).to have_selector(selector, count: 1)
|
|
|
|
end
|
|
|
|
end
|