govuk_navigation_helpers 6.3.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/govuk_navigation_helpers/content_item.rb +41 -8
- data/lib/govuk_navigation_helpers/version.rb +1 -1
- data/spec/content_item_spec.rb +212 -0
- data/spec/taxon_breadcrumbs_spec.rb +47 -37
- data/spec/taxonomy_sidebar_spec.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec1764a33f8094c760cd5a83e47ae8a51277b119
|
4
|
+
data.tar.gz: f28cae4e16260780344f7f77c5d0043f569d628e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91bade4008ffcbbaf9c51dbd2a86a93ab474b0b5fc8c9038113016e7ffc6d9de9b59e227629d000e1ded82944779534f58c3aefe72b6acd7c746fda3ce00e4d6
|
7
|
+
data.tar.gz: 865b85c47eeed422b1960e5874b391f8f298d8a01a686ddbb8699fec6ab35246ecfd89750a9534f9f227a13e9661ca6c4143d0483946406fd8093de665724592
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 7.0.0
|
2
|
+
|
3
|
+
* Root taxons are now whitelisted, so that only taxons descendant from one of
|
4
|
+
the three published root taxons (education, childcare-parenting and world)
|
5
|
+
will appear in breadcrumbs and the side bar. See the [PR](https://github.com/alphagov/govuk_navigation_helpers/pull/82) for more information
|
6
|
+
|
1
7
|
## 6.3.0
|
2
8
|
|
3
9
|
* Allow curated related links to be shown on the new navigation sidebar. If the
|
@@ -5,6 +5,18 @@ module GovukNavigationHelpers
|
|
5
5
|
#
|
6
6
|
# @private
|
7
7
|
class ContentItem
|
8
|
+
WORLD_TAXON_CONTENT_ID = "91b8ef20-74e7-4552-880c-50e6d73c2ff9".freeze
|
9
|
+
EDUCATION_TAXON_CONTENT_ID = "c58fdadd-7743-46d6-9629-90bb3ccc4ef0".freeze
|
10
|
+
CHILDCARE_PARENTING_TAXON_CONTENT_ID = "206b7f3a-49b5-476f-af0f-fd27e2a68473".freeze
|
11
|
+
|
12
|
+
def self.whitelisted_root_taxon_content_ids
|
13
|
+
[
|
14
|
+
WORLD_TAXON_CONTENT_ID,
|
15
|
+
EDUCATION_TAXON_CONTENT_ID,
|
16
|
+
CHILDCARE_PARENTING_TAXON_CONTENT_ID,
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
8
20
|
attr_reader :content_store_response
|
9
21
|
|
10
22
|
def initialize(content_store_response)
|
@@ -24,14 +36,11 @@ module GovukNavigationHelpers
|
|
24
36
|
end
|
25
37
|
|
26
38
|
def parent_taxons
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# for its parents in the taxonomy.
|
33
|
-
parent_taxons = Array(content_store_response.dig("links", "parent_taxons"))
|
34
|
-
parent_taxons.map { |taxon| ContentItem.new(taxon) }.sort_by(&:title)
|
39
|
+
@_parent_taxons ||= begin
|
40
|
+
taxon_links
|
41
|
+
.select { |t| descendent_from_whitelisted_root_taxon?(t) }
|
42
|
+
.map { |taxon| ContentItem.new(taxon) }.sort_by(&:title)
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
def mainstream_browse_pages
|
@@ -90,5 +99,29 @@ module GovukNavigationHelpers
|
|
90
99
|
def eql?(other)
|
91
100
|
self == other
|
92
101
|
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def taxon_links
|
106
|
+
# A normal content item's taxon links are stored in ["links"]["taxons"]
|
107
|
+
# whereas a Taxon content item's taxon links are stored in ["links"]["parent_taxons"]
|
108
|
+
# so here we cater for both possibilities
|
109
|
+
content_store_response.dig("links", "taxons") || content_store_response.dig("links", "parent_taxons") || []
|
110
|
+
end
|
111
|
+
|
112
|
+
def descendent_from_whitelisted_root_taxon?(taxon)
|
113
|
+
root_taxon = get_root_taxon(taxon)
|
114
|
+
ContentItem.whitelisted_root_taxon_content_ids.include?(root_taxon["content_id"])
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_root_taxon(taxon)
|
118
|
+
parent_taxons = taxon.dig("links", "parent_taxons")
|
119
|
+
|
120
|
+
if parent_taxons.nil? || parent_taxons.empty?
|
121
|
+
taxon
|
122
|
+
else
|
123
|
+
get_root_taxon(parent_taxons.first)
|
124
|
+
end
|
125
|
+
end
|
93
126
|
end
|
94
127
|
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe GovukNavigationHelpers::ContentItem do
|
4
|
+
describe ".whitelisted_root_taxon_content_ids" do
|
5
|
+
it "returns the whitelisted content_ids" do
|
6
|
+
expected_content_ids = [
|
7
|
+
"91b8ef20-74e7-4552-880c-50e6d73c2ff9",
|
8
|
+
"c58fdadd-7743-46d6-9629-90bb3ccc4ef0",
|
9
|
+
"206b7f3a-49b5-476f-af0f-fd27e2a68473",
|
10
|
+
]
|
11
|
+
|
12
|
+
content_ids = described_class.whitelisted_root_taxon_content_ids
|
13
|
+
expect(content_ids).to eq(expected_content_ids)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#parent_taxons" do
|
18
|
+
before do
|
19
|
+
allow(described_class)
|
20
|
+
.to receive(:whitelisted_root_taxon_content_ids)
|
21
|
+
.and_return(["aaaa-bbbb"])
|
22
|
+
end
|
23
|
+
|
24
|
+
context "for a content item with taxons links" do
|
25
|
+
context "with a whitelisted parent taxon" do
|
26
|
+
let(:taxon) do
|
27
|
+
{
|
28
|
+
"content_id" => "cccc-dddd",
|
29
|
+
"title" => "Taxon",
|
30
|
+
"links" => {
|
31
|
+
"parent_taxons" => [
|
32
|
+
{
|
33
|
+
"content_id" => "aaaa-bbbb",
|
34
|
+
"title" => "Taxon",
|
35
|
+
}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:content_item_response) do
|
42
|
+
{
|
43
|
+
"title" => "Some Answer Content Item",
|
44
|
+
"document_type" => "answer",
|
45
|
+
"links" => {
|
46
|
+
"taxons" => [taxon],
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns the parent taxons" do
|
52
|
+
expected_parent_taxon = described_class.new(taxon)
|
53
|
+
expect(described_class.new(content_item_response).parent_taxons).to contain_exactly(expected_parent_taxon)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with a non-whitelisted parent taxon" do
|
58
|
+
let(:taxon) do
|
59
|
+
{
|
60
|
+
"content_id" => "cccc-dddd",
|
61
|
+
"title" => "Taxon",
|
62
|
+
"links" => {
|
63
|
+
"parent_taxons" => [
|
64
|
+
{
|
65
|
+
"content_id" => "xxxx-xxxx",
|
66
|
+
"title" => "Non Whitelisted Taxon",
|
67
|
+
}
|
68
|
+
]
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
let(:content_item_response) do
|
74
|
+
{
|
75
|
+
"title" => "Some Answer Content Item",
|
76
|
+
"document_type" => "answer",
|
77
|
+
"links" => {
|
78
|
+
"taxons" => [taxon],
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns an empty array" do
|
84
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "for a content item with no taxons links" do
|
90
|
+
context "with missing links hash" do
|
91
|
+
let(:content_item_response) do
|
92
|
+
{
|
93
|
+
"title" => "Some Answer Content Item",
|
94
|
+
"document_type" => "answer",
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
it "returns an empty array" do
|
99
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "with missing taxons links hash" do
|
104
|
+
let(:content_item_response) do
|
105
|
+
{
|
106
|
+
"title" => "Some Answer Content Item",
|
107
|
+
"document_type" => "answer",
|
108
|
+
"links" => {},
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns an empty array" do
|
113
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "for a taxon content item with parent taxon links" do
|
119
|
+
context "with a whitelisted parent taxon" do
|
120
|
+
let(:taxon) do
|
121
|
+
{
|
122
|
+
"content_id" => "cccc-dddd",
|
123
|
+
"title" => "Taxon",
|
124
|
+
"links" => {
|
125
|
+
"parent_taxons" => [
|
126
|
+
{
|
127
|
+
"content_id" => "aaaa-bbbb",
|
128
|
+
"title" => "Taxon",
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
let(:content_item_response) do
|
136
|
+
{
|
137
|
+
"title" => "Some Taxon Content Item",
|
138
|
+
"document_type" => "taxon",
|
139
|
+
"links" => {
|
140
|
+
"parent_taxons" => [taxon],
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
it "returns the parent taxons" do
|
146
|
+
expected_parent_taxon = described_class.new(taxon)
|
147
|
+
expect(described_class.new(content_item_response).parent_taxons).to contain_exactly(expected_parent_taxon)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "with a non-whitelisted parent taxon" do
|
152
|
+
let(:taxon) do
|
153
|
+
{
|
154
|
+
"content_id" => "cccc-dddd",
|
155
|
+
"title" => "Taxon",
|
156
|
+
"links" => {
|
157
|
+
"parent_taxons" => [
|
158
|
+
{
|
159
|
+
"content_id" => "xxxx-xxxx",
|
160
|
+
"title" => "Non Whitelisted Taxon",
|
161
|
+
}
|
162
|
+
]
|
163
|
+
}
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
let(:content_item_response) do
|
168
|
+
{
|
169
|
+
"title" => "Some Taxon Content Item",
|
170
|
+
"document_type" => "taxon",
|
171
|
+
"links" => {
|
172
|
+
"parent_taxons" => [taxon],
|
173
|
+
}
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns an empty array" do
|
178
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "for a taxon content item with no parent taxons links" do
|
184
|
+
context "with missing links hash" do
|
185
|
+
let(:content_item_response) do
|
186
|
+
{
|
187
|
+
"title" => "Some Taxon Content Item",
|
188
|
+
"document_type" => "taxon",
|
189
|
+
}
|
190
|
+
end
|
191
|
+
|
192
|
+
it "returns an empty array" do
|
193
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "with missing parent taxons links hash" do
|
198
|
+
let(:content_item_response) do
|
199
|
+
{
|
200
|
+
"title" => "Some Taxon Content Item",
|
201
|
+
"document_type" => "taxon",
|
202
|
+
"links" => {},
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
it "returns an empty array" do
|
207
|
+
expect(described_class.new(content_item_response).parent_taxons).to eq([])
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
4
4
|
describe "Taxon breadcrumbs" do
|
5
|
+
before do
|
6
|
+
allow(GovukNavigationHelpers::ContentItem)
|
7
|
+
.to receive(:whitelisted_root_taxon_content_ids)
|
8
|
+
.and_return(['30c1b93d-2553-47c9-bc3c-fc5b513ecc32'])
|
9
|
+
end
|
10
|
+
|
5
11
|
it "can handle any valid content item" do
|
6
12
|
generator = GovukSchemas::RandomExample.for_schema(
|
7
13
|
"taxon",
|
@@ -16,7 +22,11 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
16
22
|
end
|
17
23
|
|
18
24
|
it "returns the root when taxon is not specified" do
|
19
|
-
content_item = {
|
25
|
+
content_item = {
|
26
|
+
"title" => "Some Content",
|
27
|
+
"document_type" => "answer",
|
28
|
+
"links" => {},
|
29
|
+
}
|
20
30
|
breadcrumbs = breadcrumbs_for(content_item)
|
21
31
|
|
22
32
|
expect(breadcrumbs).to eq(
|
@@ -40,23 +50,23 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
40
50
|
)
|
41
51
|
end
|
42
52
|
|
43
|
-
context 'with a taxon
|
53
|
+
context 'with a taxon with taxon parents' do
|
44
54
|
it "includes parents and grandparents when available" do
|
45
55
|
grandparent = {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
"title" => "Another-parent",
|
57
|
+
"base_path" => "/another-parent",
|
58
|
+
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
59
|
+
"locale" => "en",
|
50
60
|
}
|
51
61
|
|
52
62
|
parent = {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
64
|
+
"locale" => "en",
|
65
|
+
"title" => "A-parent",
|
66
|
+
"base_path" => "/a-parent",
|
67
|
+
"links" => {
|
68
|
+
"parent_taxons" => [grandparent]
|
69
|
+
}
|
60
70
|
}
|
61
71
|
|
62
72
|
content_item = content_item_tagged_to_taxon([parent])
|
@@ -74,16 +84,16 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
74
84
|
end
|
75
85
|
end
|
76
86
|
|
77
|
-
context 'with a taxon with parent taxons' do
|
87
|
+
context 'with a taxon content item with parent taxons' do
|
78
88
|
it "includes parents and grandparents when available" do
|
79
89
|
parent = {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
90
|
+
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
91
|
+
"locale" => "en",
|
92
|
+
"title" => "A-parent",
|
93
|
+
"base_path" => "/a-parent",
|
94
|
+
"links" => {
|
95
|
+
"parent_taxons" => []
|
96
|
+
}
|
87
97
|
}
|
88
98
|
|
89
99
|
content_item = taxon_with_parent_taxons([parent])
|
@@ -102,22 +112,22 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
102
112
|
context 'with multiple parents' do
|
103
113
|
it "selects the first parent taxon in alphabetical order by title" do
|
104
114
|
parent_1 = {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
115
|
+
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
116
|
+
"locale" => "en",
|
117
|
+
"title" => "Parent A",
|
118
|
+
"base_path" => "/parent-a",
|
119
|
+
"links" => {
|
120
|
+
"parent_taxons" => []
|
121
|
+
}
|
112
122
|
}
|
113
123
|
parent_2 = {
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
125
|
+
"locale" => "en",
|
126
|
+
"title" => "Parent B",
|
127
|
+
"base_path" => "/parent-b",
|
128
|
+
"links" => {
|
129
|
+
"parent_taxons" => []
|
130
|
+
}
|
121
131
|
}
|
122
132
|
|
123
133
|
content_item = taxon_with_parent_taxons([parent_2, parent_1])
|
@@ -135,7 +145,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
135
145
|
end
|
136
146
|
|
137
147
|
def breadcrumbs_for(content_item)
|
138
|
-
generator = GovukSchemas::RandomExample.for_schema("
|
148
|
+
generator = GovukSchemas::RandomExample.for_schema(content_item["document_type"], schema_type: "frontend")
|
139
149
|
fully_valid_content_item = generator.merge_and_validate(content_item)
|
140
150
|
|
141
151
|
# Use the main class instead of GovukNavigationHelpers::Breadcrumbs, so that
|
@@ -156,7 +166,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
156
166
|
def content_item_tagged_to_taxon(parents)
|
157
167
|
{
|
158
168
|
"title" => "Some Content",
|
159
|
-
"document_type" => "
|
169
|
+
"document_type" => "answer",
|
160
170
|
"links" => {
|
161
171
|
"taxons" => [
|
162
172
|
{
|
@@ -6,6 +6,12 @@ include GdsApi::TestHelpers::Rummager
|
|
6
6
|
|
7
7
|
RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
8
8
|
describe '#sidebar' do
|
9
|
+
before do
|
10
|
+
allow(GovukNavigationHelpers::ContentItem)
|
11
|
+
.to receive(:whitelisted_root_taxon_content_ids)
|
12
|
+
.and_return(['taxon-a', 'taxon-b', 'taxon-c'])
|
13
|
+
end
|
14
|
+
|
9
15
|
it 'can handle any valid content item' do
|
10
16
|
stub_any_rummager_search_to_return_no_results
|
11
17
|
|
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:
|
4
|
+
version: 7.0.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-
|
11
|
+
date: 2017-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gds-api-adapters
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/govuk_navigation_helpers/taxonomy_sidebar.rb
|
183
183
|
- lib/govuk_navigation_helpers/version.rb
|
184
184
|
- spec/breadcrumbs_spec.rb
|
185
|
+
- spec/content_item_spec.rb
|
185
186
|
- spec/related_items_spec.rb
|
186
187
|
- spec/spec_helper.rb
|
187
188
|
- spec/taxon_breadcrumbs_spec.rb
|
@@ -212,6 +213,7 @@ specification_version: 4
|
|
212
213
|
summary: Gem to transform items from the content-store into payloads for GOV.UK components
|
213
214
|
test_files:
|
214
215
|
- spec/breadcrumbs_spec.rb
|
216
|
+
- spec/content_item_spec.rb
|
215
217
|
- spec/related_items_spec.rb
|
216
218
|
- spec/spec_helper.rb
|
217
219
|
- spec/taxon_breadcrumbs_spec.rb
|