govuk_navigation_helpers 9.1.0 → 9.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfe90c1b0207936166968071bbe57c3b9b6e98dd
4
- data.tar.gz: 9ad575a04047684089fafa8000807e1f242833ca
3
+ metadata.gz: f4b59802a5e4240cad012f8f71ead8a747d9c0c4
4
+ data.tar.gz: bcd0dc8d17c08421870f09ef71b4ebdac55a0966
5
5
  SHA512:
6
- metadata.gz: 6bbbceff78a86fef6711c84465bba37bcf8a676a14305f959e0de2cab8cbef5f07eb3310767a13040eb5c66fad6e843421e7dcd9d89b6d85eb2b3876c71fc41e
7
- data.tar.gz: 61d239cd0fe9de022bb8c3a982f3be957c7017bc1463da20ba15d33966a96ab9d8ef2380b862333e42a9d382afab697da9cbb4ed29344262258f06b9cdfff13c
6
+ metadata.gz: 82b6de3201c4ea05df44240791c324cc22ed57ef12eb079d9a53d3e620004e957d5661a0038c8dd859914a70bc2aa5af8c5a4d505a27fa4460e13530de7434a6
7
+ data.tar.gz: 171163b628d5b0bb4e52ef65b4602de53cb797a79736290e74549b66639d365edacb4ad944a85017f766c279aaacafc7d4f6d648481c802c2f9f5a0db8f33ed8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## 9.1.0
1
+ ## 9.2.0
2
+
3
+ * Step by step navigation helpers have been removed from here. They now live
4
+ in govuk_publishing_components as they are closely coupled to components that
5
+ also live there. (All apps have been updated with this)
6
+ * Remove Related Navigation Sidebar Helper as it has now been moved to govuk_publishing_components.
7
+ * Enable Taxonomy Sidebar Helper to return collection links.
8
+
9
+ ## 9.1.0
2
10
 
3
11
  * Check if a taxon's phase is 'live' to determine if it should be passed to a navigation component to be displayed on a page.
4
12
  * Remove the old content_id whitelisting approach to filtering for taxons.
@@ -9,12 +9,9 @@ require_relative "govuk_navigation_helpers/breadcrumbs"
9
9
  require_relative "govuk_navigation_helpers/related_items"
10
10
  require_relative "govuk_navigation_helpers/taxon_breadcrumbs"
11
11
  require_relative "govuk_navigation_helpers/taxonomy_sidebar"
12
- require_relative "govuk_navigation_helpers/related_navigation_sidebar"
13
12
  require_relative "govuk_navigation_helpers/rummager_taxonomy_sidebar_links"
14
13
  require_relative "govuk_navigation_helpers/curated_taxonomy_sidebar_links"
15
14
 
16
- require_relative "govuk_navigation_helpers/step_nav_content"
17
-
18
15
  module GovukNavigationHelpers
19
16
  class NavigationHelper
20
17
  def initialize(content_item)
@@ -54,15 +51,6 @@ module GovukNavigationHelpers
54
51
  RelatedItems.new(content_item).related_items
55
52
  end
56
53
 
57
- # Generate a payload containing related navigation sidebar data. Intended for use with
58
- # the related navigation component
59
- #
60
- # @return [Hash] Payload for the GOV.UK related navigation component
61
- # @see https://government-frontend.herokuapp.com/component-guide/related-navigation
62
- def related_navigation_sidebar
63
- RelatedNavigationSidebar.new(content_item).related_navigation_sidebar
64
- end
65
-
66
54
  private
67
55
 
68
56
  attr_reader :content_item
@@ -10,6 +10,7 @@ module GovukNavigationHelpers
10
10
  def sidebar
11
11
  {
12
12
  items: related_items,
13
+ collections: collections,
13
14
  }
14
15
  end
15
16
 
@@ -32,5 +33,15 @@ module GovukNavigationHelpers
32
33
  RummagerTaxonomySidebarLinks
33
34
  end
34
35
  end
36
+
37
+ def collections
38
+ links = @content_item.related_collections
39
+ links.map do |link|
40
+ {
41
+ path: link["base_path"],
42
+ text: link["title"]
43
+ }
44
+ end
45
+ end
35
46
  end
36
47
  end
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "9.1.0".freeze
2
+ VERSION = "9.2.0".freeze
3
3
  end
@@ -17,12 +17,13 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
17
17
  expect { sidebar_for(generator.payload) }.to_not raise_error
18
18
  end
19
19
 
20
- context 'given a content item not tagged to any taxon' do
20
+ context 'given a content item not tagged to any taxon with no document collections' do
21
21
  it 'returns an empty sidebar hash' do
22
22
  content_item = { "links" => {} }
23
23
 
24
24
  expect(sidebar_for(content_item)).to eq(
25
- items: []
25
+ items: [],
26
+ collections: []
26
27
  )
27
28
  end
28
29
  end
@@ -72,7 +73,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
72
73
  { 'title': 'Related item C', 'link': '/related-item-c', },
73
74
  ],
74
75
  },
75
- ]
76
+ ],
77
+ collections: [],
76
78
  )
77
79
  end
78
80
 
@@ -121,7 +123,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
121
123
  description: "The C taxon.",
122
124
  related_content: [],
123
125
  },
