1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe Sidebars::Concerns::SuperSidebarPanel, feature_category: :navigation do
let(:menu_class_foo) { Class.new(Sidebars::Menu) }
let(:menu_foo) { menu_class_foo.new({}) }
let(:menu_class_bar) do
Class.new(Sidebars::Menu) do
def title
"Bar"
end
def pick_into_super_sidebar?
true
end
end
end
let(:menu_bar) { menu_class_bar.new({}) }
subject do
Class.new(Sidebars::Panel) do
include Sidebars::Concerns::SuperSidebarPanel
end.new({})
end
before do
allow(menu_foo).to receive(:render?).and_return(true)
allow(menu_bar).to receive(:render?).and_return(true)
end
describe '#pick_from_old_menus' do
it 'removes items with #pick_into_super_sidebar? from a list and adds them to the panel menus' do
old_menus = [menu_foo, menu_bar]
subject.pick_from_old_menus(old_menus)
expect(old_menus).to include(menu_foo)
expect(subject.renderable_menus).not_to include(menu_foo)
expect(old_menus).not_to include(menu_bar)
expect(subject.renderable_menus).to include(menu_bar)
end
end
describe '#transform_old_menus' do
let(:uncategorized_menu) { ::Sidebars::UncategorizedMenu.new({}) }
let(:menu_item) do
Sidebars::MenuItem.new(title: 'foo3', link: 'foo3', active_routes: { controller: 'barc' },
super_sidebar_parent: menu_class_foo)
end
let(:nil_menu_item) { Sidebars::NilMenuItem.new(item_id: :nil_item) }
let(:existing_item) do
Sidebars::MenuItem.new(
item_id: :exists,
title: 'Existing item',
link: 'foo2',
active_routes: { controller: 'foo2' }
)
end
let(:current_menus) { [menu_foo, uncategorized_menu] }
before do
allow(menu_bar).to receive(:serialize_as_menu_item_args).and_return(nil)
menu_foo.add_item(existing_item)
end
context 'for Menus with Menu Items' do
before do
menu_bar.add_item(menu_item)
menu_bar.add_item(nil_menu_item)
end
it 'adds Menu Items to defined super_sidebar_parent' do
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item, menu_item])
expect(uncategorized_menu.renderable_items).to eq([])
end
it 'adds Menu Items to defined super_sidebar_parent, before super_sidebar_before' do
allow(menu_item).to receive(:super_sidebar_before).and_return(:exists)
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([menu_item, existing_item])
expect(uncategorized_menu.renderable_items).to eq([])
end
it 'considers Menu Items uncategorized if super_sidebar_parent is nil' do
allow(menu_item).to receive(:super_sidebar_parent).and_return(nil)
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item])
expect(uncategorized_menu.renderable_items).to eq([menu_item])
end
it 'considers Menu Items uncategorized if super_sidebar_parent cannot be found' do
allow(menu_item).to receive(:super_sidebar_parent).and_return(menu_class_bar)
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item])
expect(uncategorized_menu.renderable_items).to eq([menu_item])
end
it 'considers Menu Items deleted if super_sidebar_parent is Sidebars::NilMenuItem' do
allow(menu_item).to receive(:super_sidebar_parent).and_return(::Sidebars::NilMenuItem)
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item])
expect(uncategorized_menu.renderable_items).to eq([])
end
end
it 'converts "solo" top-level Menu entry to Menu Item' do
allow(Sidebars::MenuItem).to receive(:new).and_return(menu_item)
allow(menu_bar).to receive(:serialize_as_menu_item_args).and_return({})
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item, menu_item])
expect(uncategorized_menu.renderable_items).to eq([])
end
it 'drops "solo" top-level Menu entries, if they serialize to nil' do
allow(Sidebars::MenuItem).to receive(:new).and_return(menu_item)
allow(menu_bar).to receive(:serialize_as_menu_item_args).and_return(nil)
subject.transform_old_menus(current_menus, menu_bar)
expect(menu_foo.renderable_items).to eq([existing_item])
expect(uncategorized_menu.renderable_items).to eq([])
end
end
end
|