gitlab-org--gitlab-foss/spec/features/projects/members/share_with_group_spec.rb

192 lines
6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2017-08-31 18:40:38 -04:00
feature 'Project > Members > Share with Group', :js do
include Select2Helper
2017-08-31 20:31:03 -04:00
include ActionView::Helpers::DateHelper
let(:master) { create(:user) }
describe 'Share with group lock' do
shared_examples 'the project can be shared with groups' do
scenario 'the "Share with group" tab exists' do
visit project_settings_members_path(project)
expect(page).to have_selector('#share-with-group-tab')
end
2017-08-31 20:31:03 -04:00
end
shared_examples 'the project cannot be shared with groups' do
scenario 'the "Share with group" tab does not exist' do
2017-08-31 20:31:03 -04:00
visit project_settings_members_path(project)
expect(page).to have_selector('#add-member-tab')
expect(page).not_to have_selector('#share-with-group-tab')
end
end
2017-08-31 20:31:03 -04:00
context 'for a project in a root group' do
let!(:group_to_share_with) { create(:group) }
let(:project) { create(:project, namespace: create(:group)) }
background do
project.add_master(master)
sign_in(master)
end
2017-08-31 20:31:03 -04:00
context 'when the group has "Share with group lock" disabled' do
it_behaves_like 'the project can be shared with groups'
scenario 'the project can be shared with another group' do
visit project_settings_members_path(project)
click_on 'share-with-group-tab'
select2 group_to_share_with.id, from: '#link_group_id'
page.find('body').click
find('.btn-create').trigger('click')
page.within('.project-members-groups') do
expect(page).to have_content(group_to_share_with.name)
end
end
2017-08-31 20:31:03 -04:00
end
context 'when the group has "Share with group lock" enabled' do
before do
project.namespace.update_column(:share_with_group_lock, true)
2017-08-31 20:31:03 -04:00
end
it_behaves_like 'the project cannot be shared with groups'
2017-08-31 20:31:03 -04:00
end
end
2017-09-01 21:22:55 -04:00
context 'for a project in a subgroup', :nested_groups do
let!(:group_to_share_with) { create(:group) }
let(:root_group) { create(:group) }
let(:subgroup) { create(:group, parent: root_group) }
let(:project) { create(:project, namespace: subgroup) }
background do
project.add_master(master)
sign_in(master)
2017-08-31 20:31:03 -04:00
end
context 'when the root_group has "Share with group lock" disabled' do
context 'when the subgroup has "Share with group lock" disabled' do
it_behaves_like 'the project can be shared with groups'
end
context 'when the subgroup has "Share with group lock" enabled' do
before do
subgroup.update_column(:share_with_group_lock, true)
end
it_behaves_like 'the project cannot be shared with groups'
end
end
context 'when the root_group has "Share with group lock" enabled' do
before do
root_group.update_column(:share_with_group_lock, true)
end
context 'when the subgroup has "Share with group lock" disabled (parent overridden)' do
it_behaves_like 'the project can be shared with groups'
end
context 'when the subgroup has "Share with group lock" enabled' do
before do
subgroup.update_column(:share_with_group_lock, true)
end
it_behaves_like 'the project cannot be shared with groups'
end
2017-08-31 20:31:03 -04:00
end
end
end
2017-08-31 20:31:03 -04:00
describe 'setting an expiration date for a group link' do
let(:project) { create(:project) }
let!(:group) { create(:group) }
around do |example|
Timecop.freeze { example.run }
end
before do
2017-08-31 20:31:03 -04:00
project.add_master(master)
sign_in(master)
visit project_settings_members_path(project)
click_on 'share-with-group-tab'
select2 group.id, from: '#link_group_id'
2017-08-31 20:31:03 -04:00
fill_in 'expires_at_groups', with: (Time.now + 4.5.days).strftime('%Y-%m-%d')
page.find('body').click
2017-06-08 10:15:14 -04:00
find('.btn-create').trigger('click')
end
2017-08-31 18:40:38 -04:00
scenario 'the group link shows the expiration time with a warning class' do
page.within('.project-members-groups') do
2017-08-31 20:31:03 -04:00
# Using distance_of_time_in_words_to_now because it is not the same as
# subtraction, and this way avoids time zone issues as well
expires_in_text = distance_of_time_in_words_to_now(project.project_group_links.first.expires_at)
expect(page).to have_content(expires_in_text)
expect(page).to have_selector('.text-warning')
end
end
end
2017-08-31 20:31:03 -04:00
describe 'the groups dropdown' do
context 'with multiple groups to choose from' do
let(:project) { create(:project) }
background do
project.add_master(master)
sign_in(master)
create(:group).add_owner(master)
create(:group).add_owner(master)
2017-08-31 20:31:03 -04:00
visit project_settings_members_path(project)
execute_script 'GroupsSelect.PER_PAGE = 1;'
open_select2 '#link_group_id'
end
2017-08-31 20:31:03 -04:00
it 'should infinitely scroll' do
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 1)
2017-08-31 20:31:03 -04:00
scroll_select2_to_bottom('.select2-drop .select2-results:visible')
2017-08-31 20:31:03 -04:00
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 2)
end
end
2017-03-30 08:14:32 -04:00
2017-08-31 20:31:03 -04:00
context 'for a project in a nested group' do
let(:group) { create(:group) }
let!(:nested_group) { create(:group, parent: group) }
let!(:group_to_share_with) { create(:group) }
2017-08-31 20:31:03 -04:00
let!(:project) { create(:project, namespace: nested_group) }
background do
project.add_master(master)
sign_in(master)
group.add_master(master)
group_to_share_with.add_master(master)
2017-08-31 20:31:03 -04:00
end
2017-03-30 08:14:32 -04:00
2017-08-31 20:31:03 -04:00
scenario 'the groups dropdown does not show ancestors', :nested_groups do
visit project_settings_members_path(project)
2017-03-30 08:14:32 -04:00
2017-08-31 20:31:03 -04:00
click_on 'share-with-group-tab'
click_link 'Search for a group'
2017-03-30 08:14:32 -04:00
2017-08-31 20:31:03 -04:00
page.within '.select2-drop' do
expect(page).to have_content(group_to_share_with.name)
2017-08-31 20:31:03 -04:00
expect(page).not_to have_content(group.name)
end
end
2017-03-30 08:14:32 -04:00
end
end
end