govuk_navigation_helpers 6.0.0 → 6.0.1

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: 6cdcea6379cf6d09c857f36769c16203d5d8b812
4
- data.tar.gz: 0e118e185e0d05725753b9a8b2d1948a595fe84f
3
+ metadata.gz: 434be3c06278a7ab5026fb992df43a9f128c089a
4
+ data.tar.gz: 0a2d1c74c4f0c23fa99246c2bf77a8dda41b5de5
5
5
  SHA512:
6
- metadata.gz: a4402b69ee51003193321c3ca76d7450238c99f62cfbc6b6a967862dee1237d21d3eb5bf8f0f811c2697b280e1c751f2fd27446558a1bdc55cc097f7039c3c6b
7
- data.tar.gz: 45fa9631f380619fc91034ba55d8c40a7f072a3c6f05b4f69583fab9f37ed9d5c41d5daeaf863931d6b413f86bf4a966b99995ae19696a3588fe92e8eebf26af
6
+ metadata.gz: 7b1b8f7edf9bd7ea448378da790de77ec89275124afd01b9cc8da42f91507af886f9b2681b1651d75d08784868c4f5baec9c110895643b666cf46d636f140f9b
7
+ data.tar.gz: eb6fcd6a1a34a4c0136d7a5ffedb3e4799d2e6fae684c0e18e12b4ed3d2ebda134bc194ddab298c7e85e249fc3a5660a145737a386878852a9fc9ba2f9c3f2ad
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 6.0.1
2
+
3
+ * Remove duplicate related links from search for the new taxonomy sidebar.
4
+
1
5
  ## 6.0.0
2
6
 
3
7
  * **BREAKING CHANGE**: Bump gds-api-adapters to 42.2, which makes `lgil`
@@ -62,12 +62,6 @@ 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
-
71
65
  def external_links
72
66
  content_store_response.dig("details", "external_related_links").to_a
73
67
  end
@@ -9,7 +9,7 @@ module GovukNavigationHelpers
9
9
 
10
10
  def sidebar
11
11
  {
12
- items: [taxons, elsewhere_on_govuk, elsewhere_on_the_web].flatten
12
+ items: taxons
13
13
  }
14
14
  end
15
15
 
@@ -21,9 +21,14 @@ module GovukNavigationHelpers
21
21
 
22
22
  def taxons
23
23
  parent_taxons = @content_item.parent_taxons
24
+ used_related_links = Set.new
24
25
 
25
26
  parent_taxons.each_with_index.map do |parent_taxon, index|
26
- related_content = index < 2 ? content_related_to(parent_taxon) : []
27
+ related_content = index < 2 ? content_related_to(parent_taxon, used_related_links) : []
28
+
29
+ used_related_links.merge(
30
+ related_content.map { |content| content[:link] }
31
+ )
27
32
 
28
33
  {
29
34
  title: parent_taxon.title,
@@ -34,47 +39,10 @@ module GovukNavigationHelpers
34
39
  end
35
40
  end
36
41
 
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.
77
- def content_related_to(taxon)
42
+ # This method will fetch content related to @content_item, and tagged to taxon. This is a
43
+ # temporary method that uses search to achieve this. This behaviour is to be moved into
44
+ # the content store
45
+ def content_related_to(taxon, used_related_links)
78
46
  statsd.time(:taxonomy_sidebar_search_time) do
79
47
  begin
80
48
  results = Services.rummager.search(
@@ -83,6 +51,7 @@ module GovukNavigationHelpers
83
51
  count: 3,
84
52
  filter_taxons: [taxon.content_id],
85
53
  filter_navigation_document_supertype: 'guidance',
54
+ reject_link: used_related_links.to_a,
86
55
  fields: %w[title link],
87
56
  )['results']
88
57
 
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "6.0.0".freeze
2
+ VERSION = "6.0.1".freeze
3
3
  end
@@ -6,9 +6,9 @@ include GdsApi::TestHelpers::Rummager
6
6
 
7
7
  RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
8
8
  describe '#sidebar' do
9
- before { stub_any_rummager_search_to_return_no_results }
10
-
11
9
  it 'can handle any valid content item' do
10
+ stub_any_rummager_search_to_return_no_results
11
+
12
12
  generator = GovukSchemas::RandomExample.for_schema(
13
13
  'placeholder',
14
14
  schema_type: 'frontend'
@@ -123,16 +123,44 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
123
123
  ]
124
124
  )
125
125
  end
126
+ end
127
+
128
+ context 'given there are repeated related links across different parent taxons' do
129
+ before do
130
+ # First taxon should have links A and B
131
+ stub_request(
132
+ :get,
133
+ %r{.*search.json?.*\&filter_taxons%5B%5D=taxon-a.*}
134
+ ).to_return(
135
+ body: {
136
+ 'results': [
137
+ { 'title': 'Related item A', 'link': '/related-item-a', },
138
+ { 'title': 'Related item B', 'link': '/related-item-b', },
139
+ ],
140
+ }.to_json
141
+ )
142
+
143
+ # Second taxon should only return link C, and reject the other 2
144
+ stub_request(
145
+ :get,
146
+ %r{.*search.json?.*\&filter_taxons%5B%5D=taxon-b.*&reject_link%5B%5D=/related-item-a&reject_link%5B%5D=/related-item-b.*}
147
+ ).to_return(
148
+ body: {
149
+ 'results': [
150
+ { 'title': 'Related item C', 'link': '/related-item-c', },
151
+ ],
152
+ }.to_json
153
+ )
154
+ end
126
155
 
127
- it "includes curated and external links when available" do
156
+ it 'does not duplicate the related links across each taxon' do
128
157
  expect(GovukNavigationHelpers.configuration.statsd).to receive(
129
158
  :increment
130
159
  ).with(
131
160
  :taxonomy_sidebar_searches
132
- ).once
161
+ ).twice
133
162
 
134
- content_item =
135
- content_item_tagged_to_taxon_with_curated_and_external_links
163
+ content_item = content_item_tagged_to_taxon
136
164
 
137
165
  expect(sidebar_for(content_item)).to eq(
138
166
  items: [
@@ -143,24 +171,15 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
143
171
  related_content: [
144
172
  { 'title': 'Related item A', 'link': '/related-item-a', },
145
173
  { 'title': 'Related item B', 'link': '/related-item-b', },
146
- { 'title': 'Related item C', 'link': '/related-item-c', },
147
174
  ],
148
175
  },
149
176
  {
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",
177
+ title: "Taxon B",
178
+ url: "/taxon-b",
179
+ description: "The B taxon.",
157
180
  related_content: [
158
- {
159
- title: "An external link",
160
- link: "www.external-link.com",
161
- rel: "external"
162
- }
163
- ]
181
+ { 'title': 'Related item C', 'link': '/related-item-c', },
182
+ ],
164
183
  }
165
184
  ]
166
185
  )
@@ -226,32 +245,4 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
226
245
  },
227
246
  }
228
247
  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
257
248
  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: 6.0.0
4
+ version: 6.0.1
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-04-24 00:00:00.000000000 Z
11
+ date: 2017-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters