govuk_navigation_helpers 9.0.0 → 9.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: 6f8820828e39de3f4448cd51867ab33863f33171
4
- data.tar.gz: ccc32400f50f9c8b52942861d56baea10cd5e745
3
+ metadata.gz: cfe90c1b0207936166968071bbe57c3b9b6e98dd
4
+ data.tar.gz: 9ad575a04047684089fafa8000807e1f242833ca
5
5
  SHA512:
6
- metadata.gz: 8b81687bb032f4b4811572a6b2c52339acfd28f635faa49ecd327f1fc17a36dec0277383ce238ca04c4e330d32e7650eb5c29b9f5223f7dbc27c9cf9f1cb717a
7
- data.tar.gz: 3bbc43ff6e987c2a4295d9f249ba8fae74a704363c2a7b9157aa8bc60dbc89e804ea22f0591abc87d13d5e529bda9a45d0636da0ca3d0ee1e3b27f9cf60ebf6d
6
+ metadata.gz: 6bbbceff78a86fef6711c84465bba37bcf8a676a14305f959e0de2cab8cbef5f07eb3310767a13040eb5c66fad6e843421e7dcd9d89b6d85eb2b3876c71fc41e
7
+ data.tar.gz: 61d239cd0fe9de022bb8c3a982f3be957c7017bc1463da20ba15d33966a96ab9d8ef2380b862333e42a9d382afab697da9cbb4ed29344262258f06b9cdfff13c
@@ -1,4 +1,7 @@
1
- ## Unreleased
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
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env groovy
2
2
 
3
+ library("govuk")
4
+
3
5
  REPOSITORY = 'govuk_navigation_helpers'
4
6
 
5
7
  node {
6
- def govuk = load '/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy'
7
8
 
8
9
  try {
9
10
  stage('Checkout') {
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| descendent_from_whitelisted_root_taxon?(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
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "9.0.0".freeze
2
+ VERSION = "9.1.0".freeze
3
3
  end
@@ -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 whitelisted parent taxon" do
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 non-whitelisted parent taxon" do
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 whitelisted parent taxon" do
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 non-whitelisted parent taxon" do
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.0.0
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-02-07 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport