diff options
Diffstat (limited to 'spec/features/projects/members/invite_group_spec.rb')
-rw-r--r-- | spec/features/projects/members/invite_group_spec.rb | 106 |
1 files changed, 69 insertions, 37 deletions
diff --git a/spec/features/projects/members/invite_group_spec.rb b/spec/features/projects/members/invite_group_spec.rb index 83ba2533a73..4caf3e947c7 100644 --- a/spec/features/projects/members/invite_group_spec.rb +++ b/spec/features/projects/members/invite_group_spec.rb @@ -6,25 +6,48 @@ RSpec.describe 'Project > Members > Invite group', :js do include Select2Helper include ActionView::Helpers::DateHelper include Spec::Support::Helpers::Features::MembersHelpers + include Spec::Support::Helpers::Features::InviteMembersModalHelper let(:maintainer) { create(:user) } - before do - stub_feature_flags(invite_members_group_modal: false) + using RSpec::Parameterized::TableSyntax + + where(:invite_members_group_modal_enabled, :expected_invite_group_selector) do + true | 'button[data-qa-selector="invite_a_group_button"]' + false | '#invite-group-tab' + end + + with_them do + before do + stub_feature_flags(invite_members_group_modal: invite_members_group_modal_enabled) + end + + it 'displays either the invite group button or the form with tabs based on the feature flag' do + project = create(:project, namespace: create(:group)) + + project.add_maintainer(maintainer) + sign_in(maintainer) + + visit project_project_members_path(project) + + expect(page).to have_selector(expected_invite_group_selector) + end end describe 'Share with group lock' do + let(:invite_group_selector) { 'button[data-qa-selector="invite_a_group_button"]' } + shared_examples 'the project can be shared with groups' do - it 'the "Invite group" tab exists' do + it 'the "Invite a group" button exists' do visit project_project_members_path(project) - expect(page).to have_selector('#invite-group-tab') + expect(page).to have_selector(invite_group_selector) end end shared_examples 'the project cannot be shared with groups' do - it 'the "Invite group" tab does not exist' do + it 'the "Invite a group" button does not exist' do visit project_project_members_path(project) - expect(page).not_to have_selector('#invite-group-tab') + expect(page).not_to have_selector(invite_group_selector) end end @@ -41,7 +64,9 @@ RSpec.describe 'Project > Members > Invite group', :js do context 'when the group has "Share with group lock" disabled' do it_behaves_like 'the project can be shared with groups' - it 'the project can be shared with another group' do + it 'the project can be shared with another group when the feature flag invite_members_group_modal is disabled' do + stub_feature_flags(invite_members_group_modal: false) + visit project_project_members_path(project) expect(page).not_to have_link 'Groups' @@ -56,6 +81,22 @@ RSpec.describe 'Project > Members > Invite group', :js do expect(members_table).to have_content(group_to_share_with.name) end + + it 'the project can be shared with another group when the feature flag invite_members_group_modal is enabled' do + stub_feature_flags(invite_members_group_modal: true) + + visit project_project_members_path(project) + + expect(page).not_to have_link 'Groups' + + invite_group(group_to_share_with.name) + + visit project_project_members_path(project) + + click_link 'Groups' + + expect(members_table).to have_content(group_to_share_with.name) + end end context 'when the group has "Share with group lock" enabled' do @@ -127,13 +168,7 @@ RSpec.describe 'Project > Members > Invite group', :js do visit project_project_members_path(project) - click_on 'invite-group-tab' - - select2 group.id, from: '#link_group_id' - - fill_in 'expires_at_groups', with: 5.days.from_now.strftime('%Y-%m-%d') - click_on 'invite-group-tab' - find('.btn-confirm').click + invite_group(group.name, role: 'Guest', expires_at: 5.days.from_now) end it 'the group link shows the expiration time with a warning class' do @@ -149,29 +184,23 @@ RSpec.describe 'Project > Members > Invite group', :js do context 'with multiple groups to choose from' do let(:project) { create(:project) } - before do + it 'includes multiple groups' do project.add_maintainer(maintainer) sign_in(maintainer) - create(:group).add_owner(maintainer) - create(:group).add_owner(maintainer) + group1 = create(:group) + group1.add_owner(maintainer) + group2 = create(:group) + group2.add_owner(maintainer) visit project_project_members_path(project) - click_link 'Invite group' + click_on 'Invite a group' + click_on 'Select a group' + wait_for_requests - find('.ajax-groups-select.select2-container') - - execute_script 'GROUP_SELECT_PER_PAGE = 1;' - open_select2 '#link_group_id' - end - - it 'infinitely scrolls' do - 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) + expect(page).to have_button(group1.name) + expect(page).to have_button(group2.name) end end @@ -188,16 +217,19 @@ RSpec.describe 'Project > Members > Invite group', :js do group_to_share_with.add_maintainer(maintainer) end - it 'the groups dropdown does not show ancestors' do + # This behavior should be changed to exclude the ancestor and project + # group from the options once issue is fixed for the modal: + # https://gitlab.com/gitlab-org/gitlab/-/issues/329835 + it 'the groups dropdown does show ancestors and the project group' do visit project_project_members_path(project) - click_on 'invite-group-tab' - click_link 'Search for a group' + click_on 'Invite a group' + click_on 'Select a group' + wait_for_requests - page.within '.select2-drop' do - expect(page).to have_content(group_to_share_with.name) - expect(page).not_to have_content(group.name) - end + expect(page).to have_button(group_to_share_with.name) + expect(page).to have_button(group.name) + expect(page).to have_button(nested_group.name) end end end |