124
- ]
126
+ ],
127
+ collections: [],
125
128
  )
126
129
  end
127
130
  end
@@ -182,7 +185,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
182
185
  { 'title': 'Related item C', 'link': '/related-item-c', },
183
186
  ],
184
187
  }
185
- ]
188
+ ],
189
+ collections: [],
186
190
  )
187
191
  end
188
192
  end
@@ -221,7 +225,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
221
225
  { title: 'Related link override B', link: '/override-b' },
222
226
  ],
223
227
  }
224
- ]
228
+ ],
229
+ collections: [],
225
230
  )
226
231
  end
227
232
 
@@ -280,7 +285,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
280
285
  { 'title': 'Related link override B', 'link': '/override-b' },
281
286
  ],
282
287
  }
283
- ]
288
+ ],
289
+ collections: [],
284
290
  )
285
291
  end
286
292
 
@@ -317,7 +323,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
317
323
  description: "The B taxon.",
318
324
  related_content: [],
319
325
  }
320
- ]
326
+ ],
327
+ collections: [],
321
328
  )
322
329
  end
323
330
 
@@ -361,7 +368,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
361
368
  { title: 'Related link override', link: '/override' }
362
369
  ],
363
370
  },
364
- ]
371
+ ],
372
+ collections: [],
365
373
  )
366
374
  end
367
375
 
@@ -397,7 +405,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
397
405
  { title: 'Related link override', link: '/override' }
398
406
  ],
399
407
  },
400
- ]
408
+ ],
409
+ collections: [],
401
410
  )
402
411
  end
403
412
 
@@ -448,12 +457,32 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
448
457
  { title: 'External related link', link: 'http://example.com' }
449
458
  ],
450
459
  },
451
- ]
460
+ ],
461
+ collections: [],
452
462
  )
453
463
  end
454
464
  end
455
465
  end
456
466
 
467
+ context 'given a content item with document collections' do
468
+ it 'returns a sidebar hash containing document collections' do
469
+ content_item = content_item_with_document_collections
470
+
471
+ expect(sidebar_for(content_item)).to eq(
472
+ items: [],
473
+ collections: [
474
+ {
475
+ path: "/collection-b",
476
+ text: "Collection B",
477
+ },
478
+ {
479
+ path: "/collection-a",
480
+ text: "Collection A",
481
+ },
482
+ ]
483
+ )
484
+ end
485
+ end
457
486
  context 'when Rummager raises an exception' do
458
487
  error_handler = nil
459
488
 
@@ -515,4 +544,27 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
515
544
  },
516
545
  }
517
546
  end
547
+
548
+ def content_item_with_document_collections
549
+ {
550
+ "title" => "A piece of content",
551
+ "base_path" => "/a-piece-of-content",
552
+ "links" => {
553
+ "document_collections" => [
554
+ {
555
+ "title" => "Collection B",
556
+ "base_path" => "/collection-b",
557
+ "content_id" => "collection-b",
558
+ "document_type" => "document_collection",
559
+ },
560
+ {
561
+ "title" => "Collection A",
562
+ "base_path" => "/collection-a",
563
+ "content_id" => "collection-a",
564
+ "document_type" => "document_collection",
565
+ },
566
+ ],
567
+ },
568
+ }
569
+ end
518
570
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_navigation_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-07 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -196,7 +196,6 @@ files:
196
196
  - LICENCE.txt
197
197
  - README.md
198
198
  - Rakefile
199
- - config/step_navs/learn-to-drive-a-car.json
200
199
  - govuk_navigation_helpers.gemspec
201
200
  - lib/govuk_navigation_helpers.rb
202
201
  - lib/govuk_navigation_helpers/breadcrumbs.rb
@@ -205,19 +204,15 @@ files:
205
204
  - lib/govuk_navigation_helpers/curated_taxonomy_sidebar_links.rb
206
205
  - lib/govuk_navigation_helpers/grouped_related_links.rb
207
206
  - lib/govuk_navigation_helpers/related_items.rb
208
- - lib/govuk_navigation_helpers/related_navigation_sidebar.rb
209
207
  - lib/govuk_navigation_helpers/rummager_taxonomy_sidebar_links.rb
210
208
  - lib/govuk_navigation_helpers/services.rb
211
- - lib/govuk_navigation_helpers/step_nav_content.rb
212
209
  - lib/govuk_navigation_helpers/taxon_breadcrumbs.rb
213
210
  - lib/govuk_navigation_helpers/taxonomy_sidebar.rb
214
211
  - lib/govuk_navigation_helpers/version.rb
215
212
  - spec/breadcrumbs_spec.rb
216
213
  - spec/content_item_spec.rb
217
214
  - spec/related_items_spec.rb
218
- - spec/related_navigation_sidebar_spec.rb
219
215
  - spec/spec_helper.rb
220
- - spec/step_nav_content_spec.rb
221
216
  - spec/taxon_breadcrumbs_spec.rb
222
217
  - spec/taxonomy_sidebar_spec.rb
223
218
  homepage: https://github.com/alphagov/govuk_navigation_helpers
@@ -248,8 +243,6 @@ test_files:
248
243
  - spec/breadcrumbs_spec.rb
249
244
  - spec/content_item_spec.rb
