govuk_navigation_helpers 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/Jenkinsfile +2 -1
- data/README.md +5 -0
- data/lib/govuk_navigation_helpers/content_item.rb +5 -28
- data/lib/govuk_navigation_helpers/version.rb +1 -1
- data/spec/content_item_spec.rb +8 -23
- data/spec/taxon_breadcrumbs_spec.rb +6 -6
- data/spec/taxonomy_sidebar_spec.rb +4 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfe90c1b0207936166968071bbe57c3b9b6e98dd
|
4
|
+
data.tar.gz: 9ad575a04047684089fafa8000807e1f242833ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bbbceff78a86fef6711c84465bba37bcf8a676a14305f959e0de2cab8cbef5f07eb3310767a13040eb5c66fad6e843421e7dcd9d89b6d85eb2b3876c71fc41e
|
7
|
+
data.tar.gz: 61d239cd0fe9de022bb8c3a982f3be957c7017bc1463da20ba15d33966a96ab9d8ef2380b862333e42a9d382afab697da9cbb4ed29344262258f06b9cdfff13c
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
##
|
1
|
+
## 9.1.0
|
2
|
+
|
3
|
+
* 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
|
+
* Remove the old content_id whitelisting approach to filtering for taxons.
|
2
5
|
|
3
6
|
## 9.0.0
|
4
7
|
* Task lists are now called "step by step navigation". Things have been renamed to support this
|
data/Jenkinsfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
This is a gem to share code between GOV.UK frontends.
|
4
4
|
|
5
|
+
** It should not be used anymore ***
|
6
|
+
|
7
|
+
This gem was a temporary solution to the problem of sharing code used to generate
|
8
|
+
the input to components. Since the components can now be built into the [govuk_publishing_components gem](https://github.com/alphagov/govuk_publishing_components), it is no longer necessary.
|
9
|
+
|
5
10
|
## Nomenclature
|
6
11
|
|
7
12
|
- **content item**: An object returned by the content store
|
@@ -5,18 +5,6 @@ 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
|
-
|
20
8
|
attr_reader :content_store_response
|
21
9
|
|
22
10
|
def initialize(content_store_response)
|
@@ -38,11 +26,15 @@ module GovukNavigationHelpers
|
|
38
26
|
def parent_taxons
|
39
27
|
@_parent_taxons ||= begin
|
40
28
|
taxon_links
|
41
|
-
.select { |t|
|
29
|
+
.select { |t| phase_is_live?(t) }
|
42
30
|
.map { |taxon| ContentItem.new(taxon) }.sort_by(&:title)
|
43
31
|
end
|
44
32
|
end
|
45
33
|
|
34
|
+
def phase_is_live?(taxon)
|
35
|
+
taxon["phase"] == "live"
|
36
|
+
end
|
37
|
+
|
46
38
|
def mainstream_browse_pages
|
47
39
|
content_store_response.dig("links", "mainstream_browse_pages").to_a.map do |link|
|
48
40
|
ContentItem.new(link)
|
@@ -153,21 +145,6 @@ module GovukNavigationHelpers
|
|
153
145
|
content_store_response.dig("links", "taxons") || content_store_response.dig("links", "parent_taxons") || []
|
154
146
|
end
|
155
147
|
|
156
|
-
def descendent_from_whitelisted_root_taxon?(taxon)
|
157
|
-
root_taxon = get_root_taxon(taxon)
|
158
|
-
ContentItem.whitelisted_root_taxon_content_ids.include?(root_taxon["content_id"])
|
159
|
-
end
|
160
|
-
|
161
|
-
def get_root_taxon(taxon)
|
162
|
-
parent_taxons = taxon.dig("links", "parent_taxons")
|
163
|
-
|
164
|
-
if parent_taxons.nil? || parent_taxons.empty?
|
165
|
-
taxon
|
166
|
-
else
|
167
|
-
get_root_taxon(parent_taxons.first)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
148
|
def filter_link_type(links, type)
|
172
149
|
links.select do |link|
|
173
150
|
link["document_type"] == type
|
data/spec/content_item_spec.rb
CHANGED
@@ -1,32 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
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
4
|
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
5
|
context "for a content item with taxons links" do
|
25
|
-
context "with a
|
6
|
+
context "with a parent taxon with phase set to 'live'" do
|
26
7
|
let(:taxon) do
|
27
8
|
{
|
28
9
|
"content_id" => "cccc-dddd",
|
29
10
|
"title" => "Taxon",
|
11
|
+
"phase" => "live",
|
30
12
|
"links" => {
|
31
13
|
"parent_taxons" => [
|
32
14
|
{
|
@@ -54,11 +36,12 @@ RSpec.describe GovukNavigationHelpers::ContentItem do
|
|
54
36
|
end
|
55
37
|
end
|
56
38
|
|
57
|
-
context "with a
|
39
|
+
context "with a parent taxon with phase not set to 'live'" do
|
58
40
|
let(:taxon) do
|
59
41
|
{
|
60
42
|
"content_id" => "cccc-dddd",
|
61
43
|
"title" => "Taxon",
|
44
|
+
"phase" => "beta",
|
62
45
|
"links" => {
|
63
46
|
"parent_taxons" => [
|
64
47
|
{
|
@@ -116,11 +99,12 @@ RSpec.describe GovukNavigationHelpers::ContentItem do
|
|
116
99
|
end
|
117
100
|
|
118
101
|
context "for a taxon content item with parent taxon links" do
|
119
|
-
context "with a
|
102
|
+
context "with a parent taxon with phase set to 'live'" do
|
120
103
|
let(:taxon) do
|
121
104
|
{
|
122
105
|
"content_id" => "cccc-dddd",
|
123
106
|
"title" => "Taxon",
|
107
|
+
"phase" => "live",
|
124
108
|
"links" => {
|
125
109
|
"parent_taxons" => [
|
126
110
|
{
|
@@ -148,11 +132,12 @@ RSpec.describe GovukNavigationHelpers::ContentItem do
|
|
148
132
|
end
|
149
133
|
end
|
150
134
|
|
151
|
-
context "with a
|
135
|
+
context "with a parent taxon with phase not set to 'live'" do
|
152
136
|
let(:taxon) do
|
153
137
|
{
|
154
138
|
"content_id" => "cccc-dddd",
|
155
139
|
"title" => "Taxon",
|
140
|
+
"phase" => "beta",
|
156
141
|
"links" => {
|
157
142
|
"parent_taxons" => [
|
158
143
|
{
|
@@ -2,12 +2,6 @@ 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
|
-
|
11
5
|
it "can handle any valid content item" do
|
12
6
|
generator = GovukSchemas::RandomExample.for_schema(
|
13
7
|
"taxon",
|
@@ -57,6 +51,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
57
51
|
"base_path" => "/another-parent",
|
58
52
|
"content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
|
59
53
|
"locale" => "en",
|
54
|
+
"phase" => "live",
|
60
55
|
}
|
61
56
|
|
62
57
|
parent = {
|
@@ -64,6 +59,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
64
59
|
"locale" => "en",
|
65
60
|
"title" => "A-parent",
|
66
61
|
"base_path" => "/a-parent",
|
62
|
+
"phase" => "live",
|
67
63
|
"links" => {
|
68
64
|
"parent_taxons" => [grandparent]
|
69
65
|
}
|
@@ -91,6 +87,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
91
87
|
"locale" => "en",
|
92
88
|
"title" => "A-parent",
|
93
89
|
"base_path" => "/a-parent",
|
90
|
+
"phase" => "live",
|
94
91
|
"links" => {
|
95
92
|
"parent_taxons" => []
|
96
93
|
}
|
@@ -116,6 +113,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
116
113
|
"locale" => "en",
|
117
114
|
"title" => "Parent A",
|
118
115
|
"base_path" => "/parent-a",
|
116
|
+
"phase" => "live",
|
119
117
|
"links" => {
|
120
118
|
"parent_taxons" => []
|
121
119
|
}
|
@@ -125,6 +123,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
125
123
|
"locale" => "en",
|
126
124
|
"title" => "Parent B",
|
127
125
|
"base_path" => "/parent-b",
|
126
|
+
"phase" => "live",
|
128
127
|
"links" => {
|
129
128
|
"parent_taxons" => []
|
130
129
|
}
|
@@ -174,6 +173,7 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
|
|
174
173
|
"locale" => "en",
|
175
174
|
"title" => "Taxon",
|
176
175
|
"base_path" => "/taxon",
|
176
|
+
"phase" => "live",
|
177
177
|
"links" => {
|
178
178
|
"parent_taxons" => parents
|
179
179
|
},
|
@@ -6,12 +6,6 @@ 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
|
-
|
15
9
|
it 'can handle any valid content item' do
|
16
10
|
stub_any_rummager_search_to_return_no_results
|
17
11
|
|
@@ -95,7 +89,8 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
|
95
89
|
"title" => "Taxon C",
|
96
90
|
"base_path" => "/taxon-c",
|
97
91
|
"content_id" => "taxon-c",
|
98
|
-
"description" => "The C taxon."
|
92
|
+
"description" => "The C taxon.",
|
93
|
+
"phase" => "live",
|
99
94
|
}
|
100
95
|
|
101
96
|
expect(sidebar_for(content_item)).to eq(
|
@@ -507,12 +502,14 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
|
|
507
502
|
"base_path" => "/taxon-b",
|
508
503
|
"content_id" => "taxon-b",
|
509
504
|
"description" => "The B taxon.",
|
505
|
+
"phase" => "live",
|
510
506
|
},
|
511
507
|
{
|
512
508
|
"title" => "Taxon A",
|
513
509
|
"base_path" => "/taxon-a",
|
514
510
|
"content_id" => "taxon-a",
|
515
511
|
"description" => "The A taxon.",
|
512
|
+
"phase" => "live",
|
516
513
|
},
|
517
514
|
],
|
518
515
|
},
|
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.
|
4
|
+
version: 9.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: 2018-
|
11
|
+
date: 2018-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|