|
|
@@ -1,6 +1,126 @@
|
1
|
1
|
require 'spec_helper'
|
2
|
2
|
|
3
|
3
|
describe ApplicationHelper do
|
|
4
|
+ describe '#nav_link' do
|
|
5
|
+ it 'returns a nav link' do
|
|
6
|
+ stub(self).current_page?('/things') { false }
|
|
7
|
+ nav = nav_link('Things', '/things')
|
|
8
|
+ a = Nokogiri(nav).at('li:not(.active) > a[href="/things"]')
|
|
9
|
+ expect(a.text.strip).to eq('Things')
|
|
10
|
+ end
|
|
11
|
+
|
|
12
|
+ it 'returns a nav link with a glyphicon' do
|
|
13
|
+ stub(self).current_page?('/things') { false }
|
|
14
|
+ nav = nav_link('Things', '/things', glyphicon: 'help')
|
|
15
|
+ expect(nav).to be_html_safe
|
|
16
|
+ a = Nokogiri(nav).at('li:not(.active) > a[href="/things"]')
|
|
17
|
+ expect(a.at('span.glyphicon.glyphicon-help')).to be_a Nokogiri::XML::Element
|
|
18
|
+ expect(a.text.strip).to eq('Things')
|
|
19
|
+ end
|
|
20
|
+
|
|
21
|
+ it 'returns an active nav link' do
|
|
22
|
+ stub(self).current_page?('/things') { true }
|
|
23
|
+ nav = nav_link('Things', '/things')
|
|
24
|
+ expect(nav).to be_html_safe
|
|
25
|
+ a = Nokogiri(nav).at('li.active > a[href="/things"]')
|
|
26
|
+ expect(a).to be_a Nokogiri::XML::Element
|
|
27
|
+ expect(a.text.strip).to eq('Things')
|
|
28
|
+ end
|
|
29
|
+
|
|
30
|
+ describe 'with block' do
|
|
31
|
+ it 'returns a nav link with menu' do
|
|
32
|
+ stub(self).current_page?('/things') { false }
|
|
33
|
+ stub(self).current_page?('/things/stuff') { false }
|
|
34
|
+ nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
|
|
35
|
+ expect(nav).to be_html_safe
|
|
36
|
+ a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > a[href="/things"]')
|
|
37
|
+ expect(a0).to be_a Nokogiri::XML::Element
|
|
38
|
+ expect(a0.text.strip).to eq('Things')
|
|
39
|
+ a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > li:not(.active) > a[href="/things/stuff"]')
|
|
40
|
+ expect(a1).to be_a Nokogiri::XML::Element
|
|
41
|
+ expect(a1.text.strip).to eq('Stuff')
|
|
42
|
+ end
|
|
43
|
+
|
|
44
|
+ it 'returns an active nav link with menu' do
|
|
45
|
+ stub(self).current_page?('/things') { true }
|
|
46
|
+ stub(self).current_page?('/things/stuff') { false }
|
|
47
|
+ nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
|
|
48
|
+ expect(nav).to be_html_safe
|
|
49
|
+ a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
|
|
50
|
+ expect(a0).to be_a Nokogiri::XML::Element
|
|
51
|
+ expect(a0.text.strip).to eq('Things')
|
|
52
|
+ a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
|
|
53
|
+ expect(a1).to be_a Nokogiri::XML::Element
|
|
54
|
+ expect(a1.text.strip).to eq('Stuff')
|
|
55
|
+ end
|
|
56
|
+
|
|
57
|
+ it 'returns an active nav link with menu when on a child page' do
|
|
58
|
+ stub(self).current_page?('/things') { false }
|
|
59
|
+ stub(self).current_page?('/things/stuff') { true }
|
|
60
|
+ nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
|
|
61
|
+ expect(nav).to be_html_safe
|
|
62
|
+ a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
|
|
63
|
+ expect(a0).to be_a Nokogiri::XML::Element
|
|
64
|
+ expect(a0.text.strip).to eq('Things')
|
|
65
|
+ a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
|
|
66
|
+ expect(a1).to be_a Nokogiri::XML::Element
|
|
67
|
+ expect(a1.text.strip).to eq('Stuff')
|
|
68
|
+ end
|
|
69
|
+ end
|
|
70
|
+ end
|
|
71
|
+
|
|
72
|
+ describe '#yes_no' do
|
|
73
|
+ it 'returns a label "Yes" if any truthy value is given' do
|
|
74
|
+ [true, Object.new].each { |value|
|
|
75
|
+ label = yes_no(value)
|
|
76
|
+ expect(label).to be_html_safe
|
|
77
|
+ expect(Nokogiri(label).text).to eq 'Yes'
|
|
78
|
+ }
|
|
79
|
+ end
|
|
80
|
+
|
|
81
|
+ it 'returns a label "No" if any falsy value is given' do
|
|
82
|
+ [false, nil].each { |value|
|
|
83
|
+ label = yes_no(value)
|
|
84
|
+ expect(label).to be_html_safe
|
|
85
|
+ expect(Nokogiri(label).text).to eq 'No'
|
|
86
|
+ }
|
|
87
|
+ end
|
|
88
|
+ end
|
|
89
|
+
|
|
90
|
+ describe '#working' do
|
|
91
|
+ before do
|
|
92
|
+ @agent = agents(:jane_website_agent)
|
|
93
|
+ end
|
|
94
|
+
|
|
95
|
+ it 'returns a label "Disabled" if a given agent is disabled' do
|
|
96
|
+ stub(@agent).disabled? { true }
|
|
97
|
+ label = working(@agent)
|
|
98
|
+ expect(label).to be_html_safe
|
|
99
|
+ expect(Nokogiri(label).text).to eq 'Disabled'
|
|
100
|
+ end
|
|
101
|
+
|
|
102
|
+ it 'returns a label "Missing Gems" if a given agent has dependencies missing' do
|
|
103
|
+ stub(@agent).dependencies_missing? { true }
|
|
104
|
+ label = working(@agent)
|
|
105
|
+ expect(label).to be_html_safe
|
|
106
|
+ expect(Nokogiri(label).text).to eq 'Missing Gems'
|
|
107
|
+ end
|
|
108
|
+
|
|
109
|
+ it 'returns a label "Yes" if a given agent is working' do
|
|
110
|
+ stub(@agent).working? { true }
|
|
111
|
+ label = working(@agent)
|
|
112
|
+ expect(label).to be_html_safe
|
|
113
|
+ expect(Nokogiri(label).text).to eq 'Yes'
|
|
114
|
+ end
|
|
115
|
+
|
|
116
|
+ it 'returns a label "No" if a given agent is not working' do
|
|
117
|
+ stub(@agent).working? { false }
|
|
118
|
+ label = working(@agent)
|
|
119
|
+ expect(label).to be_html_safe
|
|
120
|
+ expect(Nokogiri(label).text).to eq 'No'
|
|
121
|
+ end
|
|
122
|
+ end
|
|
123
|
+
|
4
|
124
|
describe '#icon_for_service' do
|
5
|
125
|
it 'returns a correct icon tag for Twitter' do
|
6
|
126
|
icon = icon_for_service(:twitter)
|