diff options
Diffstat (limited to 'spec/helpers')
27 files changed, 246 insertions, 236 deletions
diff --git a/spec/helpers/admin/background_migrations_helper_spec.rb b/spec/helpers/admin/background_migrations_helper_spec.rb index 8880a00755b..9c1bb0b9c55 100644 --- a/spec/helpers/admin/background_migrations_helper_spec.rb +++ b/spec/helpers/admin/background_migrations_helper_spec.rb @@ -3,22 +3,22 @@ require "spec_helper" RSpec.describe Admin::BackgroundMigrationsHelper do - describe '#batched_migration_status_badge_class_name' do + describe '#batched_migration_status_badge_variant' do using RSpec::Parameterized::TableSyntax - where(:status, :class_name) do - :active | 'badge-info' - :paused | 'badge-warning' - :failed | 'badge-danger' - :finished | 'badge-success' + where(:status, :variant) do + :active | :info + :paused | :warning + :failed | :danger + :finished | :success end - subject { helper.batched_migration_status_badge_class_name(migration) } + subject { helper.batched_migration_status_badge_variant(migration) } with_them do let(:migration) { build(:batched_background_migration, status: status) } - it { is_expected.to eq(class_name) } + it { is_expected.to eq(variant) } end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 7390b9b3f58..8c2b4b16075 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -477,4 +477,44 @@ RSpec.describe ApplicationHelper do expect(helper).to have_received(:form_for).with(user, expected_options) end end + + describe '#page_class' do + context 'when logged_out_marketing_header experiment is enabled' do + let_it_be(:expected_class) { 'logged-out-marketing-header-candidate' } + + let(:current_user) { nil } + let(:variant) { :candidate } + + subject do + helper.page_class.flatten + end + + before do + stub_experiments(logged_out_marketing_header: variant) + allow(helper).to receive(:current_user) { current_user } + end + + context 'when candidate' do + it { is_expected.to include(expected_class) } + end + + context 'when candidate (:trial_focused variant)' do + let(:variant) { :trial_focused } + + it { is_expected.to include(expected_class) } + end + + context 'when control' do + let(:variant) { :control } + + it { is_expected.not_to include(expected_class) } + end + + context 'when a user is logged in' do + let(:current_user) { create(:user) } + + it { is_expected.not_to include(expected_class) } + end + end + end end diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 3c2ac954fe5..e722f301522 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -253,6 +253,32 @@ RSpec.describe ApplicationSettingsHelper do end end + describe '.registration_features_can_be_prompted?' do + subject { helper.registration_features_can_be_prompted? } + + before do + if Gitlab.ee? + allow(License).to receive(:current).and_return(nil) + end + end + + context 'when service ping is enabled' do + before do + stub_application_setting(usage_ping_enabled: true) + end + + it { is_expected.to be_falsey } + end + + context 'when service ping is disabled' do + before do + stub_application_setting(usage_ping_enabled: false) + end + + it { is_expected.to be_truthy } + end + end + describe '#sidekiq_job_limiter_modes_for_select' do subject { helper.sidekiq_job_limiter_modes_for_select } diff --git a/spec/helpers/auth_helper_spec.rb b/spec/helpers/auth_helper_spec.rb index b481c214ca1..4bb09699db4 100644 --- a/spec/helpers/auth_helper_spec.rb +++ b/spec/helpers/auth_helper_spec.rb @@ -312,12 +312,6 @@ RSpec.describe AuthHelper do it { is_expected.to be_truthy } end - context 'when current user is set' do - let(:user) { instance_double('User') } - - it { is_expected.to eq(false) } - end - context 'when no key is set' do before do stub_config(extra: {}) diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index 4f060a0ae3b..1083faa5e19 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -86,7 +86,7 @@ RSpec.describe AutoDevopsHelper do context 'when another service is enabled' do before do - create(:service, project: project, category: :ci, active: true) + create(:integration, project: project, category: :ci, active: true) end it { is_expected.to eq(false) } diff --git a/spec/helpers/button_helper_spec.rb b/spec/helpers/button_helper_spec.rb index 5601ab2df2a..851e13d908f 100644 --- a/spec/helpers/button_helper_spec.rb +++ b/spec/helpers/button_helper_spec.rb @@ -167,6 +167,7 @@ RSpec.describe ButtonHelper do expect(element.attr('class')).to eq('btn btn-clipboard btn-transparent') expect(element.attr('type')).to eq('button') expect(element.attr('aria-label')).to eq('Copy') + expect(element.attr('aria-live')).to eq('polite') expect(element.attr('data-toggle')).to eq('tooltip') expect(element.attr('data-placement')).to eq('bottom') expect(element.attr('data-container')).to eq('body') diff --git a/spec/helpers/ci/jobs_helper_spec.rb b/spec/helpers/ci/jobs_helper_spec.rb index e5ef362e91b..489d9d3fcee 100644 --- a/spec/helpers/ci/jobs_helper_spec.rb +++ b/spec/helpers/ci/jobs_helper_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' RSpec.describe Ci::JobsHelper do describe 'jobs data' do let(:project) { create(:project, :repository) } - let(:bridge) { create(:ci_bridge, status: :pending) } + let(:bridge) { create(:ci_bridge) } - subject(:bridge_data) { helper.bridge_data(bridge) } + subject(:bridge_data) { helper.bridge_data(bridge, project) } before do allow(helper) @@ -17,8 +17,10 @@ RSpec.describe Ci::JobsHelper do it 'returns bridge data' do expect(bridge_data).to eq({ - "build_name" => bridge.name, - "empty-state-illustration-path" => '/path/to/illustration' + "build_id" => bridge.id, + "empty-state-illustration-path" => '/path/to/illustration', + "pipeline_iid" => bridge.pipeline.iid, + "project_full_path" => project.full_path }) end end diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb index 874937bc4ce..b15569f03c7 100644 --- a/spec/helpers/ci/pipeline_editor_helper_spec.rb +++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb @@ -46,6 +46,7 @@ RSpec.describe Ci::PipelineEditorHelper do "empty-state-illustration-path" => 'foo', "initial-branch-name" => nil, "lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'), + "lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available'), "needs-help-page-path" => help_page_path('ci/yaml/index', anchor: 'needs'), "new-merge-request-path" => '/mock/project/-/merge_requests/new', "pipeline_etag" => graphql_etag_pipeline_sha_path(project.commit.sha), @@ -72,6 +73,7 @@ RSpec.describe Ci::PipelineEditorHelper do "empty-state-illustration-path" => 'foo', "initial-branch-name" => nil, "lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'), + "lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available'), "needs-help-page-path" => help_page_path('ci/yaml/index', anchor: 'needs'), "new-merge-request-path" => '/mock/project/-/merge_requests/new', "pipeline_etag" => '', diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 173a0d3ab3c..832b4da0e20 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Ci::RunnersHelper do describe '#runner_status_icon', :clean_gitlab_redis_cache do it "returns - not contacted yet" do runner = create(:ci_runner) - expect(helper.runner_status_icon(runner)).to include("not connected yet") + expect(helper.runner_status_icon(runner)).to include("not contacted yet") end it "returns offline text" do @@ -79,12 +79,7 @@ RSpec.describe Ci::RunnersHelper do it 'returns the data in format' do expect(helper.admin_runners_data_attributes).to eq({ runner_install_help_page: 'https://docs.gitlab.com/runner/install/', - registration_token: Gitlab::CurrentSettings.runners_registration_token, - active_runners_count: '0', - all_runners_count: '2', - instance_runners_count: '1', - group_runners_count: '0', - project_runners_count: '1' + registration_token: Gitlab::CurrentSettings.runners_registration_token }) end end diff --git a/spec/helpers/environment_helper_spec.rb b/spec/helpers/environment_helper_spec.rb index 49937a3b53a..8e5f38cd95a 100644 --- a/spec/helpers/environment_helper_spec.rb +++ b/spec/helpers/environment_helper_spec.rb @@ -21,6 +21,16 @@ RSpec.describe EnvironmentHelper do expect(html).to have_css('a.ci-status.ci-success') end end + + context 'for a blocked deployment' do + subject { helper.render_deployment_status(deployment) } + + let(:deployment) { build(:deployment, :blocked) } + + it 'indicates the status' do + expect(subject).to have_text('blocked') + end + end end describe '#environments_detail_data_json' do diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb index aef240db5b8..38f06b19b94 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_service_path(project, 'prometheus'), + 'settings_path' => edit_project_integration_path(project, 'prometheus'), 'clusters_path' => project_clusters_path(project), 'metrics_dashboard_base_path' => environment_metrics_path(environment), 'current_environment_name' => environment.name, diff --git a/spec/helpers/groups/crm_settings_helper_spec.rb b/spec/helpers/groups/crm_settings_helper_spec.rb new file mode 100644 index 00000000000..6376cabda3a --- /dev/null +++ b/spec/helpers/groups/crm_settings_helper_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::CrmSettingsHelper do + let_it_be(:group) { create(:group) } + + describe '#crm_feature_flag_enabled?' do + subject do + helper.crm_feature_flag_enabled?(group) + end + + 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 diff --git a/spec/helpers/hooks_helper_spec.rb b/spec/helpers/hooks_helper_spec.rb index 3b23d705790..bac73db5dd4 100644 --- a/spec/helpers/hooks_helper_spec.rb +++ b/spec/helpers/hooks_helper_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe HooksHelper do let(:project) { create(:project) } let(:project_hook) { create(:project_hook, project: project) } + let(:service_hook) { create(:service_hook, integration: create(:drone_ci_integration)) } let(:system_hook) { create(:system_hook) } describe '#link_to_test_hook' do @@ -31,6 +32,15 @@ RSpec.describe HooksHelper do end end + context 'with a service hook' do + let(:web_hook_log) { create(:web_hook_log, web_hook: service_hook) } + + it 'returns project-namespaced link' do + expect(helper.hook_log_path(project_hook, web_hook_log)) + .to eq(web_hook_log.present.details_path) + end + end + context 'with a system hook' do let(:web_hook_log) { create(:web_hook_log, web_hook: system_hook) } diff --git a/spec/helpers/integrations_helper_spec.rb b/spec/helpers/integrations_helper_spec.rb index 3a7d4d12513..38ce17e34ba 100644 --- a/spec/helpers/integrations_helper_spec.rb +++ b/spec/helpers/integrations_helper_spec.rb @@ -20,6 +20,12 @@ RSpec.describe IntegrationsHelper do end describe '#integration_form_data' do + before do + allow(helper).to receive_messages( + request: double(referer: '/services') + ) + end + let(:fields) do [ :id, @@ -39,7 +45,9 @@ RSpec.describe IntegrationsHelper do :cancel_path, :can_test, :test_path, - :reset_path + :reset_path, + :form_path, + :redirect_to ] end @@ -61,6 +69,10 @@ RSpec.describe IntegrationsHelper do specify do expect(subject[:reset_path]).to eq(helper.scoped_reset_integration_path(integration)) end + + specify do + expect(subject[:redirect_to]).to eq('/services') + end end context 'Jira service' do @@ -70,6 +82,20 @@ RSpec.describe IntegrationsHelper do end end + describe '#integration_overrides_data' do + let(:integration) { build_stubbed(:jira_integration) } + let(:fields) do + [ + edit_path: edit_admin_application_settings_integration_path(integration), + overrides_path: overrides_admin_application_settings_integration_path(integration, format: :json) + ] + end + + subject { helper.integration_overrides_data(integration) } + + it { is_expected.to include(*fields) } + end + describe '#scoped_reset_integration_path' do let(:integration) { build_stubbed(:jira_integration) } let(:group) { nil } diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index ad0ea6911f1..065ac526ae4 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -9,7 +9,7 @@ RSpec.describe IssuesHelper do describe '#work_item_type_icon' do it 'returns icon of all standard base types' do - WorkItem::Type.base_types.each do |type| + WorkItems::Type.base_types.each do |type| expect(work_item_type_icon(type[0])).to eq "issue-type-#{type[0].to_s.dasherize}" end end @@ -246,27 +246,6 @@ RSpec.describe IssuesHelper do end end - describe '#use_startup_call' do - it 'returns false when a query param is present' do - allow(controller.request).to receive(:query_parameters).and_return({ foo: 'bar' }) - - expect(helper.use_startup_call?).to eq(false) - end - - it 'returns false when user has stored sort preference' do - controller.instance_variable_set(:@sort, 'updated_asc') - - expect(helper.use_startup_call?).to eq(false) - end - - it 'returns true when request.query_parameters is empty with default sorting preference' do - controller.instance_variable_set(:@sort, 'created_date') - allow(controller.request).to receive(:query_parameters).and_return({}) - - expect(helper.use_startup_call?).to eq(true) - end - end - describe '#issue_header_actions_data' do let(:current_user) { create(:user) } diff --git a/spec/helpers/learn_gitlab_helper_spec.rb b/spec/helpers/learn_gitlab_helper_spec.rb index 9d13fc65de7..ffc2bb31b8f 100644 --- a/spec/helpers/learn_gitlab_helper_spec.rb +++ b/spec/helpers/learn_gitlab_helper_spec.rb @@ -176,6 +176,19 @@ RSpec.describe LearnGitlabHelper do ) }) end + + it 'calls experiment with expected context & options' do + allow(helper).to receive(:current_user).and_return(user) + + expect(helper).to receive(:experiment).with( + :change_continuous_onboarding_link_urls, + namespace: namespace, + actor: user, + sticky_to: namespace + ) + + learn_gitlab_data + end end end end diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 6eb560e3f5c..00aa0fd1cba 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -188,44 +188,6 @@ RSpec.describe NamespacesHelper do helper.namespaces_options end end - - describe 'include_groups_with_developer_maintainer_access parameter' do - context 'when DEVELOPER_MAINTAINER_PROJECT_ACCESS is set for a project' do - let!(:admin_project_creation_level) { ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS } - - it 'returns groups where user is a developer' do - allow(helper).to receive(:current_user).and_return(user) - stub_application_setting(default_project_creation: ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS) - admin_group.add_user(user, GroupMember::DEVELOPER) - - options = helper.namespaces_options_with_developer_maintainer_access - - expect(options).to include(admin_group.name) - expect(options).not_to include(subgroup1.name) - expect(options).to include(subgroup2.name) - expect(options).not_to include(subgroup3.name) - expect(options).to include(user_group.name) - expect(options).to include(user.name) - end - end - - context 'when DEVELOPER_MAINTAINER_PROJECT_ACCESS is set globally' do - it 'return groups where default is not overridden' do - allow(helper).to receive(:current_user).and_return(user) - stub_application_setting(default_project_creation: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS) - admin_group.add_user(user, GroupMember::DEVELOPER) - - options = helper.namespaces_options_with_developer_maintainer_access - - expect(options).to include(admin_group.name) - expect(options).to include(subgroup1.name) - expect(options).to include(subgroup2.name) - expect(options).not_to include(subgroup3.name) - expect(options).to include(user_group.name) - expect(options).to include(user.name) - end - end - end end describe '#cascading_namespace_settings_popover_data' do diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb index 10bd45e3189..ef6a6827826 100644 --- a/spec/helpers/nav/top_nav_helper_spec.rb +++ b/spec/helpers/nav/top_nav_helper_spec.rb @@ -20,7 +20,6 @@ RSpec.describe Nav::TopNavHelper do let(:current_group) { nil } let(:with_current_settings_admin_mode) { false } let(:with_header_link_admin_mode) { false } - let(:with_sherlock_enabled) { false } let(:with_projects) { false } let(:with_groups) { false } let(:with_milestones) { false } @@ -34,7 +33,6 @@ RSpec.describe Nav::TopNavHelper do before do allow(Gitlab::CurrentSettings).to receive(:admin_mode) { with_current_settings_admin_mode } allow(helper).to receive(:header_link?).with(:admin_mode) { with_header_link_admin_mode } - allow(Gitlab::Sherlock).to receive(:enabled?) { with_sherlock_enabled } # Defaulting all `dashboard_nav_link?` calls to false ensures the EE-specific behavior # is not enabled in this CE spec @@ -434,27 +432,6 @@ RSpec.describe Nav::TopNavHelper do expect(subject[:shortcuts]).to eq([expected_shortcuts]) end end - - context 'when sherlock is enabled' do - let(:with_sherlock_enabled) { true } - - before do - # Note: We have to mock the sherlock route because the route is conditional on - # sherlock being enabled, but it parsed at Rails load time and can't be overridden - # in a spec. - allow(helper).to receive(:sherlock_transactions_path) { '/fake_sherlock_path' } - end - - it 'has sherlock as last :secondary item' do - expected_sherlock_item = ::Gitlab::Nav::TopNavMenuItem.build( - id: 'sherlock', - title: 'Sherlock Transactions', - icon: 'admin', - href: '/fake_sherlock_path' - ) - expect(subject[:secondary].last).to eq(expected_sherlock_item) - end - end end context 'when current_user is admin' do diff --git a/spec/helpers/operations_helper_spec.rb b/spec/helpers/operations_helper_spec.rb index 1864f9fad15..857771ebba6 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_service_path(project, prometheus_integration), + 'prometheus_form_path' => project_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/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb index 06c6cccd488..8b3c8411fbd 100644 --- a/spec/helpers/packages_helper_spec.rb +++ b/spec/helpers/packages_helper_spec.rb @@ -219,45 +219,4 @@ RSpec.describe PackagesHelper do it { is_expected.to eq(expected_result) } end end - - describe '#package_details_data' do - let_it_be(:package) { create(:package) } - - let(:expected_result) do - { - package_id: package.id, - can_delete: 'true', - project_name: project.name, - group_list_url: '' - } - end - - before do - allow(helper).to receive(:current_user) { project.owner } - allow(helper).to receive(:can?) { true } - end - - context 'in a project without a group' do - it 'populates presenter data' do - result = helper.package_details_data(project, package) - - expect(result).to match(hash_including(expected_result)) - end - end - - context 'in a project with a group' do - let_it_be(:group) { create(:group) } - let_it_be(:project_with_group) { create(:project, group: group) } - - it 'populates presenter data' do - result = helper.package_details_data(project_with_group, package) - expected = expected_result.merge({ - group_list_url: group_packages_path(project_with_group.group), - project_name: project_with_group.name - }) - - expect(result).to match(hash_including(expected)) - end - end - end end diff --git a/spec/helpers/projects/cluster_agents_helper_spec.rb b/spec/helpers/projects/cluster_agents_helper_spec.rb index 2935a74586b..632544797ee 100644 --- a/spec/helpers/projects/cluster_agents_helper_spec.rb +++ b/spec/helpers/projects/cluster_agents_helper_spec.rb @@ -17,5 +17,10 @@ RSpec.describe Projects::ClusterAgentsHelper do it 'returns project path' do expect(subject[:project_path]).to eq(project.full_path) end + + it 'returns string contants' do + expect(subject[:activity_empty_state_image]).to be_kind_of(String) + expect(subject[:empty_state_svg_path]).to be_kind_of(String) + end end end diff --git a/spec/helpers/projects/issues/service_desk_helper_spec.rb b/spec/helpers/projects/issues/service_desk_helper_spec.rb deleted file mode 100644 index 05766ee13c6..00000000000 --- a/spec/helpers/projects/issues/service_desk_helper_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Projects::Issues::ServiceDeskHelper do - let_it_be(:project) { create(:project, :public, service_desk_enabled: true) } - - let(:user) { build_stubbed(:user) } - let(:current_user) { user } - - describe '#service_desk_meta' do - subject { helper.service_desk_meta(project) } - - context "when service desk is supported and user can edit project settings" do - before do - allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true) - allow(Gitlab::IncomingEmail).to receive(:supports_wildcard?).and_return(true) - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:can?).with(current_user, :admin_project, project).and_return(true) - end - - it { - is_expected.to eq({ - is_service_desk_supported: true, - is_service_desk_enabled: true, - can_edit_project_settings: true, - service_desk_address: project.service_desk_address, - service_desk_help_page: help_page_path('user/project/service_desk'), - edit_project_page: edit_project_path(project), - svg_path: ActionController::Base.helpers.image_path('illustrations/service_desk_empty.svg') - }) - } - end - - context "when service desk is not supported and user cannot edit project settings" do - before do - allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(false) - allow(Gitlab::IncomingEmail).to receive(:supports_wildcard?).and_return(false) - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:can?).with(current_user, :admin_project, project).and_return(false) - end - - it { - is_expected.to eq({ - is_service_desk_supported: false, - is_service_desk_enabled: false, - can_edit_project_settings: false, - incoming_email_help_page: help_page_path('administration/incoming_email', anchor: 'set-it-up'), - svg_path: ActionController::Base.helpers.image_path('illustrations/service-desk-setup.svg') - }) - } - end - end -end diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 17dcbab09bb..40cfdafc9ac 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe SearchHelper do include MarkupHelper + include BadgesHelper # Override simple_sanitize for our testing purposes def simple_sanitize(str) @@ -640,7 +641,7 @@ RSpec.describe SearchHelper do } }, { - title: _('Last updated'), + title: _('Updated date'), sortable: true, sortParam: { asc: 'updated_asc', diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb index 12d791d8710..913be164a00 100644 --- a/spec/helpers/snippets_helper_spec.rb +++ b/spec/helpers/snippets_helper_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe SnippetsHelper do include Gitlab::Routing include IconsHelper + include BadgesHelper let_it_be(:public_personal_snippet) { create(:personal_snippet, :public, :repository) } let_it_be(:public_project_snippet) { create(:project_snippet, :public, :repository) } @@ -72,7 +73,7 @@ RSpec.describe SnippetsHelper do let(:visibility) { :private } it 'returns the snippet badge' do - expect(subject).to eq "<span class=\"badge badge-gray\">#{sprite_icon('lock', size: 14, css_class: 'gl-vertical-align-middle')} private</span>" + expect(subject).to eq gl_badge_tag('private', icon: 'lock') end end diff --git a/spec/helpers/ssh_keys_helper_spec.rb b/spec/helpers/ssh_keys_helper_spec.rb new file mode 100644 index 00000000000..1aa604f19be --- /dev/null +++ b/spec/helpers/ssh_keys_helper_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe SshKeysHelper do + describe '#ssh_key_allowed_algorithms' do + it 'returns string with the names of allowed algorithms that are quoted and joined by commas' do + allowed_algorithms = Gitlab::CurrentSettings.allowed_key_types.flat_map do |ssh_key_type_name| + Gitlab::SSHPublicKey.supported_algorithms_for_name(ssh_key_type_name) + end + + quoted_allowed_algorithms = allowed_algorithms.map { |name| "'#{name}'" } + + expected_string = Gitlab::Utils.to_exclusive_sentence(quoted_allowed_algorithms) + + expect(ssh_key_allowed_algorithms).to eq(expected_string) + end + + it 'returns only allowed algorithms' do + expect(ssh_key_allowed_algorithms).to match('ed25519') + stub_application_setting(ed25519_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE) + expect(ssh_key_allowed_algorithms).not_to match('ed25519') + end + end +end diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb index bc25a2fcdfc..1a0ecd5d903 100644 --- a/spec/helpers/tree_helper_spec.rb +++ b/spec/helpers/tree_helper_spec.rb @@ -84,14 +84,21 @@ RSpec.describe TreeHelper do describe '#web_ide_button_data' do let(:blob) { project.repository.blob_at('refs/heads/master', @path) } + let_it_be(:user_preferences_gitpod_path) { '/-/profile/preferences#user_gitpod_enabled' } + let_it_be(:user_profile_enable_gitpod_path) { '/-/profile?user%5Bgitpod_enabled%5D=true' } + before do @path = '' @project = project @ref = sha - allow(helper).to receive(:current_user).and_return(nil) - allow(helper).to receive(:can_collaborate_with_project?).and_return(true) - allow(helper).to receive(:can?).and_return(true) + allow(helper).to receive_messages( + current_user: nil, + can_collaborate_with_project?: true, + can?: true, + user_preferences_gitpod_path: user_preferences_gitpod_path, + user_profile_enable_gitpod_path: user_profile_enable_gitpod_path + ) end subject { helper.web_ide_button_data(blob: blob) } @@ -112,7 +119,10 @@ RSpec.describe TreeHelper do edit_url: '', web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}", - gitpod_url: '' + + gitpod_url: '', + user_preferences_gitpod_path: user_preferences_gitpod_path, + user_profile_enable_gitpod_path: user_profile_enable_gitpod_path ) end diff --git a/spec/helpers/version_check_helper_spec.rb b/spec/helpers/version_check_helper_spec.rb index bd52eda8a65..959c4a94a78 100644 --- a/spec/helpers/version_check_helper_spec.rb +++ b/spec/helpers/version_check_helper_spec.rb @@ -3,33 +3,34 @@ require 'spec_helper' RSpec.describe VersionCheckHelper do - describe '#version_status_badge' do - it 'returns nil if not dev environment and not enabled' do - stub_rails_env('development') - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { false } + let_it_be(:user) { create(:user) } - expect(helper.version_status_badge).to be(nil) - end - - context 'when production and enabled' do - before do - stub_rails_env('production') - allow(Gitlab::CurrentSettings.current_application_settings).to receive(:version_check_enabled) { true } - allow(VersionCheck).to receive(:image_url) { 'https://version.host.com/check.svg?gitlab_info=xxx' } + describe '#show_version_check?' do + describe 'return conditions' do + where(:enabled, :consent, :is_admin, :result) do + [ + [false, false, false, false], + [false, false, true, false], + [false, true, false, false], + [false, true, true, false], + [true, false, false, false], + [true, false, true, true], + [true, true, false, false], + [true, true, true, false] + ] end - it 'returns an image tag' do - expect(helper.version_status_badge).to start_with('<img') - end - - it 'has a js prefixed css class' do - expect(helper.version_status_badge) - .to match(/class="js-version-status-badge lazy"/) - end + with_them do + before do + stub_application_setting(version_check_enabled: enabled) + allow(User).to receive(:single_user).and_return(double(user, requires_usage_stats_consent?: consent)) + allow(helper).to receive(:current_user).and_return(user) + allow(user).to receive(:can_read_all_resources?).and_return(is_admin) + end - it 'has a VersionCheck image_url as the src' do - expect(helper.version_status_badge) - .to include(%{src="https://version.host.com/check.svg?gitlab_info=xxx"}) + it 'returns correct results' do + expect(helper.show_version_check?).to eq result + end end end end |