155 lines
5 KiB
Ruby
155 lines
5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
RSpec.describe SidebarsHelper, feature_category: :navigation do
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
describe '#sidebar_tracking_attributes_by_object' do
|
|
subject(:tracking_attrs) { helper.sidebar_tracking_attributes_by_object(object) }
|
|
|
|
before do
|
|
stub_application_setting(snowplow_enabled: true)
|
|
end
|
|
|
|
context 'when object is a project' do
|
|
let(:object) { build(:project) }
|
|
|
|
it 'returns tracking attrs for project' do
|
|
attrs = {
|
|
track_label: 'projects_side_navigation',
|
|
track_property: 'projects_side_navigation',
|
|
track_action: 'render'
|
|
}
|
|
|
|
expect(tracking_attrs[:data]).to eq(attrs)
|
|
end
|
|
end
|
|
|
|
context 'when object is a group' do
|
|
let(:object) { build(:group) }
|
|
|
|
it 'returns tracking attrs for group' do
|
|
attrs = {
|
|
track_label: 'groups_side_navigation',
|
|
track_property: 'groups_side_navigation',
|
|
track_action: 'render'
|
|
}
|
|
|
|
expect(tracking_attrs[:data]).to eq(attrs)
|
|
end
|
|
end
|
|
|
|
context 'when object is a user' do
|
|
let(:object) { build(:user) }
|
|
|
|
it 'returns tracking attrs for user' do
|
|
attrs = {
|
|
track_label: 'user_side_navigation',
|
|
track_property: 'user_side_navigation',
|
|
track_action: 'render'
|
|
}
|
|
|
|
expect(tracking_attrs[:data]).to eq(attrs)
|
|
end
|
|
end
|
|
|
|
context 'when object is something else' do
|
|
let(:object) { build(:ci_pipeline) }
|
|
|
|
it { is_expected.to eq({}) }
|
|
end
|
|
end
|
|
|
|
describe '#super_sidebar_context' do
|
|
let(:user) { build(:user) }
|
|
let(:group) { build(:group) }
|
|
|
|
subject { helper.super_sidebar_context(user, group: group, project: nil) }
|
|
|
|
before do
|
|
allow(helper).to receive(:current_user) { user }
|
|
Rails.cache.write(['users', user.id, 'assigned_open_issues_count'], 1)
|
|
Rails.cache.write(['users', user.id, 'assigned_open_merge_requests_count'], 4)
|
|
Rails.cache.write(['users', user.id, 'review_requested_open_merge_requests_count'], 0)
|
|
Rails.cache.write(['users', user.id, 'todos_pending_count'], 3)
|
|
Rails.cache.write(['users', user.id, 'total_merge_requests_count'], 4)
|
|
end
|
|
|
|
it 'returns sidebar values from user', :use_clean_rails_memory_store_caching do
|
|
expect(subject).to include({
|
|
name: user.name,
|
|
username: user.username,
|
|
avatar_url: user.avatar_url,
|
|
assigned_open_issues_count: 1,
|
|
todos_pending_count: 3,
|
|
issues_dashboard_path: issues_dashboard_path(assignee_username: user.username),
|
|
total_merge_requests_count: 4,
|
|
support_path: helper.support_url,
|
|
display_whats_new: helper.display_whats_new?,
|
|
whats_new_most_recent_release_items_count: helper.whats_new_most_recent_release_items_count,
|
|
whats_new_version_digest: helper.whats_new_version_digest,
|
|
show_version_check: helper.show_version_check?,
|
|
gitlab_version: Gitlab.version_info,
|
|
gitlab_version_check: helper.gitlab_version_check
|
|
})
|
|
end
|
|
|
|
it 'returns "Merge requests" menu', :use_clean_rails_memory_store_caching do
|
|
expect(subject[:merge_request_menu]).to eq([
|
|
{
|
|
name: _('Merge requests'),
|
|
items: [
|
|
{
|
|
text: _('Assigned'),
|
|
href: merge_requests_dashboard_path(assignee_username: user.username),
|
|
count: 4
|
|
},
|
|
{
|
|
text: _('Review requests'),
|
|
href: merge_requests_dashboard_path(reviewer_username: user.username),
|
|
count: 0
|
|
}
|
|
]
|
|
}
|
|
])
|
|
end
|
|
|
|
it 'returns "Create new" menu groups without headers', :use_clean_rails_memory_store_caching do
|
|
expect(subject[:create_new_menu_groups]).to eq([
|
|
{
|
|
name: "",
|
|
items: [
|
|
{ href: "/projects/new", text: "New project/repository" },
|
|
{ href: "/groups/new", text: "New group" },
|
|
{ href: "/-/snippets/new", text: "New snippet" }
|
|
]
|
|
}
|
|
])
|
|
end
|
|
|
|
it 'returns "Create new" menu groups with headers', :use_clean_rails_memory_store_caching do
|
|
allow(group).to receive(:persisted?).and_return(true)
|
|
allow(helper).to receive(:can?).and_return(true)
|
|
|
|
expect(subject[:create_new_menu_groups]).to contain_exactly(
|
|
a_hash_including(
|
|
name: "In this group",
|
|
items: array_including(
|
|
{ href: "/projects/new", text: "New project/repository" },
|
|
{ href: "/groups/new#create-group-pane", text: "New subgroup" },
|
|
{ href: "/groups/#{group.full_path}/-/group_members", text: "Invite members" }
|
|
)
|
|
),
|
|
a_hash_including(
|
|
name: "In GitLab",
|
|
items: array_including(
|
|
{ href: "/projects/new", text: "New project/repository" },
|
|
{ href: "/groups/new", text: "New group" },
|
|
{ href: "/-/snippets/new", text: "New snippet" }
|
|
)
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|