diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_settings_helper_spec.rb | 32 | ||||
-rw-r--r-- | spec/helpers/avatars_helper_spec.rb | 14 | ||||
-rw-r--r-- | spec/helpers/ci/runners_helper_spec.rb | 13 | ||||
-rw-r--r-- | spec/helpers/container_expiration_policies_helper_spec.rb | 1 | ||||
-rw-r--r-- | spec/helpers/feature_flags_helper_spec.rb | 23 | ||||
-rw-r--r-- | spec/helpers/groups_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/hooks_helper_spec.rb | 23 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/issues_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/one_trust_helper_spec.rb | 48 | ||||
-rw-r--r-- | spec/helpers/packages_helper_spec.rb | 30 | ||||
-rw-r--r-- | spec/helpers/projects/cluster_agents_helper_spec.rb | 21 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/routing/pseudonymization_helper_spec.rb | 30 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/startupjs_helper_spec.rb | 22 | ||||
-rw-r--r-- | spec/helpers/tab_helper_spec.rb | 54 | ||||
-rw-r--r-- | spec/helpers/time_zone_helper_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/user_callouts_helper_spec.rb | 33 |
19 files changed, 334 insertions, 56 deletions
diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb index ef5f6931d02..3c2ac954fe5 100644 --- a/spec/helpers/application_settings_helper_spec.rb +++ b/spec/helpers/application_settings_helper_spec.rb @@ -158,26 +158,6 @@ RSpec.describe ApplicationSettingsHelper do end end - describe '.show_documentation_base_url_field?' do - subject { helper.show_documentation_base_url_field? } - - before do - stub_feature_flags(help_page_documentation_redirect: feature_flag) - end - - context 'when feature flag is enabled' do - let(:feature_flag) { true } - - it { is_expected.to eq(true) } - end - - context 'when feature flag is disabled' do - let(:feature_flag) { false } - - it { is_expected.to eq(false) } - end - end - describe '.valid_runner_registrars' do subject { helper.valid_runner_registrars } @@ -271,18 +251,6 @@ RSpec.describe ApplicationSettingsHelper do expect(pending_user_count).to eq 1 end end - - context 'when the new_user_signups_cap is not present' do - let(:user_cap) { nil } - - it { is_expected.to eq 0 } - - it 'does not query users unnecessarily' do - expect(User).not_to receive(:blocked_pending_approval) - - pending_user_count - end - end end describe '#sidekiq_job_limiter_modes_for_select' do diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb index 047a6ca0b7d..7190f2fcd4a 100644 --- a/spec/helpers/avatars_helper_spec.rb +++ b/spec/helpers/avatars_helper_spec.rb @@ -7,7 +7,7 @@ RSpec.describe AvatarsHelper do let_it_be(:user) { create(:user) } - describe '#project_icon & #group_icon' do + describe '#project_icon, #group_icon, #topic_icon' do shared_examples 'resource with a default avatar' do |source_type| it 'returns a default avatar div' do expect(public_send("#{source_type}_icon", *helper_args)) @@ -71,6 +71,18 @@ RSpec.describe AvatarsHelper do let(:helper_args) { [resource] } end end + + context 'when providing a topic' do + it_behaves_like 'resource with a default avatar', 'topic' do + let(:resource) { create(:topic, name: 'foo') } + let(:helper_args) { [resource] } + end + + it_behaves_like 'resource with a custom avatar', 'topic' do + let(:resource) { create(:topic, avatar: File.open(uploaded_image_temp_path)) } + let(:helper_args) { [resource] } + end + end end describe '#avatar_icon_for' do diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 0f15f8be0a9..49ea2ac8d3b 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -83,7 +83,7 @@ RSpec.describe Ci::RunnersHelper do data = group_shared_runners_settings_data(group) expect(data[:update_path]).to eq("/api/v4/groups/#{group.id}") - expect(data[:shared_runners_availability]).to eq('disabled_and_unoverridable') + expect(data[:shared_runners_availability]).to eq(Namespace::SR_DISABLED_AND_UNOVERRIDABLE) expect(data[:parent_shared_runners_availability]).to eq('enabled') end end @@ -137,16 +137,15 @@ RSpec.describe Ci::RunnersHelper do using RSpec::Parameterized::TableSyntax where(:shared_runners_setting, :is_disabled_and_unoverridable) do - 'enabled' | "false" - 'disabled_with_override' | "false" - 'disabled_and_unoverridable' | "true" + :shared_runners_enabled | "false" + :disabled_with_override | "false" + :disabled_and_unoverridable | "true" end with_them do it 'returns the override runner status for project with group' do - group = create(:group) - project = create(:project, group: group) - allow(group).to receive(:shared_runners_setting).and_return(shared_runners_setting) + group = create(:group, shared_runners_setting) + project = create(:project, group: group, shared_runners_enabled: false) data = helper.toggle_shared_runners_settings_data(project) expect(data[:is_disabled_and_unoverridable]).to eq(is_disabled_and_unoverridable) diff --git a/spec/helpers/container_expiration_policies_helper_spec.rb b/spec/helpers/container_expiration_policies_helper_spec.rb index 7ad3804e3a9..acb6b017d2c 100644 --- a/spec/helpers/container_expiration_policies_helper_spec.rb +++ b/spec/helpers/container_expiration_policies_helper_spec.rb @@ -40,6 +40,7 @@ RSpec.describe ContainerExpirationPoliciesHelper do { key: '7d', label: '7 days until tags are automatically removed' }, { key: '14d', label: '14 days until tags are automatically removed' }, { key: '30d', label: '30 days until tags are automatically removed' }, + { key: '60d', label: '60 days until tags are automatically removed' }, { key: '90d', label: '90 days until tags are automatically removed', default: true } ] diff --git a/spec/helpers/feature_flags_helper_spec.rb b/spec/helpers/feature_flags_helper_spec.rb index 9a080736595..228459277ca 100644 --- a/spec/helpers/feature_flags_helper_spec.rb +++ b/spec/helpers/feature_flags_helper_spec.rb @@ -3,10 +3,20 @@ require 'spec_helper' RSpec.describe FeatureFlagsHelper do + include Devise::Test::ControllerHelpers + let_it_be(:project) { create(:project) } let_it_be(:feature_flag) { create(:operations_feature_flag, project: project) } let_it_be(:user) { create(:user) } + before do + allow(helper).to receive(:can?).and_return(true) + allow(helper).to receive(:current_user).and_return(user) + + self.instance_variable_set(:@project, project) + self.instance_variable_set(:@feature_flag, feature_flag) + end + describe '#unleash_api_url' do subject { helper.unleash_api_url(project) } @@ -18,4 +28,17 @@ RSpec.describe FeatureFlagsHelper do it { is_expected.not_to be_empty } end + + describe '#edit_feature_flag_data' do + subject { helper.edit_feature_flag_data } + + it 'contains all the data needed to edit feature flags' do + is_expected.to include(endpoint: "/#{project.full_path}/-/feature_flags/#{feature_flag.iid}", + project_id: project.id, + feature_flags_path: "/#{project.full_path}/-/feature_flags", + environments_endpoint: "/#{project.full_path}/-/environments/search.json", + strategy_type_docs_page_path: "/help/operations/feature_flags#feature-flag-strategies", + environments_scope_docs_path: "/help/ci/environments/index.md#scope-environments-with-specs") + end + end end diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 825d5236b5d..4d647696130 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -146,7 +146,7 @@ RSpec.describe GroupsHelper do let(:possible_help_texts) do { - default_help: "This setting will be applied to all subgroups unless overridden by a group owner", + default_help: "Applied to all subgroups unless overridden by a group owner.", ancestor_locked_but_you_can_override: %r{This setting is applied on <a .+>.+</a>\. You can override the setting or .+}, ancestor_locked_so_ask_the_owner: /This setting is applied on .+\. To share projects in this group with another group, ask the owner to override the setting or remove the share with group lock from .+/, ancestor_locked_and_has_been_overridden: /This setting is applied on .+ and has been overridden on this subgroup/ diff --git a/spec/helpers/hooks_helper_spec.rb b/spec/helpers/hooks_helper_spec.rb index 92e082c4974..3b23d705790 100644 --- a/spec/helpers/hooks_helper_spec.rb +++ b/spec/helpers/hooks_helper_spec.rb @@ -6,9 +6,10 @@ RSpec.describe HooksHelper do let(:project) { create(:project) } let(:project_hook) { create(:project_hook, project: project) } let(:system_hook) { create(:system_hook) } - let(:trigger) { 'push_events' } describe '#link_to_test_hook' do + let(:trigger) { 'push_events' } + it 'returns project namespaced link' do expect(helper.link_to_test_hook(project_hook, trigger)) .to include("href=\"#{test_project_hook_path(project, project_hook, trigger: trigger)}\"") @@ -19,4 +20,24 @@ RSpec.describe HooksHelper do .to include("href=\"#{test_admin_hook_path(system_hook, trigger: trigger)}\"") end end + + describe '#hook_log_path' do + context 'with a project hook' do + let(:web_hook_log) { create(:web_hook_log, web_hook: project_hook) } + + it 'returns project-namespaced link' do + expect(helper.hook_log_path(project_hook, web_hook_log)) + .to eq(web_hook_log.present.details_path) + end + end + + context 'with a system hook' do + let(:web_hook_log) { create(:web_hook_log, web_hook: system_hook) } + + it 'returns admin-namespaced link' do + expect(helper.hook_log_path(system_hook, web_hook_log)) + .to eq(admin_hook_hook_log_path(system_hook, web_hook_log)) + end + end + end end diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 3eb3c73cfcc..30049745433 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -133,13 +133,13 @@ RSpec.describe IssuablesHelper do it 'returns navigation with badges' do expect(helper.issuables_state_counter_text(:issues, :opened, true)) - .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">42</span>') + .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">42</span>') expect(helper.issuables_state_counter_text(:issues, :closed, true)) - .to eq('<span>Closed</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">42</span>') + .to eq('<span>Closed</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">42</span>') expect(helper.issuables_state_counter_text(:merge_requests, :merged, true)) - .to eq('<span>Merged</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">42</span>') + .to eq('<span>Merged</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">42</span>') expect(helper.issuables_state_counter_text(:merge_requests, :all, true)) - .to eq('<span>All</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">42</span>') + .to eq('<span>All</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">42</span>') end end @@ -176,7 +176,7 @@ RSpec.describe IssuablesHelper do it 'returns complete count' do expect(helper.issuables_state_counter_text(:issues, :opened, true)) - .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">1,100</span>') + .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">1,100</span>') end end @@ -187,7 +187,7 @@ RSpec.describe IssuablesHelper do it 'returns truncated count' do expect(helper.issuables_state_counter_text(:issues, :opened, true)) - .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm">1.1k</span>') + .to eq('<span>Open</span> <span class="badge badge-muted badge-pill gl-badge gl-tab-counter-badge sm gl-display-none gl-sm-display-inline-flex">1.1k</span>') end end end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index f5f26d306fb..850051c7875 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -354,6 +354,7 @@ RSpec.describe IssuesHelper do let(:group) { create(:group) } let(:current_user) { double.as_null_object } let(:issues) { [] } + let(:projects) { [] } it 'returns expected result' do allow(helper).to receive(:current_user).and_return(current_user) @@ -367,13 +368,14 @@ RSpec.describe IssuesHelper do empty_state_svg_path: '#', full_path: group.full_path, has_any_issues: issues.to_a.any?.to_s, + has_any_projects: any_projects?(projects).to_s, is_signed_in: current_user.present?.to_s, jira_integration_path: help_page_url('integration/jira/issues', anchor: 'view-jira-issues'), rss_path: '#', sign_in_path: new_user_session_path } - expect(helper.group_issues_list_data(group, current_user, issues)).to include(expected) + expect(helper.group_issues_list_data(group, current_user, issues, projects)).to include(expected) end end diff --git a/spec/helpers/one_trust_helper_spec.rb b/spec/helpers/one_trust_helper_spec.rb new file mode 100644 index 00000000000..85c38885304 --- /dev/null +++ b/spec/helpers/one_trust_helper_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe OneTrustHelper do + describe '#one_trust_enabled?' do + let(:user) { nil } + + before do + stub_config(extra: { one_trust_id: SecureRandom.uuid }) + allow(helper).to receive(:current_user).and_return(user) + end + + subject(:one_trust_enabled?) { helper.one_trust_enabled? } + + context 'with ecomm_instrumentation feature flag disabled' do + before do + stub_feature_flags(ecomm_instrumentation: false) + end + + context 'when id is set and no user is set' do + let(:user) { instance_double('User') } + + it { is_expected.to be_falsey } + end + end + + context 'with ecomm_instrumentation feature flag enabled' do + context 'when current user is set' do + let(:user) { instance_double('User') } + + it { is_expected.to be_falsey } + end + + context 'when no id is set' do + before do + stub_config(extra: {}) + end + + it { is_expected.to be_falsey } + end + + context 'when id is set and no user is set' do + it { is_expected.to be_truthy } + end + end + end +end diff --git a/spec/helpers/packages_helper_spec.rb b/spec/helpers/packages_helper_spec.rb index 06c6cccd488..2af572850da 100644 --- a/spec/helpers/packages_helper_spec.rb +++ b/spec/helpers/packages_helper_spec.rb @@ -260,4 +260,34 @@ RSpec.describe PackagesHelper do end end end + + describe '#packages_list_data' do + let_it_be(:resource) { project } + let_it_be(:type) { 'project' } + + let(:expected_result) do + { + resource_id: resource.id, + full_path: resource.full_path, + page_type: type + } + end + + subject(:result) { helper.packages_list_data(type, resource) } + + context 'at a project level' do + it 'populates presenter data' do + expect(result).to match(hash_including(expected_result)) + end + end + + context 'at a group level' do + let_it_be(:resource) { create(:group) } + let_it_be(:type) { 'group' } + + it 'populates presenter data' do + expect(result).to match(hash_including(expected_result)) + end + end + end end diff --git a/spec/helpers/projects/cluster_agents_helper_spec.rb b/spec/helpers/projects/cluster_agents_helper_spec.rb new file mode 100644 index 00000000000..2935a74586b --- /dev/null +++ b/spec/helpers/projects/cluster_agents_helper_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::ClusterAgentsHelper do + describe '#js_cluster_agent_details_data' do + let_it_be(:project) { create(:project) } + + let(:agent_name) { 'agent-name' } + + subject { helper.js_cluster_agent_details_data(agent_name, project) } + + it 'returns name' do + expect(subject[:agent_name]).to eq(agent_name) + end + + it 'returns project path' do + expect(subject[:project_path]).to eq(project.full_path) + end + end +end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 85b572d3f68..1100f4a3ad5 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -314,13 +314,13 @@ RSpec.describe ProjectsHelper do end it 'returns image tag for member avatar' do - expect(helper).to receive(:image_tag).with(expected, { width: 16, class: %w[avatar avatar-inline s16], alt: "", "data-src" => anything }) + expect(helper).to receive(:image_tag).with(expected, { width: 16, class: %w[avatar avatar-inline s16], alt: "" }) helper.link_to_member_avatar(user) end it 'returns image tag with avatar class' do - expect(helper).to receive(:image_tag).with(expected, { width: 16, class: %w[avatar avatar-inline s16 any-avatar-class], alt: "", "data-src" => anything }) + expect(helper).to receive(:image_tag).with(expected, { width: 16, class: %w[avatar avatar-inline s16 any-avatar-class], alt: "" }) helper.link_to_member_avatar(user, avatar_class: "any-avatar-class") end @@ -904,6 +904,14 @@ RSpec.describe ProjectsHelper do it { is_expected.to be_falsey } end + + context 'the :show_terraform_banner feature flag is disabled' do + before do + stub_feature_flags(show_terraform_banner: false) + end + + it { is_expected.to be_falsey } + end end end diff --git a/spec/helpers/routing/pseudonymization_helper_spec.rb b/spec/helpers/routing/pseudonymization_helper_spec.rb index 10563502555..a28a86d1f53 100644 --- a/spec/helpers/routing/pseudonymization_helper_spec.rb +++ b/spec/helpers/routing/pseudonymization_helper_spec.rb @@ -6,6 +6,7 @@ RSpec.describe ::Routing::PseudonymizationHelper do let_it_be(:group) { create(:group) } let_it_be(:subgroup) { create(:group, parent: group) } let_it_be(:project) { create(:project, group: group) } + let_it_be(:subproject) { create(:project, group: subgroup) } let_it_be(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, source_project: project) } @@ -56,16 +57,16 @@ RSpec.describe ::Routing::PseudonymizationHelper do end context 'with controller for groups with subgroups and project' do - let(:masked_url) { "http://test.host/namespace:#{subgroup.id}/project:#{project.id}"} + let(:masked_url) { "http://test.host/namespace:#{subgroup.id}/project:#{subproject.id}"} before do allow(helper).to receive(:group).and_return(subgroup) - allow(helper.project).to receive(:namespace).and_return(subgroup) + allow(helper).to receive(:project).and_return(subproject) allow(Rails.application.routes).to receive(:recognize_path).and_return({ controller: 'projects', action: 'show', namespace_id: subgroup.name, - id: project.name + id: subproject.name }) end @@ -129,6 +130,29 @@ RSpec.describe ::Routing::PseudonymizationHelper do end end + describe 'when it raises exception' do + context 'calls error tracking' do + before do + controller.request.path = '/dashboard/issues' + controller.request.query_string = 'assignee_username=root' + allow(Rails.application.routes).to receive(:recognize_path).and_return({ + controller: 'dashboard', + action: 'issues' + }) + end + + it 'sends error to sentry and returns nil' do + allow(helper).to receive(:mask_params).with(anything).and_raise(ActionController::RoutingError, 'Some routing error') + + expect(Gitlab::ErrorTracking).to receive(:track_exception).with( + ActionController::RoutingError, + url: '/dashboard/issues?assignee_username=root').and_call_original + + expect(helper.masked_page_url).to be_nil + end + end + end + describe 'when feature flag is disabled' do before do stub_feature_flags(mask_page_urls: false) diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 7b2334ab79e..9e870658870 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -248,13 +248,13 @@ RSpec.describe SearchHelper do it 'uses the correct singular label' do collection = Kaminari.paginate_array([:foo]).page(1).per(10) - expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 #{label} for<span> <code>foo</code> </span>") + expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 #{label} for <span> <code>foo</code> </span>") end it 'uses the correct plural label' do collection = Kaminari.paginate_array([:foo] * 23).page(1).per(10) - expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 - 10 of 23 #{label.pluralize} for<span> <code>foo</code> </span>") + expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 - 10 of 23 #{label.pluralize} for <span> <code>foo</code> </span>") end end diff --git a/spec/helpers/startupjs_helper_spec.rb b/spec/helpers/startupjs_helper_spec.rb index 6d61c38d4a5..8d429b59291 100644 --- a/spec/helpers/startupjs_helper_spec.rb +++ b/spec/helpers/startupjs_helper_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe StartupjsHelper do + using RSpec::Parameterized::TableSyntax + describe '#page_startup_graphql_calls' do let(:query_location) { 'repository/path_last_commit' } let(:query_content) do @@ -17,4 +19,24 @@ RSpec.describe StartupjsHelper do expect(startup_graphql_calls).to include({ query: query_content, variables: { ref: 'foo' } }) end end + + describe '#page_startup_graphql_headers' do + where(:csrf_token, :feature_category, :expected) do + 'abc' | 'web_ide' | { 'X-CSRF-Token' => 'abc', 'x-gitlab-feature-category' => 'web_ide' } + '' | '' | { 'X-CSRF-Token' => '', 'x-gitlab-feature-category' => '' } + 'abc' | nil | { 'X-CSRF-Token' => 'abc', 'x-gitlab-feature-category' => '' } + 'something' | ' ' | { 'X-CSRF-Token' => 'something', 'x-gitlab-feature-category' => '' } + end + + with_them do + before do + allow(helper).to receive(:form_authenticity_token).and_return(csrf_token) + ::Gitlab::ApplicationContext.push(feature_category: feature_category) + end + + it 'returns hash of headers for GraphQL requests' do + expect(helper.page_startup_graphql_headers).to eq(expected) + end + end + end end diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb index bd8a8fa174a..346bfc7850c 100644 --- a/spec/helpers/tab_helper_spec.rb +++ b/spec/helpers/tab_helper_spec.rb @@ -5,6 +5,60 @@ require 'spec_helper' RSpec.describe TabHelper do include ApplicationHelper + describe 'gl_tabs_nav' do + it 'creates a tabs navigation' do + expect(gl_tabs_nav).to match(%r{<ul class=".*" role="tablist"><\/ul>}) + end + + it 'captures block output' do + expect(gl_tabs_nav { "block content" }).to match(/block content/) + end + + it 'adds styles classes' do + expect(gl_tabs_nav).to match(/class="nav gl-tabs-nav"/) + end + + it 'adds custom class' do + expect(gl_tabs_nav(class: 'my-class' )).to match(/class=".*my-class.*"/) + end + end + + describe 'gl_tab_link_to' do + before do + allow(self).to receive(:current_page?).and_return(false) + end + + it 'creates a tab' do + expect(gl_tab_link_to('Link', '/url')).to eq('<li class="nav-item" role="presentation"><a class="nav-link gl-tab-nav-item" href="/url">Link</a></li>') + end + + it 'creates a tab with block output' do + expect(gl_tab_link_to('/url') { 'block content' }).to match(/block content/) + end + + it 'creates a tab with custom classes' do + expect(gl_tab_link_to('Link', '/url', { class: 'my-class' })).to match(/<a class=".*my-class.*"/) + end + + it 'creates an active tab with item_active = true' do + expect(gl_tab_link_to('Link', '/url', { item_active: true })).to match(/<a class=".*active gl-tab-nav-item-active gl-tab-nav-item-active-indigo.*"/) + end + + context 'when on the active page' do + before do + allow(self).to receive(:current_page?).and_return(true) + end + + it 'creates an active tab' do + expect(gl_tab_link_to('Link', '/url')).to match(/<a class=".*active gl-tab-nav-item-active gl-tab-nav-item-active-indigo.*"/) + end + + it 'creates an inactive tab with item_active = false' do + expect(gl_tab_link_to('Link', '/url', { item_active: false })).not_to match(/<a class=".*active.*"/) + end + end + end + describe 'nav_link' do using RSpec::Parameterized::TableSyntax diff --git a/spec/helpers/time_zone_helper_spec.rb b/spec/helpers/time_zone_helper_spec.rb index e6cb20b5800..43ad130c4b5 100644 --- a/spec/helpers/time_zone_helper_spec.rb +++ b/spec/helpers/time_zone_helper_spec.rb @@ -76,6 +76,18 @@ RSpec.describe TimeZoneHelper, :aggregate_failures do travel_to Time.find_zone(timezone).local(2021, 7, 20, 15, 30, 45) end + context 'when timezone is `nil`' do + it 'returns `nil`' do + expect(helper.local_time(nil)).to eq(nil) + end + end + + context 'when timezone is blank' do + it 'returns `nil`' do + expect(helper.local_time('')).to eq(nil) + end + end + context 'when a valid timezone is passed' do it 'returns local time' do expect(helper.local_time(timezone)).to eq('3:30 PM') diff --git a/spec/helpers/user_callouts_helper_spec.rb b/spec/helpers/user_callouts_helper_spec.rb index 794ff5ee945..f738ba855b8 100644 --- a/spec/helpers/user_callouts_helper_spec.rb +++ b/spec/helpers/user_callouts_helper_spec.rb @@ -293,4 +293,37 @@ RSpec.describe UserCalloutsHelper do it { is_expected.to eq(false) } end end + + describe '.show_security_newsletter_user_callout?' do + let_it_be(:admin) { create(:user, :admin) } + + subject { helper.show_security_newsletter_user_callout? } + + context 'when `current_user` is not an admin' do + before do + allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive(:user_dismissed?).with(described_class::SECURITY_NEWSLETTER_CALLOUT) { false } + end + + it { is_expected.to be false } + end + + context 'when user has dismissed callout' do + before do + allow(helper).to receive(:current_user).and_return(admin) + allow(helper).to receive(:user_dismissed?).with(described_class::SECURITY_NEWSLETTER_CALLOUT) { true } + end + + it { is_expected.to be false } + end + + context 'when `current_user` is an admin and user has not dismissed callout' do + before do + allow(helper).to receive(:current_user).and_return(admin) + allow(helper).to receive(:user_dismissed?).with(described_class::SECURITY_NEWSLETTER_CALLOUT) { false } + end + + it { is_expected.to be true } + end + end end |