summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
commit0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch)
tree7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/helpers
parent72123183a20411a36d607d70b12d57c484394c8e (diff)
downloadgitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/access_tokens_helper_spec.rb8
-rw-r--r--spec/helpers/admin/application_settings/settings_helper_spec.rb34
-rw-r--r--spec/helpers/ci/pipeline_editor_helper_spec.rb14
-rw-r--r--spec/helpers/ci/runners_helper_spec.rb16
-rw-r--r--spec/helpers/diff_helper_spec.rb21
-rw-r--r--spec/helpers/emails_helper_spec.rb28
-rw-r--r--spec/helpers/environments_helper_spec.rb3
-rw-r--r--spec/helpers/form_helper_spec.rb50
-rw-r--r--spec/helpers/groups/crm_settings_helper_spec.rb47
-rw-r--r--spec/helpers/groups/group_members_helper_spec.rb50
-rw-r--r--spec/helpers/groups_helper_spec.rb85
-rw-r--r--spec/helpers/issues_helper_spec.rb39
-rw-r--r--spec/helpers/jira_connect_helper_spec.rb2
-rw-r--r--spec/helpers/markup_helper_spec.rb27
-rw-r--r--spec/helpers/nav/new_dropdown_helper_spec.rb2
-rw-r--r--spec/helpers/nav/top_nav_helper_spec.rb113
-rw-r--r--spec/helpers/notes_helper_spec.rb4
-rw-r--r--spec/helpers/operations_helper_spec.rb2
-rw-r--r--spec/helpers/preferences_helper_spec.rb2
-rw-r--r--spec/helpers/projects/pipeline_helper_spec.rb8
-rw-r--r--spec/helpers/projects/project_members_helper_spec.rb26
-rw-r--r--spec/helpers/projects_helper_spec.rb196
-rw-r--r--spec/helpers/routing/pseudonymization_helper_spec.rb3
-rw-r--r--spec/helpers/search_helper_spec.rb24
-rw-r--r--spec/helpers/snippets_helper_spec.rb27
-rw-r--r--spec/helpers/sorting_helper_spec.rb6
-rw-r--r--spec/helpers/storage_helper_spec.rb27
-rw-r--r--spec/helpers/todos_helper_spec.rb16
-rw-r--r--spec/helpers/tooling/visual_review_helper_spec.rb25
29 files changed, 745 insertions, 160 deletions
diff --git a/spec/helpers/access_tokens_helper_spec.rb b/spec/helpers/access_tokens_helper_spec.rb
index c2c918bc6b0..d34251d03db 100644
--- a/spec/helpers/access_tokens_helper_spec.rb
+++ b/spec/helpers/access_tokens_helper_spec.rb
@@ -64,4 +64,12 @@ RSpec.describe AccessTokensHelper do
}.to_json)
end
end
+
+ describe '#expires_at_field_data', :freeze_time do
+ it 'returns expected hash' do
+ expect(helper.expires_at_field_data).to eq({
+ min_date: 1.day.from_now.iso8601
+ })
+ end
+ end
end
diff --git a/spec/helpers/admin/application_settings/settings_helper_spec.rb b/spec/helpers/admin/application_settings/settings_helper_spec.rb
new file mode 100644
index 00000000000..9981e0d12bd
--- /dev/null
+++ b/spec/helpers/admin/application_settings/settings_helper_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Admin::ApplicationSettings::SettingsHelper do
+ describe '#inactive_projects_deletion_data' do
+ let(:delete_inactive_projects) { true }
+ let(:inactive_projects_delete_after_months) { 2 }
+ let(:inactive_projects_min_size_mb) { 250 }
+ let(:inactive_projects_send_warning_email_after_months) { 1 }
+
+ let_it_be(:application_settings) { build(:application_setting) }
+
+ before do
+ stub_application_setting(delete_inactive_projects: delete_inactive_projects)
+ stub_application_setting(inactive_projects_delete_after_months: inactive_projects_delete_after_months)
+ stub_application_setting(inactive_projects_min_size_mb: inactive_projects_min_size_mb)
+ stub_application_setting(
+ inactive_projects_send_warning_email_after_months: inactive_projects_send_warning_email_after_months
+ )
+ end
+
+ subject(:result) { helper.inactive_projects_deletion_data(application_settings) }
+
+ it 'has the expected data' do
+ expect(result).to eq({
+ delete_inactive_projects: delete_inactive_projects.to_s,
+ inactive_projects_delete_after_months: inactive_projects_delete_after_months,
+ inactive_projects_min_size_mb: inactive_projects_min_size_mb,
+ inactive_projects_send_warning_email_after_months: inactive_projects_send_warning_email_after_months
+ })
+ end
+ end
+end
diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb
index 429d4c7941a..8366506aa45 100644
--- a/spec/helpers/ci/pipeline_editor_helper_spec.rb
+++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb
@@ -31,7 +31,13 @@ RSpec.describe Ci::PipelineEditorHelper do
allow(helper)
.to receive(:image_path)
- .and_return('foo')
+ .with('illustrations/empty-state/empty-dag-md.svg')
+ .and_return('illustrations/empty.svg')
+
+ allow(helper)
+ .to receive(:image_path)
+ .with('illustrations/project-run-CICD-pipelines-sm.svg')
+ .and_return('illustrations/validate.svg')
end
subject(:pipeline_editor_data) { helper.js_pipeline_editor_data(project) }
@@ -43,7 +49,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
"ci-help-page-path" => help_page_path('ci/index'),
"default-branch" => project.default_branch_or_main,
- "empty-state-illustration-path" => 'foo',
+ "empty-state-illustration-path" => 'illustrations/empty.svg',
"initial-branch-name" => nil,
"includes-help-page-path" => help_page_path('ci/yaml/includes'),
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'),
@@ -57,6 +63,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"project-namespace" => project.namespace.full_path,
"runner-help-page-path" => help_page_path('ci/runners/index'),
"total-branches" => project.repository.branches.length,
+ "validate-tab-illustration-path" => 'illustrations/validate.svg',
"yml-help-page-path" => help_page_path('ci/yaml/index')
})
end
@@ -71,7 +78,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"ci-examples-help-page-path" => help_page_path('ci/examples/index'),
"ci-help-page-path" => help_page_path('ci/index'),
"default-branch" => project.default_branch_or_main,
- "empty-state-illustration-path" => 'foo',
+ "empty-state-illustration-path" => 'illustrations/empty.svg',
"initial-branch-name" => nil,
"includes-help-page-path" => help_page_path('ci/yaml/includes'),
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'),
@@ -85,6 +92,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"project-namespace" => project.namespace.full_path,
"runner-help-page-path" => help_page_path('ci/runners/index'),
"total-branches" => 0,
+ "validate-tab-illustration-path" => 'illustrations/validate.svg',
"yml-help-page-path" => help_page_path('ci/yaml/index')
})
end
diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb
index cf62579338f..4d1b1c7682c 100644
--- a/spec/helpers/ci/runners_helper_spec.rb
+++ b/spec/helpers/ci/runners_helper_spec.rb
@@ -84,12 +84,14 @@ RSpec.describe Ci::RunnersHelper do
end
it 'returns the data in format' do
- expect(helper.admin_runners_data_attributes).to eq({
+ expect(helper.admin_runners_data_attributes).to include(
runner_install_help_page: 'https://docs.gitlab.com/runner/install/',
registration_token: Gitlab::CurrentSettings.runners_registration_token,
online_contact_timeout_secs: 7200,
- stale_timeout_secs: 7889238
- })
+ stale_timeout_secs: 7889238,
+ empty_state_svg_path: start_with('/assets/illustrations/pipelines_empty'),
+ empty_state_filtered_svg_path: start_with('/assets/illustrations/magnifying-glass')
+ )
end
end
@@ -130,14 +132,16 @@ RSpec.describe Ci::RunnersHelper do
let(:group) { create(:group) }
it 'returns group data to render a runner list' do
- expect(helper.group_runners_data_attributes(group)).to eq({
+ expect(helper.group_runners_data_attributes(group)).to include(
registration_token: group.runners_token,
group_id: group.id,
group_full_path: group.full_path,
runner_install_help_page: 'https://docs.gitlab.com/runner/install/',
online_contact_timeout_secs: 7200,
- stale_timeout_secs: 7889238
- })
+ stale_timeout_secs: 7889238,
+ empty_state_svg_path: start_with('/assets/illustrations/pipelines_empty'),
+ empty_state_filtered_svg_path: start_with('/assets/illustrations/magnifying-glass')
+ )
end
end
diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb
index 84e702cd6a9..cf16807723b 100644
--- a/spec/helpers/diff_helper_spec.rb
+++ b/spec/helpers/diff_helper_spec.rb
@@ -468,4 +468,25 @@ RSpec.describe DiffHelper do
it { is_expected.to be_nil }
end
end
+
+ describe '#conflicts' do
+ let(:merge_request) { instance_double(MergeRequest) }
+
+ before do
+ allow(helper).to receive(:merge_request).and_return(merge_request)
+ allow(helper).to receive(:options).and_return(merge_ref_head_diff: true)
+ end
+
+ context 'when Gitlab::Git::Conflict::Resolver::ConflictSideMissing exception is raised' do
+ before do
+ allow_next_instance_of(MergeRequests::Conflicts::ListService, merge_request, allow_tree_conflicts: true) do |svc|
+ allow(svc).to receive_message_chain(:conflicts, :files).and_raise(Gitlab::Git::Conflict::Resolver::ConflictSideMissing)
+ end
+ end
+
+ it 'returns an empty hash' do
+ expect(helper.conflicts(allow_tree_conflicts: true)).to eq({})
+ end
+ end
+ end
end
diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb
index 39b919fa925..220e154aad8 100644
--- a/spec/helpers/emails_helper_spec.rb
+++ b/spec/helpers/emails_helper_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe EmailsHelper do
+ include EmailsHelperTestHelper
+
describe 'closure_reason_text' do
context 'when given a MergeRequest' do
let(:merge_request) { create(:merge_request) }
@@ -225,30 +227,40 @@ RSpec.describe EmailsHelper do
describe '#header_logo' do
context 'there is a brand item with a logo' do
- it 'returns the brand header logo' do
- appearance = create :appearance, header_logo: fixture_file_upload('spec/fixtures/dk.png')
+ let_it_be(:appearance) { create(:appearance) }
+
+ let(:logo_path) { 'spec/fixtures/dk.png' }
+ before do
+ appearance.update!(header_logo: fixture_file_upload(logo_path))
+ end
+
+ it 'returns the brand header logo' do
expect(header_logo).to eq(
%{<img style="height: 50px" src="/uploads/-/system/appearance/header_logo/#{appearance.id}/dk.png" />}
)
end
+
+ context 'that is a SVG file' do
+ let(:logo_path) { 'spec/fixtures/logo_sample.svg' }
+
+ it 'returns the default header logo' do
+ expect(header_logo).to match(default_header_logo)
+ end
+ end
end
context 'there is a brand item without a logo' do
it 'returns the default header logo' do
create :appearance, header_logo: nil
- expect(header_logo).to match(
- %r{<img alt="GitLab" src="/images/mailers/gitlab_logo\.(?:gif|png)" width="\d+" height="\d+" />}
- )
+ expect(header_logo).to match(default_header_logo)
end
end
context 'there is no brand item' do
it 'returns the default header logo' do
- expect(header_logo).to match(
- %r{<img alt="GitLab" src="/images/mailers/gitlab_logo\.(?:gif|png)" width="\d+" height="\d+" />}
- )
+ expect(header_logo).to match(default_header_logo)
end
end
end
diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb
index 52f02fba4ec..e4d4f18ad68 100644
--- a/spec/helpers/environments_helper_spec.rb
+++ b/spec/helpers/environments_helper_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe EnvironmentsHelper do
it 'returns data' do
expect(metrics_data).to include(
- 'settings_path' => edit_project_integration_path(project, 'prometheus'),
+ 'settings_path' => edit_project_settings_integration_path(project, 'prometheus'),
'clusters_path' => project_clusters_path(project),
'metrics_dashboard_base_path' => project_metrics_dashboard_path(project, environment: environment),
'current_environment_name' => environment.name,
@@ -39,7 +39,6 @@ RSpec.describe EnvironmentsHelper do
'custom_metrics_path' => project_prometheus_metrics_path(project),
'validate_query_path' => validate_query_project_prometheus_metrics_path(project),
'custom_metrics_available' => 'true',
- 'alerts_endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'custom_dashboard_base_path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT,
'operations_settings_path' => project_settings_operations_path(project),
'can_access_operations_settings' => 'true',
diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb
index 79c96e65a0e..c9c8c6b13b6 100644
--- a/spec/helpers/form_helper_spec.rb
+++ b/spec/helpers/form_helper_spec.rb
@@ -10,11 +10,16 @@ RSpec.describe FormHelper do
expect(helper.form_errors(model)).to be_nil
end
- it 'renders an alert div' do
+ it 'renders an appropriately styled alert div' do
model = double(errors: errors_stub('Error 1'))
- expect(helper.form_errors(model))
+ expect(helper.form_errors(model, pajamas_alert: false))
.to include('<div class="alert alert-danger" id="error_explanation">')
+
+ expect(helper.form_errors(model, pajamas_alert: true))
+ .to include(
+ '<div class="gl-alert gl-mb-5 gl-alert-danger gl-alert-not-dismissible" id="error_explanation" role="alert">'
+ )
end
it 'contains a summary message' do
@@ -22,9 +27,9 @@ RSpec.describe FormHelper do
multi_errors = double(errors: errors_stub('A', 'B', 'C'))
expect(helper.form_errors(single_error))
- .to include('<h4>The form contains the following error:')
+ .to include('The form contains the following error:')
expect(helper.form_errors(multi_errors))
- .to include('<h4>The form contains the following errors:')
+ .to include('The form contains the following errors:')
end
it 'renders each message' do
@@ -58,6 +63,43 @@ RSpec.describe FormHelper do
end
end
+ it 'renders help page links' do
+ stubbed_errors = ActiveModel::Errors.new(double).tap do |errors|
+ errors.add(:base, 'No text.', help_page_url: 'http://localhost/doc/user/index.html')
+ errors.add(
+ :base,
+ 'With text.',
+ help_link_text: 'Documentation page title.',
+ help_page_url: 'http://localhost/doc/administration/index.html'
+ )
+ errors.add(
+ :base,
+ 'With HTML text.',
+ help_link_text: '<foo>',
+ help_page_url: 'http://localhost/doc/security/index.html'
+ )
+ end
+
+ model = double(errors: stubbed_errors)
+
+ errors = helper.form_errors(model)
+
+ aggregate_failures do
+ expect(errors).to include(
+ '<li>No text. <a target="_blank" rel="noopener noreferrer" ' \
+ 'href="http://localhost/doc/user/index.html">Learn more.</a></li>'
+ )
+ expect(errors).to include(
+ '<li>With text. <a target="_blank" rel="noopener noreferrer" ' \
+ 'href="http://localhost/doc/administration/index.html">Documentation page title.</a></li>'
+ )
+ expect(errors).to include(
+ '<li>With HTML text. <a target="_blank" rel="noopener noreferrer" ' \
+ 'href="http://localhost/doc/security/index.html">&lt;foo&gt;</a></li>'
+ )
+ end
+ end
+
def errors_stub(*messages)
ActiveModel::Errors.new(double).tap do |errors|
messages.each { |msg| errors.add(:base, msg) }
diff --git a/spec/helpers/groups/crm_settings_helper_spec.rb b/spec/helpers/groups/crm_settings_helper_spec.rb
deleted file mode 100644
index 87690e7debc..00000000000
--- a/spec/helpers/groups/crm_settings_helper_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Groups::CrmSettingsHelper do
- let_it_be(:root_group) { create(:group) }
-
- describe '#crm_feature_available?' do
- subject do
- helper.crm_feature_available?(group)
- end
-
- context 'in root group' do
- let(:group) { root_group }
-
- context 'when feature flag is enabled' do
- it { is_expected.to be_truthy }
- end
-
- context 'when feature flag is disabled' do
- before do
- stub_feature_flags(customer_relations: false)
- end
-
- it { is_expected.to be_falsy }
- end
- end
-
- context 'in subgroup' do
- let_it_be(:subgroup) { create(:group, parent: root_group) }
-
- let(:group) { subgroup }
-
- context 'when feature flag is enabled' do
- it { is_expected.to be_truthy }
- end
-
- context 'when feature flag is disabled' do
- before do
- stub_feature_flags(customer_relations: false)
- end
-
- it { is_expected.to be_falsy }
- end
- end
- end
-end
diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb
index ab11bc1f5fd..d308df3a017 100644
--- a/spec/helpers/groups/group_members_helper_spec.rb
+++ b/spec/helpers/groups/group_members_helper_spec.rb
@@ -5,15 +5,8 @@ require "spec_helper"
RSpec.describe Groups::GroupMembersHelper do
include MembersPresentation
- let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
- before do
- allow(helper).to receive(:can?).with(current_user, :export_group_memberships, group).and_return(false)
- allow(helper).to receive(:can?).with(current_user, :owner_access, group).and_return(true)
- allow(helper).to receive(:current_user).and_return(current_user)
- end
-
describe '.group_member_select_options' do
before do
helper.instance_variable_set(:@group, group)
@@ -27,12 +20,24 @@ RSpec.describe Groups::GroupMembersHelper do
describe '#group_members_app_data' do
include_context 'group_group_link'
+ let_it_be(:current_user) { create(:user) }
+
let(:members) { create_list(:group_member, 2, group: shared_group, created_by: current_user) }
let(:invited) { create_list(:group_member, 2, :invited, group: shared_group, created_by: current_user) }
let!(:access_requests) { create_list(:group_member, 2, :access_request, group: shared_group, created_by: current_user) }
let(:members_collection) { members }
+ before do
+ allow(helper).to receive(:can?).with(current_user, :export_group_memberships, group).and_return(false)
+ allow(helper).to receive(:can?).with(current_user, :owner_access, group).and_return(true)
+ allow(helper).to receive(:current_user).and_return(current_user)
+ allow(helper).to receive(:can?).with(current_user, :export_group_memberships, shared_group).and_return(true)
+ allow(helper).to receive(:group_group_member_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_members/:id')
+ allow(helper).to receive(:group_group_link_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_links/:id')
+ allow(helper).to receive(:can?).with(current_user, :admin_group_member, shared_group).and_return(true)
+ end
+
subject do
helper.group_members_app_data(
shared_group,
@@ -54,13 +59,6 @@ RSpec.describe Groups::GroupMembersHelper do
end
end
- before do
- allow(helper).to receive(:can?).with(current_user, :export_group_memberships, shared_group).and_return(true)
- allow(helper).to receive(:group_group_member_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_members/:id')
- allow(helper).to receive(:group_group_link_path).with(shared_group, ':id').and_return('/groups/foo-bar/-/group_links/:id')
- allow(helper).to receive(:can?).with(current_user, :admin_group_member, shared_group).and_return(true)
- end
-
it 'returns expected json' do
expected = {
source_id: shared_group.id,
@@ -137,24 +135,6 @@ RSpec.describe Groups::GroupMembersHelper do
expect(subject[:group][:members].map { |link| link[:id] }).to match_array(result)
end
end
-
- context 'when group_member_inherited_group disabled' do
- before do
- stub_feature_flags(group_member_inherited_group: false)
- end
-
- where(:include_relations, :result) do
- [:inherited, :direct] | lazy { [sub_group_group_link.id] }
- [:inherited] | lazy { [sub_group_group_link.id] }
- [:direct] | lazy { [sub_group_group_link.id] }
- end
-
- with_them do
- it 'always returns direct member links' do
- expect(subject[:group][:members].map { |link| link[:id] }).to match_array(result)
- end
- end
- end
end
end
@@ -188,4 +168,10 @@ RSpec.describe Groups::GroupMembersHelper do
end
end
end
+
+ describe '#group_member_header_subtext' do
+ it 'contains expected text with group name' do
+ expect(helper.group_member_header_subtext(group)).to match("You can invite a new member to .*#{group.name}")
+ end
+ end
end
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index 8859ed27022..bcbe571db5e 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -419,4 +419,89 @@ RSpec.describe GroupsHelper do
expect(localized_jobs_to_be_done_choices.keys).to match_array(NamespaceSetting.jobs_to_be_dones.keys)
end
end
+
+ describe '#group_name_and_path_app_data' do
+ let_it_be(:group) { build(:group, name: 'My awesome group', path: 'my-awesome-group') }
+ let_it_be(:subgroup) { build(:group, parent: group) }
+ let_it_be(:root_url) { 'https://gitlab.com/' }
+
+ before do
+ allow(Gitlab.config.mattermost).to receive(:enabled).and_return(true)
+ allow(helper).to receive(:root_url) { root_url }
+ end
+
+ context 'when group has a parent' do
+ it 'returns expected hash' do
+ expect(group_name_and_path_app_data(subgroup)).to match(
+ { base_path: 'https://gitlab.com/my-awesome-group', mattermost_enabled: 'true' }
+ )
+ end
+ end
+
+ context 'when group does not have a parent' do
+ it 'returns expected hash' do
+ expect(group_name_and_path_app_data(group)).to match(
+ { base_path: root_url, mattermost_enabled: 'true' }
+ )
+ end
+ end
+ end
+
+ describe '#subgroups_and_projects_list_app_data' do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:user) { create(:user) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+
+ allow(helper).to receive(:can?).with(user, :create_subgroup, group) { true }
+ allow(helper).to receive(:can?).with(user, :create_projects, group) { true }
+ end
+
+ it 'returns expected hash' do
+ expect(helper.subgroups_and_projects_list_app_data(group)).to match({
+ show_schema_markup: 'true',
+ new_subgroup_path: including("groups/new?parent_id=#{group.id}"),
+ new_project_path: including("/projects/new?namespace_id=#{group.id}"),
+ new_subgroup_illustration: including('illustrations/subgroup-create-new-sm'),
+ new_project_illustration: including('illustrations/project-create-new-sm'),
+ empty_subgroup_illustration: including('illustrations/empty-state/empty-subgroup-md'),
+ render_empty_state: 'true',
+ can_create_subgroups: 'true',
+ can_create_projects: 'true'
+ })
+ end
+ end
+
+ describe "#enabled_git_access_protocol_options_for_group" do
+ subject { helper.enabled_git_access_protocol_options_for_group }
+
+ before do
+ expect(::Gitlab::CurrentSettings).to receive(:enabled_git_access_protocol).and_return(instance_setting)
+ end
+
+ context "instance setting is nil" do
+ let(:instance_setting) { nil }
+
+ it { is_expected.to contain_exactly([_("Both SSH and HTTP(S)"), "all"], [_("Only SSH"), "ssh"], [_("Only HTTP(S)"), "http"]) }
+ end
+
+ context "instance setting is blank" do
+ let(:instance_setting) { nil }
+
+ it { is_expected.to contain_exactly([_("Both SSH and HTTP(S)"), "all"], [_("Only SSH"), "ssh"], [_("Only HTTP(S)"), "http"]) }
+ end
+
+ context "instance setting is ssh" do
+ let(:instance_setting) { "ssh" }
+
+ it { is_expected.to contain_exactly([_("Only SSH"), "ssh"]) }
+ end
+
+ context "instance setting is http" do
+ let(:instance_setting) { "http" }
+
+ it { is_expected.to contain_exactly([_("Only HTTP(S)"), "http"]) }
+ end
+ end
end
diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb
index 58f06899cd6..a58fe9a6cd9 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -365,12 +365,14 @@ RSpec.describe IssuesHelper do
expected = {
autocomplete_award_emojis_path: autocomplete_award_emojis_path,
calendar_path: '#',
+ can_create_projects: 'true',
empty_state_svg_path: '#',
full_path: group.full_path,
has_any_issues: false.to_s,
has_any_projects: true.to_s,
is_signed_in: current_user.present?.to_s,
jira_integration_path: help_page_url('integration/jira/issues', anchor: 'view-jira-issues'),
+ new_project_path: new_project_path(namespace_id: group.id),
rss_path: '#',
sign_in_path: new_user_session_path
}
@@ -450,6 +452,43 @@ RSpec.describe IssuesHelper do
end
end
+ describe '#status_box_class' do
+ context 'when object is expired' do
+ it 'returns orange background' do
+ milestone = build(:milestone, due_date: Date.today.prev_month)
+ expect(helper.status_box_class(milestone)).to eq('gl-bg-orange-500')
+ end
+ end
+
+ context 'when object is merged' do
+ it 'returns blue background' do
+ merge_request = build(:merge_request, :merged)
+ expect(helper.status_box_class(merge_request)).to eq('badge-info')
+ end
+ end
+
+ context 'when object is closed' do
+ it 'returns red background' do
+ merge_request = build(:merge_request, :closed)
+ expect(helper.status_box_class(merge_request)).to eq('badge-danger')
+ end
+ end
+
+ context 'when object is upcoming' do
+ it 'returns gray background' do
+ milestone = build(:milestone, start_date: Date.today.next_month)
+ expect(helper.status_box_class(milestone)).to eq('gl-bg-gray-500')
+ end
+ end
+
+ context 'when object is opened' do
+ it 'returns green background' do
+ merge_request = build(:merge_request, :opened)
+ expect(helper.status_box_class(merge_request)).to eq('badge-success')
+ end
+ end
+ end
+
describe '#issue_hidden?' do
context 'when issue is hidden' do
let_it_be(:banned_user) { build(:user, :banned) }
diff --git a/spec/helpers/jira_connect_helper_spec.rb b/spec/helpers/jira_connect_helper_spec.rb
index 169a5c0076a..4d2fc3d9ee6 100644
--- a/spec/helpers/jira_connect_helper_spec.rb
+++ b/spec/helpers/jira_connect_helper_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe JiraConnectHelper do
let(:client_id) { '123' }
before do
- stub_env('JIRA_CONNECT_OAUTH_CLIENT_ID', client_id)
+ stub_application_setting(jira_connect_application_key: client_id)
end
subject { helper.jira_connect_app_data([subscription]) }
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb
index a7e657f2636..8a7a6d003f4 100644
--- a/spec/helpers/markup_helper_spec.rb
+++ b/spec/helpers/markup_helper_spec.rb
@@ -467,6 +467,33 @@ FooBar
end
end
+ context 'when rendering takes too long' do
+ before do
+ stub_const("MarkupHelper::RENDER_TIMEOUT", 0.1)
+ allow(Gitlab::OtherMarkup).to receive(:render) { sleep(0.2) }
+ end
+
+ it 'times out' do
+ expect(Gitlab::RenderTimeout).to receive(:timeout).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
+ instance_of(Timeout::Error),
+ project_id: project.id, file_name: file_name
+ )
+
+ subject
+ end
+
+ context 'when markup_rendering_timeout is disabled' do
+ it 'waits until the execution completes' do
+ stub_feature_flags(markup_rendering_timeout: false)
+
+ expect(Gitlab::RenderTimeout).not_to receive(:timeout)
+
+ subject
+ end
+ end
+ end
+
context 'when file is a markdown file' do
let(:file_name) { 'foo.md' }
diff --git a/spec/helpers/nav/new_dropdown_helper_spec.rb b/spec/helpers/nav/new_dropdown_helper_spec.rb
index ab206152e3d..4f32ac5b5c6 100644
--- a/spec/helpers/nav/new_dropdown_helper_spec.rb
+++ b/spec/helpers/nav/new_dropdown_helper_spec.rb
@@ -55,7 +55,7 @@ RSpec.describe Nav::NewDropdownHelper do
end
it 'has title' do
- expect(subject[:title]).to eq('New...')
+ expect(subject[:title]).to eq('Create new')
end
context 'when current_user is nil (anonymous)' do
diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb
index e4422dde407..9d43e057521 100644
--- a/spec/helpers/nav/top_nav_helper_spec.rb
+++ b/spec/helpers/nav/top_nav_helper_spec.rb
@@ -10,6 +10,7 @@ RSpec.describe Nav::TopNavHelper do
let(:current_user) { nil }
before do
+ stub_application_setting(snowplow_enabled: true)
allow(helper).to receive(:current_user) { current_user }
end
@@ -50,49 +51,40 @@ RSpec.describe Nav::TopNavHelper do
context 'when current_user is nil (anonymous)' do
it 'has expected :primary' do
expected_primary = [
- ::Gitlab::Nav::TopNavMenuItem.build(
- href: '/explore',
- icon: 'project',
- id: 'project',
- title: 'Projects'
- ),
- ::Gitlab::Nav::TopNavMenuItem.build(
- href: '/explore/groups',
- icon: 'group',
- id: 'groups',
- title: 'Groups'
- ),
- ::Gitlab::Nav::TopNavMenuItem.build(
- href: '/explore/snippets',
- icon: 'snippet',
- id: 'snippets',
- title: 'Snippets'
- )
- ]
+ { href: '/explore', icon: 'project', id: 'project', title: 'Projects' },
+ { href: '/explore/groups', icon: 'group', id: 'groups', title: 'Groups' },
+ { href: '/explore/snippets', icon: 'snippet', id: 'snippets', title: 'Snippets' }
+ ].map do |item|
+ ::Gitlab::Nav::TopNavMenuItem.build(**item)
+ end
+
expect(subject[:primary]).to eq(expected_primary)
end
it 'has expected :shortcuts' do
expected_shortcuts = [
- ::Gitlab::Nav::TopNavMenuItem.build(
+ {
href: '/explore',
id: 'project-shortcut',
title: 'Projects',
css_class: 'dashboard-shortcuts-projects'
- ),
- ::Gitlab::Nav::TopNavMenuItem.build(
+ },
+ {
href: '/explore/groups',
id: 'groups-shortcut',
title: 'Groups',
css_class: 'dashboard-shortcuts-groups'
- ),
- ::Gitlab::Nav::TopNavMenuItem.build(
+ },
+ {
href: '/explore/snippets',
id: 'snippets-shortcut',
title: 'Snippets',
css_class: 'dashboard-shortcuts-snippets'
- )
- ]
+ }
+ ].map do |item|
+ ::Gitlab::Nav::TopNavMenuItem.build(**item)
+ end
+
expect(subject[:shortcuts]).to eq(expected_shortcuts)
end
@@ -171,21 +163,41 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :linksPrimary' do
expected_links_primary = [
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Your projects',
+ **menu_data_tracking_attrs('your_projects')
+ },
href: '/dashboard/projects',
id: 'your',
title: 'Your projects'
),
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Starred projects',
+ **menu_data_tracking_attrs('starred_projects')
+ },
href: '/dashboard/projects/starred',
id: 'starred',
title: 'Starred projects'
),
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Explore projects',
+ **menu_data_tracking_attrs('explore_projects')
+ },
href: '/explore',
id: 'explore',
title: 'Explore projects'
),
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Explore topics',
+ **menu_data_tracking_attrs('explore_topics')
+ },
href: '/explore/projects/topics',
id: 'topics',
title: 'Explore topics'
@@ -197,6 +209,11 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :linksSecondary' do
expected_links_secondary = [
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Create new project',
+ **menu_data_tracking_attrs('create_new_project')
+ },
href: '/projects/new',
id: 'create',
title: 'Create new project'
@@ -282,11 +299,21 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :linksPrimary' do
expected_links_primary = [
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Your groups',
+ **menu_data_tracking_attrs('your_groups')
+ },
href: '/dashboard/groups',
id: 'your',
title: 'Your groups'
),
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Explore groups',
+ **menu_data_tracking_attrs('explore_groups')
+ },
href: '/explore/groups',
id: 'explore',
title: 'Explore groups'
@@ -298,6 +325,11 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :linksSecondary' do
expected_links_secondary = [
::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Create group',
+ **menu_data_tracking_attrs('create_group')
+ },
href: '/groups/new',
id: 'create',
title: 'Create group'
@@ -356,7 +388,8 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :primary' do
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
data: {
- qa_selector: 'milestones_link'
+ qa_selector: 'milestones_link',
+ **menu_data_tracking_attrs('milestones')
},
href: '/dashboard/milestones',
icon: 'clock',
@@ -383,7 +416,8 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :primary' do
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
data: {
- qa_selector: 'snippets_link'
+ qa_selector: 'snippets_link',
+ **menu_data_tracking_attrs('snippets')
},
href: '/dashboard/snippets',
icon: 'snippet',
@@ -410,7 +444,8 @@ RSpec.describe Nav::TopNavHelper do
it 'has expected :primary' do
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
data: {
- qa_selector: 'activity_link'
+ qa_selector: 'activity_link',
+ **menu_data_tracking_attrs('activity')
},
href: '/dashboard/activity',
icon: 'history',
@@ -439,6 +474,11 @@ RSpec.describe Nav::TopNavHelper do
it 'has admin as first :secondary item' do
expected_admin_item = ::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Admin',
+ **menu_data_tracking_attrs('admin')
+ },
id: 'admin',
title: 'Admin',
icon: 'admin',
@@ -458,7 +498,7 @@ RSpec.describe Nav::TopNavHelper do
title: 'Leave Admin Mode',
icon: 'lock-open',
href: '/admin/session/destroy',
- data: { method: 'post' }
+ data: { method: 'post', **menu_data_tracking_attrs('leave_admin_mode') }
)
expect(subject[:secondary].last).to eq(expected_leave_admin_mode_item)
end
@@ -469,6 +509,11 @@ RSpec.describe Nav::TopNavHelper do
it 'has enter_admin_mode as last :secondary item' do
expected_enter_admin_mode_item = ::Gitlab::Nav::TopNavMenuItem.build(
+ data: {
+ qa_selector: 'menu_item_link',
+ qa_title: 'Enter Admin Mode',
+ **menu_data_tracking_attrs('enter_admin_mode')
+ },
id: 'enter_admin_mode',
title: 'Enter Admin Mode',
icon: 'lock',
@@ -533,4 +578,12 @@ RSpec.describe Nav::TopNavHelper do
end
end
end
+
+ def menu_data_tracking_attrs(label)
+ {
+ track_label: "menu_#{label}",
+ track_action: 'click_dropdown',
+ track_property: 'navigation'
+ }
+ end
end
diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb
index 913a38d353f..68a6b6293c8 100644
--- a/spec/helpers/notes_helper_spec.rb
+++ b/spec/helpers/notes_helper_spec.rb
@@ -329,10 +329,6 @@ RSpec.describe NotesHelper do
allow(helper).to receive(:current_user).and_return(guest)
end
- it 'sets last_fetched_at to 0 when start_at_zero is true' do
- expect(helper.notes_data(issue, true)[:lastFetchedAt]).to eq(0)
- end
-
it 'includes the current notes filter for the user' do
guest.set_notes_filter(UserPreference::NOTES_FILTERS[:only_comments], issue)
diff --git a/spec/helpers/operations_helper_spec.rb b/spec/helpers/operations_helper_spec.rb
index 857771ebba6..9e50712a386 100644
--- a/spec/helpers/operations_helper_spec.rb
+++ b/spec/helpers/operations_helper_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe OperationsHelper do
expect(subject).to eq(
'alerts_setup_url' => help_page_path('operations/incident_management/integrations.md', anchor: 'configuration'),
'alerts_usage_url' => project_alert_management_index_path(project),
- 'prometheus_form_path' => project_integration_path(project, prometheus_integration),
+ 'prometheus_form_path' => project_settings_integration_path(project, prometheus_integration),
'prometheus_reset_key_path' => reset_alerting_token_project_settings_operations_path(project),
'prometheus_authorization_key' => nil,
'prometheus_api_url' => nil,
diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb
index 01235c7bb51..99f750bb858 100644
--- a/spec/helpers/preferences_helper_spec.rb
+++ b/spec/helpers/preferences_helper_spec.rb
@@ -75,7 +75,7 @@ RSpec.describe PreferencesHelper do
it "returns user's theme's css_class" do
stub_user(theme_id: 3)
- expect(helper.user_application_theme).to eq 'ui-light'
+ expect(helper.user_application_theme).to eq 'ui-light-gray'
end
it 'returns the default when id is invalid' do
diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb
index 90cf3cb03f8..d04aa9a9d04 100644
--- a/spec/helpers/projects/pipeline_helper_spec.rb
+++ b/spec/helpers/projects/pipeline_helper_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Projects::PipelineHelper do
+ include Ci::BuildsHelper
+
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:raw_pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) }
@@ -14,10 +16,14 @@ RSpec.describe Projects::PipelineHelper do
it 'returns pipeline tabs data' do
expect(pipeline_tabs_data).to include({
can_generate_codequality_reports: pipeline.can_generate_codequality_reports?.to_json,
+ failed_jobs_count: pipeline.failed_builds.count,
+ failed_jobs_summary: prepare_failed_jobs_summary_data(pipeline.failed_builds),
+ full_path: project.full_path,
graphql_resource_etag: graphql_etag_pipeline_path(pipeline),
metrics_path: namespace_project_ci_prometheus_metrics_histograms_path(namespace_id: project.namespace, project_id: project, format: :json),
pipeline_iid: pipeline.iid,
- pipeline_project_path: project.full_path
+ pipeline_project_path: project.full_path,
+ total_job_count: pipeline.total_size
})
end
end
diff --git a/spec/helpers/projects/project_members_helper_spec.rb b/spec/helpers/projects/project_members_helper_spec.rb
index 4e3a0147509..2414a1782c5 100644
--- a/spec/helpers/projects/project_members_helper_spec.rb
+++ b/spec/helpers/projects/project_members_helper_spec.rb
@@ -86,4 +86,30 @@ RSpec.describe Projects::ProjectMembersHelper do
end
end
end
+
+ describe '#project_member_header_subtext' do
+ before do
+ allow(helper).to receive(:can?).with(current_user, :admin_project_member, project).and_return(can_admin_member)
+ end
+
+ context 'when user can admin project members' do
+ let(:can_admin_member) { true }
+
+ before do
+ assign(:project, project)
+ end
+
+ it 'contains expected text' do
+ expect(helper.project_member_header_subtext(project)).to match('You can invite a new member to')
+ end
+ end
+
+ context 'when user cannot admin project members' do
+ let(:can_admin_member) { false }
+
+ it 'contains expected text' do
+ expect(helper.project_member_header_subtext(project)).to match('Members can be added by project')
+ end
+ end
+ end
end
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index d13c5dfcc9e..e0c98bbc161 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -1112,4 +1112,200 @@ RSpec.describe ProjectsHelper do
it_behaves_like 'configure import method modal'
end
+
+ describe '#show_inactive_project_deletion_banner?' do
+ shared_examples 'does not show the banner' do |pass_project: true|
+ it { expect(helper.show_inactive_project_deletion_banner?(pass_project ? project : nil)).to be(false) }
+ end
+
+ context 'with no project' do
+ it_behaves_like 'does not show the banner', pass_project: false
+ end
+
+ context 'with unsaved project' do
+ let_it_be(:project) { build(:project) }
+
+ it_behaves_like 'does not show the banner'
+ end
+
+ context 'with the setting disabled' do
+ before do
+ stub_application_setting(delete_inactive_projects: false)
+ end
+
+ it_behaves_like 'does not show the banner'
+ end
+
+ context 'with the setting enabled' do
+ before do
+ stub_application_setting(delete_inactive_projects: true)
+ end
+
+ context 'with the feature flag disabled' do
+ before do
+ stub_feature_flags(inactive_projects_deletion: false)
+ end
+
+ it_behaves_like 'does not show the banner'
+ end
+
+ context 'with the feature flag enabled' do
+ before do
+ stub_feature_flags(inactive_projects_deletion: true)
+ stub_application_setting(inactive_projects_min_size_mb: 0)
+ stub_application_setting(inactive_projects_send_warning_email_after_months: 1)
+ end
+
+ context 'with an active project' do
+ it_behaves_like 'does not show the banner'
+ end
+
+ context 'with an inactive project' do
+ before do
+ project.statistics.storage_size = 1.megabyte
+ project.last_activity_at = 1.year.ago
+ project.save!
+ end
+
+ it 'shows the banner' do
+ expect(helper.show_inactive_project_deletion_banner?(project)).to be(true)
+ end
+ end
+ end
+ end
+ end
+
+ describe '#inactive_project_deletion_date' do
+ let(:tracker) { instance_double(::Gitlab::InactiveProjectsDeletionWarningTracker) }
+
+ before do
+ stub_application_setting(inactive_projects_delete_after_months: 2)
+ stub_application_setting(inactive_projects_send_warning_email_after_months: 1)
+
+ allow(::Gitlab::InactiveProjectsDeletionWarningTracker).to receive(:new).with(project.id).and_return(tracker)
+ allow(tracker).to receive(:scheduled_deletion_date).and_return('2022-03-01')
+ end
+
+ it 'returns the deletion date' do
+ expect(helper.inactive_project_deletion_date(project)).to eq('2022-03-01')
+ end
+ end
+
+ describe '#can_admin_associated_clusters?' do
+ let_it_be(:current_user) { create(:user) }
+ let_it_be_with_reload(:project) { create(:project) }
+
+ subject { helper.send(:can_admin_associated_clusters?, project) }
+
+ before do
+ allow(helper).to receive(:current_user).and_return(current_user)
+ allow(helper)
+ .to receive(:can?)
+ .with(current_user, :admin_cluster, namespace)
+ .and_return(user_can_admin_cluster)
+ end
+
+ context 'when project has a cluster' do
+ let_it_be(:namespace) { project }
+
+ before do
+ create(:cluster, projects: [namespace])
+ end
+
+ context 'if user can admin cluster' do
+ let_it_be(:user_can_admin_cluster) { true }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'if user can not admin cluster' do
+ let_it_be(:user_can_admin_cluster) { false }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ context 'when project has a group cluster' do
+ let_it_be(:namespace) { create(:group) }
+
+ before do
+ project.update!(namespace: namespace)
+ create(:cluster, :group, groups: [namespace])
+ end
+
+ context 'if user can admin cluster' do
+ let_it_be(:user_can_admin_cluster) { true }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'if user can not admin cluster' do
+ let_it_be(:user_can_admin_cluster) { false }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ context 'when project doesn\'t have a cluster' do
+ let_it_be(:namespace) { project }
+
+ context 'if user can admin cluster' do
+ let_it_be(:user_can_admin_cluster) { true }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'if user can not admin cluster' do
+ let_it_be(:user_can_admin_cluster) { false }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+ end
+
+ describe '#show_clusters_alert?' do
+ using RSpec::Parameterized::TableSyntax
+
+ subject { helper.show_clusters_alert?(project) }
+
+ where(:is_gitlab_com, :user_can_admin_cluster, :expected) do
+ false | false | false
+ false | true | false
+ true | false | false
+ true | true | true
+ end
+
+ with_them do
+ before do
+ allow(::Gitlab).to receive(:com?).and_return(is_gitlab_com)
+ allow(helper).to receive(:can_admin_associated_clusters?).and_return(user_can_admin_cluster)
+ end
+
+ it { is_expected.to eq(expected) }
+ end
+ end
+
+ describe '#clusters_deprecation_alert_message' do
+ subject { helper.clusters_deprecation_alert_message }
+
+ before do
+ allow(helper).to receive(:has_active_license?).and_return(has_active_license)
+ end
+
+ context 'if user has an active licence' do
+ let_it_be(:has_active_license) { true }
+
+ it 'displays the correct messagee' do
+ expect(subject).to eq(s_('Clusters|The certificate-based Kubernetes integration has been deprecated and will be turned off at the end of November 2022. Please %{linkStart}migrate to the GitLab agent for Kubernetes%{linkEnd} or reach out to GitLab support.'))
+ end
+ end
+
+ context 'if user doesn\'t have an active licence' do
+ let_it_be(:has_active_license) { false }
+
+ it 'displays the correct message' do
+ expect(subject).to eq(s_('Clusters|The certificate-based Kubernetes integration has been deprecated and will be turned off at the end of November 2022. Please %{linkStart}migrate to the GitLab agent for Kubernetes%{linkEnd}.'))
+ end
+ end
+ end
end
diff --git a/spec/helpers/routing/pseudonymization_helper_spec.rb b/spec/helpers/routing/pseudonymization_helper_spec.rb
index cf716931fe2..dd4cc55ed2b 100644
--- a/spec/helpers/routing/pseudonymization_helper_spec.rb
+++ b/spec/helpers/routing/pseudonymization_helper_spec.rb
@@ -8,8 +8,7 @@ RSpec.describe ::Routing::PseudonymizationHelper do
let_it_be(:project) { create(:project, group: group) }
let_it_be(:subproject) { create(:project, group: subgroup) }
let_it_be(:issue) { create(:issue, project: project) }
-
- let(:merge_request) { create(:merge_request, source_project: project) }
+ let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let(:subject) { helper.masked_page_url(group: group, project: project) }
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index 8e2ec014383..4117d577f20 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -534,24 +534,26 @@ RSpec.describe SearchHelper do
end
describe '#repository_ref' do
+ using RSpec::Parameterized::TableSyntax
+
let_it_be(:project) { create(:project, :repository) }
- let(:params) { { repository_ref: 'the-repository-ref-param' } }
+ let(:default_branch) { project.default_branch }
+ let(:params) { { repository_ref: ref, project_id: project_id } }
subject { repository_ref(project) }
- it { is_expected.to eq('the-repository-ref-param') }
-
- context 'when the param :repository_ref is not set' do
- let(:params) { { repository_ref: nil } }
-
- it { is_expected.to eq(project.default_branch) }
+ where(:project_id, :ref, :expected_ref) do
+ 123 | 'ref-param' | 'ref-param'
+ 123 | nil | ref(:default_branch)
+ 123 | 111111 | '111111'
+ nil | 'ref-param' | ref(:default_branch)
end
- context 'when the repository_ref param is a number' do
- let(:params) { { repository_ref: 111111 } }
-
- it { is_expected.to eq('111111') }
+ with_them do
+ it 'returns expected_ref' do
+ expect(repository_ref(project)).to eq(expected_ref)
+ end
end
end
diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb
index 913be164a00..37520affc5a 100644
--- a/spec/helpers/snippets_helper_spec.rb
+++ b/spec/helpers/snippets_helper_spec.rb
@@ -64,6 +64,33 @@ RSpec.describe SnippetsHelper do
end
end
+ describe '#embedded_snippet_copy_button' do
+ let(:blob) { snippet.blobs.first }
+ let(:ref) { blob.repository.root_ref }
+
+ subject { embedded_copy_snippet_button(blob) }
+
+ context 'for Personal Snippets' do
+ let(:snippet) { public_personal_snippet }
+
+ it 'returns copy button of embedded snippets' do
+ expect(subject).to eq(copy_button("#{blob.id}"))
+ end
+ end
+
+ context 'for Project Snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns copy button of embedded snippets' do
+ expect(subject).to eq(copy_button("#{blob.id}"))
+ end
+ end
+
+ def copy_button(blob_id)
+ "<button class=\"gl-button btn btn-default copy-to-clipboard-btn\" title=\"Copy snippet contents\" onclick=\"copyToClipboard(&#39;.blob-content[data-blob-id=&quot;#{blob_id}&quot;] &gt; pre&#39;)\">#{external_snippet_icon('copy-to-clipboard')}</button>"
+ end
+ end
+
describe '#snippet_badge' do
let(:snippet) { build(:personal_snippet, visibility) }
diff --git a/spec/helpers/sorting_helper_spec.rb b/spec/helpers/sorting_helper_spec.rb
index e20fb77ad75..1ee920d1c95 100644
--- a/spec/helpers/sorting_helper_spec.rb
+++ b/spec/helpers/sorting_helper_spec.rb
@@ -62,6 +62,12 @@ RSpec.describe SortingHelper do
end
end
+ describe '#can_sort_by_issue_weight?' do
+ it 'returns false' do
+ expect(helper.can_sort_by_issue_weight?(false)).to be_falsey
+ end
+ end
+
def stub_controller_path(value)
allow(helper.controller).to receive(:controller_path).and_return(value)
end
diff --git a/spec/helpers/storage_helper_spec.rb b/spec/helpers/storage_helper_spec.rb
index 5bc4024ae24..c2c508cf485 100644
--- a/spec/helpers/storage_helper_spec.rb
+++ b/spec/helpers/storage_helper_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe StorageHelper do
end
end
- describe "storage_enforcement_banner" do
+ describe "storage_enforcement_banner", :saas do
let_it_be_with_refind(:current_user) { create(:user) }
let_it_be(:free_group) { create(:group) }
let_it_be(:paid_group) { create(:group) }
@@ -60,8 +60,9 @@ RSpec.describe StorageHelper do
allow(helper).to receive(:can?).with(current_user, :admin_namespace, free_group).and_return(true)
allow(helper).to receive(:can?).with(current_user, :admin_namespace, paid_group).and_return(true)
allow(helper).to receive(:current_user) { current_user }
- allow(Gitlab).to receive(:com?).and_return(true)
allow(paid_group).to receive(:paid?).and_return(true)
+
+ stub_feature_flags(namespace_storage_limit_bypass_date_check: false)
end
describe "#storage_enforcement_banner_info" do
@@ -108,6 +109,28 @@ RSpec.describe StorageHelper do
expect(helper.storage_enforcement_banner_info(free_group)[:text]).to eql("From #{storage_enforcement_date} storage limits will apply to this namespace. You are currently using 100 KB of namespace storage. View and manage your usage from <strong>Group settings &gt; Usage quotas</strong>.")
end
end
+
+ context 'when the given group is a sub-group' do
+ let_it_be(:sub_group) { build(:group) }
+
+ before do
+ allow(sub_group).to receive(:root_ancestor).and_return(free_group)
+ end
+
+ it 'returns the banner hash' do
+ expect(helper.storage_enforcement_banner_info(sub_group).keys).to match_array(%i(text variant callouts_feature_name callouts_path learn_more_link))
+ end
+ end
+ end
+ end
+
+ context 'when the :storage_banner_bypass_date_check is enabled', :freeze_time do
+ before do
+ stub_feature_flags(namespace_storage_limit_bypass_date_check: true)
+ end
+
+ it 'returns the enforcement info' do
+ expect(helper.storage_enforcement_banner_info(free_group)[:text]).to include("From #{Date.current} storage limits will apply to this namespace.")
end
end
diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb
index 3787864e144..922fb1d7c92 100644
--- a/spec/helpers/todos_helper_spec.rb
+++ b/spec/helpers/todos_helper_spec.rb
@@ -152,7 +152,7 @@ RSpec.describe TodosHelper do
shared_examples 'a rendered state pill' do |attr|
it 'returns expected html' do
aggregate_failures do
- expect(subject).to have_css(".status-box-#{attr[:type]}-#{attr[:state].dasherize}")
+ expect(subject).to have_css(attr[:css])
expect(subject).to have_content(attr[:state].capitalize)
end
end
@@ -167,12 +167,20 @@ RSpec.describe TodosHelper do
it_behaves_like 'no state pill'
+ context 'closed MR' do
+ before do
+ todo.target.update!(state: 'closed')
+ end
+
+ it_behaves_like 'a rendered state pill', css: '.gl-bg-red-500', state: 'closed'
+ end
+
context 'merged MR' do
before do
todo.target.update!(state: 'merged')
end
- it_behaves_like 'a rendered state pill', type: 'mr', state: 'merged'
+ it_behaves_like 'a rendered state pill', css: '.gl-bg-blue-500', state: 'merged'
end
end
@@ -186,7 +194,7 @@ RSpec.describe TodosHelper do
todo.target.update!(state: 'closed')
end
- it_behaves_like 'a rendered state pill', type: 'issue', state: 'closed'
+ it_behaves_like 'a rendered state pill', css: '.gl-bg-blue-500', state: 'closed'
end
end
@@ -200,7 +208,7 @@ RSpec.describe TodosHelper do
todo.target.resolve!
end
- it_behaves_like 'a rendered state pill', type: 'alert', state: 'resolved'
+ it_behaves_like 'a rendered state pill', css: '.gl-bg-blue-500', state: 'resolved'
end
end
end
diff --git a/spec/helpers/tooling/visual_review_helper_spec.rb b/spec/helpers/tooling/visual_review_helper_spec.rb
new file mode 100644
index 00000000000..7fb9f5fadf2
--- /dev/null
+++ b/spec/helpers/tooling/visual_review_helper_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Tooling::VisualReviewHelper do
+ describe '#visual_review_toolbar_options' do
+ subject(:result) { helper.visual_review_toolbar_options }
+
+ before do
+ stub_env('REVIEW_APPS_MERGE_REQUEST_IID', '123')
+ end
+
+ it 'returns the correct params' do
+ expect(result).to eq(
+ 'data-merge-request-id': '123',
+ 'data-mr-url': 'https://gitlab.com',
+ 'data-project-id': '278964',
+ 'data-project-path': 'gitlab-org/gitlab',
+ 'data-require-auth': false,
+ 'id': 'review-app-toolbar-script',
+ 'src': 'https://gitlab.com/assets/webpack/visual_review_toolbar.js'
+ )
+ end
+ end
+end