diff options
Diffstat (limited to 'spec/helpers/groups_helper_spec.rb')
-rw-r--r-- | spec/helpers/groups_helper_spec.rb | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 93191cc956b..8aee337f51c 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -93,7 +93,7 @@ RSpec.describe GroupsHelper, feature_category: :groups_and_projects do shared_examples 'correct ancestor order' do it 'outputs the groups in the correct order' do expect(subject) - .to match(%r{<li><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m) + .to match(%r{<li.*><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m) end end @@ -134,7 +134,7 @@ RSpec.describe GroupsHelper, feature_category: :groups_and_projects do subject(:link) { document.css('.group-path').first } it 'uses the group name as innerText' do - expect(link.inner_text).to eq(group.name) + expect(link.inner_text).to match(group.name) end it 'links to the group path' do @@ -150,7 +150,7 @@ RSpec.describe GroupsHelper, feature_category: :groups_and_projects do end it 'uses the group\'s avatar_url' do - expect(icon.attr('src')).to eq(group.avatar_url) + expect(icon.attr('src')).to match(group.avatar_url) end end end @@ -656,6 +656,41 @@ RSpec.describe GroupsHelper, feature_category: :groups_and_projects do end end + context 'when a user has different access for different groups in the hierarchy' do + let_it_be(:grand_parent) { create(:group) } + let_it_be(:parent) { create(:group, parent: grand_parent) } + let_it_be(:child) { create(:group, parent: parent) } + let_it_be(:grand_child) { create(:group, parent: child) } + + before_all do + parent.add_developer(user) + child.add_maintainer(user) + grand_child.add_owner(user) + end + + it 'returns the access levels that are peers or lower' do + expect(helper.access_level_roles_user_can_assign(grand_parent)).to be_empty + expect(helper.access_level_roles_user_can_assign(parent)).to eq({ + 'Guest' => ::Gitlab::Access::GUEST, + 'Reporter' => ::Gitlab::Access::REPORTER, + 'Developer' => ::Gitlab::Access::DEVELOPER + }) + expect(helper.access_level_roles_user_can_assign(child)).to eq(::Gitlab::Access.options) + expect(helper.access_level_roles_user_can_assign(grand_child)).to eq(::Gitlab::Access.options_with_owner) + end + end + + context 'when a group is linked to another' do + let_it_be(:other_group) { create(:group) } + let_it_be(:group_link) { create(:group_group_link, shared_group: group, shared_with_group: other_group, group_access: Gitlab::Access::MAINTAINER) } + + before_all do + other_group.add_owner(user) + end + + it { is_expected.to eq(::Gitlab::Access.options) } + end + context 'when user is not provided' do before do allow(helper).to receive(:current_user).and_return(nil) |