diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/helpers/user_callouts_helper_spec.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/helpers/user_callouts_helper_spec.rb')
-rw-r--r-- | spec/helpers/user_callouts_helper_spec.rb | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/spec/helpers/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb index 5ef1e9d4daf..794ff5ee945 100644 --- a/spec/helpers/user_callouts_helper_spec.rb +++ b/spec/helpers/user_callouts_helper_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" RSpec.describe UserCalloutsHelper do - let_it_be(:user) { create(:user) } + let_it_be(:user, refind: true) { create(:user) } before do allow(helper).to receive(:current_user).and_return(user) @@ -202,4 +202,95 @@ RSpec.describe UserCalloutsHelper do it { is_expected.to be false } end end + + describe '.show_invite_banner?' do + let_it_be(:group) { create(:group) } + + subject { helper.show_invite_banner?(group) } + + context 'when user has the admin ability for the group' do + before do + group.add_owner(user) + end + + context 'when the invite_members_banner has not been dismissed' do + it { is_expected.to eq(true) } + + context 'when a user has dismissed this banner via cookies already' do + before do + helper.request.cookies["invite_#{group.id}_#{user.id}"] = 'true' + end + + it { is_expected.to eq(false) } + + it 'creates the callout from cookie', :aggregate_failures do + expect { subject }.to change { Users::GroupCallout.count }.by(1) + expect(Users::GroupCallout.last).to have_attributes(group_id: group.id, + feature_name: described_class::INVITE_MEMBERS_BANNER) + end + end + + context 'when the group was just created' do + before do + flash[:notice] = "Group #{group.name} was successfully created" + end + + it { is_expected.to eq(false) } + end + + context 'with concerning multiple members' do + let_it_be(:user_2) { create(:user) } + + context 'on current group' do + before do + group.add_guest(user_2) + end + + it { is_expected.to eq(false) } + end + + context 'on current group that is a subgroup' do + let_it_be(:subgroup) { create(:group, parent: group) } + + subject { helper.show_invite_banner?(subgroup) } + + context 'with only one user on parent and this group' do + it { is_expected.to eq(true) } + end + + context 'when another user is on this group' do + before do + subgroup.add_guest(user_2) + end + + it { is_expected.to eq(false) } + end + + context 'when another user is on the parent group' do + before do + group.add_guest(user_2) + end + + it { is_expected.to eq(false) } + end + end + end + end + + context 'when the invite_members_banner has been dismissed' do + before do + create(:group_callout, + user: user, + group: group, + feature_name: described_class::INVITE_MEMBERS_BANNER) + end + + it { is_expected.to eq(false) } + end + end + + context 'when user does not have admin ability for the group' do + it { is_expected.to eq(false) } + end + end end |