From 41fe97390ceddf945f3d967b8fdb3de4c66b7dea Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 18 Mar 2022 20:02:30 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-9-stable-ee --- spec/helpers/application_helper_spec.rb | 108 ++++++++++++++ spec/helpers/application_settings_helper_spec.rb | 23 ++- spec/helpers/blob_helper_spec.rb | 93 ------------ spec/helpers/broadcast_messages_helper_spec.rb | 85 ++++++++++- spec/helpers/ci/pipelines_helper_spec.rb | 59 ++++++++ spec/helpers/clusters_helper_spec.rb | 137 ++++++++++------- spec/helpers/commits_helper_spec.rb | 25 ++++ .../container_expiration_policies_helper_spec.rb | 23 ++- spec/helpers/container_registry_helper_spec.rb | 16 +- spec/helpers/deploy_tokens_helper_spec.rb | 20 +++ spec/helpers/explore_helper_spec.rb | 29 ++++ spec/helpers/groups/crm_settings_helper_spec.rb | 40 +++-- spec/helpers/icons_helper_spec.rb | 32 ++-- spec/helpers/integrations_helper_spec.rb | 27 +++- spec/helpers/invite_members_helper_spec.rb | 11 -- spec/helpers/issues_helper_spec.rb | 8 +- spec/helpers/jira_connect_helper_spec.rb | 46 ++++++ spec/helpers/labels_helper_spec.rb | 8 +- spec/helpers/learn_gitlab_helper_spec.rb | 79 ++-------- spec/helpers/listbox_helper_spec.rb | 9 +- spec/helpers/markup_helper_spec.rb | 32 ++-- spec/helpers/merge_requests_helper_spec.rb | 33 ++++- spec/helpers/nav/top_nav_helper_spec.rb | 2 - spec/helpers/notify_helper_spec.rb | 1 - spec/helpers/packages_helper_spec.rb | 165 +++++---------------- spec/helpers/preferences_helper_spec.rb | 24 +++ .../helpers/projects/cluster_agents_helper_spec.rb | 17 ++- .../helpers/projects/error_tracking_helper_spec.rb | 53 +++++-- spec/helpers/projects_helper_spec.rb | 22 ++- .../routing/pseudonymization_helper_spec.rb | 26 +++- spec/helpers/sessions_helper_spec.rb | 4 +- spec/helpers/sorting_helper_spec.rb | 12 ++ spec/helpers/storage_helper_spec.rb | 43 ++++-- spec/helpers/tree_helper_spec.rb | 2 + spec/helpers/users/callouts_helper_spec.rb | 19 ++- spec/helpers/web_ide_button_helper_spec.rb | 45 ++++++ spec/helpers/whats_new_helper_spec.rb | 6 +- 37 files changed, 892 insertions(+), 492 deletions(-) create mode 100644 spec/helpers/deploy_tokens_helper_spec.rb create mode 100644 spec/helpers/web_ide_button_helper_spec.rb (limited to 'spec/helpers') diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index e6a2e3f8211..47c31546629 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -517,4 +517,112 @@ RSpec.describe ApplicationHelper do end end end + + describe '#dispensable_render' do + context 'when an error occurs in the template to be rendered' do + before do + allow(helper).to receive(:render).and_raise + end + + it 'calls `track_and_raise_for_dev_exception`' do + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) + helper.dispensable_render + end + + context 'for development environment' do + before do + stub_rails_env('development') + end + + it 'raises an error' do + expect { helper.dispensable_render }.to raise_error(StandardError) + end + end + + context 'for production environments' do + before do + stub_rails_env('production') + end + + it 'returns nil' do + expect(helper.dispensable_render).to be_nil + end + + context 'when the feature flag is disabled' do + before do + stub_feature_flags(dispensable_render: false) + end + + it 'raises an error' do + expect { helper.dispensable_render }.to raise_error(StandardError) + end + end + end + end + + context 'when no error occurs in the template to be rendered' do + before do + allow(helper).to receive(:render).and_return('foo') + end + + it 'does not track or raise and returns the rendered content' do + expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception) + expect(helper.dispensable_render).to eq('foo') + end + end + end + + describe '#dispensable_render_if_exists' do + context 'when an error occurs in the template to be rendered' do + before do + allow(helper).to receive(:render_if_exists).and_raise + end + + it 'calls `track_and_raise_for_dev_exception`' do + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) + helper.dispensable_render_if_exists + end + + context 'for development environment' do + before do + stub_rails_env('development') + end + + it 'raises an error' do + expect { helper.dispensable_render_if_exists }.to raise_error(StandardError) + end + end + + context 'for production environments' do + before do + stub_rails_env('production') + end + + it 'returns nil' do + expect(helper.dispensable_render_if_exists).to be_nil + end + + context 'when the feature flag is disabled' do + before do + stub_feature_flags(dispensable_render: false) + end + + it 'raises an error' do + expect { helper.dispensable_render_if_exists }.to raise_error(StandardError) + end + end + end + end + + context 'when no error occurs in the template to be rendered' do + before do + allow(helper).to receive(:render_if_exists).and_return('foo') + end + + it 'does not track or raise' do + expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception) + expect(helper.dispensable_render_if_exists).to eq('foo') + end + end + end end diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 169b1c75995..26d48bef24e 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -51,7 +51,7 @@ RSpec.describe ApplicationSettingsHelper do issues_create_limit notes_create_limit project_export_limit project_download_export_limit project_export_limit project_import_limit raw_blob_request_limit group_export_limit group_download_export_limit - group_import_limit users_get_by_id_limit user_email_lookup_limit + group_import_limit users_get_by_id_limit search_rate_limit search_rate_limit_unauthenticated )) end @@ -293,4 +293,25 @@ RSpec.describe ApplicationSettingsHelper do it { is_expected.to eq([%w(Track track), %w(Compress compress)]) } end + + describe '#instance_clusters_enabled?' do + let_it_be(:user) { create(:user) } + + subject { helper.instance_clusters_enabled? } + + before do + allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive(:can?).with(user, :read_cluster, instance_of(Clusters::Instance)).and_return(true) + end + + it { is_expected.to be_truthy} + + context ':certificate_based_clusters feature flag is disabled' do + before do + stub_feature_flags(certificate_based_clusters: false) + end + + it { is_expected.to be_falsey } + end + end end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index efcb8125f68..65e46b61882 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -54,42 +54,6 @@ RSpec.describe BlobHelper do expect(Capybara.string(link_with_mr).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md?mr_id=10") end - - context 'when edit is the primary button' do - before do - stub_feature_flags(web_ide_primary_edit: false) - end - - it 'is rendered as primary' do - expect(link).not_to match(/btn-inverted/) - end - - it 'passes on primary tracking attributes' do - parsed_link = Capybara.string(link).find_link('Edit') - - expect(parsed_link[:'data-track-action']).to eq("click_edit") - expect(parsed_link[:'data-track-label']).to eq("edit") - expect(parsed_link[:'data-track-property']).to eq(nil) - end - end - - context 'when Web IDE is the primary button' do - before do - stub_feature_flags(web_ide_primary_edit: true) - end - - it 'is rendered as inverted' do - expect(link).to match(/btn-inverted/) - end - - it 'passes on secondary tracking attributes' do - parsed_link = Capybara.string(link).find_link('Edit') - - expect(parsed_link[:'data-track-action']).to eq("click_edit") - expect(parsed_link[:'data-track-label']).to eq("edit") - expect(parsed_link[:'data-track-property']).to eq("secondary") - end - end end describe "#relative_raw_path" do @@ -324,63 +288,6 @@ RSpec.describe BlobHelper do end end - describe `#ide_edit_button` do - let_it_be(:namespace) { create(:namespace, name: 'gitlab') } - let_it_be(:project) { create(:project, :repository, namespace: namespace) } - let_it_be(:current_user) { create(:user) } - - let(:can_push_code) { true } - let(:blob) { project.repository.blob_at('refs/heads/master', 'README.md') } - - subject(:link) { helper.ide_edit_button(project, 'master', 'README.md', blob: blob) } - - before do - allow(helper).to receive(:current_user).and_return(current_user) - allow(helper).to receive(:can?).with(current_user, :push_code, project).and_return(can_push_code) - allow(helper).to receive(:can_collaborate_with_project?).and_return(true) - end - - it 'returns a link with a Web IDE route' do - expect(Capybara.string(link).find_link('Web IDE')[:href]).to eq("/-/ide/project/#{project.full_path}/edit/master/-/README.md") - end - - context 'when edit is the primary button' do - before do - stub_feature_flags(web_ide_primary_edit: false) - end - - it 'is rendered as inverted' do - expect(link).to match(/btn-inverted/) - end - - it 'passes on secondary tracking attributes' do - parsed_link = Capybara.string(link).find_link('Web IDE') - - expect(parsed_link[:'data-track-action']).to eq("click_edit_ide") - expect(parsed_link[:'data-track-label']).to eq("web_ide") - expect(parsed_link[:'data-track-property']).to eq("secondary") - end - end - - context 'when Web IDE is the primary button' do - before do - stub_feature_flags(web_ide_primary_edit: true) - end - - it 'is rendered as primary' do - expect(link).not_to match(/btn-inverted/) - end - - it 'passes on primary tracking attributes' do - parsed_link = Capybara.string(link).find_link('Web IDE') - - expect(parsed_link[:'data-track-action']).to eq("click_edit_ide") - expect(parsed_link[:'data-track-label']).to eq("web_ide") - expect(parsed_link[:'data-track-property']).to eq(nil) - end - end - end - describe '#ide_edit_path' do let(:project) { create(:project) } let(:current_user) { create(:user) } diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb index 3e8cbdf89a0..e721a3fdc95 100644 --- a/spec/helpers/broadcast_messages_helper_spec.rb +++ b/spec/helpers/broadcast_messages_helper_spec.rb @@ -3,6 +3,71 @@ require 'spec_helper' RSpec.describe BroadcastMessagesHelper do + include Gitlab::Routing.url_helpers + + let_it_be(:user) { create(:user) } + + before do + allow(helper).to receive(:current_user).and_return(user) + end + + shared_examples 'returns role-targeted broadcast message when in project, group, or sub-group URL' do + let(:feature_flag_state) { true } + + before do + stub_feature_flags(role_targeted_broadcast_messages: feature_flag_state) + allow(helper).to receive(:cookies) { {} } + end + + context 'when in a project page' do + let_it_be(:project) { create(:project) } + + before do + project.add_developer(user) + + assign(:project, project) + allow(helper).to receive(:controller) { ProjectsController.new } + end + + it { is_expected.to eq message } + + context 'when feature flag is disabled' do + let(:feature_flag_state) { false } + + it { is_expected.to be_nil } + end + end + + context 'when in a group page' do + let_it_be(:group) { create(:group) } + + before do + group.add_developer(user) + + assign(:group, group) + allow(helper).to receive(:controller) { GroupsController.new } + end + + it { is_expected.to eq message } + + context 'when feature flag is disabled' do + let(:feature_flag_state) { false } + + it { is_expected.to be_nil } + end + end + + context 'when not in a project, group, or sub-group page' do + it { is_expected.to be_nil } + + context 'when feature flag is disabled' do + let(:feature_flag_state) { false } + + it { is_expected.to be_nil } + end + end + end + describe 'current_broadcast_notification_message' do subject { helper.current_broadcast_notification_message } @@ -24,16 +89,26 @@ RSpec.describe BroadcastMessagesHelper do context 'without broadcast notification messages' do it { is_expected.to be_nil } end + + describe 'user access level targeted messages' do + let_it_be(:message) { create(:broadcast_message, broadcast_type: 'notification', starts_at: Time.now, target_access_levels: [Gitlab::Access::DEVELOPER]) } + + include_examples 'returns role-targeted broadcast message when in project, group, or sub-group URL' + end end - describe 'broadcast_message' do - let_it_be(:user) { create(:user) } + describe 'current_broadcast_banner_messages' do + describe 'user access level targeted messages' do + let_it_be(:message) { create(:broadcast_message, broadcast_type: 'banner', starts_at: Time.now, target_access_levels: [Gitlab::Access::DEVELOPER]) } - let(:current_broadcast_message) { BroadcastMessage.new(message: 'Current Message') } + subject { helper.current_broadcast_banner_messages.first } - before do - allow(helper).to receive(:current_user).and_return(user) + include_examples 'returns role-targeted broadcast message when in project, group, or sub-group URL' end + end + + describe 'broadcast_message' do + let(:current_broadcast_message) { BroadcastMessage.new(message: 'Current Message') } it 'returns nil when no current message' do expect(helper.broadcast_message(nil)).to be_nil diff --git a/spec/helpers/ci/pipelines_helper_spec.rb b/spec/helpers/ci/pipelines_helper_spec.rb index 751bcc97582..2b76eaa87bc 100644 --- a/spec/helpers/ci/pipelines_helper_spec.rb +++ b/spec/helpers/ci/pipelines_helper_spec.rb @@ -93,4 +93,63 @@ RSpec.describe Ci::PipelinesHelper do end end end + + describe '#pipelines_list_data' do + let_it_be(:project) { create(:project) } + + subject(:data) { helper.pipelines_list_data(project, 'list_url') } + + before do + allow(helper).to receive(:can?).and_return(true) + end + + it 'has the expected keys' do + expect(subject.keys).to match_array([:endpoint, + :project_id, + :default_branch_name, + :params, + :artifacts_endpoint, + :artifacts_endpoint_placeholder, + :pipeline_schedule_url, + :empty_state_svg_path, + :error_state_svg_path, + :no_pipelines_svg_path, + :can_create_pipeline, + :new_pipeline_path, + :ci_lint_path, + :reset_cache_path, + :has_gitlab_ci, + :pipeline_editor_path, + :suggested_ci_templates, + :ci_runner_settings_path]) + end + + describe 'the `any_runners_available` attribute' do + subject { data[:any_runners_available] } + + context 'when the `runners_availability_section` experiment variant is control' do + before do + stub_experiments(runners_availability_section: :control) + end + + it { is_expected.to be_nil } + end + + context 'when the `runners_availability_section` experiment variant is candidate' do + before do + stub_experiments(runners_availability_section: :candidate) + end + + context 'when there are no runners' do + it { is_expected.to eq('false') } + end + + context 'when there are runners' do + let!(:runner) { create(:ci_runner, :project, projects: [project]) } + + it { is_expected.to eq('true') } + end + end + end + end end diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb index 18d233fcd63..53d33f2875f 100644 --- a/spec/helpers/clusters_helper_spec.rb +++ b/spec/helpers/clusters_helper_spec.rb @@ -31,34 +31,6 @@ RSpec.describe ClustersHelper do end end - describe '#create_new_cluster_label' do - subject { helper.create_new_cluster_label(provider: provider) } - - context 'GCP provider' do - let(:provider) { 'gcp' } - - it { is_expected.to eq('Create new cluster on GKE') } - end - - context 'AWS provider' do - let(:provider) { 'aws' } - - it { is_expected.to eq('Create new cluster on EKS') } - end - - context 'other provider' do - let(:provider) { 'other' } - - it { is_expected.to eq('Create new cluster') } - end - - context 'no provider' do - let(:provider) { nil } - - it { is_expected.to eq('Create new cluster') } - end - end - describe '#js_clusters_list_data' do let_it_be(:current_user) { create(:user) } let_it_be(:project) { build(:project) } @@ -66,6 +38,11 @@ RSpec.describe ClustersHelper do subject { helper.js_clusters_list_data(clusterable) } + before do + helper.send(:default_branch_name, clusterable) + helper.send(:clusterable_project_path, clusterable) + end + it 'displays endpoint path' do expect(subject[:endpoint]).to eq("#{project_path(project)}/-/clusters.json") end @@ -86,10 +63,31 @@ RSpec.describe ClustersHelper do it 'displays empty image path' do expect(subject[:clusters_empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-clusters|svg)) + expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg)) end it 'displays create cluster using certificate path' do - expect(subject[:new_cluster_path]).to eq("#{project_path(project)}/-/clusters/new?tab=create") + expect(subject[:new_cluster_path]).to eq("#{project_path(project)}/-/clusters/new") + end + + it 'displays add cluster using certificate path' do + expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect") + end + + it 'displays project default branch' do + expect(subject[:default_branch_name]).to eq(project.default_branch) + end + + it 'displays project path' do + expect(subject[:project_path]).to eq(project.full_path) + end + + it 'displays kas address' do + expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url) + end + + it 'displays GitLab version' do + expect(subject[:gitlab_version]).to eq(Gitlab.version_info) end context 'user has no permissions to create a cluster' do @@ -114,6 +112,10 @@ RSpec.describe ClustersHelper do it 'doesn\'t display empty state help text' do expect(subject[:empty_state_help_text]).to be_nil end + + it 'displays display_cluster_agents as true' do + expect(subject[:display_cluster_agents]).to eq("true") + end end context 'group cluster' do @@ -123,38 +125,40 @@ RSpec.describe ClustersHelper do it 'displays empty state help text' do expect(subject[:empty_state_help_text]).to eq(s_('ClusterIntegration|Adding an integration to your group will share the cluster across all your projects.')) end - end - end - describe '#js_clusters_data' do - let_it_be(:current_user) { create(:user) } - let_it_be(:project) { build(:project) } - let_it_be(:clusterable) { ClusterablePresenter.fabricate(project, current_user: current_user) } + it 'displays display_cluster_agents as false' do + expect(subject[:display_cluster_agents]).to eq("false") + end - subject { helper.js_clusters_data(clusterable) } + it 'does not include a default branch' do + expect(subject[:default_branch_name]).to be_nil + end - it 'displays project default branch' do - expect(subject[:default_branch_name]).to eq(project.default_branch) + it 'does not include a project path' do + expect(subject[:project_path]).to be_nil + end end - it 'displays image path' do - expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg)) - end + describe 'certificate based clusters enabled' do + before do + stub_feature_flags(certificate_based_clusters: flag_enabled) + end - it 'displays project path' do - expect(subject[:project_path]).to eq(project.full_path) - end + context 'feature flag is enabled' do + let(:flag_enabled) { true } - it 'displays add cluster using certificate path' do - expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/new?tab=add") - end + it do + expect(subject[:certificate_based_clusters_enabled]).to eq('true') + end + end - it 'displays kas address' do - expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url) - end + context 'feature flag is disabled' do + let(:flag_enabled) { false } - it 'displays GitLab version' do - expect(subject[:gitlab_version]).to eq(Gitlab.version_info) + it do + expect(subject[:certificate_based_clusters_enabled]).to eq('false') + end + end end end @@ -220,4 +224,33 @@ RSpec.describe ClustersHelper do end end end + + describe '#default_branch_name' do + subject { default_branch_name(clusterable) } + + context 'when clusterable is a project without a repository' do + let(:clusterable) { build(:project) } + + it 'allows default branch name to display default name from settings' do + expect(subject).to eq(Gitlab::CurrentSettings.default_branch_name) + end + end + + context 'when clusterable is a project with a repository' do + let(:clusterable) { build(:project, :repository) } + let(:repository) { clusterable.repository } + + it 'allows default branch name to display repository root branch' do + expect(subject).to eq(repository.root_ref) + end + end + + context 'when clusterable is a group' do + let(:clusterable) { build(:group) } + + it 'does not allow default branch name to display' do + expect(subject).to be_nil + end + end + end end diff --git a/spec/helpers/commits_helper_spec.rb b/spec/helpers/commits_helper_spec.rb index 34445d26258..98db185c180 100644 --- a/spec/helpers/commits_helper_spec.rb +++ b/spec/helpers/commits_helper_spec.rb @@ -86,6 +86,31 @@ RSpec.describe CommitsHelper do end end + describe '#diff_mode_swap_button' do + let(:keyword) { 'rendered' } + let(:node) { Nokogiri::HTML.parse(helper.diff_mode_swap_button(keyword, 'abc')).at_css('a') } + + context 'for rendered' do + it 'renders the correct select-rendered button' do + expect(node[:title]).to eq('Display rendered diff') + expect(node['data-file-hash']).to eq('abc') + expect(node['data-diff-toggle-entity']).to eq('toShowBtn') + expect(node.xpath("//a/svg")[0]["data-testid"]).to eq('doc-text-icon') + end + end + + context 'for raw' do + let(:keyword) { 'raw' } + + it 'renders the correct select-raw button' do + expect(node[:title]).to eq('Display raw diff') + expect(node['data-file-hash']).to eq('abc') + expect(node['data-diff-toggle-entity']).to eq('toHideBtn') + expect(node.xpath("//a/svg")[0]["data-testid"]).to eq('doc-code-icon') + end + end + end + describe '#commit_to_html' do let(:project) { create(:project, :repository) } let(:ref) { 'master' } diff --git a/spec/helpers/container_expiration_policies_helper_spec.rb b/spec/helpers/container_expiration_policies_helper_spec.rb index acb6b017d2c..704e63730c8 100644 --- a/spec/helpers/container_expiration_policies_helper_spec.rb +++ b/spec/helpers/container_expiration_policies_helper_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe ContainerExpirationPoliciesHelper do - using RSpec::Parameterized::TableSyntax - describe '#keep_n_options' do it 'returns keep_n options formatted for dropdown usage' do expected_result = [ @@ -51,23 +49,22 @@ RSpec.describe ContainerExpirationPoliciesHelper do describe '#container_expiration_policies_historic_entry_enabled?' do let_it_be(:project) { build_stubbed(:project) } - subject { helper.container_expiration_policies_historic_entry_enabled?(project) } + subject { helper.container_expiration_policies_historic_entry_enabled? } + + context 'when the application setting is enabled' do + before do + stub_application_setting(container_expiration_policies_enable_historic_entries: true) + end - where(:application_setting, :feature_flag, :expected_result) do - true | true | true - true | false | true - false | true | true - false | false | false + it { is_expected.to be_truthy } end - with_them do + context 'when the application setting is disabled' do before do - stub_feature_flags(container_expiration_policies_historic_entry: false) - stub_application_setting(container_expiration_policies_enable_historic_entries: application_setting) - stub_feature_flags(container_expiration_policies_historic_entry: project) if feature_flag + stub_application_setting(container_expiration_policies_enable_historic_entries: false) end - it { is_expected.to eq(expected_result) } + it { is_expected.to be_falsey } end end end diff --git a/spec/helpers/container_registry_helper_spec.rb b/spec/helpers/container_registry_helper_spec.rb index 49e56113dd8..57641d4b5df 100644 --- a/spec/helpers/container_registry_helper_spec.rb +++ b/spec/helpers/container_registry_helper_spec.rb @@ -3,25 +3,17 @@ require 'spec_helper' RSpec.describe ContainerRegistryHelper do - using RSpec::Parameterized::TableSyntax - describe '#container_registry_expiration_policies_throttling?' do subject { helper.container_registry_expiration_policies_throttling? } - where(:feature_flag_enabled, :client_support, :expected_result) do - true | true | true - true | false | false - false | true | false - false | false | false - end + it { is_expected.to eq(true) } - with_them do + context 'with container_registry_expiration_policies_throttling disabled' do before do - stub_feature_flags(container_registry_expiration_policies_throttling: feature_flag_enabled) - allow(ContainerRegistry::Client).to receive(:supports_tag_delete?).and_return(client_support) + stub_feature_flags(container_registry_expiration_policies_throttling: false) end - it { is_expected.to eq(expected_result) } + it { is_expected.to eq(false) } end end end diff --git a/spec/helpers/deploy_tokens_helper_spec.rb b/spec/helpers/deploy_tokens_helper_spec.rb new file mode 100644 index 00000000000..e5dd5ff79a2 --- /dev/null +++ b/spec/helpers/deploy_tokens_helper_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DeployTokensHelper do + describe '#deploy_token_revoke_button_data' do + let_it_be(:token) { build(:deploy_token) } + let_it_be(:project) { build(:project) } + let_it_be(:revoke_deploy_token_path) { '/foobar/baz/-/deploy_tokens/1/revoke' } + + it 'returns expected hash' do + expect(helper).to receive(:revoke_deploy_token_path).with(project, token).and_return(revoke_deploy_token_path) + + expect(helper.deploy_token_revoke_button_data(token: token, group_or_project: project)).to match({ + token: token.to_json(only: [:id, :name]), + revoke_path: revoke_deploy_token_path + }) + end + end +end diff --git a/spec/helpers/explore_helper_spec.rb b/spec/helpers/explore_helper_spec.rb index d843a9d3ce5..4ae1b738858 100644 --- a/spec/helpers/explore_helper_spec.rb +++ b/spec/helpers/explore_helper_spec.rb @@ -25,4 +25,33 @@ RSpec.describe ExploreHelper do helper.public_visibility_restricted? end end + + describe '#projects_filter_items' do + let(:projects_filter_items) do + [ + { href: '?', text: 'Any', value: 'Any' }, + { href: '?visibility_level=0', text: 'Private', value: 'Private' }, + { href: '?visibility_level=10', text: 'Internal', value: 'Internal' }, + { href: '?visibility_level=20', text: 'Public', value: 'Public' } + ] + end + + it 'returns correct dropdown items' do + expect(helper.projects_filter_items).to eq(projects_filter_items) + end + end + + describe '#projects_filter_selected' do + context 'when visibility_level is present' do + it 'returns corresponding item' do + expect(helper.projects_filter_selected('0')).to eq('Private') + end + end + + context 'when visibility_level is empty' do + it 'returns corresponding item' do + expect(helper.projects_filter_selected(nil)).to eq('Any') + end + end + end end diff --git a/spec/helpers/groups/crm_settings_helper_spec.rb b/spec/helpers/groups/crm_settings_helper_spec.rb index 6376cabda3a..87690e7debc 100644 --- a/spec/helpers/groups/crm_settings_helper_spec.rb +++ b/spec/helpers/groups/crm_settings_helper_spec.rb @@ -3,23 +3,45 @@ require 'spec_helper' RSpec.describe Groups::CrmSettingsHelper do - let_it_be(:group) { create(:group) } + let_it_be(:root_group) { create(:group) } - describe '#crm_feature_flag_enabled?' do + describe '#crm_feature_available?' do subject do - helper.crm_feature_flag_enabled?(group) + helper.crm_feature_available?(group) end - context 'when feature flag is enabled' do - it { is_expected.to be_truthy } + 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 'when feature flag is disabled' do - before do - stub_feature_flags(customer_relations: false) + 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 - it { is_expected.to be_falsy } + 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/icons_helper_spec.rb b/spec/helpers/icons_helper_spec.rb index af2957d72c7..139e8be33d5 100644 --- a/spec/helpers/icons_helper_spec.rb +++ b/spec/helpers/icons_helper_spec.rb @@ -231,23 +231,33 @@ RSpec.describe IconsHelper do end end - describe 'loading_icon' do - it 'returns span with gl-spinner class and default configuration' do - expect(loading_icon.to_s) - .to eq '' + describe 'gl_loading_icon' do + it 'returns the default spinner markup' do + expect(gl_loading_icon.to_s) + .to eq '
' end context 'when css_class is provided' do - it 'appends css_class to gl-spinner element' do - expect(loading_icon(css_class: 'gl-mr-2').to_s) - .to eq '' + it 'appends css_class to container element' do + expect(gl_loading_icon(css_class: 'gl-mr-2').to_s).to match 'gl-spinner-container gl-mr-2' end end - context 'when container is true' do - it 'creates a container that has the gl-spinner-container class selector' do - expect(loading_icon(container: true).to_s) - .to eq '
' + context 'when size is provided' do + it 'sets the size class' do + expect(gl_loading_icon(size: 'xl').to_s).to match 'gl-spinner-xl' + end + end + + context 'when color is provided' do + it 'sets the color class' do + expect(gl_loading_icon(color: 'light').to_s).to match 'gl-spinner-light' + end + end + + context 'when inline is true' do + it 'creates an inline container' do + expect(gl_loading_icon(inline: true).to_s).to start_with ' client_id, + 'response_type' => 'code', + 'scope' => 'api', + 'redirect_uri' => 'http://test.host/-/jira_connect/oauth_callbacks', + 'state' => parsed_oauth_metadata[:state] + ) + end + + context 'jira_connect_oauth feature is disabled' do + before do + stub_feature_flags(jira_connect_oauth: false) + end + + it 'does not assign oauth_metadata' do + expect(oauth_metadata).to be_nil + end + end + end + it 'passes group as "skip_groups" param' do skip_groups_param = CGI.escape('skip_groups[]') diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index 526983a0d5f..5efa88a2a7d 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -114,16 +114,16 @@ RSpec.describe LabelsHelper do describe 'text_color_for_bg' do it 'uses light text on dark backgrounds' do - expect(text_color_for_bg('#222E2E')).to eq('#FFFFFF') + expect(text_color_for_bg('#222E2E')).to be_color('#FFFFFF') end it 'uses dark text on light backgrounds' do - expect(text_color_for_bg('#EEEEEE')).to eq('#333333') + expect(text_color_for_bg('#EEEEEE')).to be_color('#333333') end it 'supports RGB triplets' do - expect(text_color_for_bg('#FFF')).to eq '#333333' - expect(text_color_for_bg('#000')).to eq '#FFFFFF' + expect(text_color_for_bg('#FFF')).to be_color '#333333' + expect(text_color_for_bg('#000')).to be_color '#FFFFFF' end end diff --git a/spec/helpers/learn_gitlab_helper_spec.rb b/spec/helpers/learn_gitlab_helper_spec.rb index ffc2bb31b8f..9fce7495b5a 100644 --- a/spec/helpers/learn_gitlab_helper_spec.rb +++ b/spec/helpers/learn_gitlab_helper_spec.rb @@ -97,29 +97,29 @@ RSpec.describe LearnGitlabHelper do trial_started: a_hash_including( url: a_string_matching(%r{/learn_gitlab/-/issues/2\z}) ), - issue_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/4\z}) - ), - git_write: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/6\z}) - ), pipeline_created: a_hash_including( url: a_string_matching(%r{/learn_gitlab/-/issues/7\z}) ), - user_added: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/8\z}) - ), - merge_request_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/9\z}) - ), code_owners_enabled: a_hash_including( url: a_string_matching(%r{/learn_gitlab/-/issues/10\z}) ), required_mr_approvals_enabled: a_hash_including( url: a_string_matching(%r{/learn_gitlab/-/issues/11\z}) ), + issue_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues\z}) + ), + git_write: a_hash_including( + url: a_string_matching(%r{/learn_gitlab\z}) + ), + user_added: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/project_members\z}) + ), + merge_request_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/merge_requests\z}) + ), security_scan_enabled: a_hash_including( - url: a_string_matching(%r{docs\.gitlab\.com/ee/user/application_security/security_dashboard/#gitlab-security-dashboard-security-center-and-vulnerability-reports\z}) + url: a_string_matching(%r{/learn_gitlab/-/security/configuration\z}) ) }) end @@ -137,58 +137,5 @@ RSpec.describe LearnGitlabHelper do security_scan_enabled: a_hash_including(completed: false) }) end - - context 'when in the new action URLs experiment' do - before do - stub_experiments(change_continuous_onboarding_link_urls: :candidate) - end - - it_behaves_like 'has all data' - - it 'sets mostly new paths' do - expect(onboarding_actions_data).to match({ - trial_started: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/2\z}) - ), - issue_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues\z}) - ), - git_write: a_hash_including( - url: a_string_matching(%r{/learn_gitlab\z}) - ), - pipeline_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/pipelines\z}) - ), - user_added: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/project_members\z}) - ), - merge_request_created: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/merge_requests\z}) - ), - code_owners_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/10\z}) - ), - required_mr_approvals_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/issues/11\z}) - ), - security_scan_enabled: a_hash_including( - url: a_string_matching(%r{/learn_gitlab/-/security/configuration\z}) - ) - }) - 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/listbox_helper_spec.rb b/spec/helpers/listbox_helper_spec.rb index 8935d69d4f7..0a27aa04b37 100644 --- a/spec/helpers/listbox_helper_spec.rb +++ b/spec/helpers/listbox_helper_spec.rb @@ -65,10 +65,13 @@ RSpec.describe ListboxHelper do end context 'when selected does not match any item' do - let(:selected) { 'qux' } + where(selected: [nil, 'qux']) - it 'raises an error' do - expect { subject }.to raise_error(ArgumentError, /cannot find qux/) + with_them do + it 'selects first item' do + expect(subject.at_css('button').content).to eq('Foo') + expect(subject.attributes['data-selected'].value).to eq('foo') + end end end end diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index ab2f6fa5b7e..a7e657f2636 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -315,33 +315,27 @@ RSpec.describe MarkupHelper do end describe '#render_wiki_content' do - let(:wiki) { double('WikiPage', path: "file.#{extension}") } - let(:wiki_repository) { double('Repository') } + let(:wiki) { build(:wiki, container: project) } let(:content) { 'wiki content' } + let(:slug) { 'nested/page' } + let(:path) { "file.#{extension}" } + let(:wiki_page) { double('WikiPage', path: path, content: content, slug: slug, wiki: wiki) } + let(:context) do { pipeline: :wiki, project: project, wiki: wiki, - page_slug: 'nested/page', issuable_reference_expansion_enabled: true, - repository: wiki_repository + page_slug: slug, issuable_reference_expansion_enabled: true, + repository: wiki.repository, requested_path: path } end - before do - expect(wiki).to receive(:content).and_return(content) - expect(wiki).to receive(:slug).and_return('nested/page') - expect(wiki).to receive(:repository).and_return(wiki_repository) - allow(wiki).to receive(:container).and_return(project) - - helper.instance_variable_set(:@wiki, wiki) - end - context 'when file is Markdown' do let(:extension) { 'md' } it 'renders using #markdown_unsafe helper method' do expect(helper).to receive(:markdown_unsafe).with('wiki content', context) - helper.render_wiki_content(wiki) + helper.render_wiki_content(wiki_page) end context 'when context has labels' do @@ -350,7 +344,7 @@ RSpec.describe MarkupHelper do let(:content) { '~Bug' } it 'renders label' do - result = helper.render_wiki_content(wiki) + result = helper.render_wiki_content(wiki_page) doc = Nokogiri::HTML.parse(result) expect(doc.css('.gl-label-link')).not_to be_empty @@ -366,7 +360,7 @@ RSpec.describe MarkupHelper do end it 'renders uploads relative to project' do - result = helper.render_wiki_content(wiki) + result = helper.render_wiki_content(wiki_page) expect(result).to include("#{project.full_path}#{upload_link}") end @@ -379,7 +373,7 @@ RSpec.describe MarkupHelper do it 'renders using Gitlab::Asciidoc' do expect(Gitlab::Asciidoc).to receive(:render) - helper.render_wiki_content(wiki) + helper.render_wiki_content(wiki_page) end end @@ -398,7 +392,7 @@ FooBar it 'renders using #markdown_unsafe helper method' do expect(helper).to receive(:markdown_unsafe).with(content, context) - result = helper.render_wiki_content(wiki) + result = helper.render_wiki_content(wiki_page) expect(result).to be_empty end @@ -410,7 +404,7 @@ FooBar it 'renders all other formats using Gitlab::OtherMarkup' do expect(Gitlab::OtherMarkup).to receive(:render) - helper.render_wiki_content(wiki) + helper.render_wiki_content(wiki_page) end end end diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index 3cf855229bb..38f2efd75a8 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' RSpec.describe MergeRequestsHelper do - include ActionView::Helpers::UrlHelper include ProjectForksHelper describe '#state_name_with_icon' do @@ -72,7 +71,8 @@ RSpec.describe MergeRequestsHelper do let(:user) do double( assigned_open_merge_requests_count: 1, - review_requested_open_merge_requests_count: 2 + review_requested_open_merge_requests_count: 2, + attention_requested_open_merge_requests_count: 3 ) end @@ -82,12 +82,29 @@ RSpec.describe MergeRequestsHelper do allow(helper).to receive(:current_user).and_return(user) end - it "returns assigned, review requested and total merge request counts" do - expect(subject).to eq( - assigned: user.assigned_open_merge_requests_count, - review_requested: user.review_requested_open_merge_requests_count, - total: user.assigned_open_merge_requests_count + user.review_requested_open_merge_requests_count - ) + describe 'mr_attention_requests disabled' do + before do + stub_feature_flags(mr_attention_requests: false) + end + + it "returns assigned, review requested and total merge request counts" do + expect(subject).to eq( + assigned: user.assigned_open_merge_requests_count, + review_requested: user.review_requested_open_merge_requests_count, + total: user.assigned_open_merge_requests_count + user.review_requested_open_merge_requests_count + ) + end + end + + describe 'mr_attention_requests enabled' do + it "returns assigned, review requested, attention requests and total merge request counts" do + expect(subject).to eq( + assigned: user.assigned_open_merge_requests_count, + review_requested: user.review_requested_open_merge_requests_count, + attention_requested_count: user.attention_requested_open_merge_requests_count, + total: user.attention_requested_open_merge_requests_count + ) + end end end diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb index ef6a6827826..e4422dde407 100644 --- a/spec/helpers/nav/top_nav_helper_spec.rb +++ b/spec/helpers/nav/top_nav_helper_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe Nav::TopNavHelper do - include ActionView::Helpers::UrlHelper - let_it_be(:user) { build_stubbed(:user) } let_it_be(:admin) { build_stubbed(:user, :admin) } let_it_be(:external_user) { build_stubbed(:user, :external, can_create_group: false) } diff --git a/spec/helpers/notify_helper_spec.rb b/spec/helpers/notify_helper_spec.rb index e2a7a212b1b..654fb9bb3f8 100644 --- a/spec/helpers/notify_helper_spec.rb +++ b/spec/helpers/notify_helper_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' RSpec.describe NotifyHelper do - include ActionView::Helpers::UrlHelper using RSpec::Parameterized::TableSyntax describe 'merge_request_reference_link' do diff --git a/spec/helpers/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb index 8b3c8411fbd..d7be4194e67 100644 --- a/spec/helpers/packages_helper_spec.rb +++ b/spec/helpers/packages_helper_spec.rb @@ -71,135 +71,39 @@ RSpec.describe PackagesHelper do subject { helper.show_cleanup_policy_on_alert(project.reload) } - where(:com, :config_registry, :project_registry, :historic_entries, :historic_entry, :nil_policy, :container_repositories_exist, :expected_result) do - false | false | false | false | false | false | false | false - false | false | false | false | false | false | true | false - false | false | false | false | false | true | false | false - false | false | false | false | false | true | true | false - false | false | false | false | true | false | false | false - false | false | false | false | true | false | true | false - false | false | false | false | true | true | false | false - false | false | false | false | true | true | true | false - false | false | false | true | false | false | false | false - false | false | false | true | false | false | true | false - false | false | false | true | false | true | false | false - false | false | false | true | false | true | true | false - false | false | false | true | true | false | false | false - false | false | false | true | true | false | true | false - false | false | false | true | true | true | false | false - false | false | false | true | true | true | true | false - false | false | true | false | false | false | false | false - false | false | true | false | false | false | true | false - false | false | true | false | false | true | false | false - false | false | true | false | false | true | true | false - false | false | true | false | true | false | false | false - false | false | true | false | true | false | true | false - false | false | true | false | true | true | false | false - false | false | true | false | true | true | true | false - false | false | true | true | false | false | false | false - false | false | true | true | false | false | true | false - false | false | true | true | false | true | false | false - false | false | true | true | false | true | true | false - false | false | true | true | true | false | false | false - false | false | true | true | true | false | true | false - false | false | true | true | true | true | false | false - false | false | true | true | true | true | true | false - false | true | false | false | false | false | false | false - false | true | false | false | false | false | true | false - false | true | false | false | false | true | false | false - false | true | false | false | false | true | true | false - false | true | false | false | true | false | false | false - false | true | false | false | true | false | true | false - false | true | false | false | true | true | false | false - false | true | false | false | true | true | true | false - false | true | false | true | false | false | false | false - false | true | false | true | false | false | true | false - false | true | false | true | false | true | false | false - false | true | false | true | false | true | true | false - false | true | false | true | true | false | false | false - false | true | false | true | true | false | true | false - false | true | false | true | true | true | false | false - false | true | false | true | true | true | true | false - false | true | true | false | false | false | false | false - false | true | true | false | false | false | true | false - false | true | true | false | false | true | false | false - false | true | true | false | false | true | true | false - false | true | true | false | true | false | false | false - false | true | true | false | true | false | true | false - false | true | true | false | true | true | false | false - false | true | true | false | true | true | true | false - false | true | true | true | false | false | false | false - false | true | true | true | false | false | true | false - false | true | true | true | false | true | false | false - false | true | true | true | false | true | true | false - false | true | true | true | true | false | false | false - false | true | true | true | true | false | true | false - false | true | true | true | true | true | false | false - false | true | true | true | true | true | true | false - true | false | false | false | false | false | false | false - true | false | false | false | false | false | true | false - true | false | false | false | false | true | false | false - true | false | false | false | false | true | true | false - true | false | false | false | true | false | false | false - true | false | false | false | true | false | true | false - true | false | false | false | true | true | false | false - true | false | false | false | true | true | true | false - true | false | false | true | false | false | false | false - true | false | false | true | false | false | true | false - true | false | false | true | false | true | false | false - true | false | false | true | false | true | true | false - true | false | false | true | true | false | false | false - true | false | false | true | true | false | true | false - true | false | false | true | true | true | false | false - true | false | false | true | true | true | true | false - true | false | true | false | false | false | false | false - true | false | true | false | false | false | true | false - true | false | true | false | false | true | false | false - true | false | true | false | false | true | true | false - true | false | true | false | true | false | false | false - true | false | true | false | true | false | true | false - true | false | true | false | true | true | false | false - true | false | true | false | true | true | true | false - true | false | true | true | false | false | false | false - true | false | true | true | false | false | true | false - true | false | true | true | false | true | false | false - true | false | true | true | false | true | true | false - true | false | true | true | true | false | false | false - true | false | true | true | true | false | true | false - true | false | true | true | true | true | false | false - true | false | true | true | true | true | true | false - true | true | false | false | false | false | false | false - true | true | false | false | false | false | true | false - true | true | false | false | false | true | false | false - true | true | false | false | false | true | true | false - true | true | false | false | true | false | false | false - true | true | false | false | true | false | true | false - true | true | false | false | true | true | false | false - true | true | false | false | true | true | true | false - true | true | false | true | false | false | false | false - true | true | false | true | false | false | true | false - true | true | false | true | false | true | false | false - true | true | false | true | false | true | true | false - true | true | false | true | true | false | false | false - true | true | false | true | true | false | true | false - true | true | false | true | true | true | false | false - true | true | false | true | true | true | true | false - true | true | true | false | false | false | false | false - true | true | true | false | false | false | true | false - true | true | true | false | false | true | false | false - true | true | true | false | false | true | true | false - true | true | true | false | true | false | false | false - true | true | true | false | true | false | true | false - true | true | true | false | true | true | false | false - true | true | true | false | true | true | true | true - true | true | true | true | false | false | false | false - true | true | true | true | false | false | true | false - true | true | true | true | false | true | false | false - true | true | true | true | false | true | true | false - true | true | true | true | true | false | false | false - true | true | true | true | true | false | true | false - true | true | true | true | true | true | false | false - true | true | true | true | true | true | true | false + where(:com, :config_registry, :project_registry, :nil_policy, :container_repositories_exist, :expected_result) do + false | false | false | false | false | false + false | false | false | false | true | false + false | false | false | true | false | false + false | false | false | true | true | false + false | false | true | false | false | false + false | false | true | false | true | false + false | false | true | true | false | false + false | false | true | true | true | false + false | true | false | false | false | false + false | true | false | false | true | false + false | true | false | true | false | false + false | true | false | true | true | false + false | true | true | false | false | false + false | true | true | false | true | false + false | true | true | true | false | false + false | true | true | true | true | false + true | false | false | false | false | false + true | false | false | false | true | false + true | false | false | true | false | false + true | false | false | true | true | false + true | false | true | false | false | false + true | false | true | false | true | false + true | false | true | true | false | false + true | false | true | true | true | false + true | true | false | false | false | false + true | true | false | false | true | false + true | true | false | true | false | false + true | true | false | true | true | false + true | true | true | false | false | false + true | true | true | false | true | false + true | true | true | true | false | false + true | true | true | true | true | true end with_them do @@ -208,9 +112,6 @@ RSpec.describe PackagesHelper do allow(Gitlab).to receive(:com?).and_return(com) stub_config(registry: { enabled: config_registry }) allow(project).to receive(:feature_available?).with(:container_registry, user).and_return(project_registry) - stub_application_setting(container_expiration_policies_enable_historic_entries: historic_entries) - stub_feature_flags(container_expiration_policies_historic_entry: false) - stub_feature_flags(container_expiration_policies_historic_entry: project) if historic_entry project.container_expiration_policy.destroy! if nil_policy container_repository.update!(project_id: project.id) if container_repositories_exist diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index ad2f142e3ff..8c13afc2b45 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -96,6 +96,30 @@ RSpec.describe PreferencesHelper do end end + describe '#user_application_dark_mode?' do + context 'with a user' do + it "returns true if user's selected dark theme" do + stub_user(theme_id: 11) + + expect(helper.user_application_dark_mode?).to eq true + end + + it "returns false if user's selected any light theme" do + stub_user(theme_id: 1) + + expect(helper.user_application_dark_mode?).to eq false + end + end + + context 'without a user' do + it 'returns false' do + stub_user + + expect(helper.user_application_dark_mode?).to eq false + end + end + end + describe '#user_color_scheme' do context 'with a user' do it "returns user's scheme's css_class" do diff --git a/spec/helpers/projects/cluster_agents_helper_spec.rb b/spec/helpers/projects/cluster_agents_helper_spec.rb index d94a5fa9f8a..6849ec8b5ea 100644 --- a/spec/helpers/projects/cluster_agents_helper_spec.rb +++ b/spec/helpers/projects/cluster_agents_helper_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Projects::ClusterAgentsHelper do let_it_be(:current_user) { create(:user) } let(:user_can_admin_vulerability) { true } + let(:user_can_admin_cluster) { false } let(:agent_name) { 'agent-name' } before do @@ -16,6 +17,10 @@ RSpec.describe Projects::ClusterAgentsHelper do .to receive(:can?) .with(current_user, :admin_vulnerability, project) .and_return(user_can_admin_vulerability) + allow(helper) + .to receive(:can?) + .with(current_user, :admin_cluster, project) + .and_return(user_can_admin_cluster) end subject { helper.js_cluster_agent_details_data(agent_name, project) } @@ -26,8 +31,18 @@ RSpec.describe Projects::ClusterAgentsHelper do project_path: project.full_path, activity_empty_state_image: kind_of(String), empty_state_svg_path: kind_of(String), - can_admin_vulnerability: "true" + can_admin_vulnerability: "true", + kas_address: Gitlab::Kas.external_url, + can_admin_cluster: "false" }) } + + context 'user has admin cluster permissions' do + let(:user_can_admin_cluster) { true } + + it 'displays that the user can admin cluster' do + expect(subject[:can_admin_cluster]).to eq("true") + end + end end end diff --git a/spec/helpers/projects/error_tracking_helper_spec.rb b/spec/helpers/projects/error_tracking_helper_spec.rb index 882031a9c86..f49458be40d 100644 --- a/spec/helpers/projects/error_tracking_helper_spec.rb +++ b/spec/helpers/projects/error_tracking_helper_spec.rb @@ -5,8 +5,8 @@ require 'spec_helper' RSpec.describe Projects::ErrorTrackingHelper do include Gitlab::Routing.url_helpers - let_it_be(:project, reload: true) { create(:project) } - let_it_be(:current_user) { create(:user) } + let(:project) { build_stubbed(:project) } + let(:current_user) { build_stubbed(:user) } describe '#error_tracking_data' do let(:can_enable_error_tracking) { true } @@ -34,20 +34,21 @@ RSpec.describe Projects::ErrorTrackingHelper do 'error-tracking-enabled' => 'false', 'list-path' => list_path, 'project-path' => project_path, - 'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg') + 'illustration-path' => match_asset_path('/assets/illustrations/cluster_popover.svg'), + 'show-integrated-tracking-disabled-alert' => 'false' ) end end context 'with error_tracking_setting' do - let(:error_tracking_setting) do - create(:project_error_tracking_setting, project: project) + let(:project) { build_stubbed(:project, :with_error_tracking_setting) } + + before do + project.error_tracking_setting.enabled = enabled end context 'when enabled' do - before do - error_tracking_setting.update!(enabled: true) - end + let(:enabled) { true } it 'show error tracking enabled' do expect(helper.error_tracking_data(current_user, project)).to include( @@ -57,9 +58,7 @@ RSpec.describe Projects::ErrorTrackingHelper do end context 'when disabled' do - before do - error_tracking_setting.update!(enabled: false) - end + let(:enabled) { false } it 'show error tracking not enabled' do expect(helper.error_tracking_data(current_user, project)).to include( @@ -67,6 +66,38 @@ RSpec.describe Projects::ErrorTrackingHelper do ) end end + + context 'with integrated error tracking feature' do + using RSpec::Parameterized::TableSyntax + + where(:feature_flag, :enabled, :integrated, :show_alert) do + false | true | true | true + false | true | false | false + false | false | true | false + false | false | false | false + true | true | true | false + true | true | false | false + true | false | true | false + true | false | false | false + end + + with_them do + before do + stub_feature_flags(integrated_error_tracking: feature_flag) + + project.error_tracking_setting.attributes = { + enabled: enabled, + integrated: integrated + } + end + + specify do + expect(helper.error_tracking_data(current_user, project)).to include( + 'show-integrated-tracking-disabled-alert' => show_alert.to_s + ) + end + end + end end context 'when user is not maintainer' do diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 604ce0fe0c1..24d908a5dd3 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1027,7 +1027,7 @@ RSpec.describe ProjectsHelper do end end - describe '#import_from_bitbucket_message' do + shared_examples 'configure import method modal' do before do allow(helper).to receive(:current_user).and_return(user) end @@ -1036,7 +1036,7 @@ RSpec.describe ProjectsHelper do it 'returns a link to contact an administrator' do allow(user).to receive(:admin?).and_return(false) - expect(helper.import_from_bitbucket_message).to have_text('To enable importing projects from Bitbucket, ask your GitLab administrator to configure OAuth integration') + expect(subject).to have_text("To enable importing projects from #{import_method}, ask your GitLab administrator to configure OAuth integration") end end @@ -1044,8 +1044,24 @@ RSpec.describe ProjectsHelper do it 'returns a link to configure bitbucket' do allow(user).to receive(:admin?).and_return(true) - expect(helper.import_from_bitbucket_message).to have_text('To enable importing projects from Bitbucket, as administrator you need to configure OAuth integration') + expect(subject).to have_text("To enable importing projects from #{import_method}, as administrator you need to configure OAuth integration") end end end + + describe '#import_from_bitbucket_message' do + let(:import_method) { 'Bitbucket' } + + subject { helper.import_from_bitbucket_message } + + it_behaves_like 'configure import method modal' + end + + describe '#import_from_gitlab_message' do + let(:import_method) { 'GitLab.com' } + + subject { helper.import_from_gitlab_message } + + it_behaves_like 'configure import method modal' + end end diff --git a/spec/helpers/routing/pseudonymization_helper_spec.rb b/spec/helpers/routing/pseudonymization_helper_spec.rb index d7905edb098..1221917e6b7 100644 --- a/spec/helpers/routing/pseudonymization_helper_spec.rb +++ b/spec/helpers/routing/pseudonymization_helper_spec.rb @@ -222,16 +222,26 @@ RSpec.describe ::Routing::PseudonymizationHelper do end describe 'when url has no params to mask' do - let(:root_url) { 'http://localhost/some/path' } + let(:original_url) { 'http://localhost/-/security/vulnerabilities' } + let(:request) do + double(:Request, + path_parameters: { + controller: 'security/vulnerabilities', + action: 'index' + }, + protocol: 'http', + host: 'localhost', + query_string: '', + original_fullpath: '/-/security/vulnerabilities', + original_url: original_url) + end - context 'returns root url' do - before do - controller.request.path = 'some/path' - end + before do + allow(helper).to receive(:request).and_return(request) + end - it 'masked_page_url' do - expect(subject).to eq(root_url) - end + it 'returns unchanged url' do + expect(subject).to eq(original_url) end end diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb index 816e43669bd..fd3d7100ba1 100644 --- a/spec/helpers/sessions_helper_spec.rb +++ b/spec/helpers/sessions_helper_spec.rb @@ -8,7 +8,7 @@ RSpec.describe SessionsHelper do context 'when on .com' do before do - allow(Gitlab).to receive(:dev_env_or_com?).and_return(true) + allow(Gitlab).to receive(:com?).and_return(true) end it 'when flash notice is empty it is false' do @@ -29,7 +29,7 @@ RSpec.describe SessionsHelper do context 'when not on .com' do before do - allow(Gitlab).to receive(:dev_env_or_com?).and_return(false) + allow(Gitlab).to receive(:com?).and_return(false) end it 'when flash notice is devise confirmed message it is false' do diff --git a/spec/helpers/sorting_helper_spec.rb b/spec/helpers/sorting_helper_spec.rb index b49b4ad6e7e..e20fb77ad75 100644 --- a/spec/helpers/sorting_helper_spec.rb +++ b/spec/helpers/sorting_helper_spec.rb @@ -10,6 +10,18 @@ RSpec.describe SortingHelper do allow(self).to receive(:request).and_return(double(path: 'http://test.com', query_parameters: { label_name: option })) end + describe '#admin_users_sort_options' do + it 'returns correct link attributes in array' do + options = admin_users_sort_options(filter: 'filter', search_query: 'search') + + expect(options[0][:href]).to include('filter') + expect(options[0][:href]).to include('search') + options.each do |option| + expect(option[:href]).to include(option[:value]) + end + end + end + describe '#issuable_sort_option_title' do it 'returns correct title for issuable_sort_option_overrides key' do expect(issuable_sort_option_title('created_asc')).to eq('Created date') diff --git a/spec/helpers/storage_helper_spec.rb b/spec/helpers/storage_helper_spec.rb index 82b78ed831c..6b743422b04 100644 --- a/spec/helpers/storage_helper_spec.rb +++ b/spec/helpers/storage_helper_spec.rb @@ -57,6 +57,8 @@ RSpec.describe StorageHelper do let_it_be(:paid_group) { create(:group) } before 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) @@ -64,26 +66,37 @@ RSpec.describe StorageHelper do describe "#storage_enforcement_banner_info" do it 'returns nil when namespace is not free' do - expect(storage_enforcement_banner_info(paid_group)).to be(nil) + expect(helper.storage_enforcement_banner_info(paid_group)).to be(nil) end it 'returns nil when storage_enforcement_date is not set' do allow(free_group).to receive(:storage_enforcement_date).and_return(nil) - expect(storage_enforcement_banner_info(free_group)).to be(nil) + expect(helper.storage_enforcement_banner_info(free_group)).to be(nil) end - it 'returns a hash when storage_enforcement_date is set' do - storage_enforcement_date = Date.today + 30 - allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) - - expect(storage_enforcement_banner_info(free_group)).to eql({ - text: "From #{storage_enforcement_date} storage limits will apply to this namespace. View and manage your usage in Group Settings > Usage quotas.", - variant: 'warning', - callouts_feature_name: 'storage_enforcement_banner_second_enforcement_threshold', - callouts_path: '/-/users/group_callouts', - learn_more_link: 'Learn more.' - }) + describe 'when storage_enforcement_date is set' do + let_it_be(:storage_enforcement_date) { Date.today + 30 } + + before do + allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) + end + + it 'returns nil when current_user do not have access usage quotas page' do + allow(helper).to receive(:can?).with(current_user, :admin_namespace, free_group).and_return(false) + + expect(helper.storage_enforcement_banner_info(free_group)).to be(nil) + end + + it 'returns a hash when current_user can access usage quotas page' do + expect(helper.storage_enforcement_banner_info(free_group)).to eql({ + text: "From #{storage_enforcement_date} storage limits will apply to this namespace. View and manage your usage in Group settings > Usage quotas.", + variant: 'warning', + callouts_feature_name: 'storage_enforcement_banner_second_enforcement_threshold', + callouts_path: '/-/users/group_callouts', + learn_more_link: 'Learn more.' + }) + end end context 'when storage_enforcement_date is set and dismissed callout exists' do @@ -96,7 +109,7 @@ RSpec.describe StorageHelper do allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) end - it { expect(storage_enforcement_banner_info(free_group)).to be(nil) } + it { expect(helper.storage_enforcement_banner_info(free_group)).to be(nil) } end context 'callouts_feature_name' do @@ -106,7 +119,7 @@ RSpec.describe StorageHelper do storage_enforcement_date = Date.today + days_from_now allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date) - storage_enforcement_banner_info(free_group)[:callouts_feature_name] + helper.storage_enforcement_banner_info(free_group)[:callouts_feature_name] end it 'returns first callouts_feature_name' do diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb index 1a0ecd5d903..026432adf99 100644 --- a/spec/helpers/tree_helper_spec.rb +++ b/spec/helpers/tree_helper_spec.rb @@ -116,9 +116,11 @@ RSpec.describe TreeHelper do show_edit_button: false, show_web_ide_button: true, show_gitpod_button: false, + show_pipeline_editor_button: false, edit_url: '', web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}", + pipeline_editor_url: "/#{project.full_path}/-/ci/editor?branch_name=#{@ref}", gitpod_url: '', user_preferences_gitpod_path: user_preferences_gitpod_path, diff --git a/spec/helpers/users/callouts_helper_spec.rb b/spec/helpers/users/callouts_helper_spec.rb index 85e11c2ed3b..71a8d340b30 100644 --- a/spec/helpers/users/callouts_helper_spec.rb +++ b/spec/helpers/users/callouts_helper_spec.rb @@ -103,6 +103,7 @@ RSpec.describe Users::CalloutsHelper do allow(helper).to receive(:current_user).and_return(admin) stub_application_setting(signup_enabled: true) allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } + allow(helper.controller).to receive(:controller_path).and_return("admin/users") end it { is_expected.to be false } @@ -114,6 +115,7 @@ RSpec.describe Users::CalloutsHelper do allow(helper).to receive(:current_user).and_return(user) stub_application_setting(signup_enabled: true) allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } + allow(helper.controller).to receive(:controller_path).and_return("admin/users") end it { is_expected.to be false } @@ -125,6 +127,7 @@ RSpec.describe Users::CalloutsHelper do allow(helper).to receive(:current_user).and_return(admin) stub_application_setting(signup_enabled: false) allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } + allow(helper.controller).to receive(:controller_path).and_return("admin/users") end it { is_expected.to be false } @@ -136,17 +139,31 @@ RSpec.describe Users::CalloutsHelper do allow(helper).to receive(:current_user).and_return(admin) stub_application_setting(signup_enabled: true) allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { true } + allow(helper.controller).to receive(:controller_path).and_return("admin/users") end it { is_expected.to be false } end - context 'when not gitlab.com, `current_user` is an admin, signup is enabled, and user has not dismissed callout' do + context 'when controller path is not allowed' do before do allow(::Gitlab).to receive(:com?).and_return(false) allow(helper).to receive(:current_user).and_return(admin) stub_application_setting(signup_enabled: true) allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } + allow(helper.controller).to receive(:controller_path).and_return("projects/issues") + end + + it { is_expected.to be false } + end + + context 'when not gitlab.com, `current_user` is an admin, signup is enabled, user has not dismissed callout, and controller path is allowed' do + before do + allow(::Gitlab).to receive(:com?).and_return(false) + allow(helper).to receive(:current_user).and_return(admin) + stub_application_setting(signup_enabled: true) + allow(helper).to receive(:user_dismissed?).with(described_class::REGISTRATION_ENABLED_CALLOUT) { false } + allow(helper.controller).to receive(:controller_path).and_return("admin/users") end it { is_expected.to be true } diff --git a/spec/helpers/web_ide_button_helper_spec.rb b/spec/helpers/web_ide_button_helper_spec.rb new file mode 100644 index 00000000000..3dd46021c11 --- /dev/null +++ b/spec/helpers/web_ide_button_helper_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WebIdeButtonHelper do + describe '#show_pipeline_editor_button?' do + subject(:result) { helper.show_pipeline_editor_button?(project, path) } + + let_it_be(:project) { build(:project) } + + context 'when can view pipeline editor' do + before do + allow(helper).to receive(:can_view_pipeline_editor?).and_return(true) + end + + context 'when path is ci config path' do + let(:path) { project.ci_config_path_or_default } + + it 'returns true' do + expect(result).to eq(true) + end + end + + context 'when path is not config path' do + let(:path) { '/' } + + it 'returns false' do + expect(result).to eq(false) + end + end + end + + context 'when can not view pipeline editor' do + before do + allow(helper).to receive(:can_view_pipeline_editor?).and_return(false) + end + + let(:path) { project.ci_config_path_or_default } + + it 'returns false' do + expect(result).to eq(false) + end + end + end +end diff --git a/spec/helpers/whats_new_helper_spec.rb b/spec/helpers/whats_new_helper_spec.rb index 9ae7ef38736..011152b2d6a 100644 --- a/spec/helpers/whats_new_helper_spec.rb +++ b/spec/helpers/whats_new_helper_spec.rb @@ -39,14 +39,14 @@ RSpec.describe WhatsNewHelper do subject { helper.display_whats_new? } it 'returns true when gitlab.com' do - allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(true) + allow(Gitlab).to receive(:org_or_com?).and_return(true) expect(subject).to be true end context 'when self-managed' do before do - allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(false) + allow(Gitlab).to receive(:org_or_com?).and_return(false) end it 'returns true if user is signed in' do @@ -71,7 +71,7 @@ RSpec.describe WhatsNewHelper do with_them do it 'returns correct result depending on variant' do - allow(Gitlab).to receive(:dev_env_org_or_com?).and_return(true) + allow(Gitlab).to receive(:org_or_com?).and_return(true) Gitlab::CurrentSettings.update!(whats_new_variant: ApplicationSetting.whats_new_variants[variant]) expect(subject).to eq(result) -- cgit v1.2.3