Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/application_helper_spec.rb2
-rw-r--r--spec/helpers/application_settings_helper_spec.rb9
-rw-r--r--spec/helpers/avatars_helper_spec.rb47
-rw-r--r--spec/helpers/bizible_helper_spec.rb47
-rw-r--r--spec/helpers/ci/pipeline_editor_helper_spec.rb11
-rw-r--r--spec/helpers/clusters_helper_spec.rb8
-rw-r--r--spec/helpers/invite_members_helper_spec.rb40
-rw-r--r--spec/helpers/issuables_description_templates_helper_spec.rb31
-rw-r--r--spec/helpers/issuables_helper_spec.rb10
-rw-r--r--spec/helpers/issues_helper_spec.rb12
-rw-r--r--spec/helpers/listbox_helper_spec.rb75
-rw-r--r--spec/helpers/projects/cluster_agents_helper_spec.rb29
-rw-r--r--spec/helpers/projects_helper_spec.rb30
-rw-r--r--spec/helpers/search_helper_spec.rb148
-rw-r--r--spec/helpers/ssh_keys_helper_spec.rb6
-rw-r--r--spec/helpers/storage_helper_spec.rb83
-rw-r--r--spec/helpers/tab_helper_spec.rb4
-rw-r--r--spec/helpers/users_helper_spec.rb38
18 files changed, 592 insertions, 38 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 8c2b4b16075..e6a2e3f8211 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -289,7 +289,7 @@ RSpec.describe ApplicationHelper do
it 'returns paths for autocomplete_sources_controller' do
sources = helper.autocomplete_data_sources(project, noteable_type)
- expect(sources.keys).to match_array([:members, :issues, :mergeRequests, :labels, :milestones, :commands, :snippets])
+ expect(sources.keys).to match_array([:members, :issues, :mergeRequests, :labels, :milestones, :commands, :snippets, :contacts])
sources.keys.each do |key|
expect(sources[key]).not_to be_nil
end
diff --git a/spec/helpers/application_settings_helper_spec.rb b/spec/helpers/application_settings_helper_spec.rb
index e722f301522..169b1c75995 100644
--- a/spec/helpers/application_settings_helper_spec.rb
+++ b/spec/helpers/application_settings_helper_spec.rb
@@ -46,6 +46,15 @@ RSpec.describe ApplicationSettingsHelper do
expect(helper.visible_attributes).to include(:deactivate_dormant_users)
end
+ it 'contains rate limit parameters' do
+ expect(helper.visible_attributes).to include(*%i(
+ 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
+ ))
+ end
+
context 'when GitLab.com' do
before do
allow(Gitlab).to receive(:com?).and_return(true)
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb
index 7190f2fcd4a..192e48f43e5 100644
--- a/spec/helpers/avatars_helper_spec.rb
+++ b/spec/helpers/avatars_helper_spec.rb
@@ -146,11 +146,52 @@ RSpec.describe AvatarsHelper do
describe '#avatar_icon_for_user' do
let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) }
+ shared_examples 'blocked or unconfirmed user with avatar' do
+ context 'when the viewer is not an admin' do
+ let!(:viewing_user) { create(:user) }
+
+ it 'returns the default avatar' do
+ expect(helper.avatar_icon_for_user(user, current_user: viewing_user).to_s)
+ .to match_asset_path(described_class::DEFAULT_AVATAR_PATH)
+ end
+ end
+
+ context 'when the viewer is an admin', :enable_admin_mode do
+ let!(:viewing_user) { create(:user, :admin) }
+
+ it 'returns the default avatar when the user is not passed' do
+ expect(helper.avatar_icon_for_user(user).to_s)
+ .to match_asset_path(described_class::DEFAULT_AVATAR_PATH)
+ end
+
+ it 'returns the user avatar when the user is passed' do
+ expect(helper.avatar_icon_for_user(user, current_user: viewing_user).to_s)
+ .to eq(user.avatar.url)
+ end
+ end
+ end
+
context 'with a user object passed' do
it 'returns a relative URL for the avatar' do
expect(helper.avatar_icon_for_user(user).to_s)
.to eq(user.avatar.url)
end
+
+ context 'when the user is blocked' do
+ before do
+ user.block!
+ end
+
+ it_behaves_like 'blocked or unconfirmed user with avatar'
+ end
+
+ context 'when the user is unconfirmed' do
+ before do
+ user.update!(confirmed_at: nil)
+ end
+
+ it_behaves_like 'blocked or unconfirmed user with avatar'
+ end
end
context 'without a user object passed' do
@@ -171,7 +212,7 @@ RSpec.describe AvatarsHelper do
end
it 'returns a generic avatar' do
- expect(helper.gravatar_icon(user_email)).to match_asset_path('no_avatar.png')
+ expect(helper.gravatar_icon(user_email)).to match_asset_path(described_class::DEFAULT_AVATAR_PATH)
end
end
@@ -181,7 +222,7 @@ RSpec.describe AvatarsHelper do
end
it 'returns a generic avatar when email is blank' do
- expect(helper.gravatar_icon('')).to match_asset_path('no_avatar.png')
+ expect(helper.gravatar_icon('')).to match_asset_path(described_class::DEFAULT_AVATAR_PATH)
end
it 'returns a valid Gravatar URL' do
@@ -428,7 +469,7 @@ RSpec.describe AvatarsHelper do
subject { helper.avatar_without_link(resource, options) }
context 'with users' do
- let(:resource) { user }
+ let(:resource) { user.namespace }
it 'displays user avatar' do
is_expected.to eq tag(
diff --git a/spec/helpers/bizible_helper_spec.rb b/spec/helpers/bizible_helper_spec.rb
new file mode 100644
index 00000000000..b82211d51ec
--- /dev/null
+++ b/spec/helpers/bizible_helper_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe BizibleHelper do
+ describe '#bizible_enabled?' do
+ before do
+ stub_config(extra: { bizible: SecureRandom.uuid })
+ end
+
+ context 'when bizible is disabled' do
+ before do
+ allow(helper).to receive(:bizible_enabled?).and_return(false)
+ end
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when bizible is enabled' do
+ before do
+ allow(helper).to receive(:bizible_enabled?).and_return(true)
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ subject(:bizible_enabled?) { helper.bizible_enabled? }
+
+ context 'with ecomm_instrumentation feature flag disabled' do
+ before do
+ stub_feature_flags(ecomm_instrumentation: false)
+ end
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'with ecomm_instrumentation feature flag enabled' do
+ context 'when no id is set' do
+ before do
+ stub_config(extra: {})
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+ end
+end
diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb
index b15569f03c7..b844cc2e22b 100644
--- a/spec/helpers/ci/pipeline_editor_helper_spec.rb
+++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb
@@ -88,6 +88,17 @@ RSpec.describe Ci::PipelineEditorHelper do
end
end
+ context 'with a project with no repository' do
+ let(:project) { create(:project) }
+
+ it 'returns pipeline editor data' do
+ expect(pipeline_editor_data).to include({
+ "pipeline_etag" => '',
+ "total-branches" => 0
+ })
+ end
+ end
+
context 'with a non-default branch name' do
let(:user) { create(:user) }
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb
index 51f111917d1..18d233fcd63 100644
--- a/spec/helpers/clusters_helper_spec.rb
+++ b/spec/helpers/clusters_helper_spec.rb
@@ -93,8 +93,9 @@ RSpec.describe ClustersHelper do
end
context 'user has no permissions to create a cluster' do
- it 'displays that user can\t add cluster' do
+ it 'displays that user can\'t add cluster' do
expect(subject[:can_add_cluster]).to eq("false")
+ expect(subject[:can_admin_cluster]).to eq("false")
end
end
@@ -105,6 +106,7 @@ RSpec.describe ClustersHelper do
it 'displays that the user can add cluster' do
expect(subject[:can_add_cluster]).to eq("true")
+ expect(subject[:can_admin_cluster]).to eq("true")
end
end
@@ -150,6 +152,10 @@ RSpec.describe ClustersHelper do
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
end
describe '#js_cluster_new' do
diff --git a/spec/helpers/invite_members_helper_spec.rb b/spec/helpers/invite_members_helper_spec.rb
index d8a97b93bc9..6a854a65920 100644
--- a/spec/helpers/invite_members_helper_spec.rb
+++ b/spec/helpers/invite_members_helper_spec.rb
@@ -15,6 +15,22 @@ RSpec.describe InviteMembersHelper do
helper.extend(Gitlab::Experimentation::ControllerConcern)
end
+ describe '#common_invite_group_modal_data' do
+ it 'has expected common attributes' do
+ attributes = {
+ id: project.id,
+ name: project.name,
+ default_access_level: Gitlab::Access::GUEST,
+ invalid_groups: project.related_group_ids,
+ help_link: help_page_url('user/permissions'),
+ is_project: 'true',
+ access_levels: ProjectMember.access_level_roles.to_json
+ }
+
+ expect(helper.common_invite_group_modal_data(project, ProjectMember, 'true')).to include(attributes)
+ end
+ end
+
describe '#common_invite_modal_dataset' do
it 'has expected common attributes' do
attributes = {
@@ -155,4 +171,28 @@ RSpec.describe InviteMembersHelper do
end
end
end
+
+ describe '#group_select_data' do
+ let_it_be(:group) { create(:group) }
+
+ context 'when sharing with groups outside the hierarchy is disabled' do
+ before do
+ group.namespace_settings.update!(prevent_sharing_groups_outside_hierarchy: true)
+ end
+
+ it 'provides the correct attributes' do
+ expect(helper.group_select_data(group)).to eq({ groups_filter: 'descendant_groups', parent_id: group.id })
+ end
+ end
+
+ context 'when sharing with groups outside the hierarchy is enabled' do
+ before do
+ group.namespace_settings.update!(prevent_sharing_groups_outside_hierarchy: false)
+ end
+
+ it 'returns an empty hash' do
+ expect(helper.group_select_data(project.group)).to eq({})
+ end
+ end
+ end
end
diff --git a/spec/helpers/issuables_description_templates_helper_spec.rb b/spec/helpers/issuables_description_templates_helper_spec.rb
index 6b05bab7432..768ce5975c1 100644
--- a/spec/helpers/issuables_description_templates_helper_spec.rb
+++ b/spec/helpers/issuables_description_templates_helper_spec.rb
@@ -72,6 +72,37 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
].to_json
expect(helper.available_service_desk_templates_for(@project)).to eq(value)
end
+
+ context 'when no issuable_template parameter or default template is present' do
+ it 'does not select a template' do
+ expect(helper.selected_template(project)).to be(nil)
+ end
+ end
+
+ context 'when an issuable_template parameter has been provided' do
+ before do
+ allow(helper).to receive(:params).and_return({ issuable_template: 'another_issue_template' })
+ end
+
+ it 'selects the issuable template' do
+ expect(helper.selected_template(project)).to eq('another_issue_template')
+ end
+ end
+
+ context 'when there is a default template' do
+ let(:templates) do
+ {
+ "" => [
+ { name: "another_issue_template", id: "another_issue_template", project_id: project.id },
+ { name: "default", id: "default", project_id: project.id }
+ ]
+ }
+ end
+
+ it 'selects the default template' do
+ expect(helper.selected_template(project)).to eq('default')
+ end
+ end
end
context 'when there are not templates in the project' do
diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb
index fa19395ebc7..ed50a4daae8 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 gl-display-none gl-sm-display-inline-flex">42</span>')
+ .to eq('<span>Open</span> <span class="gl-badge badge badge-pill badge-muted sm gl-tab-counter-badge 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 gl-display-none gl-sm-display-inline-flex">42</span>')
+ .to eq('<span>Closed</span> <span class="gl-badge badge badge-pill badge-muted sm gl-tab-counter-badge 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 gl-display-none gl-sm-display-inline-flex">42</span>')
+ .to eq('<span>Merged</span> <span class="gl-badge badge badge-pill badge-muted sm gl-tab-counter-badge 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 gl-display-none gl-sm-display-inline-flex">42</span>')
+ .to eq('<span>All</span> <span class="gl-badge badge badge-pill badge-muted sm gl-tab-counter-badge gl-display-none gl-sm-display-inline-flex">42</span>')
end
end
@@ -171,7 +171,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 gl-display-none gl-sm-display-inline-flex">1.1k</span>')
+ .to eq('<span>Open</span> <span class="gl-badge badge badge-pill badge-muted sm gl-tab-counter-badge 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 065ac526ae4..2f57657736d 100644
--- a/spec/helpers/issues_helper_spec.rb
+++ b/spec/helpers/issues_helper_spec.rb
@@ -300,6 +300,7 @@ RSpec.describe IssuesHelper do
has_any_issues: project_issues(project).exists?.to_s,
import_csv_issues_path: '#',
initial_email: project.new_issuable_address(current_user, 'issue'),
+ initial_sort: current_user&.user_preference&.issues_sort,
is_anonymous_search_disabled: 'true',
is_issue_repositioning_disabled: 'true',
is_project: 'true',
@@ -342,8 +343,6 @@ RSpec.describe IssuesHelper do
describe '#group_issues_list_data' 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)
@@ -351,20 +350,23 @@ RSpec.describe IssuesHelper do
allow(helper).to receive(:image_path).and_return('#')
allow(helper).to receive(:url_for).and_return('#')
+ assign(:has_issues, false)
+ assign(:has_projects, true)
+
expected = {
autocomplete_award_emojis_path: autocomplete_award_emojis_path,
calendar_path: '#',
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,
+ has_any_issues: false.to_s,
+ has_any_projects: true.to_s,
is_signed_in: current_user.present?.to_s,
jira_integration_path: help_page_url('integration/jira/issues', anchor: 'view-jira-issues'),
rss_path: '#',
sign_in_path: new_user_session_path
}
- expect(helper.group_issues_list_data(group, current_user, issues, projects)).to include(expected)
+ expect(helper.group_issues_list_data(group, current_user)).to include(expected)
end
end
diff --git a/spec/helpers/listbox_helper_spec.rb b/spec/helpers/listbox_helper_spec.rb
new file mode 100644
index 00000000000..8935d69d4f7
--- /dev/null
+++ b/spec/helpers/listbox_helper_spec.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ListboxHelper do
+ subject do
+ tag = helper.gl_redirect_listbox_tag(items, selected, html_options)
+ Nokogiri::HTML.fragment(tag).children.first
+ end
+
+ before do
+ allow(helper).to receive(:sprite_icon).with(
+ 'chevron-down',
+ css_class: 'gl-button-icon dropdown-chevron gl-icon'
+ ).and_return('<span class="icon"></span>'.html_safe)
+ end
+
+ let(:selected) { 'bar' }
+ let(:html_options) { {} }
+ let(:items) do
+ [
+ { value: 'foo', text: 'Foo' },
+ { value: 'bar', text: 'Bar' }
+ ]
+ end
+
+ describe '#gl_redirect_listbox_tag' do
+ it 'creates root element with expected classes' do
+ expect(subject.classes).to include(*%w[
+ dropdown
+ b-dropdown
+ gl-new-dropdown
+ btn-group
+ js-redirect-listbox
+ ])
+ end
+
+ it 'sets data attributes for items and selected' do
+ expect(subject.attributes['data-items'].value).to eq(items.to_json)
+ expect(subject.attributes['data-selected'].value).to eq(selected)
+ end
+
+ it 'adds styled button' do
+ expect(subject.at_css('button').classes).to include(*%w[
+ btn
+ dropdown-toggle
+ btn-default
+ btn-md
+ gl-button
+ gl-dropdown-toggle
+ ])
+ end
+
+ it 'sets button text to selected item' do
+ expect(subject.at_css('button').content).to eq('Bar')
+ end
+
+ context 'given html_options' do
+ let(:html_options) { { class: 'test-class', data: { qux: 'qux' } } }
+
+ it 'applies them to the root element' do
+ expect(subject.attributes['data-qux'].value).to eq('qux')
+ expect(subject.classes).to include('test-class')
+ end
+ end
+
+ context 'when selected does not match any item' do
+ let(:selected) { 'qux' }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(ArgumentError, /cannot find qux/)
+ end
+ end
+ end
+end
diff --git a/spec/helpers/projects/cluster_agents_helper_spec.rb b/spec/helpers/projects/cluster_agents_helper_spec.rb
index 632544797ee..d94a5fa9f8a 100644
--- a/spec/helpers/projects/cluster_agents_helper_spec.rb
+++ b/spec/helpers/projects/cluster_agents_helper_spec.rb
@@ -5,22 +5,29 @@ require 'spec_helper'
RSpec.describe Projects::ClusterAgentsHelper do
describe '#js_cluster_agent_details_data' do
let_it_be(:project) { create(:project) }
+ let_it_be(:current_user) { create(:user) }
+ let(:user_can_admin_vulerability) { true }
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)
+ before do
+ allow(helper).to receive(:current_user).and_return(current_user)
+ allow(helper)
+ .to receive(:can?)
+ .with(current_user, :admin_vulnerability, project)
+ .and_return(user_can_admin_vulerability)
end
- it 'returns project path' do
- expect(subject[:project_path]).to eq(project.full_path)
- end
+ subject { helper.js_cluster_agent_details_data(agent_name, project) }
- it 'returns string contants' do
- expect(subject[:activity_empty_state_image]).to be_kind_of(String)
- expect(subject[:empty_state_svg_path]).to be_kind_of(String)
- end
+ it {
+ is_expected.to match({
+ agent_name: agent_name,
+ project_path: project.full_path,
+ activity_empty_state_image: kind_of(String),
+ empty_state_svg_path: kind_of(String),
+ can_admin_vulnerability: "true"
+ })
+ }
end
end
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index cc443afee6e..604ce0fe0c1 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -345,6 +345,14 @@ RSpec.describe ProjectsHelper do
expect(link).not_to include(user.name)
end
end
+
+ context 'when user is nil' do
+ it 'returns "(deleted)"' do
+ link = helper.link_to_member(project, nil)
+
+ expect(link).to eq("(deleted)")
+ end
+ end
end
describe 'default_clone_protocol' do
@@ -1018,4 +1026,26 @@ RSpec.describe ProjectsHelper do
end
end
end
+
+ describe '#import_from_bitbucket_message' do
+ before do
+ allow(helper).to receive(:current_user).and_return(user)
+ end
+
+ context 'as a user' 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')
+ end
+ end
+
+ context 'as an administrator' 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')
+ end
+ end
+ end
end
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index 40cfdafc9ac..78cc1dcee01 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -658,4 +658,152 @@ RSpec.describe SearchHelper do
expect(search_sort_options).to eq(mock_created_sort)
end
end
+
+ describe '#header_search_context' do
+ let(:user) { create(:user) }
+ let(:can_download) { false }
+
+ let(:for_group) { false }
+ let(:group) { nil }
+ let(:group_metadata) { nil }
+
+ let(:for_project) { false }
+ let(:project) { nil }
+ let(:project_metadata) { nil }
+
+ let(:scope) { nil }
+ let(:code_search) { false }
+ let(:ref) { nil }
+ let(:for_snippets) { false }
+
+ let(:search_context) do
+ instance_double(Gitlab::SearchContext,
+ group: group,
+ group_metadata: group_metadata,
+ project: project,
+ project_metadata: project_metadata,
+ scope: scope,
+ ref: ref)
+ end
+
+ before do
+ allow(self).to receive(:search_context).and_return(search_context)
+ allow(self).to receive(:current_user).and_return(user)
+ allow(self).to receive(:can?).and_return(can_download)
+
+ allow(search_context).to receive(:for_group?).and_return(for_group)
+ allow(search_context).to receive(:for_project?).and_return(for_project)
+
+ allow(search_context).to receive(:code_search?).and_return(code_search)
+ allow(search_context).to receive(:for_snippets?).and_return(for_snippets)
+ end
+
+ context 'group data' do
+ let(:group) { create(:group) }
+ let(:group_metadata) { { group_path: group.path, issues_path: "/issues" } }
+ let(:scope) { 'issues' }
+ let(:code_search) { true }
+
+ context 'when for_group? is true' do
+ let(:for_group) { true }
+
+ it 'adds the :group and :group_metadata correctly to hash' do
+ expect(header_search_context[:group]).to eq({ id: group.id, name: group.name })
+ expect(header_search_context[:group_metadata]).to eq(group_metadata)
+ end
+
+ it 'adds scope and code_search? correctly to hash' do
+ expect(header_search_context[:scope]).to eq(scope)
+ expect(header_search_context[:code_search]).to eq(code_search)
+ end
+ end
+
+ context 'when for_group? is false' do
+ let(:for_group) { false }
+
+ it 'does not add the :group and :group_metadata to hash' do
+ expect(header_search_context[:group]).to eq(nil)
+ expect(header_search_context[:group_metadata]).to eq(nil)
+ end
+
+ it 'does not add scope and code_search? to hash' do
+ expect(header_search_context[:scope]).to eq(nil)
+ expect(header_search_context[:code_search]).to eq(nil)
+ end
+ end
+ end
+
+ context 'project data' do
+ let(:project) { create(:project) }
+ let(:project_metadata) { { project_path: project.path, issues_path: "/issues" } }
+ let(:scope) { 'issues' }
+ let(:code_search) { true }
+
+ context 'when for_project? is true' do
+ let(:for_project) { true }
+
+ it 'adds the :project and :project_metadata correctly to hash' do
+ expect(header_search_context[:project]).to eq({ id: project.id, name: project.name })
+ expect(header_search_context[:project_metadata]).to eq(project_metadata)
+ end
+
+ it 'adds scope and code_search? correctly to hash' do
+ expect(header_search_context[:scope]).to eq(scope)
+ expect(header_search_context[:code_search]).to eq(code_search)
+ end
+ end
+
+ context 'when for_project? is false' do
+ let(:for_project) { false }
+
+ it 'does not add the :project and :project_metadata to hash' do
+ expect(header_search_context[:project]).to eq(nil)
+ expect(header_search_context[:project_metadata]).to eq(nil)
+ end
+
+ it 'does not add scope and code_search? to hash' do
+ expect(header_search_context[:scope]).to eq(nil)
+ expect(header_search_context[:code_search]).to eq(nil)
+ end
+ end
+ end
+
+ context 'ref data' do
+ let(:ref) { 'test-branch' }
+
+ context 'when user can? download project data' do
+ let(:can_download) { true }
+
+ it 'adds the :ref correctly to hash' do
+ expect(header_search_context[:ref]).to eq(ref)
+ end
+ end
+
+ context 'when user cannot download project data' do
+ let(:can_download) { false }
+
+ it 'does not add the :ref to hash' do
+ expect(header_search_context[:ref]).to eq(nil)
+ end
+ end
+ end
+
+ context 'snippets' do
+ context 'when for_snippets? is true' do
+ let(:for_snippets) { true }
+
+ it 'adds :for_snippets correctly to hash' do
+ expect(header_search_context[:for_snippets]).to eq(for_snippets)
+ end
+ end
+
+ context 'when for_snippets? is false' do
+ let(:for_snippets) { false }
+
+ it 'adds :for_snippets correctly to hash' do
+ expect(header_search_context[:for_snippets]).to eq(for_snippets)
+ end
+ end
+ end
+ end
end
diff --git a/spec/helpers/ssh_keys_helper_spec.rb b/spec/helpers/ssh_keys_helper_spec.rb
index 1aa604f19be..522331090e4 100644
--- a/spec/helpers/ssh_keys_helper_spec.rb
+++ b/spec/helpers/ssh_keys_helper_spec.rb
@@ -17,9 +17,9 @@ RSpec.describe SshKeysHelper do
end
it 'returns only allowed algorithms' do
- expect(ssh_key_allowed_algorithms).to match('ed25519')
- stub_application_setting(ed25519_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE)
- expect(ssh_key_allowed_algorithms).not_to match('ed25519')
+ expect(ssh_key_allowed_algorithms).to match('rsa')
+ stub_application_setting(rsa_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE)
+ expect(ssh_key_allowed_algorithms).not_to match('rsa')
end
end
end
diff --git a/spec/helpers/storage_helper_spec.rb b/spec/helpers/storage_helper_spec.rb
index d0646b30161..82b78ed831c 100644
--- a/spec/helpers/storage_helper_spec.rb
+++ b/spec/helpers/storage_helper_spec.rb
@@ -50,4 +50,87 @@ RSpec.describe StorageHelper do
expect(helper.storage_counters_details(namespace_stats)).to eq(message)
end
end
+
+ describe "storage_enforcement_banner" do
+ let_it_be_with_refind(:current_user) { create(:user) }
+ let_it_be(:free_group) { create(:group) }
+ let_it_be(:paid_group) { create(:group) }
+
+ before do
+ 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)
+ end
+
+ 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)
+ 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)
+ 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 <strong>Group Settings &gt; Usage quotas</strong>.",
+ variant: 'warning',
+ callouts_feature_name: 'storage_enforcement_banner_second_enforcement_threshold',
+ callouts_path: '/-/users/group_callouts',
+ learn_more_link: '<a rel="noopener noreferrer" target="_blank" href="/help//">Learn more.</a>'
+ })
+ end
+
+ context 'when storage_enforcement_date is set and dismissed callout exists' do
+ before do
+ create(:group_callout,
+ user: current_user,
+ group_id: free_group.id,
+ feature_name: 'storage_enforcement_banner_second_enforcement_threshold')
+ storage_enforcement_date = Date.today + 30
+ 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) }
+ end
+
+ context 'callouts_feature_name' do
+ let(:days_from_now) { 45 }
+
+ subject 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]
+ end
+
+ it 'returns first callouts_feature_name' do
+ is_expected.to eq('storage_enforcement_banner_first_enforcement_threshold')
+ end
+
+ context 'returns second callouts_feature_name' do
+ let(:days_from_now) { 20 }
+
+ it { is_expected.to eq('storage_enforcement_banner_second_enforcement_threshold') }
+ end
+
+ context 'returns third callouts_feature_name' do
+ let(:days_from_now) { 13 }
+
+ it { is_expected.to eq('storage_enforcement_banner_third_enforcement_threshold') }
+ end
+
+ context 'returns fourth callouts_feature_name' do
+ let(:days_from_now) { 3 }
+
+ it { is_expected.to eq('storage_enforcement_banner_fourth_enforcement_threshold') }
+ end
+ end
+ end
+ end
end
diff --git a/spec/helpers/tab_helper_spec.rb b/spec/helpers/tab_helper_spec.rb
index f338eddedfd..dd5707e2aff 100644
--- a/spec/helpers/tab_helper_spec.rb
+++ b/spec/helpers/tab_helper_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe TabHelper do
end
it 'creates an active tab with item_active = true' do
- expect(helper.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.*"/)
+ expect(helper.gl_tab_link_to('Link', '/url', { item_active: true })).to match(/<a class=".*active gl-tab-nav-item-active.*"/)
end
context 'when on the active page' do
@@ -54,7 +54,7 @@ RSpec.describe TabHelper do
end
it 'creates an active tab' do
- expect(helper.gl_tab_link_to('Link', '/url')).to match(/<a class=".*active gl-tab-nav-item-active gl-tab-nav-item-active-indigo.*"/)
+ expect(helper.gl_tab_link_to('Link', '/url')).to match(/<a class=".*active gl-tab-nav-item-active.*"/)
end
it 'creates an inactive tab with item_active = false' do
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
index 2b55319c70c..82f4ae596e1 100644
--- a/spec/helpers/users_helper_spec.rb
+++ b/spec/helpers/users_helper_spec.rb
@@ -11,6 +11,20 @@ RSpec.describe UsersHelper do
badges.reject { |badge| badge[:text] == 'Is using seat' }
end
+ describe 'display_public_email?' do
+ let_it_be(:user) { create(:user, :public_email) }
+
+ subject { helper.display_public_email?(user) }
+
+ it { is_expected.to be true }
+
+ context 'when user public email is blank' do
+ let_it_be(:user) { create(:user, public_email: '') }
+
+ it { is_expected.to be false }
+ end
+ end
+
describe '#user_link' do
subject { helper.user_link(user) }
@@ -122,7 +136,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(blocked_user)
- expect(filter_ee_badges(badges)).to eq([text: "Blocked", variant: "danger"])
+ expect(filter_ee_badges(badges)).to match_array([text: "Blocked", variant: "danger"])
end
end
@@ -132,7 +146,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(blocked_pending_approval_user)
- expect(filter_ee_badges(badges)).to eq([text: 'Pending approval', variant: 'info'])
+ expect(filter_ee_badges(badges)).to match_array([text: 'Pending approval', variant: 'info'])
end
end
@@ -142,7 +156,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(banned_user)
- expect(filter_ee_badges(badges)).to eq([text: 'Banned', variant: 'danger'])
+ expect(filter_ee_badges(badges)).to match_array([text: 'Banned', variant: 'danger'])
end
end
@@ -152,7 +166,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(admin_user)
- expect(filter_ee_badges(badges)).to eq([text: "Admin", variant: "success"])
+ expect(filter_ee_badges(badges)).to match_array([text: "Admin", variant: "success"])
end
end
@@ -162,7 +176,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(external_user)
- expect(filter_ee_badges(badges)).to eq([text: "External", variant: "secondary"])
+ expect(filter_ee_badges(badges)).to match_array([text: "External", variant: "secondary"])
end
end
@@ -170,7 +184,7 @@ RSpec.describe UsersHelper do
it 'returns the "It\'s You" badge' do
badges = helper.user_badges_in_admin_section(user)
- expect(filter_ee_badges(badges)).to eq([text: "It's you!", variant: "muted"])
+ expect(filter_ee_badges(badges)).to match_array([text: "It's you!", variant: "muted"])
end
end
@@ -180,7 +194,7 @@ RSpec.describe UsersHelper do
badges = helper.user_badges_in_admin_section(user)
- expect(badges).to eq([
+ expect(badges).to match_array([
{ text: "Blocked", variant: "danger" },
{ text: "Admin", variant: "success" },
{ text: "External", variant: "secondary" }
@@ -188,6 +202,16 @@ RSpec.describe UsersHelper do
end
end
+ context 'with a locked user', time_travel_to: '2020-02-25 10:30:45 -0700' do
+ it 'returns the "Locked" badge' do
+ locked_user = create(:user, locked_at: DateTime.parse('2020-02-25 10:30:00 -0700'))
+
+ badges = helper.user_badges_in_admin_section(locked_user)
+
+ expect(filter_ee_badges(badges)).to match_array([text: "Locked", variant: "warning"])
+ end
+ end
+
context 'get badges for normal user' do
it 'returns no badges' do
user = create(:user)