From 3cccd102ba543e02725d247893729e5c73b38295 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Apr 2022 10:00:54 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-10-stable-ee --- .../admin/background_migrations_helper_spec.rb | 10 +-- spec/helpers/application_settings_helper_spec.rb | 15 ++-- spec/helpers/boards_helper_spec.rb | 17 ++++- spec/helpers/broadcast_messages_helper_spec.rb | 29 ------- spec/helpers/button_helper_spec.rb | 2 +- spec/helpers/ci/pipeline_editor_helper_spec.rb | 8 +- spec/helpers/ci/pipelines_helper_spec.rb | 41 ++++++++++ spec/helpers/ci/runners_helper_spec.rb | 45 ++++++----- spec/helpers/clusters_helper_spec.rb | 4 + spec/helpers/colors_helper_spec.rb | 89 ++++++++++++++++++++++ spec/helpers/commits_helper_spec.rb | 10 +-- spec/helpers/diff_helper_spec.rb | 57 +++++++++++--- spec/helpers/environment_helper_spec.rb | 2 +- spec/helpers/environments_helper_spec.rb | 2 +- spec/helpers/groups/group_members_helper_spec.rb | 62 ++++++++++++++- spec/helpers/invite_members_helper_spec.rb | 2 + spec/helpers/issuables_helper_spec.rb | 2 +- spec/helpers/issues_helper_spec.rb | 14 +++- spec/helpers/namespaces_helper_spec.rb | 11 +++ spec/helpers/packages_helper_spec.rb | 4 +- spec/helpers/preferences_helper_spec.rb | 61 +++++++++++++++ .../projects/alert_management_helper_spec.rb | 23 +++++- spec/helpers/projects/pipeline_helper_spec.rb | 23 ++++++ .../projects/security/configuration_helper_spec.rb | 6 ++ spec/helpers/projects_helper_spec.rb | 48 ++++++++++++ .../routing/pseudonymization_helper_spec.rb | 6 +- spec/helpers/search_helper_spec.rb | 46 +++++++++-- spec/helpers/timeboxes_helper_spec.rb | 28 ------- spec/helpers/wiki_helper_spec.rb | 4 + 29 files changed, 541 insertions(+), 130 deletions(-) create mode 100644 spec/helpers/colors_helper_spec.rb create mode 100644 spec/helpers/projects/pipeline_helper_spec.rb (limited to 'spec/helpers') diff --git a/spec/helpers/admin/background_migrations_helper_spec.rb b/spec/helpers/admin/background_migrations_helper_spec.rb index 9c1bb0b9c55..e3639ef778e 100644 --- a/spec/helpers/admin/background_migrations_helper_spec.rb +++ b/spec/helpers/admin/background_migrations_helper_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Admin::BackgroundMigrationsHelper do describe '#batched_migration_status_badge_variant' do using RSpec::Parameterized::TableSyntax - where(:status, :variant) do + where(:status_name, :variant) do :active | :info :paused | :warning :failed | :danger @@ -16,7 +16,7 @@ RSpec.describe Admin::BackgroundMigrationsHelper do subject { helper.batched_migration_status_badge_variant(migration) } with_them do - let(:migration) { build(:batched_background_migration, status: status) } + let(:migration) { build(:batched_background_migration, status_name) } it { is_expected.to eq(variant) } end @@ -25,7 +25,7 @@ RSpec.describe Admin::BackgroundMigrationsHelper do describe '#batched_migration_progress' do subject { helper.batched_migration_progress(migration, completed_rows) } - let(:migration) { build(:batched_background_migration, status: :active, total_tuple_count: 100) } + let(:migration) { build(:batched_background_migration, :active, total_tuple_count: 100) } let(:completed_rows) { 25 } it 'returns completion percentage' do @@ -33,7 +33,7 @@ RSpec.describe Admin::BackgroundMigrationsHelper do end context 'when migration is finished' do - let(:migration) { build(:batched_background_migration, status: :finished, total_tuple_count: nil) } + let(:migration) { build(:batched_background_migration, :finished, total_tuple_count: nil) } it 'returns 100 percent' do expect(subject).to eq(100) @@ -41,7 +41,7 @@ RSpec.describe Admin::BackgroundMigrationsHelper do end context 'when total_tuple_count is nil' do - let(:migration) { build(:batched_background_migration, status: :active, total_tuple_count: nil) } + let(:migration) { build(:batched_background_migration, :active, total_tuple_count: nil) } it 'returns nil' do expect(subject).to eq(nil) diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index 26d48bef24e..c93762416f5 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -149,7 +149,7 @@ RSpec.describe ApplicationSettingsHelper do end end - describe '.storage_weights' do + describe '#storage_weights' do let(:application_setting) { build(:application_setting) } before do @@ -158,12 +158,13 @@ RSpec.describe ApplicationSettingsHelper do stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil }) end - it 'returns storages correctly' do - expect(helper.storage_weights).to eq(OpenStruct.new( - default: 100, - storage_1: 50, - storage_2: 0 - )) + it 'returns storage objects with assigned weights' do + expect(helper.storage_weights) + .to have_attributes( + default: 100, + storage_1: 50, + storage_2: 0 + ) end end diff --git a/spec/helpers/boards_helper_spec.rb b/spec/helpers/boards_helper_spec.rb index ec949fde30e..8d5dc3fb4be 100644 --- a/spec/helpers/boards_helper_spec.rb +++ b/spec/helpers/boards_helper_spec.rb @@ -102,6 +102,7 @@ RSpec.describe BoardsHelper do allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, project_board).and_return(true) allow(helper).to receive(:can?).with(user, :admin_issue, project_board).and_return(true) allow(helper).to receive(:can?).with(user, :admin_issue_board_list, project).and_return(false) + allow(helper).to receive(:can?).with(user, :admin_issue_board, project).and_return(false) end it 'returns a board_lists_path as lists_endpoint' do @@ -129,12 +130,23 @@ RSpec.describe BoardsHelper do it 'returns can_admin_list as false by default' do expect(helper.board_data[:can_admin_list]).to eq('false') end - it 'returns can_admin_list as true when user can admin the board' do + it 'returns can_admin_list as true when user can admin the board lists' do allow(helper).to receive(:can?).with(user, :admin_issue_board_list, project).and_return(true) expect(helper.board_data[:can_admin_list]).to eq('true') end end + + context 'can_admin_board' do + it 'returns can_admin_board as false by default' do + expect(helper.board_data[:can_admin_board]).to eq('false') + end + it 'returns can_admin_board as true when user can admin the board' do + allow(helper).to receive(:can?).with(user, :admin_issue_board, project).and_return(true) + + expect(helper.board_data[:can_admin_board]).to eq('true') + end + end end context 'group board' do @@ -146,6 +158,7 @@ RSpec.describe BoardsHelper do allow(helper).to receive(:can?).with(user, :create_non_backlog_issues, group_board).and_return(true) allow(helper).to receive(:can?).with(user, :admin_issue, group_board).and_return(true) allow(helper).to receive(:can?).with(user, :admin_issue_board_list, base_group).and_return(false) + allow(helper).to receive(:can?).with(user, :admin_issue_board, base_group).and_return(false) end it 'returns correct path for base group' do @@ -165,7 +178,7 @@ RSpec.describe BoardsHelper do it 'returns can_admin_list as false by default' do expect(helper.board_data[:can_admin_list]).to eq('false') end - it 'returns can_admin_list as true when user can admin the board' do + it 'returns can_admin_list as true when user can admin the board lists' do allow(helper).to receive(:can?).with(user, :admin_issue_board_list, base_group).and_return(true) expect(helper.board_data[:can_admin_list]).to eq('true') diff --git a/spec/helpers/broadcast_messages_helper_spec.rb b/spec/helpers/broadcast_messages_helper_spec.rb index e721a3fdc95..d4021a2eb59 100644 --- a/spec/helpers/broadcast_messages_helper_spec.rb +++ b/spec/helpers/broadcast_messages_helper_spec.rb @@ -115,37 +115,8 @@ RSpec.describe BroadcastMessagesHelper do end it 'includes the current message' do - allow(helper).to receive(:broadcast_message_style).and_return(nil) - expect(helper.broadcast_message(current_broadcast_message)).to include 'Current Message' end - - it 'includes custom style' do - allow(helper).to receive(:broadcast_message_style).and_return('foo') - - expect(helper.broadcast_message(current_broadcast_message)).to include 'style="foo"' - end - end - - describe 'broadcast_message_style' do - it 'defaults to no style' do - broadcast_message = spy - - expect(helper.broadcast_message_style(broadcast_message)).to eq '' - end - - it 'allows custom style for banner messages' do - broadcast_message = BroadcastMessage.new(color: '#f2dede', font: '#b94a48', broadcast_type: "banner") - - expect(helper.broadcast_message_style(broadcast_message)) - .to match('background-color: #f2dede; color: #b94a48') - end - - it 'does not add style for notification messages' do - broadcast_message = BroadcastMessage.new(color: '#f2dede', broadcast_type: "notification") - - expect(helper.broadcast_message_style(broadcast_message)).to eq '' - end end describe 'broadcast_message_status' do diff --git a/spec/helpers/button_helper_spec.rb b/spec/helpers/button_helper_spec.rb index 851e13d908f..a7f65aa3134 100644 --- a/spec/helpers/button_helper_spec.rb +++ b/spec/helpers/button_helper_spec.rb @@ -164,7 +164,7 @@ RSpec.describe ButtonHelper do context 'with default options' do context 'when no `text` attribute is not provided' do it 'shows copy to clipboard button with default configuration and no text set to copy' do - expect(element.attr('class')).to eq('btn btn-clipboard btn-transparent') + expect(element.attr('class')).to eq('btn btn-clipboard gl-button btn-default-tertiary btn-icon btn-sm') expect(element.attr('type')).to eq('button') expect(element.attr('aria-label')).to eq('Copy') expect(element.attr('aria-live')).to eq('polite') diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb index b844cc2e22b..12456deb538 100644 --- a/spec/helpers/ci/pipeline_editor_helper_spec.rb +++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb @@ -45,8 +45,8 @@ RSpec.describe Ci::PipelineEditorHelper do "default-branch" => project.default_branch_or_main, "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'), + "lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'), + "lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available-message'), "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,8 +72,8 @@ RSpec.describe Ci::PipelineEditorHelper do "default-branch" => project.default_branch_or_main, "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'), + "lint-help-page-path" => help_page_path('ci/lint', anchor: 'check-cicd-syntax'), + "lint-unavailable-help-page-path" => help_page_path('ci/pipeline_editor/index', anchor: 'configuration-validation-currently-not-available-message'), "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/pipelines_helper_spec.rb b/spec/helpers/ci/pipelines_helper_spec.rb index 2b76eaa87bc..c473e1e4ab6 100644 --- a/spec/helpers/ci/pipelines_helper_spec.rb +++ b/spec/helpers/ci/pipelines_helper_spec.rb @@ -151,5 +151,46 @@ RSpec.describe Ci::PipelinesHelper do end end end + + describe 'the `registration_token` attribute' do + subject { data[:registration_token] } + + describe 'when the project is eligible for the `ios_specific_templates` experiment' do + let_it_be(:project) { create(:project, :auto_devops_disabled) } + let_it_be(:user) { create(:user) } + + before do + allow(helper).to receive(:current_user).and_return(user) + project.add_developer(user) + create(:project_setting, project: project, target_platforms: %w(ios)) + end + + context 'when the `ios_specific_templates` experiment variant is control' do + before do + stub_experiments(ios_specific_templates: :control) + end + + it { is_expected.to be_nil } + end + + context 'when the `ios_specific_templates` experiment variant is candidate' do + before do + stub_experiments(ios_specific_templates: :candidate) + end + + context 'when the user cannot register project runners' do + before do + allow(helper).to receive(:can?).with(user, :register_project_runners, project).and_return(false) + end + + it { is_expected.to be_nil } + end + + context 'when the user can register project runners' do + it { is_expected.to eq(project.runners_token) } + end + end + end + end end end diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 832b4da0e20..0046d481282 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -10,24 +10,31 @@ RSpec.describe Ci::RunnersHelper do end describe '#runner_status_icon', :clean_gitlab_redis_cache do - it "returns - not contacted yet" do + it "returns online text" do + runner = create(:ci_runner, contacted_at: 1.second.ago) + expect(helper.runner_status_icon(runner)).to include("is online") + end + + it "returns never contacted" do runner = create(:ci_runner) - expect(helper.runner_status_icon(runner)).to include("not contacted yet") + expect(helper.runner_status_icon(runner)).to include("never contacted") end it "returns offline text" do - runner = create(:ci_runner, contacted_at: 1.day.ago, active: true) - expect(helper.runner_status_icon(runner)).to include("Runner is offline") + runner = create(:ci_runner, contacted_at: 1.day.ago) + expect(helper.runner_status_icon(runner)).to include("is offline") end - it "returns online text" do - runner = create(:ci_runner, contacted_at: 1.second.ago, active: true) - expect(helper.runner_status_icon(runner)).to include("Runner is online") + it "returns stale text" do + runner = create(:ci_runner, created_at: 4.months.ago, contacted_at: 4.months.ago) + expect(helper.runner_status_icon(runner)).to include("is stale") + expect(helper.runner_status_icon(runner)).to include("last contact was") end - it "returns paused text" do - runner = create(:ci_runner, contacted_at: 1.second.ago, active: false) - expect(helper.runner_status_icon(runner)).to include("Runner is paused") + it "returns stale text, when runner never contacted" do + runner = create(:ci_runner, created_at: 4.months.ago) + expect(helper.runner_status_icon(runner)).to include("is stale") + expect(helper.runner_status_icon(runner)).to include("never contacted") end end @@ -79,7 +86,9 @@ 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 + registration_token: Gitlab::CurrentSettings.runners_registration_token, + online_contact_timeout_secs: 7200, + stale_timeout_secs: 7889238 }) end end @@ -121,12 +130,14 @@ RSpec.describe Ci::RunnersHelper do let(:group) { create(:group) } it 'returns group data to render a runner list' do - data = helper.group_runners_data_attributes(group) - - expect(data[:registration_token]).to eq(group.runners_token) - expect(data[:group_id]).to eq(group.id) - expect(data[:group_full_path]).to eq(group.full_path) - expect(data[:runner_install_help_page]).to eq('https://docs.gitlab.com/runner/install/') + expect(helper.group_runners_data_attributes(group)).to eq({ + registration_token: group.runners_token, + group_id: group.id, + group_full_path: group.full_path, + runner_install_help_page: 'https://docs.gitlab.com/runner/install/', + online_contact_timeout_secs: 7200, + stale_timeout_secs: 7889238 + }) end end diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb index 53d33f2875f..4feb9d1a2cd 100644 --- a/spec/helpers/clusters_helper_spec.rb +++ b/spec/helpers/clusters_helper_spec.rb @@ -74,6 +74,10 @@ RSpec.describe ClustersHelper do expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect") end + it 'displays create cluster path' do + expect(subject[:new_cluster_docs_path]).to eq("#{project_path(project)}/-/clusters/new_cluster_docs") + end + it 'displays project default branch' do expect(subject[:default_branch_name]).to eq(project.default_branch) end diff --git a/spec/helpers/colors_helper_spec.rb b/spec/helpers/colors_helper_spec.rb new file mode 100644 index 00000000000..ca5cafb7ebe --- /dev/null +++ b/spec/helpers/colors_helper_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ColorsHelper do + using RSpec::Parameterized::TableSyntax + + describe '#hex_color_to_rgb_array' do + context 'valid hex color' do + where(:hex_color, :rgb_array) do + '#000000' | [0, 0, 0] + '#aaaaaa' | [170, 170, 170] + '#cCcCcC' | [204, 204, 204] + '#FFFFFF' | [255, 255, 255] + '#000abc' | [0, 10, 188] + '#123456' | [18, 52, 86] + '#a1b2c3' | [161, 178, 195] + '#000' | [0, 0, 0] + '#abc' | [170, 187, 204] + '#321' | [51, 34, 17] + '#7E2' | [119, 238, 34] + '#fFf' | [255, 255, 255] + end + + with_them do + it 'returns correct RGB array' do + expect(helper.hex_color_to_rgb_array(hex_color)).to eq(rgb_array) + end + end + end + + context 'invalid hex color' do + where(:hex_color) { ['', '0', '#00', '#ffff', '#1234567', 'invalid', [], 1, nil] } + + with_them do + it 'raise ArgumentError' do + expect { helper.hex_color_to_rgb_array(hex_color) }.to raise_error(ArgumentError) + end + end + end + end + + describe '#rgb_array_to_hex_color' do + context 'valid RGB array' do + where(:rgb_array, :hex_color) do + [0, 0, 0] | '#000000' + [0, 0, 255] | '#0000ff' + [0, 255, 0] | '#00ff00' + [255, 0, 0] | '#ff0000' + [12, 34, 56] | '#0c2238' + [222, 111, 88] | '#de6f58' + [255, 255, 255] | '#ffffff' + end + + with_them do + it 'returns correct hex color' do + expect(helper.rgb_array_to_hex_color(rgb_array)).to eq(hex_color) + end + end + end + + context 'invalid RGB array' do + where(:rgb_array) do + [ + '', + '#000000', + 0, + nil, + [], + [0], + [0, 0], + [0, 0, 0, 0], + [-1, 0, 0], + [0, -1, 0], + [0, 0, -1], + [256, 0, 0], + [0, 256, 0], + [0, 0, 256] + ] + end + + with_them do + it 'raise ArgumentError' do + expect { helper.rgb_array_to_hex_color(rgb_array) }.to raise_error(ArgumentError) + end + end + end + end +end diff --git a/spec/helpers/commits_helper_spec.rb b/spec/helpers/commits_helper_spec.rb index 98db185c180..961e7688202 100644 --- a/spec/helpers/commits_helper_spec.rb +++ b/spec/helpers/commits_helper_spec.rb @@ -163,13 +163,7 @@ RSpec.describe CommitsHelper do end end - let(:params) do - { - page: page - } - end - - subject { helper.conditionally_paginate_diff_files(diffs_collection, paginate: paginate, per: Projects::CommitController::COMMIT_DIFFS_PER_PAGE) } + subject { helper.conditionally_paginate_diff_files(diffs_collection, paginate: paginate, page: page, per: Projects::CommitController::COMMIT_DIFFS_PER_PAGE) } before do allow(helper).to receive(:params).and_return(params) @@ -183,7 +177,7 @@ RSpec.describe CommitsHelper do end it "can change the number of items per page" do - commits = helper.conditionally_paginate_diff_files(diffs_collection, paginate: paginate, per: 10) + commits = helper.conditionally_paginate_diff_files(diffs_collection, page: page, paginate: paginate, per: 10) expect(commits).to be_an(Array) expect(commits.size).to eq(10) diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index 29708f10de4..84e702cd6a9 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -290,6 +290,53 @@ RSpec.describe DiffHelper do end end + describe "#diff_nomappinginraw_line" do + using RSpec::Parameterized::TableSyntax + + let(:line) { double("line") } + let(:line_type) { 'line_type' } + + before do + allow(line).to receive(:rich_text).and_return('line_text') + allow(line).to receive(:type).and_return(line_type) + end + + it 'generates only single line num' do + output = diff_nomappinginraw_line(line, ['line_num_1'], nil, ['line_content']) + + expect(output).to be_html_safe + expect(output).to have_css 'td:nth-child(1).line_num_1' + expect(output).to have_css 'td:nth-child(2).line_content', text: 'line_text' + expect(output).not_to have_css 'td:nth-child(3)' + end + + it 'generates only both line nums' do + output = diff_nomappinginraw_line(line, ['line_num_1'], ['line_num_2'], ['line_content']) + + expect(output).to be_html_safe + expect(output).to have_css 'td:nth-child(1).line_num_1' + expect(output).to have_css 'td:nth-child(2).line_num_2' + expect(output).to have_css 'td:nth-child(3).line_content', text: 'line_text' + end + + where(:line_type, :added_class) do + 'old-nomappinginraw' | '.old' + 'new-nomappinginraw' | '.new' + 'unchanged-nomappinginraw' | '' + end + + with_them do + it "appends the correct class" do + output = diff_nomappinginraw_line(line, ['line_num_1'], ['line_num_2'], ['line_content']) + + expect(output).to be_html_safe + expect(output).to have_css 'td:nth-child(1).line_num_1' + added_class + expect(output).to have_css 'td:nth-child(2).line_num_2' + added_class + expect(output).to have_css 'td:nth-child(3).line_content' + added_class, text: 'line_text' + end + end + end + describe '#render_overflow_warning?' do using RSpec::Parameterized::TableSyntax @@ -378,16 +425,6 @@ RSpec.describe DiffHelper do end end - describe '#diff_file_path_text' do - it 'returns full path by default' do - expect(diff_file_path_text(diff_file)).to eq(diff_file.new_path) - end - - it 'returns truncated path' do - expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb") - end - end - describe "#collapsed_diff_url" do let(:params) do { diff --git a/spec/helpers/environment_helper_spec.rb b/spec/helpers/environment_helper_spec.rb index 8e5f38cd95a..1fcbcd8c4f9 100644 --- a/spec/helpers/environment_helper_spec.rb +++ b/spec/helpers/environment_helper_spec.rb @@ -55,7 +55,7 @@ RSpec.describe EnvironmentHelper do can_destroy_environment: true, can_stop_environment: true, can_admin_environment: true, - environment_metrics_path: environment_metrics_path(environment), + environment_metrics_path: project_metrics_dashboard_path(project, environment: environment), environments_fetch_path: project_environments_path(project, format: :json), environment_edit_path: edit_project_environment_path(project, environment), environment_stop_path: stop_project_environment_path(project, environment), diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb index 38f06b19b94..52f02fba4ec 100644 --- a/spec/helpers/environments_helper_spec.rb +++ b/spec/helpers/environments_helper_spec.rb @@ -20,7 +20,7 @@ RSpec.describe EnvironmentsHelper do expect(metrics_data).to include( 'settings_path' => edit_project_integration_path(project, 'prometheus'), 'clusters_path' => project_clusters_path(project), - 'metrics_dashboard_base_path' => environment_metrics_path(environment), + 'metrics_dashboard_base_path' => project_metrics_dashboard_path(project, environment: environment), 'current_environment_name' => environment.name, 'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'), 'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), diff --git a/spec/helpers/groups/group_members_helper_spec.rb b/spec/helpers/groups/group_members_helper_spec.rb index f5bc587bce3..ab11bc1f5fd 100644 --- a/spec/helpers/groups/group_members_helper_spec.rb +++ b/spec/helpers/groups/group_members_helper_spec.rb @@ -38,7 +38,9 @@ RSpec.describe Groups::GroupMembersHelper do shared_group, members: present_members(members_collection), invited: present_members(invited), - access_requests: present_members(access_requests) + access_requests: present_members(access_requests), + include_relations: [:inherited, :direct], + search: nil ) end @@ -96,6 +98,64 @@ RSpec.describe Groups::GroupMembersHelper do it 'sets `member_path` property' do expect(subject[:group][:member_path]).to eq('/groups/foo-bar/-/group_links/:id') end + + context 'inherited' do + let_it_be(:sub_shared_group) { create(:group, parent: shared_group) } + let_it_be(:sub_shared_with_group) { create(:group) } + let_it_be(:sub_group_group_link) { create(:group_group_link, shared_group: sub_shared_group, shared_with_group: sub_shared_with_group) } + + let_it_be(:subject_group) { sub_shared_group } + + before do + allow(helper).to receive(:group_group_member_path).with(sub_shared_group, ':id').and_return('/groups/foo-bar/-/group_members/:id') + allow(helper).to receive(:group_group_link_path).with(sub_shared_group, ':id').and_return('/groups/foo-bar/-/group_links/:id') + allow(helper).to receive(:can?).with(current_user, :admin_group_member, sub_shared_group).and_return(true) + allow(helper).to receive(:can?).with(current_user, :export_group_memberships, sub_shared_group).and_return(true) + end + + subject do + helper.group_members_app_data( + sub_shared_group, + members: present_members(members_collection), + invited: present_members(invited), + access_requests: present_members(access_requests), + include_relations: include_relations, + search: nil + ) + end + + using RSpec::Parameterized::TableSyntax + + where(:include_relations, :result) do + [:inherited, :direct] | lazy { [group_group_link, sub_group_group_link].map(&:id) } + [:inherited] | lazy { [group_group_link].map(&:id) } + [:direct] | lazy { [sub_group_group_link].map(&:id) } + end + + with_them do + it 'returns correct group links' do + expect(subject[:group][:members].map { |link| link[:id] }).to match_array(result) + end + end + + context 'when group_member_inherited_group disabled' do + before do + stub_feature_flags(group_member_inherited_group: false) + end + + where(:include_relations, :result) do + [:inherited, :direct] | lazy { [sub_group_group_link.id] } + [:inherited] | lazy { [sub_group_group_link.id] } + [:direct] | lazy { [sub_group_group_link.id] } + end + + with_them do + it 'always returns direct member links' do + expect(subject[:group][:members].map { |link| link[:id] }).to match_array(result) + end + end + end + end end context 'when pagination is not available' do diff --git a/spec/helpers/invite_members_helper_spec.rb b/spec/helpers/invite_members_helper_spec.rb index 796d68e290e..859d145eb53 100644 --- a/spec/helpers/invite_members_helper_spec.rb +++ b/spec/helpers/invite_members_helper_spec.rb @@ -19,6 +19,7 @@ RSpec.describe InviteMembersHelper do it 'has expected common attributes' do attributes = { id: project.id, + root_id: project.root_ancestor.id, name: project.name, default_access_level: Gitlab::Access::GUEST, invalid_groups: project.related_group_ids, @@ -35,6 +36,7 @@ RSpec.describe InviteMembersHelper do it 'has expected common attributes' do attributes = { id: project.id, + root_id: project.root_ancestor.id, name: project.name, default_access_level: Gitlab::Access::GUEST } diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index ed50a4daae8..ee5b0145d13 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -288,7 +288,7 @@ RSpec.describe IssuablesHelper do canUpdate: true, canDestroy: true, issuableRef: "##{issue.iid}", - markdownPreviewPath: "/#{@project.full_path}/preview_markdown", + markdownPreviewPath: "/#{@project.full_path}/preview_markdown?target_id=#{issue.iid}&target_type=Issue", markdownDocsPath: '/help/user/markdown', lockVersion: issue.lock_version, projectPath: @project.path, diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index a85b1bd0a48..0f653fdd282 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -74,8 +74,8 @@ RSpec.describe IssuesHelper do expect(helper.award_state_class(awardable, AwardEmoji.all, build(:user))).to eq('disabled') end - it 'returns active string for author' do - expect(helper.award_state_class(awardable, AwardEmoji.all, upvote.user)).to eq('active') + it 'returns selected class for author' do + expect(helper.award_state_class(awardable, AwardEmoji.all, upvote.user)).to eq('selected') end it 'is blank for a user that has access to the awardable' do @@ -368,6 +368,16 @@ RSpec.describe IssuesHelper do end end + describe '#issues_form_data' do + it 'returns expected result' do + expected = { + new_issue_path: new_project_issue_path(project) + } + + expect(helper.issues_form_data(project)).to include(expected) + end + end + describe '#issue_manual_ordering_class' do context 'when sorting by relative position' do before do diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 00aa0fd1cba..52c1130e818 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -268,4 +268,15 @@ RSpec.describe NamespacesHelper do end end end + + describe '#pipeline_usage_quota_app_data' do + it 'returns a hash with necessary data for the frontend' do + expect(helper.pipeline_usage_quota_app_data(user_group)).to eql({ + namespace_actual_plan_name: user_group.actual_plan_name, + namespace_path: user_group.full_path, + namespace_id: user_group.id, + page_size: Kaminari.config.default_per_page + }) + end + end end diff --git a/spec/helpers/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb index d7be4194e67..fc69aee4e04 100644 --- a/spec/helpers/packages_helper_spec.rb +++ b/spec/helpers/packages_helper_spec.rb @@ -65,11 +65,11 @@ RSpec.describe PackagesHelper do end end - describe '#show_cleanup_policy_on_alert' do + describe '#show_cleanup_policy_link' do let_it_be(:user) { create(:user) } let_it_be_with_reload(:container_repository) { create(:container_repository) } - subject { helper.show_cleanup_policy_on_alert(project.reload) } + subject { helper.show_cleanup_policy_link(project.reload) } where(:com, :config_registry, :project_registry, :nil_policy, :container_repositories_exist, :expected_result) do false | false | false | false | false | false diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index 8c13afc2b45..01235c7bb51 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -145,6 +145,67 @@ RSpec.describe PreferencesHelper do end end + describe '#user_diffs_colors' do + context 'with a user' do + it "returns user's diffs colors" do + stub_user(diffs_addition_color: '#123456', diffs_deletion_color: '#abcdef') + + expect(helper.user_diffs_colors).to eq({ addition: '#123456', deletion: '#abcdef' }) + end + + it 'omits property if nil' do + stub_user(diffs_addition_color: '#123456', diffs_deletion_color: nil) + + expect(helper.user_diffs_colors).to eq({ addition: '#123456' }) + end + + it 'omits property if blank' do + stub_user(diffs_addition_color: '', diffs_deletion_color: '#abcdef') + + expect(helper.user_diffs_colors).to eq({ deletion: '#abcdef' }) + end + end + + context 'without a user' do + it 'returns no properties' do + stub_user + + expect(helper.user_diffs_colors).to eq({}) + end + end + end + + describe '#custom_diff_color_classes' do + context 'with a user' do + it 'returns color classes' do + stub_user(diffs_addition_color: '#123456', diffs_deletion_color: '#abcdef') + + expect(helper.custom_diff_color_classes) + .to match_array(%w[diff-custom-addition-color diff-custom-deletion-color]) + end + + it 'omits property if nil' do + stub_user(diffs_addition_color: '#123456', diffs_deletion_color: nil) + + expect(helper.custom_diff_color_classes).to match_array(['diff-custom-addition-color']) + end + + it 'omits property if blank' do + stub_user(diffs_addition_color: '', diffs_deletion_color: '#abcdef') + + expect(helper.custom_diff_color_classes).to match_array(['diff-custom-deletion-color']) + end + end + + context 'without a user' do + it 'returns no classes' do + stub_user + + expect(helper.custom_diff_color_classes).to match_array([]) + end + end + end + describe '#language_choices' do include StubLanguagesTranslationPercentage diff --git a/spec/helpers/projects/alert_management_helper_spec.rb b/spec/helpers/projects/alert_management_helper_spec.rb index 0a5c4bedaa6..a78a8add336 100644 --- a/spec/helpers/projects/alert_management_helper_spec.rb +++ b/spec/helpers/projects/alert_management_helper_spec.rb @@ -110,15 +110,34 @@ RSpec.describe Projects::AlertManagementHelper do describe '#alert_management_detail_data' do let(:alert_id) { 1 } let(:issues_path) { project_issues_path(project) } + let(:can_update_alert) { true } + + before do + allow(helper) + .to receive(:can?) + .with(current_user, :update_alert_management_alert, project) + .and_return(can_update_alert) + end it 'returns detail page configuration' do - expect(helper.alert_management_detail_data(project, alert_id)).to eq( + expect(helper.alert_management_detail_data(current_user, project, alert_id)).to eq( 'alert-id' => alert_id, 'project-path' => project_path, 'project-id' => project_id, 'project-issues-path' => issues_path, - 'page' => 'OPERATIONS' + 'page' => 'OPERATIONS', + 'can-update' => 'true' ) end + + context 'when user cannot update alert' do + let(:can_update_alert) { false } + + it 'shows error tracking enablement as disabled' do + expect(helper.alert_management_detail_data(current_user, project, alert_id)).to include( + 'can-update' => 'false' + ) + end + end end end diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb new file mode 100644 index 00000000000..67405ee3b21 --- /dev/null +++ b/spec/helpers/projects/pipeline_helper_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::PipelineHelper do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:raw_pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id) } + let_it_be(:pipeline) { Ci::PipelinePresenter.new(raw_pipeline, current_user: user)} + + describe '#js_pipeline_tabs_data' do + subject(:pipeline_tabs_data) { helper.js_pipeline_tabs_data(project, pipeline) } + + it 'returns pipeline tabs data' do + expect(pipeline_tabs_data).to include({ + can_generate_codequality_reports: pipeline.can_generate_codequality_reports?.to_json, + graphql_resource_etag: graphql_etag_pipeline_path(pipeline), + metrics_path: namespace_project_ci_prometheus_metrics_histograms_path(namespace_id: project.namespace, project_id: project, format: :json), + pipeline_project_path: project.full_path + }) + end + end +end diff --git a/spec/helpers/projects/security/configuration_helper_spec.rb b/spec/helpers/projects/security/configuration_helper_spec.rb index 4c30ba87897..034bfd27844 100644 --- a/spec/helpers/projects/security/configuration_helper_spec.rb +++ b/spec/helpers/projects/security/configuration_helper_spec.rb @@ -10,4 +10,10 @@ RSpec.describe Projects::Security::ConfigurationHelper do it { is_expected.to eq("https://#{ApplicationHelper.promo_host}/pricing/") } end + + describe 'vulnerability_training_docs_path' do + subject { helper.vulnerability_training_docs_path } + + it { is_expected.to eq(help_page_path('user/application_security/vulnerabilities/index', anchor: 'enable-security-training-for-vulnerabilities')) } + end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 24d908a5dd3..1cf36fd69cf 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1000,6 +1000,54 @@ RSpec.describe ProjectsHelper do end end + context 'fork security helpers' do + using RSpec::Parameterized::TableSyntax + + describe "#able_to_see_merge_requests?" do + subject { helper.able_to_see_merge_requests?(project, user) } + + where(:can_read_merge_request, :merge_requests_enabled, :expected) do + false | false | false + true | false | false + false | true | false + true | true | true + end + + with_them do + before do + allow(project).to receive(:merge_requests_enabled?).and_return(merge_requests_enabled) + allow(helper).to receive(:can?).with(user, :read_merge_request, project).and_return(can_read_merge_request) + end + + it 'returns the correct response' do + expect(subject).to eq(expected) + end + end + end + + describe "#able_to_see_issues?" do + subject { helper.able_to_see_issues?(project, user) } + + where(:can_read_issues, :issues_enabled, :expected) do + false | false | false + true | false | false + false | true | false + true | true | true + end + + with_them do + before do + allow(project).to receive(:issues_enabled?).and_return(issues_enabled) + allow(helper).to receive(:can?).with(user, :read_issue, project).and_return(can_read_issues) + end + + it 'returns the correct response' do + expect(subject).to eq(expected) + end + end + end + end + describe '#fork_button_disabled_tooltip' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/routing/pseudonymization_helper_spec.rb b/spec/helpers/routing/pseudonymization_helper_spec.rb index 1221917e6b7..cf716931fe2 100644 --- a/spec/helpers/routing/pseudonymization_helper_spec.rb +++ b/spec/helpers/routing/pseudonymization_helper_spec.rb @@ -180,7 +180,7 @@ RSpec.describe ::Routing::PseudonymizationHelper do end context 'when some query params are not required to be masked' do - let(:masked_url) { "http://localhost/dashboard/issues?author_username=masked_author_username&scope=all&state=masked_state" } + let(:masked_url) { "http://localhost/dashboard/issues?author_username=masked_author_username&scope=all&state=masked_state&tab=2" } let(:request) do double(:Request, path_parameters: { @@ -189,11 +189,11 @@ RSpec.describe ::Routing::PseudonymizationHelper do }, protocol: 'http', host: 'localhost', - query_string: 'author_username=root&scope=all&state=opened') + query_string: 'author_username=root&scope=all&state=opened&tab=2') end before do - stub_const('Routing::PseudonymizationHelper::MaskHelper::QUERY_PARAMS_TO_NOT_MASK', %w[scope].freeze) + stub_const('Routing::PseudonymizationHelper::MaskHelper::QUERY_PARAMS_TO_NOT_MASK', %w[scope tab].freeze) allow(helper).to receive(:request).and_return(request) end diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 78cc1dcee01..d1be451a759 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -71,7 +71,7 @@ RSpec.describe SearchHelper do create(:group).add_owner(user) result = search_autocomplete_opts("gro").first - expect(result.keys).to match_array(%i[category id label url avatar_url]) + expect(result.keys).to match_array(%i[category id value label url avatar_url]) end it 'includes the users recently viewed issues', :aggregate_failures do @@ -467,6 +467,12 @@ RSpec.describe SearchHelper do describe '#show_user_search_tab?' do subject { show_user_search_tab? } + let(:current_user) { build(:user) } + + before do + allow(self).to receive(:current_user).and_return(current_user) + end + context 'when project search' do before do @project = :some_project @@ -481,20 +487,48 @@ RSpec.describe SearchHelper do end end - context 'when not project search' do + context 'when group search' do + before do + @group = :some_group + end + + context 'when current_user can read_users_list' do + before do + allow(self).to receive(:can?).with(current_user, :read_users_list).and_return(true) + end + + it { is_expected.to eq(true) } + end + + context 'when current_user cannot read_users_list' do + before do + allow(self).to receive(:can?).with(current_user, :read_users_list).and_return(false) + end + + it { is_expected.to eq(false) } + end + end + + context 'when global search' do context 'when current_user can read_users_list' do before do - allow(self).to receive(:current_user).and_return(:the_current_user) - allow(self).to receive(:can?).with(:the_current_user, :read_users_list).and_return(true) + allow(self).to receive(:can?).with(current_user, :read_users_list).and_return(true) end it { is_expected.to eq(true) } + + context 'when global_search_user_tab feature flag is disabled' do + before do + stub_feature_flags(global_search_users_tab: false) + end + + it { is_expected.to eq(false) } + end end context 'when current_user cannot read_users_list' do before do - allow(self).to receive(:current_user).and_return(:the_current_user) - allow(self).to receive(:can?).with(:the_current_user, :read_users_list).and_return(false) + allow(self).to receive(:can?).with(current_user, :read_users_list).and_return(false) end it { is_expected.to eq(false) } diff --git a/spec/helpers/timeboxes_helper_spec.rb b/spec/helpers/timeboxes_helper_spec.rb index 1b9442c0a09..e31f2df7372 100644 --- a/spec/helpers/timeboxes_helper_spec.rb +++ b/spec/helpers/timeboxes_helper_spec.rb @@ -24,34 +24,6 @@ RSpec.describe TimeboxesHelper do end end - describe '#milestone_counts' do - let(:project) { create(:project) } - let(:counts) { helper.milestone_counts(project.milestones) } - - context 'when there are milestones' do - it 'returns the correct counts' do - create_list(:active_milestone, 2, project: project) - create(:closed_milestone, project: project) - - expect(counts).to eq(opened: 2, closed: 1, all: 3) - end - end - - context 'when there are only milestones of one type' do - it 'returns the correct counts' do - create_list(:active_milestone, 2, project: project) - - expect(counts).to eq(opened: 2, closed: 0, all: 2) - end - end - - context 'when there are no milestones' do - it 'returns the correct counts' do - expect(counts).to eq(opened: 0, closed: 0, all: 0) - end - end - end - describe "#group_milestone_route" do let(:group) { build_stubbed(:group) } let(:subgroup) { build_stubbed(:group, parent: group, name: "Test Subgrp") } diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index 0d04ca2b876..5adcbe3334d 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -145,4 +145,8 @@ RSpec.describe WikiHelper do expect(subject).to include('wiki-directory-nest-level' => 0) end end + + it_behaves_like 'wiki endpoint helpers' do + let_it_be(:page) { create(:wiki_page) } + end end -- cgit v1.2.3