Commit 168d6bb0 authored by Jackie Fraser's avatar Jackie Fraser Committed by Rémy Coutable

Enable invite members modal tests [RUN ALL RSPEC]

parent cf2ca269
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Admin Groups' do
include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
......@@ -202,6 +203,7 @@ RSpec.describe 'Admin Groups' 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')
......@@ -220,19 +222,13 @@ RSpec.describe 'Admin Groups' do
describe 'add admin himself to a group' do
before do
stub_feature_flags(invite_members_group_modal: false)
group.add_user(:user, Gitlab::Access::OWNER)
end
it 'adds admin a to a group as developer', :js do
visit group_group_members_path(group)
page.within '.invite-users-form' do
select2(current_user.id, from: '#user_ids', multiple: true)
select 'Developer', from: 'access_level'
end
click_button 'Invite'
invite_member(current_user.name, role: 'Developer')
page.within members_table do
expect(page).to have_content(current_user.name)
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe "Admin::Projects" do
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Select2Helper
let(:user) { create :user }
......@@ -95,21 +96,27 @@ RSpec.describe "Admin::Projects" do
describe 'admin adds themselves to the project', :js do
before do
project.add_maintainer(user)
stub_feature_flags(invite_members_group_modal: false)
end
it 'adds admin to the project as developer' do
visit project_project_members_path(project)
page.within '.invite-users-form' do
select2(current_user.id, from: '#user_ids', multiple: true)
select 'Developer', from: 'access_level'
end
click_button 'Invite'
invite_member(current_user.name, role: 'Developer')
expect(find_member_row(current_user)).to have_content('Developer')
end
context 'with the invite_members_group_modal feature flag disabled' do
it 'adds admin to the project as developer' do
stub_feature_flags(invite_members_group_modal: false)
visit project_project_members_path(project)
add_member_using_form(current_user.id, role: 'Developer')
expect(find_member_row(current_user)).to have_content('Developer')
end
end
end
describe 'admin removes themselves from the project', :js do
......@@ -134,4 +141,19 @@ RSpec.describe "Admin::Projects" do
expect(current_path).to match dashboard_projects_path
end
end
# temporary method for the form until the :invite_members_group_modal feature flag is
# enabled: https://gitlab.com/gitlab-org/gitlab/-/issues/247208
def add_member_using_form(id, role: 'Developer')
page.within '.invite-users-form' do
select2(id, from: '#user_ids', multiple: true)
fill_in 'expires_at', with: 5.days.from_now.to_date
find_field('expires_at').native.send_keys :enter
select(role, from: "access_level")
click_on 'Invite'
end
end
end
......@@ -5,13 +5,13 @@ require 'spec_helper'
RSpec.describe 'Groups > Members > Manage members' do
include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
let(:user1) { create(:user, name: 'John Doe') }
let(:user2) { create(:user, name: 'Mary Jane') }
let(:group) { create(:group) }
before do
stub_feature_flags(invite_members_group_modal: false)
sign_in(user1)
end
......@@ -27,15 +27,15 @@ RSpec.describe 'Groups > Members > Manage members' do
end
context 'when Invite Members modal is enabled' do
before do
stub_feature_flags(invite_members_group_modal: true)
end
it_behaves_like 'includes the correct Invite link', '.js-invite-members-trigger', '.invite-users-form'
it_behaves_like 'includes the correct Invite link', '.js-invite-group-trigger', '.invite-group-form'
end
context 'when Invite Members modal is disabled' do
before do
stub_feature_flags(invite_members_group_modal: false)
end
it_behaves_like 'includes the correct Invite link', '.invite-users-form', '.js-invite-members-trigger'
it_behaves_like 'includes the correct Invite link', '.invite-group-form', '.js-invite-group-trigger'
end
......@@ -59,7 +59,7 @@ RSpec.describe 'Groups > Members > Manage members' do
visit group_group_members_path(group)
add_user(user2.id, 'Reporter')
invite_member(user2.name, role: 'Reporter')
page.within(second_row) do
expect(page).to have_content(user2.name)
......@@ -73,21 +73,46 @@ RSpec.describe 'Groups > Members > Manage members' do
visit group_group_members_path(group)
find('.select2-container').click
select_input = find('.select2-input')
click_on 'Invite members'
fill_in 'Select members or type email addresses', with: '@gitlab.com'
select_input.send_keys('@gitlab.com')
wait_for_requests
expect(page).to have_content('No matches found')
select_input.native.clear
select_input.send_keys('undisclosed_email@gitlab.com')
fill_in 'Select members or type email addresses', with: 'undisclosed_email@gitlab.com'
wait_for_requests
expect(page).to have_content("Jane 'invisible' Doe")
end
context 'when Invite Members modal is disabled' do
before do
stub_feature_flags(invite_members_group_modal: false)
end
it 'do not disclose email addresses', :js do
group.add_owner(user1)
create(:user, email: 'undisclosed_email@gitlab.com', name: "Jane 'invisible' Doe")
visit group_group_members_path(group)
find('.select2-container').click
select_input = find('.select2-input')
select_input.send_keys('@gitlab.com')
wait_for_requests
expect(page).to have_content('No matches found')
select_input.native.clear
select_input.send_keys('undisclosed_email@gitlab.com')
wait_for_requests
expect(page).to have_content("Jane 'invisible' Doe")
end
end
it 'remove user from group', :js do
group.add_owner(user1)
group.add_developer(user2)
......@@ -115,7 +140,7 @@ RSpec.describe 'Groups > Members > Manage members' do
visit group_group_members_path(group)
add_user(user1.id, 'Reporter')
invite_member(user1.name, role: 'Reporter')
page.within(first_row) do
expect(page).to have_content(user1.name)
......@@ -128,7 +153,7 @@ RSpec.describe 'Groups > Members > Manage members' do
visit group_group_members_path(group)
add_user('test@example.com', 'Reporter')
invite_member('test@example.com', role: 'Reporter')
expect(page).to have_link 'Invited'
click_link 'Invited'
......@@ -148,6 +173,8 @@ RSpec.describe 'Groups > Members > Manage members' do
expect(page).not_to have_selector '.invite-users-form'
expect(page).not_to have_selector '.invite-group-form'
expect(page).not_to have_selector '.js-invite-members-modal'
expect(page).not_to have_selector '.js-invite-group-modal'
page.within(second_row) do
# Can not modify user2 role
......@@ -157,12 +184,4 @@ RSpec.describe 'Groups > Members > Manage members' do
expect(page).not_to have_selector 'button[title="Remove member"]'
end
end
def add_user(id, role)
page.within ".invite-users-form" do
select2(id, from: "#user_ids", multiple: true)
select(role, from: "access_level")
click_button "Invite"
end
end
end
......@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe 'Groups > Members > Owner adds member with expiration date', :js do
include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
let_it_be(:user1) { create(:user, name: 'John Doe') }
let_it_be(:group) { create(:group) }
......@@ -12,7 +12,6 @@ RSpec.describe 'Groups > Members > Owner adds member with expiration date', :js
let(:new_member) { create(:user, name: 'Mary Jane') }
before do
stub_feature_flags(invite_members_group_modal: false)
group.add_owner(user1)
sign_in(user1)
end
......@@ -20,14 +19,7 @@ RSpec.describe 'Groups > Members > Owner adds member with expiration date', :js
it 'expiration date is displayed in the members list' do
visit group_group_members_path(group)
page.within invite_users_form do
select2(new_member.id, from: '#user_ids', multiple: true)
fill_in 'expires_at', with: 5.days.from_now.to_date
find_field('expires_at').native.send_keys :enter
click_on 'Invite'
end
invite_member(new_member.name, role: 'Guest', expires_at: 5.days.from_now.to_date)
page.within second_row do
expect(page).to have_content(/in \d days/)
......
......@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe 'Project members list', :js do
include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
let(:user1) { create(:user, name: 'John Doe') }
let(:user2) { create(:user, name: 'Mary Jane') }
......@@ -12,8 +12,6 @@ RSpec.describe 'Project members list', :js do
let(:project) { create(:project, :internal, namespace: group) }
before do
stub_feature_flags(invite_members_group_modal: true)
sign_in(user1)
group.add_owner(user1)
end
......@@ -52,7 +50,7 @@ RSpec.describe 'Project members list', :js do
it 'add user to project' do
visit_members_page
add_user(user2.name, 'Reporter')
invite_member(user2.name, role: 'Reporter')
page.within find_member_row(user2) do
expect(page).to have_button('Reporter')
......@@ -100,7 +98,7 @@ RSpec.describe 'Project members list', :js do
it 'invite user to project' do
visit_members_page
add_user('test@example.com', 'Reporter')
invite_member('test@example.com', role: 'Reporter')
click_link 'Invited'
......@@ -171,25 +169,6 @@ RSpec.describe 'Project members list', :js do
private
def add_user(id, role)
click_on 'Invite members'
page.within '#invite-members-modal' do
fill_in 'Select members or type email addresses', with: id
wait_for_requests
click_button id
click_button 'Guest'
wait_for_requests
click_button role
click_button 'Invite'
end
page.refresh
end
def visit_members_page
visit project_project_members_path(project)
end
......
......@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe 'Projects > Members > Maintainer adds member with expiration date', :js do
include Select2Helper
include ActiveSupport::Testing::TimeHelpers
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
let_it_be(:maintainer) { create(:user) }
let_it_be(:project) { create(:project) }
......@@ -20,18 +20,9 @@ RSpec.describe 'Projects > Members > Maintainer adds member with expiration date
end
it 'expiration date is displayed in the members list' do
stub_feature_flags(invite_members_group_modal: false)
visit project_project_members_path(project)
page.within '.invite-users-form' do
select2(new_member.id, from: '#user_ids', multiple: true)
fill_in 'expires_at', with: 5.days.from_now.to_date
find_field('expires_at').native.send_keys :enter
click_on 'Invite'
end
invite_member(new_member.name, role: 'Guest', expires_at: 5.days.from_now.to_date)
page.within find_member_row(new_member) do
expect(page).to have_content(/in \d days/)
......
......@@ -150,8 +150,6 @@ RSpec.describe InviteMembersHelper do
end
it 'returns false' do
stub_feature_flags(invite_members_group_modal: false)
expect(helper.can_invite_members_for_group?(group)).to eq false
expect(helper).not_to have_received(:can?)
end
......
# frozen_string_literal: true
module Spec
module Support
module Helpers
module Features
module InviteMembersModalHelper
def invite_member(name, role: 'Guest', expires_at: nil)
click_on 'Invite members'
page.within '#invite-members-modal' do
fill_in 'Select members or type email addresses', with: name
wait_for_requests
click_button name
fill_in 'YYYY-MM-DD', with: expires_at.try(:strftime, '%Y-%m-%d')
unless role == 'Guest'
click_button 'Guest'
wait_for_requests
click_button role
end
click_button 'Invite'
end
page.refresh
end
end
end
end
end
end
......@@ -27,10 +27,6 @@ module Spec
all_rows[2]
end
def invite_users_form
page.find('[data-testid="invite-users-form"]')
end
def find_row(name)
page.within(members_table) do
page.find('tbody > tr', text: name)
......
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