govuk_navigation_helpers 5.0.0 → 5.1.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: d4930be4a5498eeb6b86415ba59fca3ebcbb14e6
4
- data.tar.gz: c0f02bb16a2056a6e7fbcf19209ac01f54222c9b
3
+ metadata.gz: 6ac714eea19839eabbed2cec6ed4b2afdd1203d9
4
+ data.tar.gz: 202443d3c79e4e6124f158178a3a988107ac06fa
5
5
  SHA512:
6
- metadata.gz: 3f5fba2c927c6d120277a1ec511ea6578d9ca85f582124a569212508cc13c580b1ee030aee06fdb6c0f2b426dab364c04efca497ca491670cf5657c958277e02
7
- data.tar.gz: 24a32d862aa6ca7579f6bb474e0295e9f2c97fc80aa2b0204102caab97b6b4cc7e4104c852aac7fa123c24f4f4df676703bf5729c6ac0be627ccf5ced08d725d
6
+ metadata.gz: 024044fab1cae98132ceebc1256415cec5a89760ee44044b8ee7399751fa85a46d6265b219afedd6a568a6c14d01ca95cd71c3ee5adc976a7741bb201c53a03e
7
+ data.tar.gz: bac53adaa9c93b8e8c719171b8c627dc7cc54487a86a373af08b968c97c38d83f6080ac309ecc63a8d943865cd7cbb6df893c5506e25a47492ebbfeef9adb1cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 5.1.0
2
+
3
+ * Display Elsewhere in GOV.UK and Elsewhere on the web related links on new
4
+ taxonomy sidebar.
5
+
1
6
  ## 5.0.0
2
7
 
3
8
  * **BREAKING CHANGE**: Update the gds-api-adapters gem. This includes a change
@@ -62,6 +62,12 @@ module GovukNavigationHelpers
62
62
  end
63
63
  end
64
64
 
65
+ def related_overrides
66
+ content_store_response.dig("links", "ordered_related_items_overrides").to_a.map do |link|
67
+ ContentItem.new(link)
68
+ end
69
+ end
70
+
65
71
  def external_links
66
72
  content_store_response.dig("details", "external_related_links").to_a
67
73
  end
@@ -9,7 +9,7 @@ module GovukNavigationHelpers
9
9
 
10
10
  def sidebar
11
11
  {
12
- items: taxons
12
+ items: [taxons, elsewhere_on_govuk, elsewhere_on_the_web].flatten
13
13
  }
14
14
  end
15
15
 
@@ -34,9 +34,46 @@ module GovukNavigationHelpers
34
34
  end
35
35
  end
36
36
 
37
- # This method will fetch content related to @content_item, and tagged to taxon. This is a
38
- # temporary method that uses search to achieve this. This behaviour is to be moved into
39
- # the content store
37
+ def elsewhere_on_govuk
38
+ return [] if @content_item.related_overrides.empty?
39
+
40
+ related_content = @content_item.related_overrides.map do |override|
41
+ {
42
+ title: override.title,
43
+ link: override.base_path
44
+ }
45
+ end
46
+
47
+ [
48
+ {
49
+ title: "Elsewhere on GOV.UK",
50
+ related_content: related_content
51
+ }
52
+ ]
53
+ end
54
+
55
+ def elsewhere_on_the_web
56
+ return [] if @content_item.external_links.empty?
57
+
58
+ related_content = @content_item.external_links.map do |external_link|
59
+ {
60
+ title: external_link.fetch('title'),
61
+ link: external_link.fetch('url'),
62
+ rel: 'external'
63
+ }
64
+ end
65
+
66
+ [
67
+ {
68
+ title: "Elsewhere on the web",
69
+ related_content: related_content
70
+ }
71
+ ]
72
+ end
73
+
74
+ # This method will fetch content related to @content_item, and tagged to
75
+ # taxon. This is a temporary method that uses search to achieve this. This
76
+ # behaviour is to be moved into the content store.
40
77
  def content_related_to(taxon)
41
78
  statsd.time(:taxonomy_sidebar_search_time) do
42
79
  begin
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "5.0.0".freeze
2
+ VERSION = "5.1.0".freeze
3
3
  end
@@ -123,6 +123,48 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
123
123
  ]
124
124
  )
125
125
  end
126
+
127
+ it "includes curated and external links when available" do
128
+ expect(GovukNavigationHelpers.configuration.statsd).to receive(
129
+ :increment
130
+ ).with(
131
+ :taxonomy_sidebar_searches
132
+ ).once
133
+
134
+ content_item =
135
+ content_item_tagged_to_taxon_with_curated_and_external_links
136
+
137
+ expect(sidebar_for(content_item)).to eq(
138
+ items: [
139
+ {
140
+ title: "Taxon A",
141
+ url: "/taxon-a",
142
+ description: "The A taxon.",
143
+ related_content: [
144
+ { 'title': 'Related item A', 'link': '/related-item-a', },
145
+ { 'title': 'Related item B', 'link': '/related-item-b', },
146
+ { 'title': 'Related item C', 'link': '/related-item-c', },
147
+ ],
148
+ },
149
+ {
150
+ title: "Elsewhere on GOV.UK",
151
+ related_content: [
152
+ { title: "Curated link 1", link: "/curated-link-1" }
153
+ ]
154
+ },
155
+ {
156
+ title: "Elsewhere on the web",
157
+ related_content: [
158
+ {
159
+ title: "An external link",
160
+ link: "www.external-link.com",
161
+ rel: "external"
162
+ }
163
+ ]
164
+ }
165
+ ]
166
+ )
167
+ end
126
168
  end
127
169
 
128
170
  context 'when Rummager raises an exception' do
@@ -184,4 +226,32 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
184
226
  },
185
227
  }
186
228
  end
229
+
230
+ def content_item_tagged_to_taxon_with_curated_and_external_links
231
+ {
232
+ "title" => "A piece of content",
233
+ "base_path" => "/a-piece-of-content",
234
+ "links" => {
235
+ "taxons" => [
236
+ {
237
+ "title" => "Taxon A",
238
+ "base_path" => "/taxon-a",
239
+ "content_id" => "taxon-a",
240
+ "description" => "The A taxon.",
241
+ }
242
+ ],
243
+ "ordered_related_items_overrides" => [
244
+ "title" => "Curated link 1",
245
+ "base_path" => "/curated-link-1",
246
+ "content_id" => "curated-link-1",
247
+ ]
248
+ },
249
+ "details" => {
250
+ "external_related_links" => [
251
+ "url" => "www.external-link.com",
252
+ "title" => "An external link"
253
+ ]
254
+ }
255
+ }
256
+ end
187
257
  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: 5.0.0
4
+ version: 5.1.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: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters