Commit 700086b4 authored by Denys Mishunov's avatar Denys Mishunov

Introduce `has-sub-items` class to top links

parent a663a5e9
......@@ -83,6 +83,17 @@ module Sidebars
insert_element_after(@items, after_item, new_item)
end
override :container_html_options
def container_html_options
super.tap do |html_options|
# Flagging menus that can be rendered but without any children
# like the merge requests or the requirements menu
if render? && has_renderable_items?
html_options[:class] = [*html_options[:class], 'has-sub-items'].join(' ')
end
end
end
private
override :index_of
......
......@@ -34,6 +34,11 @@ module Sidebars
{ class: 'context-header' }
end
override :render?
def render?
true
end
end
end
end
......
......@@ -144,4 +144,56 @@ RSpec.describe Sidebars::Menu do
end
end
end
describe '#container_html_options' do
before do
allow(menu).to receive(:title).and_return('Foo Menu')
end
context 'when menu can be rendered' do
before do
allow(menu).to receive(:render?).and_return(true)
end
context 'when menu has renderable items' do
before do
allow(menu).to receive(:has_renderable_items?).and_return(true)
end
it 'contains the special class' do
menu.add_item(Sidebars::MenuItem.new(title: 'foo1', link: 'foo1', active_routes: { path: 'bar' }))
expect(menu.container_html_options[:class]).to eq 'has-sub-items'
end
context 'when menu already has other classes' do
it 'appends special class' do
allow(menu).to receive(:extra_container_html_options).and_return(class: 'foo')
expect(menu.container_html_options[:class]).to eq 'foo has-sub-items'
end
end
end
context 'when menu does not have renderable items' do
before do
allow(menu).to receive(:has_renderable_items?).and_return(false)
end
it 'does not contain the special class' do
expect(menu.container_html_options[:class]).to be_nil
end
end
end
context 'when menu cannot be rendered' do
before do
allow(menu).to receive(:render?).and_return(false)
end
it 'does not contain "has-sub-items" class' do
expect(menu.container_html_options[:class]).to be_nil
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