diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/models/sidebars/menu_spec.rb | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/models/sidebars/menu_spec.rb')
-rw-r--r-- | spec/models/sidebars/menu_spec.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/models/sidebars/menu_spec.rb b/spec/models/sidebars/menu_spec.rb new file mode 100644 index 00000000000..320f5f1ad1e --- /dev/null +++ b/spec/models/sidebars/menu_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Sidebars::Menu do + let(:menu) { described_class.new(context) } + let(:context) { Sidebars::Context.new(current_user: nil, container: nil) } + + describe '#all_active_routes' do + it 'gathers all active routes of items and the current menu' do + menu_item1 = Sidebars::MenuItem.new(context) + menu_item2 = Sidebars::MenuItem.new(context) + menu_item3 = Sidebars::MenuItem.new(context) + menu.add_item(menu_item1) + menu.add_item(menu_item2) + menu.add_item(menu_item3) + + allow(menu).to receive(:active_routes).and_return({ path: 'foo' }) + allow(menu_item1).to receive(:active_routes).and_return({ path: %w(bar test) }) + allow(menu_item2).to receive(:active_routes).and_return({ controller: 'fooc' }) + allow(menu_item3).to receive(:active_routes).and_return({ controller: 'barc' }) + + expect(menu.all_active_routes).to eq({ path: %w(foo bar test), controller: %w(fooc barc) }) + end + + it 'does not include routes for non renderable items' do + menu_item = Sidebars::MenuItem.new(context) + menu.add_item(menu_item) + + allow(menu).to receive(:active_routes).and_return({ path: 'foo' }) + allow(menu_item).to receive(:render?).and_return(false) + allow(menu_item).to receive(:active_routes).and_return({ controller: 'bar' }) + + expect(menu.all_active_routes).to eq({ path: ['foo'] }) + end + end + + describe '#render?' do + context 'when the menus has no items' do + it 'returns true' do + expect(menu.render?).to be true + end + end + + context 'when the menu has items' do + let(:menu_item) { Sidebars::MenuItem.new(context) } + + before do + menu.add_item(menu_item) + end + + context 'when items are not renderable' do + it 'returns false' do + allow(menu_item).to receive(:render?).and_return(false) + + expect(menu.render?).to be false + end + end + + context 'when there are renderable items' do + it 'returns true' do + expect(menu.render?).to be true + end + end + end + end +end |