slimmer 9.6.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,119 +0,0 @@
1
- require_relative "test_helper"
2
- require 'gds_api/test_helpers/content_api'
3
-
4
- describe Slimmer::Artefact do
5
- include GdsApi::TestHelpers::ContentApi
6
-
7
- it "should pull the slug out of the id" do
8
- a = Slimmer::Artefact.new(artefact_for_slug('vat-rates'))
9
- assert_equal 'vat-rates', a.slug
10
- end
11
-
12
- describe "Primary section" do
13
- before do
14
- @data = artefact_for_slug('something')
15
- @tag1 = tag_for_slug("fooey", "section")
16
- @tag2 = tag_for_slug("gooey", "section")
17
- @data["tags"] << @tag1 << @tag2
18
- end
19
-
20
- it "should return the first section tag" do
21
- assert_equal @tag1, Slimmer::Artefact.new(@data).primary_section
22
- end
23
-
24
- it "should ignore other tag types" do
25
- @data["tags"].unshift(tag_for_slug("other_tag", "another_tag"))
26
- assert_equal @tag1, Slimmer::Artefact.new(@data).primary_section
27
- end
28
-
29
- it "should return nil if there are no sections" do
30
- @data["tags"] = [tag_for_slug("other_tag", "another_tag")]
31
- assert_equal nil, Slimmer::Artefact.new(@data).primary_section
32
- end
33
-
34
- it "should return nil if there is no tags element" do
35
- @data.delete("tags")
36
- assert_equal nil, Slimmer::Artefact.new(@data).primary_section
37
- end
38
- end
39
-
40
- describe "Primary root section" do
41
- before do
42
- @artefact = Slimmer::Artefact.new(artefact_for_slug('something'))
43
- @tag1 = tag_for_slug("fooey", "section")
44
- @tag2 = tag_for_slug("gooey", "section")
45
- @tag3 = tag_for_slug("kablooie", "section")
46
- end
47
-
48
- it "should return the primary section if it has no parent" do
49
- @artefact.stubs(:primary_section).returns(@tag1)
50
- assert_equal @tag1, @artefact.primary_root_section
51
- end
52
-
53
- it "should return the primary section's parent" do
54
- @tag1["parent"] = @tag2
55
- @artefact.stubs(:primary_section).returns(@tag1)
56
- assert_equal @tag2, @artefact.primary_root_section
57
- end
58
-
59
- it "should support arbitrarily deep heirarchies" do
60
- @tag1["parent"] = @tag3
61
- @tag3["parent"] = @tag2
62
- @artefact.stubs(:primary_section).returns(@tag1)
63
- assert_equal @tag2, @artefact.primary_root_section
64
- end
65
-
66
- it "should return nil if there is no primary section" do
67
- @artefact.stubs(:primary_section).returns(nil)
68
- assert_equal nil, @artefact.primary_root_section
69
- end
70
- end
71
-
72
- describe "Related artefacts" do
73
- before do
74
- @data = artefact_for_slug('something')
75
- end
76
-
77
- it "should return an array of corresponding artefact instances" do
78
- @data["related"] << artefact_for_slug('vat')
79
- @data["related"] << artefact_for_slug('something-else')
80
- a = Slimmer::Artefact.new(@data)
81
- related = a.related_artefacts
82
- assert_equal [Slimmer::Artefact, Slimmer::Artefact], related.map(&:class)
83
- assert_equal %w(vat something-else), related.map(&:slug)
84
- end
85
-
86
- it "should return empty array if there is no 'related' element" do
87
- @data.delete("related")
88
- assert_equal [], Slimmer::Artefact.new(@data).related_artefacts
89
- end
90
- end
91
-
92
- describe "method_missing accessing artefact fields" do
93
- before do
94
- @data = artefact_for_slug('something')
95
- @data["foo"] = "bar"
96
- @a = Slimmer::Artefact.new(@data)
97
- end
98
-
99
- it "should return corresponding field" do
100
- assert_equal @data["title"], @a.title
101
- assert_equal "bar", @a.foo
102
- end
103
-
104
- it "should return the corresponding field from details if it doesn't exist at the top level" do
105
- @data["details"]["foo"] = "baz"
106
- assert_equal @data["details"]["need_id"], @a.need_id
107
- assert_equal "bar", @a.foo
108
- end
109
-
110
- it "should return nil if the field doesn't exist" do
111
- assert_equal nil, @a.non_existent
112
- end
113
-
114
- it "should not blow up if the details attribute doesn't exist" do
115
- @data.delete("details")
116
- assert_equal nil, @a.non_existent
117
- end
118
- end
119
- end
@@ -1,33 +0,0 @@
1
- <%# Whilst they are both in use, this and the test copy in slimmer should be kept in sync %>
2
- <% if artefact and artefact.related_artefacts.any? %>
3
-
4
- <!-- related -->
5
- <div class="related-positioning">
6
- <div class="related-container">
7
-
8
- <div class="related" id="related">
9
- <div class="inner group">
10
- <h2>Other relevant links</h2>
11
- <nav role="navigation">
12
- <ul>
13
- <% artefact.related_artefacts.each do |item| %>
14
- <li>
15
- <a href="<%= h item.web_url %>"><%= h item.title %></a>
16
- </li>
17
- <% end %>
18
- <% if root_section = artefact.primary_root_section %>
19
- <li class="related-topic"><a href="<%= h root_section["content_with_tag"]["web_url"] %>"
20
- >More from the <span><%= h root_section["title"] %></span> category</a></li>
21
- <% end %>
22
- </ul>
23
- </nav>
24
- <nav role="navigation" class="return-to-top">
25
- <a href="#content">Return to top &uarr;</a>
26
- </nav>
27
- </div>
28
- </div>
29
-
30
- </div>
31
- </div>
32
- <!-- end related -->
33
- <% end %>
@@ -1,59 +0,0 @@
1
- require_relative '../test_helper'
2
- require 'gds_api/test_helpers/content_api'
3
-
4
- class RelatedItemsInserterTest < MiniTest::Test
5
- include GdsApi::TestHelpers::ContentApi
6
-
7
- def setup
8
- super
9
- @related_template = File.read( File.dirname(__FILE__) + "/../fixtures/related.raw.html.erb" )
10
- @skin = stub("Skin", :template => @related_template)
11
- @artefact = Slimmer::Artefact.new artefact_for_slug_with_related_artefacts("vat", ["vat-rates", "starting-to-import"])
12
- end
13
-
14
- def test_should_add_related_items
15
- source = as_nokogiri %{
16
- <html>
17
- <body class="mainstream">
18
- <div id="wrapper">The body of the page<div id="related-items"></div></div>
19
- </body>
20
- </html>
21
- }
22
- template = as_nokogiri %{
23
- <html>
24
- <body class="mainstream">
25
- <div id="wrapper"></div>
26
- <div id="related-items"></div>
27
- </body>
28
- </html>
29
- }
30
-
31
- Slimmer::Processors::RelatedItemsInserter.new(@skin, @artefact).filter(source, template)
32
- assert_in template, "div.related h2", "Other relevant links"
33
- assert_in template, "div.related nav[role=navigation] ul li:nth-child(1) a[href='https://www.test.gov.uk/vat-rates']", "Vat rates"
34
- assert_in template, "div.related nav[role=navigation] ul li:nth-child(2) a[href='https://www.test.gov.uk/starting-to-import']", "Starting to import"
35
- end
36
-
37
- def test_should_not_add_related_items_for_non_mainstream_source
38
- source = as_nokogiri %{
39
- <html>
40
- <body class="nonmainstream">
41
- <div id="wrapper">The body of the page<div id="related-items"></div></div>
42
- </body>
43
- </html>
44
- }
45
- template = as_nokogiri %{
46
- <html>
47
- <body class="mainstream">
48
- <div id="wrapper"></div>
49
- <div id="related-items"></div>
50
- </body>
51
- </html>
52
- }
53
-
54
- @skin.expects(:template).never # Shouldn't fetch template when not inserting block
55
-
56
- Slimmer::Processors::RelatedItemsInserter.new(@skin, @artefact).filter(source, template)
57
- assert_not_in template, "div.related"
58
- end
59
- end
@@ -1,193 +0,0 @@
1
- require_relative "../test_helper"
2
- require 'gds_api/test_helpers/content_api'
3
-
4
- class SectionInserterTest < MiniTest::Test
5
- include GdsApi::TestHelpers::ContentApi
6
-
7
- def create_artefact(slug, attributes = {})
8
- if section_slug = attributes.delete("section_slug")
9
- if subsection_slug = attributes.delete("subsection_slug")
10
- a = artefact_for_slug_in_a_subsection(slug, "#{section_slug}/#{subsection_slug}")
11
- else
12
- a = artefact_for_slug_in_a_section(slug, section_slug)
13
- end
14
- else
15
- a = artefact_for_slug(slug)
16
- end
17
- Slimmer::Artefact.new(a.merge(attributes))
18
- end
19
-
20
- def test_should_add_section_link_and_title_to_breadcrumb
21
- artefact = create_artefact("something",
22
- "section_slug" => "business")
23
-
24
- template = as_nokogiri %{
25
- <html>
26
- <body>
27
- <div id="global-breadcrumb" class="header-context">
28
- <ol role="navigation">
29
- <li><a href="/">Home</a></li>
30
- </ol>
31
- </div>
32
- </body>
33
- </html>
34
- }
35
-
36
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
37
- list = template.at_css("#global-breadcrumb ol")
38
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
39
- assert_in list, "li:nth-child(2)", %{<strong><a href="https://www.test.gov.uk/browse/business">Business</a></strong>}
40
- end
41
-
42
- def test_should_add_section_link_with_old_version_of_markup
43
- artefact = create_artefact("something",
44
- "section_slug" => "business")
45
-
46
- template = as_nokogiri %{
47
- <html>
48
- <body>
49
- <div id="global-breadcrumb" class="header-context">
50
- <nav role="navigation">
51
- <ol class="group">
52
- <li><a href="/">Home</a></li>
53
- </ol>
54
- </nav>
55
- </div>
56
- </body>
57
- </html>
58
- }
59
-
60
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
61
- list = template.at_css("#global-breadcrumb nav[role=navigation] ol")
62
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
63
- assert_in list, "li:nth-child(2)", %{<strong><a href="https://www.test.gov.uk/browse/business">Business</a></strong>}
64
- end
65
-
66
- def test_should_add_section_link_subsection_link_and_title_to_breadcrumb
67
- artefact = create_artefact("something",
68
- "section_slug" => "business",
69
- "subsection_slug" => "employing-people")
70
-
71
- template = as_nokogiri %{
72
- <html>
73
- <body>
74
- <div id="global-breadcrumb" class="header-context">
75
- <ol role="navigation"><li><a href="/">Home</a></li></ol>
76
- </div>
77
- </body>
78
- </html>
79
- }
80
-
81
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
82
- list = template.at_css("#global-breadcrumb ol")
83
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
84
- assert_in list, "li:nth-child(2)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
85
- assert_in list, "li:nth-child(3)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a></strong>}
86
- end
87
-
88
- def test_should_add_links_after_last_item_in_breadcrumb
89
- artefact = create_artefact("something",
90
- "section_slug" => "business",
91
- "subsection_slug" => "employing-people")
92
-
93
- template = as_nokogiri %{
94
- <html>
95
- <body>
96
- <div id="global-breadcrumb" class="header-context">
97
- <ol role="navigation">
98
- <li><a href="/">Home</a></li>
99
- <li><a href="/browse">All Sections</a></li>
100
- </ol>
101
- </div>
102
- </body>
103
- </html>
104
- }
105
-
106
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
107
- list = template.at_css("#global-breadcrumb ol")
108
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
109
- assert_in list, "li:nth-child(2)", %{<a href="/browse">All Sections</a>}
110
- assert_in list, "li:nth-child(3)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
111
- assert_in list, "li:nth-child(4)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a></strong>}
112
- end
113
-
114
- def test_should_do_nothing_if_navigation_not_in_template
115
- artefact = create_artefact("something",
116
- "section_slug" => "business",
117
- "subsection_slug" => "employing-people")
118
- template = as_nokogiri %{
119
- <html>
120
- <body>
121
- </body>
122
- </html>
123
- }
124
-
125
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
126
- assert_not_in template, "ol[role=navigation]"
127
- end
128
-
129
- def test_should_do_nothing_with_no_artefact
130
- template = as_nokogiri %{
131
- <html>
132
- <body>
133
- <div id="global-breadcrumb" class="header-context">
134
- <ol role="navigation"><li><a href="/">Home</a></li></ol>
135
- </div>
136
- </body>
137
- </html>
138
- }
139
-
140
- Slimmer::Processors::SectionInserter.new(nil).filter(:any_source, template)
141
- list = template.at_css("#global-breadcrumb ol")
142
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
143
- assert_not_in list, "li:nth-child(2)"
144
- end
145
-
146
- def test_should_not_fail_with_no_sections
147
- artefact = create_artefact("something")
148
-
149
- template = as_nokogiri %{
150
- <html>
151
- <body>
152
- <div id="global-breadcrumb" class="header-context">
153
- <ol role="navigation">
154
- <li><a href="/">Home</a></li>
155
- </ol>
156
- </div>
157
- </body>
158
- </html>
159
- }
160
-
161
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
162
- list = template.at_css("#global-breadcrumb ol")
163
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
164
- end
165
-
166
- def test_should_support_multiple_levels_of_navigation
167
- artefact = create_artefact("something",
168
- "section_slug" => "business",
169
- "subsection_slug" => "employing-people/deep-section")
170
-
171
- template = as_nokogiri %{
172
- <html>
173
- <body>
174
- <div id="global-breadcrumb" class="header-context">
175
- <ol role="navigation">
176
- <li><a href="/">Home</a></li>
177
- <li><a href="/browse">All Sections</a></li>
178
- </ol>
179
- </div>
180
- </body>
181
- </html>
182
- }
183
-
184
- Slimmer::Processors::SectionInserter.new(artefact).filter(:any_source, template)
185
- list = template.at_css("#global-breadcrumb ol")
186
- assert_in list, "li:nth-child(1)", %{<a href="/">Home</a>}
187
- assert_in list, "li:nth-child(2)", %{<a href="/browse">All Sections</a>}
188
- assert_in list, "li:nth-child(3)", %{<a href="https://www.test.gov.uk/browse/business">Business</a>}
189
- assert_in list, "li:nth-child(4)", %{<a href="https://www.test.gov.uk/browse/business/employing-people">Employing people</a>}
190
- assert_in list, "li:nth-child(5)", %{<strong><a href="https://www.test.gov.uk/browse/business/employing-people/deep-section">Deep section</a></strong>}
191
- end
192
-
193
- end