250
245
  - spec/related_items_spec.rb
251
- - spec/related_navigation_sidebar_spec.rb
252
246
  - spec/spec_helper.rb
253
- - spec/step_nav_content_spec.rb
254
247
  - spec/taxon_breadcrumbs_spec.rb
255
248
  - spec/taxonomy_sidebar_spec.rb
@@ -1,248 +0,0 @@
1
- {
2
- "title": "Learn to drive a car: step by step",
3
- "base_path": "/learn-to-drive-a-car",
4
- "description": "<p>Check what you need to do to learn to drive.</p>",
5
- "links": {
6
- "breadcrumbs": [
7
- { "title": "Home", "url": "/" },
8
- { "title": "Driving and transport", "url": "/browse/driving"},
9
- { "title": "Learning to drive", "url": "/browse/driving/learning-to-drive"}
10
- ]
11
- },
12
- "related_paths": [
13
- "/apply-for-your-full-driving-licence",
14
- "/automatic-driving-licence-to-manual",
15
- "/complain-about-a-driving-instructor",
16
- "/driving-licence-fees",
17
- "/driving-test-cost",
18
- "/dvlaforms",
19
- "/find-theory-test-pass-number",
20
- "/government/publications/application-for-refunding-out-of-pocket-expenses",
21
- "/government/publications/drivers-record-for-learner-drivers",
22
- "/government/publications/driving-instructor-grades-explained",
23
- "/government/publications/know-your-traffic-signs",
24
- "/government/publications/l-plate-size-rules",
25
- "/guidance/rules-for-observing-driving-tests",
26
- "/report-an-illegal-driving-instructor",
27
- "/report-driving-test-impersonation",
28
- "/track-your-driving-licence-application",
29
- "/driving-lessons-learning-to-drive/practising-with-family-or-friends",
30
- "/driving-lessons-learning-to-drive/taking-driving-lessons",
31
- "/driving-lessons-learning-to-drive/using-l-and-p-plates",
32
- "/driving-test",
33
- "/driving-test/changes-december-2017",
34
- "/driving-test/disability-health-condition-or-learning-difficulty",
35
- "/driving-test/driving-test-faults-result",
36
- "/driving-test/test-cancelled-bad-weather",
37
- "/driving-test/using-your-own-car",
38
- "/driving-test/what-happens-during-test",
39
- "/pass-plus/apply-for-a-pass-plus-certificate",
40
- "/pass-plus/booking-pass-plus",
41
- "/pass-plus/car-insurance-discounts",
42
- "/pass-plus/local-councils-offering-discounts",
43
- "/pass-plus/how-pass-plus-training-works",
44
- "/theory-test",
45
- "/theory-test/hazard-perception-test",
46
- "/theory-test/if-you-have-safe-road-user-award",
47
- "/theory-test/multiple-choice-questions",
48
- "/theory-test/pass-mark-and-result",
49
- "/theory-test/reading-difficulty-disability-or-health-condition"
50
- ],
51
- "step_by_step_nav": {
52
- "steps": [
53
- {
54
- "title": "Check you're allowed to drive",
55
- "contents": [
56
- {
57
- "type": "paragraph",
58
- "text": "Most people can start learning to drive when they’re 17."
59
- },
60
- {
61
- "type": "list",
62
- "style": "required",
63
- "contents": [
64
- {
65
- "href": "/vehicles-can-drive",
66
- "text": "Check what age you can drive"
67
- },
68
- {
69
- "href": "/legal-obligations-drivers-riders",
70
- "text": "Requirements for driving legally"
71
- },
72
- {
73
- "href": "/driving-eyesight-rules",
74
- "text": "Driving eyesight rules"
75
- }
76
- ]
77
- }
78
- ]
79
- },
80
- {
81
- "title": "Get a provisional driving licence",
82
- "contents": [
83
- {
84
- "type": "list",
85
- "style": "required",
86
- "contents": [
87
- {
88
- "href": "/apply-first-provisional-driving-licence",
89
- "text": "Apply for your first provisional driving licence",
90
- "context": "£34"
91
- }
92
- ]
93
- }
94
- ]
95
- },
96
- {
97
- "title": "Driving lessons and practice",
98
- "contents": [
99
- {
100
- "type": "paragraph",
101
- "text": "You need a provisional driving licence to take lessons or practice."
102
- },
103
- {
104
- "type": "list",
105
- "style": "required",
106
- "contents": [
107
- {
108
- "href": "/guidance/the-highway-code",
109
- "text": "The Highway Code"
110
- },
111
- {
112
- "href": "/driving-lessons-learning-to-drive",
113
- "text": "Taking driving lessons"
114
- },
115
- {
116
- "href": "/find-driving-schools-and-lessons",
117
- "text": "Find driving schools, lessons and instructors"
118
- },
119
- {
120
- "href": "/government/publications/car-show-me-tell-me-vehicle-safety-questions",
121
- "text": "Practise vehicle safety questions"
122
- }
123
- ]
124
- }
125
- ]
126
- },
127
- {
128
- "title": "Prepare for your theory test",
129
- "logic": "and",
130
- "contents": [
131
- {
132
- "type": "list",
133
- "style": "required",
134
- "contents": [
135
- {
136
- "href": "/theory-test/revision-and-practice",
137
- "text": "Theory test revision and practice"
138
- },
139
- {
140
- "href": "/take-practice-theory-test",
141
- "text": "Take a practice theory test"
142
- },
143
- {
144
- "href": "https://www.safedrivingforlife.info/shop/product/official-dvsa-theory-test-kit-app-app",
145
- "text": "Theory and hazard perception test app"
146
- }
147
- ]
148
- }
149
- ]
150
- },
151
- {
152
- "title": "Book and manage your theory test",
153
- "contents": [
154
- {
155
- "type": "paragraph",
156
- "text": "You need a provisional driving licence to book your theory test."
157
- },
158
- {
159
- "type": "list",
160
- "style": "required",
161
- "contents": [
162
- {
163
- "href": "/book-theory-test",
164
- "text": "Book your theory test",
165
- "context": "£23"
166
- },
167
- {
168
- "href": "/theory-test/what-to-take",
169
- "text": "What to take to your test"
170
- },
171
- {
172
- "href": "/change-theory-test",
173
- "text": "Change your theory test appointment"
174
- },
175
- {
176
- "href": "/check-theory-test",
177
- "text": "Check your theory test appointment details"
178
- },
179
- {
180
- "href": "/cancel-theory-test",
181
- "text": "Cancel your theory test"
182
- }
183
- ]
184
- }
185
- ]
186
- },
187
- {
188
- "title": "Book and manage your driving test",
189
- "contents": [
190
- {
191
- "type": "paragraph",
192
- "text": "You must pass your theory test before you can book your driving test."
193
- },
194
- {
195
- "type": "list",
196
- "style": "required",
197
- "contents": [
198
- {
199
- "href": "/book-driving-test",
200
- "text": "Book your driving test",
201
- "context": "£62"
202
- },
203
- {
204
- "href": "/driving-test/what-to-take",
205
- "text": "What to take to your test"
206
- },
207
- {
208
- "href": "/change-driving-test",
209
- "text": "Change your driving test appointment"
210
- },
211
- {
212
- "href": "/check-driving-test",
213
- "text": "Check your driving test appointment details"
214
- },
215
- {
216
- "href": "/cancel-driving-test",
217
- "text": "Cancel your driving test"
218
- }
219
- ]
220
- }
221
- ]
222
- },
223
- {
224
- "title": "When you pass",
225
- "contents": [
226
- {
227
- "type": "paragraph",
228
- "text": "You can start driving as soon as you pass your driving test."
229
- },
230
- {
231
- "type": "paragraph",
232
- "text": "You must have an insurance policy that allows you to drive without supervision."
233
- },
234
- {
235
- "type": "list",
236
- "style": "required",
237
- "contents": [
238
- {
239
- "href": "/pass-plus",
240
- "text": "Find out about Pass Plus training courses"
241
- }
242
- ]
243
- }
244
- ]
245
- }
246
- ]
247
- }
248
- }
@@ -1,140 +0,0 @@
1
- require 'govuk_navigation_helpers/services'
2
- require 'govuk_navigation_helpers/configuration'
3
-
4
- module GovukNavigationHelpers
5
- class RelatedNavigationSidebar
6
- def initialize(content_item)
7
- @content_item = ContentItem.new content_item
8
- end
9
-
10
- def related_navigation_sidebar
11
- {
12
- related_items: related_items,
13
- collections: related_collections,
14
- statistical_data_sets: related_statistical_data_sets,
15
- topics: related_topics,
16
- topical_events: related_topical_events,
17
- policies: related_policies,
18
- publishers: related_organisations,
19
- world_locations: related_world_locations,
20
- worldwide_organisations: related_worldwide_organisations,
21
- other: [related_external_links, related_contacts]
22
- }
23
- end
24
-
25
- private
26
-
27
- def build_links_for_sidebar(collection, path_key = "base_path", additional_attr = {})
28
- collection.map do |link|
29
- {
30
- text: link["title"],
31
- path: link[path_key]
32
- }.merge(additional_attr)
33
- end
34
- end
35
-
36
- def world_location_base_path(title)
37
- "/world/#{parameterise(title)}/news"
38
- end
39
-
40
- def related_items
41
- quick_links = build_links_for_sidebar(@content_item.quick_links, "url")
42
-
43
- quick_links.any? ? quick_links : build_links_for_sidebar(@content_item.related_ordered_items)
44
- end
45
-
46
- def related_organisations
47
- build_links_for_sidebar(@content_item.related_organisations)
48
- end
49
-
50
- def related_world_locations
51
- locations = @content_item.related_world_locations
52
- locations.map! { |link| link.merge("base_path" => world_location_base_path(link["title"])) }
53
- build_links_for_sidebar(locations)
54
- end
55
-
56
- def related_worldwide_organisations
57
- build_links_for_sidebar(@content_item.related_worldwide_organisations)
58
- end
59
-
60
- def related_collections
61
- build_links_for_sidebar(@content_item.related_collections)
62
- end
63
-
64
- def related_policies
65
- build_links_for_sidebar(@content_item.related_policies)
66
- end
67
-
68
- def related_statistical_data_sets
69
- build_links_for_sidebar(@content_item.related_statistical_data_sets)
70
- end
71
-
72
- def related_topics
73
- topics = build_links_for_sidebar(@content_item.related_topics)
74
- topics << related_mainstream_topic << related_mainstream_parent_topic
75
- deduplicate_topics_by_title(topics.compact)
76
- end
77
-
78
- def related_topical_events
79
- build_links_for_sidebar(@content_item.related_topical_events)
80
- end
81
-
82
- def related_contacts
83
- return [] unless @content_item.related_other_contacts.any?
84
- [
85
- title: "Other contacts",
86
- links: build_links_for_sidebar(@content_item.related_other_contacts).map
87
- ]
88
- end
89
-
90
- def related_external_links
91
- return [] unless @content_item.external_links.any?
92
- [
93
- title: "Elsewhere on the web",
94
- links: build_links_for_sidebar(@content_item.external_links, "url", rel: 'external')
95
- ]
96
- end
97
-
98
- def related_mainstream_topic
99
- return unless grouped.tagged_to_same_mainstream_browse_page.any?
100
- { text: @content_item.parent.title, path: @content_item.parent.base_path }
101
- end
102
-
103
- def related_mainstream_parent_topic
104
- return unless grouped.parents_tagged_to_same_mainstream_browse_page.any?
105
- { text: @content_item.parent.parent.title, path: @content_item.parent.parent.base_path }
106
- end
107
-
108
- # This method post-processes the topics collated by the helper.
109
- # We add mainstream browse page links if they are present, however
110
- # if these have the same title as an existing topic we should prefer
111
- # the mainstream version and remove the existing topic.
112
- # @see spec/related_navigation_sidebar_spec.rb:260 for test coverage.
113
- def deduplicate_topics_by_title(topics)
114
- is_dupe = lambda { |a, b| a && a != b && a[:text] == b[:text] }
115
-
116
- topics.delete_if do |t|
117
- is_dupe.call(related_mainstream_topic, t) ||
118
- is_dupe.call(related_mainstream_parent_topic, t)
119
- end
120
-
121
- topics
122
- end
123
-
124
- def parameterise(str, sep = "-")
125
- parameterised_str = str.gsub(/[^\w\-]+/, sep)
126
- unless sep.nil? || sep.empty?
127
- re_sep = Regexp.escape(sep)
128
- # No more than one of the separator in a row.
129
- parameterised_str.gsub!(/#{re_sep}{2,}/, sep)
130
- # Remove leading/trailing separator.
131
- parameterised_str.gsub!(/^#{re_sep}|#{re_sep}$/, '')
132
- end
133
- parameterised_str.downcase
134
- end
135
-
136
- def grouped
137
- @grouped ||= GroupedRelatedLinks.new(@content_item)
138
- end
139
- end
140
- end
@@ -1,107 +0,0 @@
1
- module GovukNavigationHelpers
2
- class StepNavContent
3
- STEP_NAV_NAMES = %w(
4
- learn-to-drive-a-car
5
- ).freeze
6
-
7
- def self.current_step_nav(path)
8
- STEP_NAV_NAMES.each do |step_nav_name|
9
- step_nav = new(file_name: step_nav_name, path: path)
10
- return step_nav if step_nav.current?
11
- end
12
- nil
13
- end
14
-
15
- def initialize(file_name: nil, path: nil)
16
- @file_name = file_name
17
- @path = path
18
- end
19
-
20
- def title
21
- parsed_file.dig(:title)
22
- end
23
-
24
- def base_path
25
- parsed_file.dig(:base_path)
26
- end
27
-
28
- def step_nav
29
- parsed_file.dig(:step_by_step_nav)
30
- end
31
-
32
- def skip_link
33
- "##{steps.first[:title].downcase.tr(' ', '-')}"
34
- end
35
-
36
- def primary_paths
37
- primary_content.reject { |href|
38
- href.start_with?('http')
39
- }.select(&:present?)
40
- end
41
-
42
- def steps
43
- step_nav.dig(:steps)
44
- end
45
-
46
- def related_paths
47
- parsed_file.dig(:related_paths)
48
- end
49
-
50
- def set_current_step
51
- set_step_as_active_if_current_page
52
- end
53
-
54
- def show_step_nav?
55
- primary_paths.include?(path) ||
56
- related_paths.include?(path)
57
- end
58
-
59
- def current?
60
- primary_paths.include?(path) ||
61
- related_paths.include?(path)
62
- end
63
-
64
- private
65
-
66
- attr_reader :file_name, :file, :path
67
-
68
- def set_step_as_active_if_current_page
69
- steps.each_with_index do |step, step_index|
70
- step[:contents].each do |content|
71
- next unless content[:contents]
72
-
73
- content[:contents].each do |link|
74
- if link[:href] == path
75
- link[:active] = true
76
- step_nav[:show_step] = step_index + 1
77
- step_nav[:highlight_step] = step_index + 1
78
- return step_nav
79
- end
80
- end
81
- end
82
- end
83
-
84
- step_nav
85
- end
86
-
87
- def primary_content
88
- list_content = steps.flat_map do |step|
89
- step[:contents].select { |item| item[:type] == "list" }
90
- .flat_map { |item| item[:contents] }
91
- end
92
-
93
- list_content.map { |list_item| list_item[:href] }
94
- end
95
-
96
- def parsed_file
97
- @parsed_file ||=
98
- JSON.parse(
99
- File.read(
100
- File.join(File.dirname(__FILE__), "../../", "config", "step_navs", "#{file_name}.json")
101
- )
102
- ).deep_symbolize_keys.tap do |json_file|
103
- json_file[:step_by_step_nav].merge!(small: true, heading_level: 3)
104
- end
105
- end
106
- end
107
- end
@@ -1,306 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe GovukNavigationHelpers::RelatedNavigationSidebar do
4
- def payload_for(schema, content_item)
5
- generator = GovukSchemas::RandomExample.for_schema(schema, schema_type: "frontend")
6
- fully_valid_content_item = generator.merge_and_validate(content_item)
7
- GovukNavigationHelpers::NavigationHelper.new(fully_valid_content_item).related_navigation_sidebar
8
- end
9
-
10
- describe "#related-navigation-sidebar" do
11
- it "can handle randomly generated content" do
12
- generator = GovukSchemas::RandomExample.for_schema("placeholder", schema_type: "frontend")
13
-
14
- expect { payload_for("placeholder", generator.payload) }.to_not raise_error
15
- end
16
-
17
- it "returns empty arrays if there are no related navigation sidebar links" do
18
- nothing = payload_for("placeholder",
19
- "details" => {
20
- "external_related_links" => []
21
- },
22
- "links" => {
23
- })
24
-
25
- expected = {
26
- related_items: [],
27
- collections: [],
28
- statistical_data_sets: [],
29
- topics: [],
30
- topical_events: [],
31
- policies: [],
32
- publishers: [],
33
- world_locations: [],
34
- worldwide_organisations: [],
35
- other: [[], []]
36
- }
37
-
38
- expect(nothing).to eql(expected)
39
- end
40
-
41
- it "extracts and returns the appropriate related links" do
42
- payload = payload_for("speech",
43
- "details" => {
44
- "body" => "body",
45
- "government" => {
46
- "title" => "government",
47
- "slug" => "government",
48
- "current" => true
49
- },
50
- "political" => true,
51
- "delivered_on" => "2017-09-22T14:30:00+01:00"
52
- },
53
- "links" => {
54
- "parent" => [
55
- {
56
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
57
- "locale" => "en",
58
- "base_path" => "/mainstream-topic",
59
- "title" => "mainstream topic"
60
- }
61
- ],
62
- "ordered_related_items" => [
63
- {
64
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
65
- "locale" => "en",
66
- "base_path" => "/related-item",
67
- "title" => "related item",
68
- "links" => {
69
- "mainstream_browse_pages" => [
70
- {
71
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
72
- "locale" => "en",
73
- "base_path" => "/mainstream-topic",
74
- "title" => "mainstream topic"
75
- }
76
- ]
77
- }
78
- }
79
- ],
80
- "document_collections" => [
81
- {
82
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
83
- "locale" => "en",
84
- "base_path" => "/related-collection",
85
- "title" => "related collection",
86
- "document_type" => "document_collection"
87
- }
88
- ],
89
- "topics" => [
90
- {
91
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
92
- "locale" => "en",
93
- "base_path" => "/related-topic",
94
- "title" => "related topic",
95
- "document_type" => "topic"
96
- }
97
- ],
98
- "topical_events" => [
99
- {
100
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
101
- "locale" => "en",
102
- "base_path" => "/related-topical-event",
103
- "title" => "related topical event",
104
- "document_type" => "topical_event"
105
- }
106
- ],
107
- "organisations" => [
108
- {
109
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
110
- "locale" => "en",
111
- "base_path" => "/related-organisation",
112
- "title" => "related organisation",
113
- "document_type" => "organisation"
114
- }
115
- ],
116
- "related_policies" => [
117
- {
118
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
119
- "locale" => "en",
120
- "base_path" => "/related-policy",
121
- "title" => "related policy",
122
- "document_type" => "policy"
123
- }
124
- ],
125
- "world_locations" => [
126
- {
127
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
128
- "title" => "World, ~ (@Location)",
129
- "locale" => "en"
130
- }
131
- ],
132
- })
133
-
134
- expected = {
135
- related_items: [{ path: "/related-item", text: "related item" }],
136
- collections: [{ path: "/related-collection", text: "related collection" }],
137
- topics: [{ path: "/related-topic", text: "related topic" }, { path: "/mainstream-topic", text: "mainstream topic" }],
138
- topical_events: [{ path: "/related-topical-event", text: "related topical event" }],
139
- policies: [{ path: "/related-policy", text: "related policy" }],
140
- publishers: [{ path: "/related-organisation", text: "related organisation" }],
141
- world_locations: [{ path: "/world/world-location/news", text: "World, ~ (@Location)" }],
142
- worldwide_organisations: [],
143
- statistical_data_sets: [],
144
- other: [[], []]
145
- }
146
-
147
- expect(payload).to eql(expected)
148
- end
149
-
150
- it "returns worldwide organisations" do
151
- payload = payload_for("world_location_news_article",
152
- "details" => {
153
- "body" => "body",
154
- "government" => {
155
- "title" => "government",
156
- "slug" => "government",
157
- "current" => true
158
- },
159
- "political" => true,
160
- "first_public_at" => "2016-01-01T19:00:00Z",
161
- },
162
- "links" => {
163
- "worldwide_organisations" => [
164
- {
165
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
166
- "title" => "related worldwide organisation",
167
- "base_path" => "/related-worldwide-organisation",
168
- "document_type" => "worldwide_organisation",
169
- "locale" => "en"
170
- }
171
- ],
172
- })
173
- expected = {
174
- related_items: [],
175
- collections: [],
176
- statistical_data_sets: [],
177
- topics: [],
178
- topical_events: [],
179
- policies: [],
180
- publishers: [],
181
- world_locations: [],
182
- worldwide_organisations: [{ path: "/related-worldwide-organisation", text: "related worldwide organisation" }],
183
- other: [[], []]
184
- }
185
- expect(payload).to eql(expected)
186
- end
187
-
188
- it "returns statistical data sets" do
189
- payload = payload_for("publication",
190
- "details" => {
191
- "body" => "body",
192
- "government" => {
193
- "title" => "government",
194
- "slug" => "government",
195
- "current" => true
196
- },
197
- "political" => false,
198
- "documents" => [],
199
- "first_public_at" => "2016-01-01T19:00:00Z",
200
- },
201
- "links" => {
202
- "related_statistical_data_sets" => [
203
- {
204
- "content_id" => "32c1b93d-2553-47c9-bc3c-fc5b513ecc32",
205
- "title" => "related statistical data set",
206
- "base_path" => "/related-statistical-data-set",
207
- "document_type" => "statistical_data_set",
208
- "locale" => "en"
209
- }
210
- ],
211
- })
212
- expected = {
213
- related_items: [],
214
- collections: [],
215
- statistical_data_sets: [{ path: "/related-statistical-data-set", text: "related statistical data set" }],
216
- topics: [],
217
- topical_events: [],
218
- policies: [],
219
- publishers: [],
220
- world_locations: [],
221
- worldwide_organisations: [],
222
- other: [[], []]
223
- }
224
- expect(payload).to eql(expected)
225
- end
226
-
227
- it "returns an Elsewhere on the web section for external related links" do
228
- payload = payload_for("placeholder",
229
- "details" => {
230
- "external_related_links" => [
231
- {
232
- "title" => "external-link",
233
- "url" => "https://external"
234
- }
235
- ]
236
- },)
237
-
238
- expected = [
239
- [
240
- {
241
- title: "Elsewhere on the web",
242
- links: [{
243
- text: "external-link",
244
- path: "https://external",
245
- rel: "external"
246
- }]
247
- }
248
- ],
249
- []
250
- ]
251
-
252
- expect(payload[:other]).to eql(expected)
253
- end
254
-
255
- it "deduplicates topics for mainstream content" do
256
- mainstream_browse_link = {
257
- "content_id" => "fecdc8c8-4006-4f8e-95d5-fe40ca49c7a8",
258
- "locale" => "en",
259
- "title" => "Self Assessment",
260
- "base_path" => "/browse/tax/self-assessment",
261
- "document_type" => "mainstream_browse_page",
262
- }
263
- payload = payload_for("answer",
264
- "details" => {
265
- "external_related_links" => []
266
- },
267
- "links" => {
268
- "mainstream_browse_pages" => [mainstream_browse_link],
269
- "ordered_related_items" => [
270
- {
271
- "content_id" => "f29ca4a8-8ed9-4b0f-bb6a-11e373095dee",
272
- "locale" => "en",
273
- "title" => "Self Assessment tax returns",
274
- "base_path" => "/self-assessment-tax-returns",
275
- "document_type" => "guide",
276
- "links" => { "mainstream_browse_pages" => [mainstream_browse_link] },
277
- }
278
- ],
279
- "parent" => [mainstream_browse_link],
280
- "topics" => [
281
- {
282
- "content_id" => "7beb97b6-75c9-4aa7-86be-a733ab3a21aa",
283
- "locale" => "en",
284
- "base_path" => "/topic/personal-tax/self-assessment",
285
- "title" => "Self Assessment",
286
- "document_type" => "topic",
287
- }
288
- ],
289
- })
290
- expected = {
291
- related_items: [{ text: "Self Assessment tax returns", path: "/self-assessment-tax-returns" }],
292
- collections: [],
293
- statistical_data_sets: [],
294
- topics: [{ text: "Self Assessment", path: "/browse/tax/self-assessment" }],
295
- topical_events: [],
296
- policies: [],
297
- publishers: [],
298
- world_locations: [],
299
- worldwide_organisations: [],
300
- other: [[], []]
301
- }
302
-
303
- expect(payload).to eql(expected)
304
- end
305
- end
306
- end
@@ -1,163 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module GovukNavigationHelpers
4
- RSpec.describe StepNavContent do
5
- let(:path) { '/pass-plus' }
6
- let(:step_nav_content) { described_class.new(file_name: "learn-to-drive-a-car", path: path) }
7
-
8
- context '.current_step_nav' do
9
- context 'based on the request' do
10
- context 'when the path is /pass-plus' do
11
- it 'returns "Learn to Drive" step nav' do
12
- current_step_nav = described_class.current_step_nav(path)
13
-
14
- expect(
15
- current_step_nav.title
16
- ).to eql('Learn to drive a car: step by step')
17
- end
18
- end
19
- end
20
- end
21
-
22
- context '#show_step_nav?' do
23
- context 'when the requested path is part of the current step nav' do
24
- it 'returns true' do
25
- expect(
26
- step_nav_content.show_step_nav?
27
- ).to be true
28
- end
29
- end
30
-
31
- context 'when the requested path is not part of the current step nav' do
32
- let(:path) { '/pink-plus' }
33
-
34
- it 'returns false' do
35
- expect(
36
- step_nav_content.show_step_nav?
37
- ).to be false
38
- end
39
- end
40
- end
41
-
42
- context '#set_current_step' do
43
- it 'sets /pass-plus as active' do
44
- step_nav_content.set_current_step
45
-
46
- expect(
47
- step_nav_content.steps.last[:contents].last[:contents][0][:href]
48
- ).to eql('/pass-plus')
49
-
50
- expect(
51
- step_nav_content.step_nav[:show_step]
52
- ).to eql(7)
53
-
54
- expect(
55
- step_nav_content.steps.last[:contents].last[:contents][0][:active]
56
- ).to be true
57
- end
58
- end
59
-
60
- context "learning to drive a car step nav content" do
61
- it "has symbolized keys" do
62
- step_nav_content.step_nav.each_key do |key|
63
- expect(key.is_a?(Symbol)).to be true
64
- end
65
- end
66
-
67
- it "has a title" do
68
- expect(step_nav_content.title).to eql("Learn to drive a car: step by step")
69
- end
70
-
71
- it "has a base_path" do
72
- expect(step_nav_content.base_path).to eql("/learn-to-drive-a-car")
73
- end
74
-
75
- it "configures a sidebar" do
76
- expect(step_nav_content.step_nav[:heading_level]).to eql(3)
77
- expect(step_nav_content.step_nav[:small]).to be true
78
- end
79
-
80
- it "has a link in the correct structure" do
81
- first_link = step_nav_content.step_nav[:steps][0][:contents][1][:contents][0]
82
- expect(first_link[:href]).to eql("/vehicles-can-drive")
83
- expect(first_link[:text]).to eql("Check what age you can drive")
84
- end
85
-
86
- it 'has all the primary paths' do
87
- primary_paths = %w(
88
- /apply-first-provisional-driving-licence
89
- /book-driving-test
90
- /book-theory-test
91
- /cancel-driving-test
92
- /cancel-theory-test
93
- /change-driving-test
94
- /change-theory-test
95
- /check-driving-test
96
- /check-theory-test
97
- /driving-eyesight-rules
98
- /driving-lessons-learning-to-drive
99
- /driving-test/what-to-take
100
- /find-driving-schools-and-lessons
101
- /government/publications/car-show-me-tell-me-vehicle-safety-questions
102
- /guidance/the-highway-code
103
- /legal-obligations-drivers-riders
104
- /pass-plus
105
- /take-practice-theory-test
106
- /theory-test/revision-and-practice
107
- /theory-test/what-to-take
108
- /vehicles-can-drive
109
- ).sort
110
-
111
- expect(
112
- step_nav_content.primary_paths.sort
113
- ).to match_array(primary_paths)
114
- end
115
-
116
- it 'has related paths' do
117
- related_paths = %w(
118
- /apply-for-your-full-driving-licence
119
- /automatic-driving-licence-to-manual
120
- /complain-about-a-driving-instructor
121
- /driving-licence-fees
122
- /driving-test-cost
123
- /dvlaforms
124
- /find-theory-test-pass-number
125
- /government/publications/application-for-refunding-out-of-pocket-expenses
126
- /government/publications/drivers-record-for-learner-drivers
127
- /government/publications/driving-instructor-grades-explained
128
- /government/publications/know-your-traffic-signs
129
- /government/publications/l-plate-size-rules
130
- /guidance/rules-for-observing-driving-tests
131
- /report-an-illegal-driving-instructor
132
- /report-driving-test-impersonation
133
- /track-your-driving-licence-application
134
- /driving-lessons-learning-to-drive/practising-with-family-or-friends
135
- /driving-lessons-learning-to-drive/taking-driving-lessons
136
- /driving-lessons-learning-to-drive/using-l-and-p-plates
137
- /driving-test
138
- /driving-test/changes-december-2017
139
- /driving-test/disability-health-condition-or-learning-difficulty
140
- /driving-test/driving-test-faults-result
141
- /driving-test/test-cancelled-bad-weather
142
- /driving-test/using-your-own-car
143
- /driving-test/what-happens-during-test
144
- /pass-plus/apply-for-a-pass-plus-certificate
145
- /pass-plus/booking-pass-plus
146
- /pass-plus/car-insurance-discounts
147
- /pass-plus/local-councils-offering-discounts
148
- /pass-plus/how-pass-plus-training-works
149
- /theory-test
150
- /theory-test/hazard-perception-test
151
- /theory-test/if-you-have-safe-road-user-award
152
- /theory-test/multiple-choice-questions
153
- /theory-test/pass-mark-and-result
154
- /theory-test/reading-difficulty-disability-or-health-condition
155
- ).sort
156
-
157
- expect(
158
- step_nav_content.related_paths.sort
159
- ).to match_array(related_paths)
160
- end
161
- end
162
- end
163
- end