2021-05-05 23:10:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Nav::TopNavHelper do
|
2021-06-09 11:10:05 -04:00
|
|
|
let_it_be(:user) { build_stubbed(:user) }
|
|
|
|
let_it_be(:admin) { build_stubbed(:user, :admin) }
|
2021-06-14 11:09:48 -04:00
|
|
|
let_it_be(:external_user) { build_stubbed(:user, :external, can_create_group: false) }
|
2021-06-09 11:10:05 -04:00
|
|
|
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
before do
|
2022-06-03 14:08:54 -04:00
|
|
|
stub_application_setting(snowplow_enabled: true)
|
2021-06-09 11:10:05 -04:00
|
|
|
allow(helper).to receive(:current_user) { current_user }
|
|
|
|
end
|
2021-05-05 23:10:25 -04:00
|
|
|
|
2021-06-09 11:10:05 -04:00
|
|
|
describe '#top_nav_view_model' do
|
2021-05-05 23:10:25 -04:00
|
|
|
let(:current_project) { nil }
|
2021-05-12 05:10:19 -04:00
|
|
|
let(:current_group) { nil }
|
2021-05-05 23:10:25 -04:00
|
|
|
let(:with_current_settings_admin_mode) { false }
|
|
|
|
let(:with_header_link_admin_mode) { false }
|
|
|
|
let(:with_projects) { false }
|
2021-05-12 05:10:19 -04:00
|
|
|
let(:with_groups) { false }
|
2021-05-05 23:10:25 -04:00
|
|
|
let(:with_milestones) { false }
|
2021-05-12 05:10:19 -04:00
|
|
|
let(:with_snippets) { false }
|
|
|
|
let(:with_activity) { false }
|
2021-05-05 23:10:25 -04:00
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
let(:subject) { helper.top_nav_view_model(project: current_project, group: current_group) }
|
2021-05-05 23:10:25 -04:00
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
let(:menu_tooltip) { 'Main menu' }
|
2021-05-05 23:10:25 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:admin_mode) { with_current_settings_admin_mode }
|
|
|
|
allow(helper).to receive(:header_link?).with(:admin_mode) { with_header_link_admin_mode }
|
|
|
|
|
|
|
|
# Defaulting all `dashboard_nav_link?` calls to false ensures the EE-specific behavior
|
|
|
|
# is not enabled in this CE spec
|
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(anything) { false }
|
|
|
|
|
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(:projects) { with_projects }
|
2021-05-12 05:10:19 -04:00
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(:groups) { with_groups }
|
2021-05-05 23:10:25 -04:00
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(:milestones) { with_milestones }
|
2021-05-12 05:10:19 -04:00
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(:snippets) { with_snippets }
|
|
|
|
allow(helper).to receive(:dashboard_nav_link?).with(:activity) { with_activity }
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
|
|
|
|
2022-10-20 02:09:59 -04:00
|
|
|
it 'has :menuTooltip' do
|
|
|
|
expect(subject[:menuTooltip]).to eq(menu_tooltip)
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current_user is nil (anonymous)' do
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Explore'
|
|
|
|
)
|
2021-05-19 17:12:42 -04:00
|
|
|
expected_primary = [
|
2022-06-03 14:08:54 -04:00
|
|
|
{ href: '/explore', icon: 'project', id: 'project', title: 'Projects' },
|
|
|
|
{ href: '/explore/groups', icon: 'group', id: 'groups', title: 'Groups' },
|
|
|
|
{ href: '/explore/snippets', icon: 'snippet', id: 'snippets', title: 'Snippets' }
|
|
|
|
].map do |item|
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(**item)
|
|
|
|
end
|
|
|
|
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, *expected_primary])
|
2021-05-19 17:12:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = [
|
2022-06-03 14:08:54 -04:00
|
|
|
{
|
2021-05-19 17:12:42 -04:00
|
|
|
href: '/explore',
|
|
|
|
id: 'project-shortcut',
|
|
|
|
title: 'Projects',
|
|
|
|
css_class: 'dashboard-shortcuts-projects'
|
2022-06-03 14:08:54 -04:00
|
|
|
},
|
|
|
|
{
|
2021-05-19 17:12:42 -04:00
|
|
|
href: '/explore/groups',
|
|
|
|
id: 'groups-shortcut',
|
|
|
|
title: 'Groups',
|
|
|
|
css_class: 'dashboard-shortcuts-groups'
|
2022-06-03 14:08:54 -04:00
|
|
|
},
|
|
|
|
{
|
2021-05-19 17:12:42 -04:00
|
|
|
href: '/explore/snippets',
|
|
|
|
id: 'snippets-shortcut',
|
|
|
|
title: 'Snippets',
|
|
|
|
css_class: 'dashboard-shortcuts-snippets'
|
2022-06-03 14:08:54 -04:00
|
|
|
}
|
|
|
|
].map do |item|
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(**item)
|
|
|
|
end
|
|
|
|
|
2021-05-19 17:12:42 -04:00
|
|
|
expect(subject[:shortcuts]).to eq(expected_shortcuts)
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
2021-05-24 05:10:31 -04:00
|
|
|
|
2021-06-07 20:10:34 -04:00
|
|
|
context 'with current nav as project' do
|
|
|
|
before do
|
|
|
|
helper.nav('project')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :active' do
|
|
|
|
expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current_user is non-admin' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it 'has no menu items or views by default' do
|
2022-10-20 02:09:59 -04:00
|
|
|
expect(subject).to eq({ menuTooltip: menu_tooltip,
|
2021-05-05 23:10:25 -04:00
|
|
|
primary: [],
|
|
|
|
secondary: [],
|
2021-05-19 17:12:42 -04:00
|
|
|
shortcuts: [],
|
2021-05-05 23:10:25 -04:00
|
|
|
views: {} })
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with projects' do
|
|
|
|
let(:with_projects) { true }
|
|
|
|
let(:projects_view) { subject[:views][:projects] }
|
|
|
|
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Switch to'
|
|
|
|
)
|
2021-05-05 23:10:25 -04:00
|
|
|
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
css_class: 'qa-projects-dropdown',
|
|
|
|
data: {
|
2021-09-15 14:11:29 -04:00
|
|
|
track_action: 'click_dropdown',
|
2021-05-05 23:10:25 -04:00
|
|
|
track_label: 'projects_dropdown'
|
|
|
|
},
|
|
|
|
icon: 'project',
|
|
|
|
id: 'project',
|
|
|
|
title: 'Projects',
|
|
|
|
view: 'projects'
|
|
|
|
)
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, expected_primary])
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
|
|
|
|
2021-05-19 17:12:42 -04:00
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'project-shortcut',
|
|
|
|
title: 'Projects',
|
|
|
|
href: '/dashboard/projects',
|
|
|
|
css_class: 'dashboard-shortcuts-projects'
|
|
|
|
)
|
|
|
|
expect(subject[:shortcuts]).to eq([expected_shortcuts])
|
|
|
|
end
|
|
|
|
|
2021-05-05 23:10:25 -04:00
|
|
|
context 'projects' do
|
|
|
|
it 'has expected :currentUserName' do
|
|
|
|
expect(projects_view[:currentUserName]).to eq(current_user.username)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :namespace' do
|
|
|
|
expect(projects_view[:namespace]).to eq('projects')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :linksPrimary' do
|
|
|
|
expected_links_primary = [
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
2022-06-03 14:08:54 -04:00
|
|
|
data: {
|
|
|
|
qa_selector: 'menu_item_link',
|
2022-09-09 17:10:12 -04:00
|
|
|
qa_title: 'View all projects',
|
|
|
|
**menu_data_tracking_attrs('view_all_projects')
|
2022-06-03 14:08:54 -04:00
|
|
|
},
|
2021-05-05 23:10:25 -04:00
|
|
|
href: '/dashboard/projects',
|
|
|
|
id: 'your',
|
2022-09-09 17:10:12 -04:00
|
|
|
title: 'View all projects'
|
2021-05-05 23:10:25 -04:00
|
|
|
)
|
|
|
|
]
|
|
|
|
expect(projects_view[:linksPrimary]).to eq(expected_links_primary)
|
|
|
|
end
|
|
|
|
|
2022-09-09 17:10:12 -04:00
|
|
|
it 'does not have any :linksSecondary' do
|
|
|
|
expect(projects_view[:linksSecondary]).to eq([])
|
|
|
|
end
|
|
|
|
|
2021-06-07 20:10:34 -04:00
|
|
|
context 'with current nav as project' do
|
|
|
|
before do
|
|
|
|
helper.nav('project')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :active' do
|
|
|
|
expect(subject[:primary].detect { |entry| entry[:id] == 'project' }[:active]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-05 23:10:25 -04:00
|
|
|
context 'with persisted project' do
|
|
|
|
let_it_be(:project) { build_stubbed(:project) }
|
|
|
|
|
|
|
|
let(:current_project) { project }
|
2021-05-12 05:10:19 -04:00
|
|
|
let(:avatar_url) { 'project_avatar_url' }
|
2021-05-05 23:10:25 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:persisted?) { true }
|
|
|
|
allow(project).to receive(:avatar_url) { avatar_url }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has project as :container' do
|
|
|
|
expected_container = {
|
|
|
|
avatarUrl: avatar_url,
|
|
|
|
id: project.id,
|
|
|
|
name: project.name,
|
|
|
|
namespace: project.full_name,
|
|
|
|
webUrl: project_path(project)
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(projects_view[:currentItem]).to eq(expected_container)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
context 'with groups' do
|
|
|
|
let(:with_groups) { true }
|
|
|
|
let(:groups_view) { subject[:views][:groups] }
|
|
|
|
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Switch to'
|
|
|
|
)
|
2021-05-12 05:10:19 -04:00
|
|
|
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
css_class: 'qa-groups-dropdown',
|
|
|
|
data: {
|
2021-09-15 14:11:29 -04:00
|
|
|
track_action: 'click_dropdown',
|
2021-05-12 05:10:19 -04:00
|
|
|
track_label: 'groups_dropdown'
|
|
|
|
},
|
|
|
|
icon: 'group',
|
|
|
|
id: 'groups',
|
|
|
|
title: 'Groups',
|
|
|
|
view: 'groups'
|
|
|
|
)
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, expected_primary])
|
2021-05-12 05:10:19 -04:00
|
|
|
end
|
|
|
|
|
2021-05-19 17:12:42 -04:00
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'groups-shortcut',
|
|
|
|
title: 'Groups',
|
|
|
|
href: '/dashboard/groups',
|
|
|
|
css_class: 'dashboard-shortcuts-groups'
|
|
|
|
)
|
|
|
|
expect(subject[:shortcuts]).to eq([expected_shortcuts])
|
|
|
|
end
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
context 'groups' do
|
|
|
|
it 'has expected :currentUserName' do
|
|
|
|
expect(groups_view[:currentUserName]).to eq(current_user.username)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :namespace' do
|
|
|
|
expect(groups_view[:namespace]).to eq('groups')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :linksPrimary' do
|
|
|
|
expected_links_primary = [
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
2022-06-03 14:08:54 -04:00
|
|
|
data: {
|
|
|
|
qa_selector: 'menu_item_link',
|
2022-09-09 17:10:12 -04:00
|
|
|
qa_title: 'View all groups',
|
|
|
|
**menu_data_tracking_attrs('view_all_groups')
|
2022-06-03 14:08:54 -04:00
|
|
|
},
|
2021-05-12 05:10:19 -04:00
|
|
|
href: '/dashboard/groups',
|
|
|
|
id: 'your',
|
2022-09-09 17:10:12 -04:00
|
|
|
title: 'View all groups'
|
2021-05-12 05:10:19 -04:00
|
|
|
)
|
|
|
|
]
|
|
|
|
expect(groups_view[:linksPrimary]).to eq(expected_links_primary)
|
|
|
|
end
|
|
|
|
|
2022-09-09 17:10:12 -04:00
|
|
|
it 'does not have any :linksSecondary' do
|
|
|
|
expect(groups_view[:linksSecondary]).to eq([])
|
|
|
|
end
|
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
context 'with external user' do
|
|
|
|
let(:current_user) { external_user }
|
|
|
|
|
|
|
|
it 'does not have create group link' do
|
|
|
|
expect(groups_view[:linksSecondary]).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-07 20:10:34 -04:00
|
|
|
context 'with current nav as group' do
|
|
|
|
before do
|
|
|
|
helper.nav('group')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :active' do
|
|
|
|
expect(subject[:primary].detect { |entry| entry[:id] == 'groups' }[:active]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
context 'with persisted group' do
|
|
|
|
let_it_be(:group) { build_stubbed(:group) }
|
|
|
|
|
|
|
|
let(:current_group) { group }
|
|
|
|
let(:avatar_url) { 'group_avatar_url' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(group).to receive(:persisted?) { true }
|
|
|
|
allow(group).to receive(:avatar_url) { avatar_url }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected :container' do
|
|
|
|
expected_container = {
|
|
|
|
avatarUrl: avatar_url,
|
|
|
|
id: group.id,
|
|
|
|
name: group.name,
|
|
|
|
namespace: group.full_name,
|
|
|
|
webUrl: group_path(group)
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(groups_view[:currentItem]).to eq(expected_container)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-05 23:10:25 -04:00
|
|
|
context 'with milestones' do
|
|
|
|
let(:with_milestones) { true }
|
|
|
|
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Explore'
|
|
|
|
)
|
2021-05-05 23:10:25 -04:00
|
|
|
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
data: {
|
2022-06-03 14:08:54 -04:00
|
|
|
qa_selector: 'milestones_link',
|
|
|
|
**menu_data_tracking_attrs('milestones')
|
2021-05-05 23:10:25 -04:00
|
|
|
},
|
|
|
|
href: '/dashboard/milestones',
|
|
|
|
icon: 'clock',
|
|
|
|
id: 'milestones',
|
|
|
|
title: 'Milestones'
|
|
|
|
)
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, expected_primary])
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
2021-05-19 17:12:42 -04:00
|
|
|
|
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'milestones-shortcut',
|
|
|
|
title: 'Milestones',
|
|
|
|
href: '/dashboard/milestones',
|
|
|
|
css_class: 'dashboard-shortcuts-milestones'
|
|
|
|
)
|
|
|
|
expect(subject[:shortcuts]).to eq([expected_shortcuts])
|
|
|
|
end
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
2021-05-12 05:10:19 -04:00
|
|
|
|
|
|
|
context 'with snippets' do
|
|
|
|
let(:with_snippets) { true }
|
|
|
|
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Explore'
|
|
|
|
)
|
2021-05-12 05:10:19 -04:00
|
|
|
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
data: {
|
2022-06-03 14:08:54 -04:00
|
|
|
qa_selector: 'snippets_link',
|
|
|
|
**menu_data_tracking_attrs('snippets')
|
2021-05-12 05:10:19 -04:00
|
|
|
},
|
|
|
|
href: '/dashboard/snippets',
|
|
|
|
icon: 'snippet',
|
|
|
|
id: 'snippets',
|
|
|
|
title: 'Snippets'
|
|
|
|
)
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, expected_primary])
|
2021-05-12 05:10:19 -04:00
|
|
|
end
|
2021-05-19 17:12:42 -04:00
|
|
|
|
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'snippets-shortcut',
|
|
|
|
title: 'Snippets',
|
|
|
|
href: '/dashboard/snippets',
|
|
|
|
css_class: 'dashboard-shortcuts-snippets'
|
|
|
|
)
|
|
|
|
expect(subject[:shortcuts]).to eq([expected_shortcuts])
|
|
|
|
end
|
2021-05-12 05:10:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with activity' do
|
|
|
|
let(:with_activity) { true }
|
|
|
|
|
|
|
|
it 'has expected :primary' do
|
2022-09-09 11:13:16 -04:00
|
|
|
expected_header = ::Gitlab::Nav::TopNavMenuHeader.build(
|
|
|
|
title: 'Explore'
|
|
|
|
)
|
2021-05-12 05:10:19 -04:00
|
|
|
expected_primary = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
data: {
|
2022-06-03 14:08:54 -04:00
|
|
|
qa_selector: 'activity_link',
|
|
|
|
**menu_data_tracking_attrs('activity')
|
2021-05-12 05:10:19 -04:00
|
|
|
},
|
|
|
|
href: '/dashboard/activity',
|
|
|
|
icon: 'history',
|
|
|
|
id: 'activity',
|
|
|
|
title: 'Activity'
|
|
|
|
)
|
2022-09-09 11:13:16 -04:00
|
|
|
expect(subject[:primary]).to eq([expected_header, expected_primary])
|
2021-05-12 05:10:19 -04:00
|
|
|
end
|
2021-05-19 17:12:42 -04:00
|
|
|
|
|
|
|
it 'has expected :shortcuts' do
|
|
|
|
expected_shortcuts = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'activity-shortcut',
|
|
|
|
title: 'Activity',
|
|
|
|
href: '/dashboard/activity',
|
|
|
|
css_class: 'dashboard-shortcuts-activity'
|
|
|
|
)
|
|
|
|
expect(subject[:shortcuts]).to eq([expected_shortcuts])
|
|
|
|
end
|
2021-05-12 05:10:19 -04:00
|
|
|
end
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current_user is admin' do
|
|
|
|
let_it_be(:current_user) { admin }
|
|
|
|
|
|
|
|
let(:with_current_settings_admin_mode) { true }
|
|
|
|
|
|
|
|
it 'has admin as first :secondary item' do
|
|
|
|
expected_admin_item = ::Gitlab::Nav::TopNavMenuItem.build(
|
2022-06-03 14:08:54 -04:00
|
|
|
data: {
|
|
|
|
qa_selector: 'menu_item_link',
|
|
|
|
qa_title: 'Admin',
|
|
|
|
**menu_data_tracking_attrs('admin')
|
|
|
|
},
|
2021-05-05 23:10:25 -04:00
|
|
|
id: 'admin',
|
|
|
|
title: 'Admin',
|
|
|
|
icon: 'admin',
|
|
|
|
href: '/admin',
|
|
|
|
css_class: 'qa-admin-area-link'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(subject[:secondary].first).to eq(expected_admin_item)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with header link admin_mode true' do
|
|
|
|
let(:with_header_link_admin_mode) { true }
|
|
|
|
|
|
|
|
it 'has leave_admin_mode as last :secondary item' do
|
|
|
|
expected_leave_admin_mode_item = ::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'leave_admin_mode',
|
|
|
|
title: 'Leave Admin Mode',
|
|
|
|
icon: 'lock-open',
|
|
|
|
href: '/admin/session/destroy',
|
2022-06-03 14:08:54 -04:00
|
|
|
data: { method: 'post', **menu_data_tracking_attrs('leave_admin_mode') }
|
2021-05-05 23:10:25 -04:00
|
|
|
)
|
|
|
|
expect(subject[:secondary].last).to eq(expected_leave_admin_mode_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with header link admin_mode false' do
|
|
|
|
let(:with_header_link_admin_mode) { false }
|
|
|
|
|
|
|
|
it 'has enter_admin_mode as last :secondary item' do
|
|
|
|
expected_enter_admin_mode_item = ::Gitlab::Nav::TopNavMenuItem.build(
|
2022-06-03 14:08:54 -04:00
|
|
|
data: {
|
|
|
|
qa_selector: 'menu_item_link',
|
|
|
|
qa_title: 'Enter Admin Mode',
|
|
|
|
**menu_data_tracking_attrs('enter_admin_mode')
|
|
|
|
},
|
2021-05-05 23:10:25 -04:00
|
|
|
id: 'enter_admin_mode',
|
|
|
|
title: 'Enter Admin Mode',
|
|
|
|
icon: 'lock',
|
|
|
|
href: '/admin/session/new'
|
|
|
|
)
|
|
|
|
expect(subject[:secondary].last).to eq(expected_enter_admin_mode_item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-09 11:10:05 -04:00
|
|
|
|
|
|
|
describe '#top_nav_responsive_view_model' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
|
|
|
|
let(:with_search) { false }
|
|
|
|
let(:with_new_view_model) { nil }
|
|
|
|
|
|
|
|
let(:subject) { helper.top_nav_responsive_view_model(project: project, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:header_link?).with(:search) { with_search }
|
|
|
|
allow(helper).to receive(:new_dropdown_view_model).with(project: project, group: group) { with_new_view_model }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has nil new subview' do
|
|
|
|
expect(subject[:views][:new]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has nil search subview' do
|
|
|
|
expect(subject[:views][:search]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with search' do
|
|
|
|
let(:with_search) { true }
|
|
|
|
|
|
|
|
it 'has search subview' do
|
|
|
|
expect(subject[:views][:search]).to eq(
|
|
|
|
::Gitlab::Nav::TopNavMenuItem.build(
|
|
|
|
id: 'search',
|
|
|
|
title: 'Search',
|
|
|
|
icon: 'search',
|
|
|
|
href: search_path
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with new' do
|
2021-06-17 23:10:18 -04:00
|
|
|
let(:with_new_view_model) { { menu_sections: [{ id: 'test-new-view-model' }] } }
|
2021-06-09 11:10:05 -04:00
|
|
|
|
|
|
|
it 'has new subview' do
|
2021-06-17 23:10:18 -04:00
|
|
|
expect(subject[:views][:new]).to eq(with_new_view_model)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with new and no menu_sections' do
|
|
|
|
let(:with_new_view_model) { { menu_sections: [] } }
|
|
|
|
|
|
|
|
it 'has new subview' do
|
|
|
|
expect(subject[:views][:new]).to be_nil
|
2021-06-09 11:10:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-06-03 14:08:54 -04:00
|
|
|
|
|
|
|
def menu_data_tracking_attrs(label)
|
|
|
|
{
|
|
|
|
track_label: "menu_#{label}",
|
|
|
|
track_action: 'click_dropdown',
|
|
|
|
track_property: 'navigation'
|
|
|
|
}
|
|
|
|
end
|
2021-05-05 23:10:25 -04:00
|
|
|
end
|