Add Packages & Registries menu to project sidebar refactor

This commits move the Packages & Registries menu
from the HAML view to the new refactor.
parent cc3ee889
= render_if_exists 'layouts/nav/sidebar/project_packages_link'
- if project_nav_tab? :analytics - if project_nav_tab? :analytics
= render 'layouts/nav/sidebar/analytics_links', links: project_analytics_navbar_links(@project, current_user) = render 'layouts/nav/sidebar/analytics_links', links: project_analytics_navbar_links(@project, current_user)
......
- packages_link = project_nav_tab?(:packages) ? project_packages_path(@project) : project_container_registry_index_path(@project)
- if project_nav_tab?(:packages) || project_nav_tab?(:container_registry)
= nav_link controller: [:packages, :repositories, :infrastructure_registry] do
= link_to packages_link, data: { qa_selector: 'packages_link' } do
.nav-icon-container
= sprite_icon('package')
%span.nav-item-name
= _('Packages & Registries')
%ul.sidebar-sub-level-items
= nav_link(controller: [:packages, :repositories, :infrastructure_registry], html_options: { class: "fly-out-top-item" } ) do
= link_to packages_link do
%strong.fly-out-top-item-name
= _('Packages & Registries')
%li.divider.fly-out-top-item
- if project_nav_tab? :packages
= nav_link controller: :packages do
= link_to project_packages_path(@project), title: _('Package Registry') do
%span= _('Package Registry')
- if project_nav_tab? :container_registry
= nav_link controller: :repositories do
= link_to project_container_registry_index_path(@project), class: 'shortcuts-container-registry', title: _('Container Registry') do
%span= _('Container Registry')
- if project_nav_tab? :infrastructure_registry
= nav_link controller: :infrastructure_registry do
= link_to project_infrastructure_registry_index_path(@project), title: _('Infrastructure Registry') do
%span= _('Infrastructure Registry')
# frozen_string_literal: true
module Sidebars
module Projects
module Menus
class PackagesRegistriesMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
add_item(packages_registry_menu_item)
add_item(container_registry_menu_item)
add_item(infrastructure_registry_menu_item)
true
end
override :link
def link
items.first.link
end
override :title
def title
_('Packages & Registries')
end
override :sprite_icon
def sprite_icon
'package'
end
private
def packages_registry_menu_item
return unless ::Gitlab.config.packages.enabled
return unless can?(context.current_user, :read_package, context.project)
::Sidebars::MenuItem.new(
title: _('Package Registry'),
link: project_packages_path(context.project),
active_routes: { controller: :packages },
item_id: :packages_registry,
container_html_options: { class: 'shortcuts-container-registry' }
)
end
def container_registry_menu_item
return unless ::Gitlab.config.registry.enabled
return unless can?(context.current_user, :read_container_image, context.project)
::Sidebars::MenuItem.new(
title: _('Container Registry'),
link: project_container_registry_index_path(context.project),
active_routes: { controller: :repositories },
item_id: :container_registry
)
end
def infrastructure_registry_menu_item
return if Feature.disabled?(:infrastructure_registry_page, context.current_user)
::Sidebars::MenuItem.new(
title: _('Infrastructure Registry'),
link: project_infrastructure_registry_index_path(context.project),
active_routes: { controller: :infrastructure_registry },
item_id: :infrastructure_registry
)
end
end
end
end
end
...@@ -17,6 +17,7 @@ module Sidebars ...@@ -17,6 +17,7 @@ module Sidebars
add_menu(Sidebars::Projects::Menus::CiCdMenu.new(context)) add_menu(Sidebars::Projects::Menus::CiCdMenu.new(context))
add_menu(Sidebars::Projects::Menus::SecurityComplianceMenu.new(context)) add_menu(Sidebars::Projects::Menus::SecurityComplianceMenu.new(context))
add_menu(Sidebars::Projects::Menus::OperationsMenu.new(context)) add_menu(Sidebars::Projects::Menus::OperationsMenu.new(context))
add_menu(Sidebars::Projects::Menus::PackagesRegistriesMenu.new(context))
end end
override :render_raw_menus_partial override :render_raw_menus_partial
......
...@@ -7,19 +7,11 @@ module QA ...@@ -7,19 +7,11 @@ module QA
module Packages module Packages
extend QA::Page::PageConcern extend QA::Page::PageConcern
def self.included(base)
super
base.class_eval do
view 'app/views/layouts/nav/sidebar/_project_packages_link.html.haml' do
element :packages_link
end
end
end
def click_packages_link def click_packages_link
within_sidebar do hover_registry do
click_element :packages_link within_submenu do
click_element(:sidebar_menu_item_link, menu_item: 'Package Registry')
end
end end
end end
...@@ -35,8 +27,8 @@ module QA ...@@ -35,8 +27,8 @@ module QA
def hover_registry def hover_registry
within_sidebar do within_sidebar do
scroll_to_element(:packages_link) scroll_to_element(:sidebar_menu_link, menu_item: 'Packages & Registries')
find_element(:packages_link).hover find_element(:sidebar_menu_link, menu_item: 'Packages & Registries').hover
yield yield
end end
......
...@@ -3,36 +3,32 @@ ...@@ -3,36 +3,32 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Projects > Settings > Packages', :js do RSpec.describe 'Projects > Settings > Packages', :js do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { create(:user) }
let(:user) { project.owner }
before do before do
sign_in(user) sign_in(user)
project.add_maintainer(user)
stub_config(packages: { enabled: packages_enabled })
visit edit_project_path(project)
end end
context 'Packages enabled in config' do context 'Packages enabled in config' do
before do let(:packages_enabled) { true }
allow(Gitlab.config.packages).to receive(:enabled).and_return(true)
end
it 'displays the packages toggle button' do it 'displays the packages toggle button' do
visit edit_project_path(project) expect(page).to have_button('Packages', class: 'gl-toggle')
expect(page).to have_content('Packages')
expect(page).to have_selector('input[name="project[packages_enabled]"] + button', visible: true) expect(page).to have_selector('input[name="project[packages_enabled]"] + button', visible: true)
end end
end end
context 'Packages disabled in config' do context 'Packages disabled in config' do
before do let(:packages_enabled) { false }
allow(Gitlab.config.packages).to receive(:enabled).and_return(false)
end
it 'does not show up in UI' do it 'does not show up in UI' do
visit edit_project_path(project) expect(page).not_to have_button('Packages', class: 'gl-toggle')
expect(page).not_to have_content('Packages')
end end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Projects::Menus::PackagesRegistriesMenu do
let(:project) { build(:project) }
let(:user) { project.owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
subject { described_class.new(context) }
describe '#render?' do
context 'when menu does not have any menu item to show' do
it 'returns false' do
allow(subject).to receive(:has_items?).and_return(false)
expect(subject.render?).to eq false
end
end
context 'when menu has menu items to show' do
it 'returns true' do
expect(subject.render?).to eq true
end
end
end
describe '#link' do
let(:registry_enabled) { true }
let(:packages_enabled) { true }
before do
stub_container_registry_config(enabled: registry_enabled)
stub_config(packages: { enabled: packages_enabled })
end
context 'when Packages Registry is visible' do
it 'menu link points to Packages Registry page' do
expect(subject.link).to eq described_class.new(context).items.find { |i| i.item_id == :packages_registry }.link
end
end
context 'when Packages Registry is not visible' do
let(:packages_enabled) { false }
it 'menu link points to Container Registry page' do
expect(subject.link).to eq described_class.new(context).items.find { |i| i.item_id == :container_registry }.link
end
context 'when Container Registry is not visible' do
let(:registry_enabled) { false }
it 'menu link points to Infrastructure Registry page' do
expect(subject.link).to eq described_class.new(context).items.find { |i| i.item_id == :infrastructure_registry }.link
end
end
end
end
describe 'Packages Registry' do
subject { described_class.new(context).items.find { |i| i.item_id == :packages_registry }}
context 'when user can read packages' do
context 'when config package setting is disabled' do
it 'the menu item is not added to list of menu items' do
stub_config(packages: { enabled: false })
is_expected.to be_nil
end
end
context 'when config package setting is enabled' do
it 'the menu item is added to list of menu items' do
stub_config(packages: { enabled: true })
is_expected.not_to be_nil
end
end
end
context 'when user cannot read packages' do
let(:user) { nil }
it 'the menu item is not added to list of menu items' do
is_expected.to be_nil
end
end
end
describe 'Container Registry' do
subject { described_class.new(context).items.find { |i| i.item_id == :container_registry }}
context 'when user can read container images' do
context 'when config registry setting is disabled' do
it 'the menu item is not added to list of menu items' do
stub_container_registry_config(enabled: false)
is_expected.to be_nil
end
end
context 'when config registry setting is enabled' do
it 'the menu item is added to list of menu items' do
stub_container_registry_config(enabled: true)
is_expected.not_to be_nil
end
end
end
context 'when user cannot read container images' do
let(:user) { nil }
it 'the menu item is not added to list of menu items' do
is_expected.to be_nil
end
end
end
describe 'Infrastructure Registry' do
subject { described_class.new(context).items.find { |i| i.item_id == :infrastructure_registry }}
context 'when feature flag :infrastructure_registry_page is enabled' do
it 'the menu item is added to list of menu items' do
stub_feature_flags(infrastructure_registry_page: true)
is_expected.not_to be_nil
end
end
context 'when feature flag :infrastructure_registry_page is disabled' do
it 'the menu item is not added to list of menu items' do
stub_feature_flags(infrastructure_registry_page: false)
is_expected.to be_nil
end
end
end
end
...@@ -580,78 +580,72 @@ RSpec.describe 'layouts/nav/sidebar/_project' do ...@@ -580,78 +580,72 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end end
end end
describe 'packages tab' do describe 'Packages and Registries' do
before do let(:registry_enabled) { true }
stub_container_registry_config(enabled: true) let(:packages_enabled) { true }
allow(controller).to receive(:controller_name) before do
.and_return('repositories') stub_container_registry_config(enabled: registry_enabled)
allow(controller).to receive(:controller_path) stub_config(packages: { enabled: packages_enabled })
.and_return('projects/registry/repositories')
end end
it 'highlights sidebar item and flyout' do it 'top level navigation link is visible and points to package registry page' do
render render
expect(rendered).to have_css('.sidebar-top-level-items > li.active', count: 1) expect(rendered).to have_link('Packages & Registries', href: project_packages_path(project))
expect(rendered).to have_css('.sidebar-sub-level-items > li.fly-out-top-item.active', count: 1)
end end
it 'highlights container registry tab' do describe 'Packages Registry' do
render it 'shows link to package registry page' do
render
expect(rendered).to have_css('.sidebar-sub-level-items > li:not(.fly-out-top-item).active', text: 'Container Registry') expect(rendered).to have_link('Package Registry', href: project_packages_path(project))
end end
end
describe 'Packages' do context 'when packages config setting is not enabled' do
let_it_be(:user) { create(:user) } let(:packages_enabled) { false }
let_it_be(:package_menu_name) { 'Packages & Registries' } it 'does not show link to package registry page' do
let_it_be(:package_entry_name) { 'Package Registry' } render
before do expect(rendered).not_to have_link('Package Registry', href: project_packages_path(project))
project.team.add_developer(user) end
sign_in(user) end
stub_container_registry_config(enabled: true)
end end
context 'when packages is enabled' do describe 'Container Registry' do
it 'packages link is visible' do it 'shows link to container registry page' do
render render
expect(rendered).to have_link(package_menu_name, href: project_packages_path(project)) expect(rendered).to have_link('Container Registry', href: project_container_registry_index_path(project))
end end
it 'packages list link is visible' do context 'when container config setting is not enabled' do
render let(:registry_enabled) { false }
expect(rendered).to have_link(package_entry_name, href: project_packages_path(project))
end
it 'container registry link is visible' do it 'does not show link to package registry page' do
render render
expect(rendered).to have_link('Container Registry', href: project_container_registry_index_path(project)) expect(rendered).not_to have_link('Container Registry', href: project_container_registry_index_path(project))
end
end end
end end
context 'when container registry is disabled' do describe 'Infrastructure Registry' do
before do it 'shows link to infrastructure registry page' do
stub_container_registry_config(enabled: false)
end
it 'packages top level and list link are visible' do
render render
expect(rendered).to have_link(package_menu_name, href: project_packages_path(project)) expect(rendered).to have_link('Infrastructure Registry', href: project_infrastructure_registry_index_path(project))
expect(rendered).to have_link(package_entry_name, href: project_packages_path(project))
end end
it 'container registry link is not visible' do context 'when feature flag :infrastructure_registry_page is disabled' do
render it 'does not show link to package registry page' do
stub_feature_flags(infrastructure_registry_page: false)
expect(rendered).not_to have_link('Container Registry', href: project_container_registry_index_path(project)) render
expect(rendered).not_to have_link('Infrastructure Registry', href: project_infrastructure_registry_index_path(project))
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment