Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3347 from martinpovolny/menu_plug
Menu pluggability improvements (cherry picked from commit 19b59d9)
- Loading branch information
Showing
5 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
describe Menu::CustomLoader do | ||
before :each do | ||
Singleton.__init__(Menu::Manager) | ||
Singleton.__init__(Menu::CustomLoader) | ||
end | ||
|
||
context '.register' do | ||
it 'loads custom menu items' do | ||
# create custom section with 2 custom items | ||
described_class.register( | ||
Menu::Section.new(:spike, N_('Plugin'), 'fa fa-map-pin', [ | ||
Menu::Item.new('plug1', N_('Test'), 'miq_report', {:feature => 'miq_report', :any => true}, '/plug'), | ||
Menu::Item.new('plug2', N_('Demo'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo') | ||
]) | ||
) | ||
|
||
expect(Menu::Manager.item('plug1')).to be | ||
expect(Menu::Manager.item('plug2')).to be | ||
end | ||
|
||
it 'loads a custom menu item under an existing section' do | ||
# create custom item placed in an existing section 'vi' (Cloud Intel) | ||
described_class.register( | ||
Menu::Item.new('plug3', N_('Plug Item'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo', :default, :vi) | ||
) | ||
|
||
item = Menu::Manager.item('plug3') | ||
expect(item).to be | ||
expect(item.parent.id).to eq(:vi) | ||
end | ||
|
||
it 'loads a custom menu section and places it before an existing section' do | ||
# create custom section and place it before existing section 'compute' (Compute) | ||
described_class.register( | ||
Menu::Section.new(:spike3, N_('Plugin 2'), 'fa fa-map-pin', [ | ||
Menu::Item.new('plug4', N_('Demo'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo') | ||
], :default, :compute) | ||
) | ||
|
||
item = Menu::Manager.item('plug4') | ||
expect(item).to be | ||
|
||
menu = Menu::Manager.instance.instance_eval { @menu } | ||
compute_index = menu.find_index { |s| s.id == :compute } | ||
|
||
expect(menu[compute_index - 1].id).to eq(:spike3) | ||
end | ||
|
||
it 'loads a custom menu section and places it at a given position in inside an existing section' do | ||
# create custom section and place it inside an existing section 'compute' (Compute), before existing subsection 'clo' (Cloud) | ||
described_class.register( | ||
Menu::Section.new(:spike3, N_('Nested section after'), 'fa fa-map-pin', [ | ||
Menu::Item.new('plug5', N_('Test item'), 'miq_report', {:feature => 'miq_report', :any => true}, '/demo') | ||
], :default, :clo, :default, nil, :compute) | ||
) | ||
|
||
item = Menu::Manager.item('plug5') | ||
expect(item).to be | ||
|
||
compute_section = Menu::Manager.section(:compute) | ||
spike_index = compute_section.items.find_index { |i| i.id == :spike3 } | ||
clo_index = compute_section.items.find_index { |i| i.id == :clo } | ||
expect(spike_index).to eq(clo_index - 1) | ||
end | ||
end | ||
end |