debian-mirror-gitlab/spec/features/projects/members/invite_group_spec.rb

198 lines
6.1 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
require 'spec_helper'
2018-11-20 20:47:30 +05:30
describe 'Project > Members > Invite group', :js do
2018-03-17 18:26:18 +05:30
include Select2Helper
include ActionView::Helpers::DateHelper
2018-11-18 11:00:15 +05:30
let(:maintainer) { create(:user) }
2018-03-17 18:26:18 +05:30
describe 'Share with group lock' do
shared_examples 'the project can be shared with groups' do
2018-11-20 20:47:30 +05:30
it 'the "Invite group" tab exists' do
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-11-20 20:47:30 +05:30
expect(page).to have_selector('#invite-group-tab')
2018-03-17 18:26:18 +05:30
end
end
shared_examples 'the project cannot be shared with groups' do
2018-11-20 20:47:30 +05:30
it 'the "Invite group" tab does not exist' do
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-11-20 20:47:30 +05:30
expect(page).not_to have_selector('#invite-group-tab')
2018-03-17 18:26:18 +05:30
end
end
context 'for a project in a root group' do
let!(:group_to_share_with) { create(:group) }
let(:project) { create(:project, namespace: create(:group)) }
2018-11-08 19:23:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(maintainer)
2019-03-13 22:55:13 +05:30
group_to_share_with.add_guest(maintainer)
2018-11-18 11:00:15 +05:30
sign_in(maintainer)
2018-03-17 18:26:18 +05:30
end
context 'when the group has "Share with group lock" disabled' do
it_behaves_like 'the project can be shared with groups'
2018-11-08 19:23:39 +05:30
it 'the project can be shared with another group' do
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-11-20 20:47:30 +05:30
click_on 'invite-group-tab'
2018-03-17 18:26:18 +05:30
select2 group_to_share_with.id, from: '#link_group_id'
page.find('body').click
2018-12-05 23:21:45 +05:30
find('.btn-success').click
2018-03-17 18:26:18 +05:30
page.within('.project-members-groups') do
expect(page).to have_content(group_to_share_with.name)
end
end
end
context 'when the group has "Share with group lock" enabled' do
before do
project.namespace.update_column(:share_with_group_lock, true)
end
it_behaves_like 'the project cannot be shared with groups'
end
end
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) }
2018-11-08 19:23:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(maintainer)
sign_in(maintainer)
2018-03-17 18:26:18 +05:30
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
end
end
end
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
2018-11-18 11:00:15 +05:30
project.add_maintainer(maintainer)
2019-03-13 22:55:13 +05:30
group.add_guest(maintainer)
2018-11-18 11:00:15 +05:30
sign_in(maintainer)
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-11-20 20:47:30 +05:30
click_on 'invite-group-tab'
2018-03-17 18:26:18 +05:30
select2 group.id, from: '#link_group_id'
fill_in 'expires_at_groups', with: (Time.now + 4.5.days).strftime('%Y-%m-%d')
2018-11-20 20:47:30 +05:30
click_on 'invite-group-tab'
2018-12-05 23:21:45 +05:30
find('.btn-success').click
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
it 'the group link shows the expiration time with a warning class' do
2018-03-17 18:26:18 +05:30
page.within('.project-members-groups') do
# 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
describe 'the groups dropdown' do
context 'with multiple groups to choose from' do
let(:project) { create(:project) }
2018-11-08 19:23:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(maintainer)
sign_in(maintainer)
2018-03-17 18:26:18 +05:30
2018-11-18 11:00:15 +05:30
create(:group).add_owner(maintainer)
create(:group).add_owner(maintainer)
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-03-27 19:54:05 +05:30
2018-11-20 20:47:30 +05:30
click_link 'Invite group'
2018-03-27 19:54:05 +05:30
find('.ajax-groups-select.select2-container')
2018-03-17 18:26:18 +05:30
execute_script 'GROUP_SELECT_PER_PAGE = 1;'
open_select2 '#link_group_id'
end
2019-07-07 11:18:12 +05:30
it 'infinitely scrolls' do
2018-03-17 18:26:18 +05:30
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 1)
scroll_select2_to_bottom('.select2-drop .select2-results:visible')
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 2)
end
end
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) }
let!(:project) { create(:project, namespace: nested_group) }
2018-11-08 19:23:39 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(maintainer)
sign_in(maintainer)
group.add_maintainer(maintainer)
group_to_share_with.add_maintainer(maintainer)
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
it 'the groups dropdown does not show ancestors', :nested_groups do
2018-03-17 18:26:18 +05:30
visit project_settings_members_path(project)
2018-11-20 20:47:30 +05:30
click_on 'invite-group-tab'
2018-03-17 18:26:18 +05:30
click_link 'Search for a group'
page.within '.select2-drop' do
expect(page).to have_content(group_to_share_with.name)
expect(page).not_to have_content(group.name)
end
end
end
end
end