Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers/projects_helper_spec.rb')
-rw-r--r--spec/helpers/projects_helper_spec.rb117
1 files changed, 104 insertions, 13 deletions
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index 768038d8736..aa064a26ec4 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -993,6 +993,7 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do
expect(settings).to include(
packagesEnabled: !!project.packages_enabled,
+ packageRegistryAllowAnyoneToPullOption: ::Gitlab::CurrentSettings.package_registry_allow_anyone_to_pull_option,
visibilityLevel: project.visibility_level,
requestAccessEnabled: !!project.request_access_enabled,
issuesAccessLevel: project.project_feature.issues_access_level,
@@ -1006,7 +1007,7 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do
analyticsAccessLevel: project.project_feature.analytics_access_level,
containerRegistryEnabled: !!project.container_registry_enabled,
lfsEnabled: !!project.lfs_enabled,
- emailsDisabled: project.emails_disabled?,
+ emailsEnabled: project.emails_enabled?,
showDefaultAwardEmojis: project.show_default_award_emojis?,
securityAndComplianceAccessLevel: project.security_and_compliance_access_level,
containerRegistryAccessLevel: project.project_feature.container_registry_access_level,
@@ -1129,16 +1130,39 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do
end
end
- describe '#fork_button_disabled_tooltip' do
+ describe '#fork_button_data_attributes' do
using RSpec::Parameterized::TableSyntax
- subject { helper.fork_button_disabled_tooltip(project) }
+ let_it_be(:project) { create(:project, :repository, :public) }
- where(:has_user, :can_fork_project, :can_create_fork, :expected) do
- false | false | false | nil
- true | true | true | nil
- true | false | true | 'You don\'t have permission to fork this project'
- true | true | false | 'You have reached your project limit'
+ project_path = '/project/path'
+ project_forks_path = '/project/forks'
+ project_new_fork_path = '/project/new/fork'
+ user_fork_url = '/user/fork'
+
+ common_data_attributes = {
+ forks_count: 4,
+ project_full_path: project_path,
+ project_forks_url: project_forks_path,
+ can_create_fork: "true",
+ can_fork_project: "true",
+ can_read_code: "true",
+ new_fork_url: project_new_fork_path
+ }
+
+ data_attributes_with_user_fork_url = common_data_attributes.merge({ user_fork_url: user_fork_url })
+ data_attributes_without_user_fork_url = common_data_attributes.merge({ user_fork_url: nil })
+
+ subject { helper.fork_button_data_attributes(project) }
+
+ # The stubs for the forkable namespaces seem not to make sense (they're just numbers),
+ # but they're set up that way because we don't really care about what the array contains, only about its length
+ where(:has_user, :project_already_forked, :forkable_namespaces, :expected) do
+ false | false | [] | nil
+ true | false | [0] | data_attributes_without_user_fork_url
+ true | false | [0, 1] | data_attributes_without_user_fork_url
+ true | true | [0] | data_attributes_with_user_fork_url
+ true | true | [0, 1] | data_attributes_without_user_fork_url
end
with_them do
@@ -1146,13 +1170,22 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do
current_user = user if has_user
allow(helper).to receive(:current_user).and_return(current_user)
- allow(user).to receive(:can?).with(:fork_project, project).and_return(can_fork_project)
- allow(user).to receive(:can?).with(:create_fork).and_return(can_create_fork)
- end
+ allow(user).to receive(:can?).with(:fork_project, project).and_return(true)
+ allow(user).to receive(:can?).with(:create_fork).and_return(true)
+ allow(user).to receive(:can?).with(:create_projects, anything).and_return(true)
+ allow(user).to receive(:already_forked?).with(project).and_return(project_already_forked)
+ allow(user).to receive(:forkable_namespaces).and_return(forkable_namespaces)
- it 'returns tooltip text when user lacks privilege' do
- expect(subject).to eq(expected)
+ allow(project).to receive(:forks_count).and_return(4)
+ allow(project).to receive(:full_path).and_return(project_path)
+
+ user_fork_path = user_fork_url if project_already_forked
+ allow(helper).to receive(:namespace_project_path).with(user, anything).and_return(user_fork_path)
+ allow(helper).to receive(:new_project_fork_path).with(project).and_return(project_new_fork_path)
+ allow(helper).to receive(:project_forks_path).with(project).and_return(project_forks_path)
end
+
+ it { is_expected.to eq(expected) }
end
end
@@ -1614,4 +1647,62 @@ RSpec.describe ProjectsHelper, feature_category: :source_code_management do
it { is_expected.to eq(project_settings_repository_path(project, anchor: 'js-branch-rules')) }
end
+
+ describe '#visibility_level_content' do
+ shared_examples 'returns visibility level content_tag' do
+ let(:icon) { '<svg>fake visib level icon</svg>'.html_safe }
+ let(:description) { 'Fake visib desc' }
+
+ before do
+ allow(helper).to receive(:visibility_icon_description).and_return(description)
+ allow(helper).to receive(:visibility_level_icon).and_return(icon)
+ end
+
+ it 'returns visibility level content_tag' do
+ expected_result = "<span class=\"has-tooltip\" data-container=\"body\" data-placement=\"top\" title=\"#{description}\">#{icon}</span>"
+ expect(helper.visibility_level_content(project)).to eq(expected_result)
+ end
+
+ it 'returns visibility level content_tag with extra CSS classes' do
+ expected_result = "<span class=\"has-tooltip extra-class\" data-container=\"body\" data-placement=\"top\" title=\"#{description}\">#{icon}</span>"
+
+ expect(helper).to receive(:visibility_level_icon)
+ .with(anything, options: { class: 'extra-icon-class' })
+ .and_return(icon)
+ result = helper.visibility_level_content(project, css_class: 'extra-class', icon_css_class: 'extra-icon-class')
+ expect(result).to eq(expected_result)
+ end
+ end
+
+ it_behaves_like 'returns visibility level content_tag'
+
+ context 'when project creator is banned' do
+ let(:hidden_resource_icon) { '<svg>fake hidden resource icon</svg>' }
+
+ before do
+ allow(project).to receive(:created_and_owned_by_banned_user?).and_return(true)
+ allow(helper).to receive(:hidden_resource_icon).and_return(hidden_resource_icon)
+ end
+
+ it 'returns hidden resource icon' do
+ expect(helper.visibility_level_content(project)).to eq hidden_resource_icon
+ end
+ end
+
+ context 'with hide_projects_of_banned_users feature flag disabled' do
+ before do
+ stub_feature_flags(hide_projects_of_banned_users: false)
+ end
+
+ it_behaves_like 'returns visibility level content_tag'
+
+ context 'when project creator is banned' do
+ before do
+ allow(project).to receive(:created_and_owned_by_banned_user?).and_return(true)
+ end
+
+ it_behaves_like 'returns visibility level content_tag'
+ end
+ end
+ end
end