This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
forked from danielharan/semantic-menu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
semantic_menu_test.rb
100 lines (89 loc) · 3.33 KB
/
semantic_menu_test.rb
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
require 'test/unit'
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
require 'action_controller' # grr, action_view now breaks without it
require 'semantic_menu'
require 'mocha'
class SemanticMenuTest < ActiveSupport::TestCase
def test_menu_to_s
assert_equal SemanticMenu::Menu.new(nil).to_s, '<ul class="semantic-menu"></ul>'
end
def test_menu_item_to_s
SemanticMenu::Item.any_instance.stubs(:active?).returns(false)
assert_equal '<li><a href="link">title</a></li>',
SemanticMenu::Item.new("title", "link").to_s
end
def test_menu_item_passes_options_to_link
SemanticMenu::Item.any_instance.stubs(:active?).returns(false)
assert_equal '<li><a href="link" class="button">title</a></li>',
SemanticMenu::Item.new("title", "link", :class => 'button').to_s
end
def test_menu_item_with_one_child
SemanticMenu::Item.any_instance.stubs(:active?).returns(false)
assert_equal '<ul class="mymenu"><li><a href="link">title</a></li></ul>', default_menu.to_s
end
def test_menu_item_with_two_children
SemanticMenu::Item.any_instance.stubs(:active?).returns(false)
menu = default_menu
menu.add 'title2', 'link2'
assert_equal '<ul class="mymenu">' +
'<li><a href="link">title</a></li>' +
'<li><a href="link2">title2</a></li></ul>', menu.to_s
end
def test_menu_item_shows_active_if_on_current_page
item = SemanticMenu::Item.new("title", "link")
item.stubs(:active?).returns(true)
assert_equal '<li class="active"><a href="link">title</a></li>', item.to_s
end
def test_nested_menu
SemanticMenu::Item.any_instance.stubs(:active?).returns(true)
menu = SemanticMenu::Menu.new(nil) do |root|
root.add 'top_level', 'some_page_path' do |link1|
link1.add 'first_child', 'lower_page_path'
end
end
expected = <<NESTED
<ul class="menu">
<li class="active"><a href="some_page_path">top_level</a>
<ul class="menu_level_1">
<li class="active"><a href="lower_page_path">first_child</a></li>
</ul>
</li>
</ul>
NESTED
assert_equal expected.gsub(/\n */, '').gsub(/\n/, ''), menu.to_s
end
def test_parent_is_active_when_any_child_is
l1, l1_1, l1_2 = [nil] * 3
menu = SemanticMenu::Menu.new(nil) do |root|
l1 = root.add 'level1.1', 'link_1.1' do |link1|
l1_1 = link1.add 'I-1', 'link_I-1'
l1_2 = link1.add 'I-2', 'link_I-2-active'
end
end
l1_1.stubs(:active?).returns(false)
l1_2.stubs(:active?).returns(true)
l1.stubs(:on_current_page?).returns(false)
assert l1.active?
end
# def test_example_output_for_developer_laziness
# MenuItem.any_instance.stubs(:active?).returns(false)
# menu = SemanticMenu.new(nil, :class => 'top_level_nav') do |root|
# root.add "overview", "root_path"
# root.add "comments", "comments_path", :class => 'button' do |comments|
# comments.stubs(:active?).returns(true)
# comment_item = comments.add "My Comments", "my_comments_path"
# comment_item.stubs(:active?).returns(true)
# comments.add "Recent", "recent_comments_path"
# end
# end
# puts menu
# end
protected
def default_menu
SemanticMenu::Menu.new nil, :class => 'mymenu' do |root|
root.add 'title', 'link'
end
end
end