govuk_navigation_helpers 3.1.1 → 3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f91260ea75a1db921c4b82de4aff1cceb0ed68
|
4
|
+
data.tar.gz: 28253a57bee243f566f2588bf70325a44134f76b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2406adc6eb2b21a485c910f05fcb9c531a3b82b96c631bfea410e377e2df028c164ac5bf4b9ce6ac00744a540eee47aae9589e98d6edb25d1486dda5d97dea8
|
7
|
+
data.tar.gz: 00664e1d2ecce5b360899b158a1645d8c507519b2a1b80c2d5513ad4e81eefadbc4f91d64f856acc43655310e49888e18da5d39e5037f818fd704848e0a1e3bd
|
data/CHANGELOG.md
CHANGED
@@ -26,12 +26,12 @@ module GovukNavigationHelpers
|
|
26
26
|
def parent_taxons
|
27
27
|
# First handle the case for content items tagged to the taxonomy.
|
28
28
|
taxons = Array(content_store_response.dig("links", "taxons"))
|
29
|
-
return taxons.map { |taxon| ContentItem.new(taxon) } if taxons.any?
|
29
|
+
return taxons.map { |taxon| ContentItem.new(taxon) }.sort_by(&:title) if taxons.any?
|
30
30
|
|
31
31
|
# If that link isn't present, assume we're dealing with a taxon and check
|
32
32
|
# for its parents in the taxonomy.
|
33
33
|
parent_taxons = Array(content_store_response.dig("links", "parent_taxons"))
|
34
|
-
parent_taxons.map { |taxon| ContentItem.new(taxon) }
|
34
|
+
parent_taxons.map { |taxon| ContentItem.new(taxon) }.sort_by(&:title)
|
35
35
|
end
|
36
36
|
|
37
37
|
def mainstream_browse_pages
|
@@ -49,12 +49,9 @@ module GovukNavigationHelpers
|
|
49
49
|
|
50
50
|
statsd.increment(:taxonomy_sidebar_searches)
|
51
51
|
|
52
|
-
results
|
53
|
-
{
|
54
|
-
|
55
|
-
link: result['link'],
|
56
|
-
}
|
57
|
-
end
|
52
|
+
results
|
53
|
+
.map { |result| { title: result['title'], link: result['link'], } }
|
54
|
+
.sort_by { |result| result[:title] }
|
58
55
|
rescue StandardError => e
|
59
56
|
GovukNavigationHelpers.configuration.error_handler.notify(e)
|
60
57
|
[]
|
@@ -6,19 +6,7 @@ include GdsApi::TestHelpers::Rummager
|
|
6
6
|
|
7
7
|
RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
8
8
|
describe '#sidebar' do
|
9
|
-
before
|
10
|
-
stub_any_rummager_search
|
11
|
-
.to_return(
|
12
|
-
body: {
|
13
|
-
'results': [
|
14
|
-
{
|
15
|
-
'title': 'Result Content',
|
16
|
-
'link': '/result-content',
|
17
|
-
},
|
18
|
-
],
|
19
|
-
}.to_json
|
20
|
-
)
|
21
|
-
end
|
9
|
+
before { stub_any_rummager_search_to_return_no_results }
|
22
10
|
|
23
11
|
it 'can handle any valid content item' do
|
24
12
|
generator = GovukSchemas::RandomExample.for_schema(
|
@@ -39,8 +27,21 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
|
39
27
|
end
|
40
28
|
end
|
41
29
|
|
42
|
-
context 'given a content item tagged to taxons' do
|
43
|
-
|
30
|
+
context 'given a content item tagged to taxons and with related items' do
|
31
|
+
before do
|
32
|
+
stub_any_rummager_search
|
33
|
+
.to_return(
|
34
|
+
body: {
|
35
|
+
'results': [
|
36
|
+
{ 'title': 'Related item C', 'link': '/related-item-c', },
|
37
|
+
{ 'title': 'Related item B', 'link': '/related-item-b', },
|
38
|
+
{ 'title': 'Related item A', 'link': '/related-item-a', },
|
39
|
+
],
|
40
|
+
}.to_json
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns a sidebar hash containing a sorted list of parent taxons and related content' do
|
44
45
|
expect(GovukNavigationHelpers.configuration.statsd).to receive(
|
45
46
|
:increment
|
46
47
|
).with(
|
@@ -52,25 +53,23 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
|
52
53
|
expect(sidebar_for(content_item)).to eq(
|
53
54
|
items: [
|
54
55
|
{
|
55
|
-
title: "Taxon
|
56
|
-
url: "/taxon-
|
57
|
-
description: "The
|
56
|
+
title: "Taxon A",
|
57
|
+
url: "/taxon-a",
|
58
|
+
description: "The A taxon.",
|
58
59
|
related_content: [
|
59
|
-
{
|
60
|
-
|
61
|
-
|
62
|
-
},
|
60
|
+
{ 'title': 'Related item A', 'link': '/related-item-a', },
|
61
|
+
{ 'title': 'Related item B', 'link': '/related-item-b', },
|
62
|
+
{ 'title': 'Related item C', 'link': '/related-item-c', },
|
63
63
|
],
|
64
64
|
},
|
65
65
|
{
|
66
|
-
title: "Taxon
|
67
|
-
url: "/taxon-
|
68
|
-
description: "The
|
66
|
+
title: "Taxon B",
|
67
|
+
url: "/taxon-b",
|
68
|
+
description: "The B taxon.",
|
69
69
|
related_content: [
|
70
|
-
{
|
71
|
-
|
72
|
-
|
73
|
-
},
|
70
|
+
{ 'title': 'Related item A', 'link': '/related-item-a', },
|
71
|
+
{ 'title': 'Related item B', 'link': '/related-item-b', },
|
72
|
+
{ 'title': 'Related item C', 'link': '/related-item-c', },
|
74
73
|
],
|
75
74
|
},
|
76
75
|
]
|
@@ -122,16 +121,16 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
|
122
121
|
"links" => {
|
123
122
|
"taxons" => [
|
124
123
|
{
|
125
|
-
"title" => "Taxon
|
126
|
-
"base_path" => "/taxon-
|
127
|
-
"content_id" => "
|
128
|
-
"description" => "The
|
124
|
+
"title" => "Taxon B",
|
125
|
+
"base_path" => "/taxon-b",
|
126
|
+
"content_id" => "taxon-b",
|
127
|
+
"description" => "The B taxon.",
|
129
128
|
},
|
130
129
|
{
|
131
|
-
"title" => "Taxon
|
132
|
-
"base_path" => "/taxon-
|
133
|
-
"content_id" => "
|
134
|
-
"description" => "The
|
130
|
+
"title" => "Taxon A",
|
131
|
+
"base_path" => "/taxon-a",
|
132
|
+
"content_id" => "taxon-a",
|
133
|
+
"description" => "The A taxon.",
|
135
134
|
},
|
136
135
|
],
|
137
136
|
},
|