simple-navigation 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +11 -0
- data/Gemfile +2 -16
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -39
- data/generators/navigation_config/templates/config/navigation.rb +7 -5
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/adapters/rails.rb +5 -1
- data/lib/simple_navigation/core/configuration.rb +5 -1
- data/lib/simple_navigation/core/item.rb +2 -1
- data/lib/simple_navigation/core/item_adapter.rb +4 -4
- data/lib/simple_navigation/core/item_container.rb +6 -1
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
- data/lib/simple_navigation/version.rb +3 -0
- data/lib/simple_navigation.rb +1 -0
- data/simple-navigation.gemspec +40 -0
- data/spec/initializers/have_css_matcher.rb +13 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
- data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
- data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
- data/spec/lib/simple_navigation_spec.rb +207 -225
- data/spec/spec_helper.rb +53 -82
- data/uninstall.rb +1 -0
- metadata +100 -22
- data/README +0 -22
- data/VERSION +0 -1
@@ -1,48 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'json_spec'
|
2
3
|
|
3
|
-
|
4
|
+
RSpec.configure { |config| config.include JsonSpec::Helpers }
|
4
5
|
|
5
|
-
|
6
|
+
module SimpleNavigation
|
7
|
+
module Renderer
|
8
|
+
describe Json do
|
9
|
+
describe '#render' do
|
10
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
12
|
+
let(:item) { :invoices }
|
13
|
+
let(:options) {{ level: :all }}
|
14
|
+
let(:output) { renderer.render(navigation) }
|
15
|
+
let(:parsed_output) { parse_json(output) }
|
16
|
+
let(:renderer) { setup_renderer(Json, options) }
|
13
17
|
|
14
|
-
|
15
|
-
'[{"name":"users","url":"first_url","selected":false,"items":null},{"name":"invoices","url":"second_url","selected":true,"items":[{"name":"subnav1","url":"subnav1_url","selected":false,"items":null},{"name":"subnav2","url":"subnav2_url","selected":false,"items":null}]},{"name":"accounts","url":"third_url","selected":false,"items":null},{"name":"miscellany","url":null,"selected":false,"items":null}]'
|
16
|
-
end
|
18
|
+
before { select_an_item(navigation[item]) if item }
|
17
19
|
|
18
|
-
|
20
|
+
context 'when an item is selected' do
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
it 'renders the selected page' do
|
23
|
+
invoices_item = parsed_output.find { |item| item['name'] == 'Invoices' }
|
24
|
+
expect(invoices_item).to include('selected' => true)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# FIXME: not sure if :as_hash returning an array makes sense...
|
29
|
+
context 'when the :as_hash option is true' do
|
30
|
+
let(:options) {{ level: :all, as_hash: true }}
|
31
|
+
|
32
|
+
it 'returns a hash' do
|
33
|
+
expect(output).to be_an Array
|
34
|
+
end
|
23
35
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
it 'renders the selected page' do
|
37
|
+
invoices_item = output.find { |item| item[:name] == 'Invoices' }
|
38
|
+
expect(invoices_item).to include(selected: true)
|
39
|
+
end
|
28
40
|
end
|
29
|
-
found.should == true
|
30
|
-
end
|
31
41
|
|
32
|
-
|
42
|
+
context 'when a sub navigation item is selected' do
|
43
|
+
let(:invoices_item) do
|
44
|
+
parsed_output.find { |item| item['name'] == 'Invoices' }
|
45
|
+
end
|
46
|
+
let(:unpaid_item) do
|
47
|
+
invoices_item['items'].find { |item| item['name'] == 'Unpaid' }
|
48
|
+
end
|
33
49
|
|
34
|
-
|
35
|
-
|
36
|
-
render(:invoices, :as_hash => true).class.should == Array
|
37
|
-
end
|
50
|
+
before do
|
51
|
+
navigation[:invoices].stub(selected?: true)
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
53
|
+
navigation[:invoices]
|
54
|
+
.sub_navigation[:unpaid]
|
55
|
+
.stub(selected?: true, selected_by_condition?: true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'marks all the parent items as selected' do
|
59
|
+
expect(invoices_item).to include('selected' => true)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'marks the item as selected' do
|
63
|
+
expect(unpaid_item).to include('selected' => true)
|
64
|
+
end
|
42
65
|
end
|
43
|
-
found.should == true
|
44
66
|
end
|
45
|
-
|
46
67
|
end
|
47
68
|
end
|
48
69
|
end
|
@@ -1,64 +1,91 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'html/document' unless defined? HTML::Document
|
3
2
|
|
4
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
module Renderer
|
5
|
+
describe Links do
|
6
|
+
describe '#render' do
|
7
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
let(:item) { nil }
|
10
|
+
let(:options) {{ level: :all }}
|
11
|
+
let(:output) { HTML::Document.new(raw_output).root }
|
12
|
+
let(:raw_output) { renderer.render(navigation) }
|
13
|
+
let(:renderer) { setup_renderer(Links, options) }
|
8
14
|
|
9
|
-
|
10
|
-
primary_navigation = primary_container
|
11
|
-
select_item(current_nav) if current_nav
|
12
|
-
setup_renderer_for SimpleNavigation::Renderer::Links, :rails, options
|
13
|
-
HTML::Document.new(@renderer.render(primary_navigation)).root
|
14
|
-
end
|
15
|
+
before { select_an_item(navigation[item]) if item }
|
15
16
|
|
16
|
-
|
17
|
+
it "renders a 'div' tag for the navigation" do
|
18
|
+
expect(output).to have_css('div')
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
it "the rendered div-tag should have the specified dom_id" do
|
22
|
-
HTML::Selector.new('div#nav_dom_id').select(render).should have(1).entries
|
23
|
-
end
|
24
|
-
it "the rendered div-tag should have the specified class" do
|
25
|
-
HTML::Selector.new('div.nav_dom_class').select(render).should have(1).entries
|
26
|
-
end
|
27
|
-
it "should render an a-tag for each item" do
|
28
|
-
HTML::Selector.new('a').select(render).should have(3).entries
|
29
|
-
end
|
30
|
-
it "should pass the specified html_options to the a element" do
|
31
|
-
HTML::Selector.new('a[style=float:right]').select(render).should have(1).entries
|
32
|
-
end
|
33
|
-
it "should give the a-tag the id specified in the html_options" do
|
34
|
-
HTML::Selector.new('a#my_id').select(render).should have(1).entries
|
35
|
-
end
|
36
|
-
it "should give the a-tag the default id (stringified key) if no id is specified in the html_options" do
|
37
|
-
HTML::Selector.new('a#invoices').select(render).should have(1).entries
|
38
|
-
end
|
39
|
-
it "should not apply the the default id where there is an id specified in the html_options" do
|
40
|
-
HTML::Selector.new('a#users').select(render).should be_empty
|
41
|
-
end
|
21
|
+
it "sets the right html id on the rendered 'div' tag" do
|
22
|
+
expect(output).to have_css('div#nav_id')
|
23
|
+
end
|
42
24
|
|
43
|
-
|
44
|
-
|
45
|
-
HTML::Selector.new('a.selected').select(render(:invoices)).should have(1).entries
|
25
|
+
it "sets the right html classes on the rendered 'div' tag" do
|
26
|
+
expect(output).to have_css('div.nav_class')
|
46
27
|
end
|
47
|
-
end
|
48
28
|
|
49
|
-
|
50
|
-
|
51
|
-
HTML::Selector.new('a.selected').select(render).should be_empty
|
29
|
+
it "renders an 'a' tag for each item" do
|
30
|
+
expect(output).to have_css('a', 3)
|
52
31
|
end
|
53
|
-
end
|
54
32
|
|
55
|
-
|
56
|
-
|
57
|
-
|
33
|
+
it "renders the 'a' tags with the corresponding item's :html_options" do
|
34
|
+
expect(output).to have_css('a[style=float:right]')
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when an item has a specified id' do
|
38
|
+
it "renders the 'a' tags with the specified id" do
|
39
|
+
expect(output).to have_css('a#users_id')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when an item has no specified id' do
|
44
|
+
it "uses a default id by stringifying the item's key" do
|
45
|
+
expect(output).to have_css('a#invoices')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when no item is selected' do
|
50
|
+
it "renders items without the 'selected' class" do
|
51
|
+
expect(output).not_to have_css('a.selected')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when an item is selected' do
|
56
|
+
let(:item) { :invoices }
|
57
|
+
|
58
|
+
it "renders the selected item with the 'selected' class" do
|
59
|
+
expect(output).to have_css('a#invoices.selected')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when the :join_with option is set" do
|
64
|
+
let(:options) {{ level: :all, join_with: ' | ' }}
|
65
|
+
|
66
|
+
it 'separates the items with the specified separator' do
|
67
|
+
expect(raw_output.scan(' | ')).to have(3).items
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when a sub navigation item is selected' do
|
72
|
+
before do
|
73
|
+
navigation[:invoices].stub(selected?: true)
|
74
|
+
|
75
|
+
navigation[:invoices]
|
76
|
+
.sub_navigation[:unpaid]
|
77
|
+
.stub(selected?: true, selected_by_condition?: true)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'renders the main parent as selected' do
|
81
|
+
expect(output).to have_css('a#invoices.selected')
|
82
|
+
end
|
83
|
+
|
84
|
+
it "doesn't render the nested item's link" do
|
85
|
+
expect(output).not_to have_css('a#unpaid')
|
86
|
+
end
|
58
87
|
end
|
59
88
|
end
|
60
|
-
|
61
89
|
end
|
62
|
-
|
63
90
|
end
|
64
91
|
end
|
@@ -1,211 +1,99 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'html/document' unless defined? HTML::Document
|
3
2
|
|
4
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
module Renderer
|
5
|
+
describe List do
|
6
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
5
7
|
|
6
|
-
|
8
|
+
let(:item) { nil }
|
9
|
+
let(:options) {{ level: :all }}
|
10
|
+
let(:output) { HTML::Document.new(raw_output).root }
|
11
|
+
let(:raw_output) { renderer.render(navigation) }
|
12
|
+
let(:renderer) { setup_renderer(List, options) }
|
7
13
|
|
8
|
-
|
9
|
-
primary_navigation = primary_container
|
10
|
-
select_item(current_nav) if current_nav
|
11
|
-
setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
|
12
|
-
HTML::Document.new(@renderer.render(primary_navigation)).root
|
13
|
-
end
|
14
|
+
before { select_an_item(navigation[item]) if item }
|
14
15
|
|
15
|
-
|
16
|
+
describe '#render' do
|
17
|
+
it "renders an 'ul' tag for the navigation" do
|
18
|
+
expect(output).to have_css('ul')
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
it "the rendered ul-tag should have the specified dom_id" do
|
21
|
-
HTML::Selector.new('ul#nav_dom_id').select(render).should have(1).entries
|
22
|
-
end
|
23
|
-
it "the rendered ul-tag should have the specified class" do
|
24
|
-
HTML::Selector.new('ul.nav_dom_class').select(render).should have(1).entries
|
25
|
-
end
|
26
|
-
it "should render a li tag for each item" do
|
27
|
-
HTML::Selector.new('li').select(render).should have(4).entries
|
28
|
-
end
|
29
|
-
it "should render an a-tag inside each li-tag (for items with links)" do
|
30
|
-
HTML::Selector.new('li a').select(render).should have(3).entries
|
31
|
-
end
|
32
|
-
it "should render a span-tag inside each li-tag (for items without links)" do
|
33
|
-
HTML::Selector.new('li span').select(render).should have(1).entries
|
34
|
-
end
|
21
|
+
it "sets the right html id on the rendered 'ul' tag" do
|
22
|
+
expect(output).to have_css('ul#nav_id')
|
23
|
+
end
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
before(:each) do
|
39
|
-
SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
|
40
|
-
end
|
41
|
-
it "should apply the name generator" do
|
42
|
-
HTML::Selector.new('li a span').select(render).should have(3).entries
|
43
|
-
end
|
25
|
+
it "sets the right html classes on the rendered 'ul' tag" do
|
26
|
+
expect(output).to have_css('ul.nav_class')
|
44
27
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
it "should apply the name generator" do
|
50
|
-
HTML::Selector.new('li a span').select(render).should have(0).entries
|
28
|
+
|
29
|
+
context 'when an item has no specified id' do
|
30
|
+
it "renders the item's 'li' tag with the item's stingified key as id" do
|
31
|
+
expect(output).to have_css('li#invoices')
|
51
32
|
end
|
52
33
|
end
|
53
|
-
end
|
54
34
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
|
59
|
-
end
|
60
|
-
it "should give the li the id specified in the html_options" do
|
61
|
-
HTML::Selector.new('li#my_id').select(render).should have(1).entries
|
62
|
-
end
|
63
|
-
it "should give the li the default id (stringified key) if no id is specified in the html_options" do
|
64
|
-
HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
|
65
|
-
end
|
66
|
-
it "should not apply the the default id where there is an id specified in the html_options" do
|
67
|
-
HTML::Selector.new('ul li#users').select(render).should be_empty
|
35
|
+
context 'when an item has a specified id' do
|
36
|
+
it "renders the item's 'li' tag with the specified id" do
|
37
|
+
expect(output).to have_css('li#users_id')
|
68
38
|
end
|
69
39
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
it "should add the li attributes to the li element" do
|
75
|
-
HTML::Selector.new('li[style=float:right]').select(render).should have(1).entries
|
76
|
-
end
|
77
|
-
it "should give the li the default id (stringified key) if no id is specified in the html_options for the li-element" do
|
78
|
-
HTML::Selector.new('ul li#invoices').select(render).should have(1).entries
|
40
|
+
|
41
|
+
context 'when no item is selected' do
|
42
|
+
it "renders each item as 'li' tag without any selected class" do
|
43
|
+
expect(output).not_to have_css('ul li.selected')
|
79
44
|
end
|
80
|
-
|
81
|
-
|
45
|
+
|
46
|
+
it "renders each item as 'a' tag without any selected class" do
|
47
|
+
expect(output).not_to have_css('ul li a.selected')
|
82
48
|
end
|
83
49
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'with current_navigation set' do
|
87
|
-
it "should mark the matching li-item as selected (with the css_class specified in configuration)" do
|
88
|
-
HTML::Selector.new('li.selected').select(render(:invoices)).should have(1).entries
|
89
|
-
end
|
90
|
-
it "should also mark the links inside the selected li's as selected" do
|
91
|
-
HTML::Selector.new('li.selected a.selected').select(render(:invoices)).should have(1).entries
|
92
|
-
end
|
93
|
-
end
|
94
50
|
|
95
|
-
|
96
|
-
|
97
|
-
HTML::Selector.new('li.selected').select(render).should be_empty
|
98
|
-
end
|
99
|
-
it "should not mark any links as selected" do
|
100
|
-
HTML::Selector.new('a.selected').select(render).should be_empty
|
101
|
-
end
|
102
|
-
end
|
51
|
+
context 'when an item is selected' do
|
52
|
+
let(:item) { :invoices }
|
103
53
|
|
104
|
-
|
105
|
-
|
106
|
-
HTML::Selector.new('li.selected ul li').select(render(:invoices)).should have(2).entries
|
107
|
-
end
|
108
|
-
it "should be possible to identify sub items using an html selector (using ids)" do
|
109
|
-
HTML::Selector.new('#invoices #subnav1').select(render(:invoices)).should have(1).entries
|
110
|
-
end
|
111
|
-
context 'expand_all => false' do
|
112
|
-
it "should not render the invoices submenu if the user-primary is active" do
|
113
|
-
HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => false)).should be_empty
|
114
|
-
HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => false)).should be_empty
|
54
|
+
it "renders the item's 'li' tag with its id and selected classes" do
|
55
|
+
expect(output).to have_css('li#invoices.selected')
|
115
56
|
end
|
116
|
-
end
|
117
57
|
|
118
|
-
|
119
|
-
|
120
|
-
HTML::Selector.new('#invoices #subnav1').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
|
121
|
-
HTML::Selector.new('#invoices #subnav2').select(render(:users, :level => :all, :expand_all => true)).should have(1).entry
|
58
|
+
it "renders the item's 'a' tag with the selected classes" do
|
59
|
+
expect(output).to have_css('li#invoices a.selected')
|
122
60
|
end
|
123
61
|
end
|
124
62
|
|
125
|
-
|
63
|
+
context 'when the :ordered option is true' do
|
64
|
+
let(:options) {{ level: :all, ordered: true }}
|
126
65
|
|
127
|
-
|
128
|
-
|
129
|
-
def render_container(options={})
|
130
|
-
setup_renderer_for SimpleNavigation::Renderer::List, :rails, options
|
131
|
-
HTML::Document.new(@renderer.render(@container)).root
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'container is empty' do
|
135
|
-
before(:each) do
|
136
|
-
@container = SimpleNavigation::ItemContainer.new(0)
|
66
|
+
it "renders an 'ol' tag for the navigation" do
|
67
|
+
expect(output).to have_css('ol')
|
137
68
|
end
|
138
|
-
context 'skip_if_empty is true' do
|
139
|
-
it "should not render a ul tag for the empty container" do
|
140
|
-
HTML::Selector.new('ul').select(render_container(:skip_if_empty => true)).should be_empty
|
141
|
-
end
|
142
|
-
end
|
143
|
-
context 'skip_if_empty is false' do
|
144
|
-
it "should render a ul tag for the empty container" do
|
145
|
-
HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
69
|
|
150
|
-
|
151
|
-
|
152
|
-
@container = primary_container
|
70
|
+
it "sets the right html id on the rendered 'ol' tag" do
|
71
|
+
expect(output).to have_css('ol#nav_id')
|
153
72
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
context 'skip_if_empty is false' do
|
160
|
-
it "should render a ul tag for the container" do
|
161
|
-
HTML::Selector.new('ul').select(render_container(:skip_if_empty => false)).should have(1).entry
|
162
|
-
end
|
73
|
+
|
74
|
+
it "sets the right html classes on the rendered 'ol' tag" do
|
75
|
+
expect(output).to have_css('ol.nav_class')
|
163
76
|
end
|
164
77
|
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
context 'method specified' do
|
174
|
-
context 'item selected' do
|
175
|
-
before(:each) do
|
176
|
-
@item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {})
|
177
|
-
end
|
178
|
-
it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'selected'}}
|
78
|
+
|
79
|
+
context 'when a sub navigation item is selected' do
|
80
|
+
before do
|
81
|
+
navigation[:invoices].stub(selected?: true)
|
82
|
+
|
83
|
+
navigation[:invoices]
|
84
|
+
.sub_navigation[:unpaid]
|
85
|
+
.stub(selected?: true, selected_by_condition?: true)
|
179
86
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
it {@renderer.send(:link_options_for, @item).should == {:method => :delete}}
|
87
|
+
|
88
|
+
it 'renders the parent items as selected' do
|
89
|
+
expect(output).to have_css('li#invoices.selected')
|
185
90
|
end
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
before(:each) do
|
190
|
-
@item = stub(:item, :method => nil, :selected_class => 'selected', :html_options => {})
|
191
|
-
end
|
192
|
-
it {@renderer.send(:link_options_for, @item).should == {:class => 'selected'}}
|
91
|
+
|
92
|
+
it "renders the selected nested item's link as selected" do
|
93
|
+
expect(output).to have_css('li#unpaid.selected')
|
193
94
|
end
|
194
|
-
context 'item not selected' do
|
195
|
-
before(:each) do
|
196
|
-
@item = stub(:item, :method => nil, :selected_class => nil, :html_options => {})
|
197
|
-
end
|
198
|
-
it {@renderer.send(:link_options_for, @item).should == {}}
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
context 'link options specified' do
|
203
|
-
before(:each) do
|
204
|
-
@item = stub(:item, :method => :delete, :selected_class => 'selected', :html_options => {:link => {:class => 'link_class', :style => 'float:left'}})
|
205
95
|
end
|
206
|
-
it {@renderer.send(:link_options_for, @item).should == {:method => :delete, :class => 'link_class selected', :style => 'float:left'}}
|
207
96
|
end
|
208
97
|
end
|
209
|
-
|
210
98
|
end
|
211
99
|
end
|
@@ -1,39 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
module Renderer
|
5
|
+
describe Text do
|
6
|
+
let!(:navigation) { setup_navigation('nav_id', 'nav_class') }
|
4
7
|
|
5
|
-
|
8
|
+
let(:item) { nil }
|
9
|
+
let(:options) {{ level: :all }}
|
10
|
+
let(:output) { renderer.render(navigation) }
|
11
|
+
let(:renderer) { setup_renderer(Text, options) }
|
6
12
|
|
7
|
-
|
8
|
-
primary_navigation = primary_container
|
9
|
-
select_item(current_nav)
|
10
|
-
setup_renderer_for SimpleNavigation::Renderer::Text, :rails, options
|
11
|
-
@renderer.render(primary_navigation)
|
12
|
-
end
|
13
|
-
context 'regarding result' do
|
14
|
-
|
15
|
-
it "should render the selected page" do
|
16
|
-
render(:invoices).should == "invoices"
|
17
|
-
end
|
13
|
+
before { select_an_item(navigation[item]) if item }
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
describe '#render' do
|
16
|
+
context 'when no item is selected' do
|
17
|
+
it 'renders an empty string' do
|
18
|
+
expect(output).to eq ''
|
19
|
+
end
|
22
20
|
end
|
23
|
-
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
context 'custom name generator is set' do
|
32
|
-
before(:each) do
|
33
|
-
SimpleNavigation.config.stub!(:name_generator => Proc.new {|name| "<span>name</span>"})
|
22
|
+
context 'when an item is selected' do
|
23
|
+
let(:item) { :invoices }
|
24
|
+
|
25
|
+
it "renders the selected item's name" do
|
26
|
+
expect(output).to eq 'Invoices'
|
27
|
+
end
|
34
28
|
end
|
35
|
-
|
36
|
-
|
29
|
+
|
30
|
+
context 'when a sub navigation item is selected' do
|
31
|
+
before do
|
32
|
+
navigation[:invoices].stub(selected?: true)
|
33
|
+
|
34
|
+
navigation[:invoices]
|
35
|
+
.sub_navigation[:unpaid]
|
36
|
+
.stub(selected?: true, selected_by_condition?: true)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'separates the items with a space' do
|
40
|
+
expect(output).to eq 'Invoices Unpaid'
|
41
|
+
end
|
42
|
+
|
43
|
+
context "and the :join_with option is set" do
|
44
|
+
let(:options) {{ level: :all, join_with: ' | ' }}
|
45
|
+
|
46
|
+
it 'separates the items with the specified separator' do
|
47
|
+
expect(output).to eq 'Invoices | Unpaid'
|
48
|
+
end
|
49
|
+
end
|
37
50
|
end
|
38
51
|
end
|
39
52
|
end
|