govuk_navigation_helpers 2.2.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80cac05a9d17cb8067c82327c9c24ea3f2d319b2
4
- data.tar.gz: c9f0298eaad59f93128f8924f53cdc958a461bf6
3
+ metadata.gz: 4b95f1233b8c92f48aa8322db214c9063c198087
4
+ data.tar.gz: 39c48d33844ad4f5e4f50e4a1cd8523e6aa82725
5
5
  SHA512:
6
- metadata.gz: 8a6de31aa86ae19a3c0e64aa72bda842098f3ff4853f6b68a1a18773b6e56d60a528bbbbf561d2eaa90811ab767b749041ec0a97552b21358102347107fabb26
7
- data.tar.gz: 81ac62a637462a5de3055ecd7c639f8c898edf64c62080214158499d227c27e7a5a8ee93a2df48cde78ad2af2db1bcb4688a692539e12089ad3d5290a4481bc9
6
+ metadata.gz: b34e178430bb1c7cd8d8ce57653f5374c1cdefcc3d4f246be721e550fdd999fe7f10e2944ae70fe4f143a933cbdb79c60b2fcc30e2757d8274d9f7f0e69a67e6
7
+ data.tar.gz: 5231d56178f8bb94d3732548b8f35c200587059d7722930f3e199502b8eabb206b3e6077dd38877e7b485f0e9b38b9fc4f99adf9615130fe6b1b16f6004d388a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.3.0
2
+
3
+ * Add support for adding the current page to Taxon breadcrumbs
4
+
1
5
  ## 2.2.0
2
6
 
3
7
  * make sure `taxon_breadcrumbs` generates data for both `taxons` and other
@@ -11,8 +11,11 @@ module GovukNavigationHelpers
11
11
 
12
12
  ordered_parents << { title: "Home", url: "/" }
13
13
 
14
+ ordered_breadcrumbs = ordered_parents.reverse
15
+ ordered_breadcrumbs << { title: content_item.title, is_current_page: true }
16
+
14
17
  {
15
- breadcrumbs: ordered_parents.reverse
18
+ breadcrumbs: ordered_breadcrumbs
16
19
  }
17
20
  end
18
21
 
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "2.2.0".freeze
2
+ VERSION = "2.3.0".freeze
3
3
  end
@@ -3,63 +3,100 @@ require 'spec_helper'
3
3
  RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
4
4
  describe "Taxon breadcrumbs" do
5
5
  it "can handle any valid content item" do
6
- generator = GovukSchemas::RandomExample.for_schema("taxon", schema_type: "frontend")
6
+ generator = GovukSchemas::RandomExample.for_schema(
7
+ "taxon",
8
+ schema_type: "frontend"
9
+ )
7
10
 
8
- expect { GovukNavigationHelpers::TaxonBreadcrumbs.new(generator.payload).breadcrumbs }.to_not raise_error
11
+ expect {
12
+ GovukNavigationHelpers::TaxonBreadcrumbs.new(
13
+ generator.payload
14
+ ).breadcrumbs
15
+ }.to_not raise_error
9
16
  end
10
17
 
11
18
  it "returns the root when taxon is not specified" do
12
- content_item = { "links" => {} }
19
+ content_item = { "title" => "Some Content", "links" => {} }
13
20
  breadcrumbs = breadcrumbs_for(content_item)
14
21
 
15
22
  expect(breadcrumbs).to eq(
16
23
  breadcrumbs: [
17
24
  { title: "Home", url: "/" },
25
+ { title: "Some Content", is_current_page: true }
18
26
  ]
19
27
  )
20
28
  end
21
29
 
22
30
  it "places parent under the root when there is a taxon" do
23
- content_item = content_item_with_parents([])
31
+ content_item = content_item_tagged_to_taxon([])
24
32
  breadcrumbs = breadcrumbs_for(content_item)
25
33
 
26
34
  expect(breadcrumbs).to eq(
27
35
  breadcrumbs: [
28
36
  { title: "Home", url: "/" },
29
- { title: "Taxon", url: "/a-taxon" }
37
+ { title: "Taxon", url: "/taxon" },
38
+ { title: "Some Content", is_current_page: true },
30
39
  ]
31
40
  )
32
41
  end
33
42
 
34
- it "includes parents and grandparents when available" do
35
- grandparent = {
36
- "title" => "Another-parent",
37
- "base_path" => "/another-parent",
38
- "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
39
- "locale" => "en",
40
- }
41
-
42
- parent = {
43
- "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
44
- "locale" => "en",
45
- "title" => "A-parent",
46
- "base_path" => "/a-parent",
47
- "links" => {
48
- "parent_taxons" => [grandparent]
49
- }
50
- }
51
-
52
- content_item = content_item_with_parents([parent])
53
- breadcrumbs = breadcrumbs_for(content_item)
43
+ context 'with a taxon content item with taxon parents' do
44
+ it "includes parents and grandparents when available" do
45
+ grandparent = {
46
+ "title" => "Another-parent",
47
+ "base_path" => "/another-parent",
48
+ "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
49
+ "locale" => "en",
50
+ }
54
51
 
55
- expect(breadcrumbs).to eq(
56
- breadcrumbs: [
57
- { title: "Home", url: "/" },
58
- { title: "Another-parent", url: "/another-parent" },
59
- { title: "A-parent", url: "/a-parent" },
60
- { title: "Taxon", url: "/a-taxon" },
61
- ]
62
- )
52
+ parent = {
53
+ "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
54
+ "locale" => "en",
55
+ "title" => "A-parent",
56
+ "base_path" => "/a-parent",
57
+ "links" => {
58
+ "parent_taxons" => [grandparent]
59
+ }
60
+ }
61
+
62
+ content_item = content_item_tagged_to_taxon([parent])
63
+ breadcrumbs = breadcrumbs_for(content_item)
64
+
65
+ expect(breadcrumbs).to eq(
66
+ breadcrumbs: [
67
+ { title: "Home", url: "/" },
68
+ { title: "Another-parent", url: "/another-parent" },
69
+ { title: "A-parent", url: "/a-parent" },
70
+ { title: "Taxon", url: "/taxon" },
71
+ { title: "Some Content", is_current_page: true },
72
+ ]
73
+ )
74
+ end
75
+ end
76
+
77
+ context 'with a taxon with parent taxons' do
78
+ it "includes parents and grandparents when available" do
79
+ parent = {
80
+ "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
81
+ "locale" => "en",
82
+ "title" => "A-parent",
83
+ "base_path" => "/a-parent",
84
+ "links" => {
85
+ "parent_taxons" => []
86
+ }
87
+ }
88
+
89
+ content_item = taxon_with_parent_taxons([parent])
90
+ breadcrumbs = breadcrumbs_for(content_item)
91
+
92
+ expect(breadcrumbs).to eq(
93
+ breadcrumbs: [
94
+ { title: "Home", url: "/" },
95
+ { title: "A-parent", url: "/a-parent" },
96
+ { title: "Taxon", is_current_page: true },
97
+ ]
98
+ )
99
+ end
63
100
  end
64
101
  end
65
102
 
@@ -72,15 +109,27 @@ RSpec.describe GovukNavigationHelpers::TaxonBreadcrumbs do
72
109
  GovukNavigationHelpers::NavigationHelper.new(fully_valid_content_item).taxon_breadcrumbs
73
110
  end
74
111
 
75
- def content_item_with_parents(parents)
112
+ def taxon_with_parent_taxons(parents)
113
+ {
114
+ "title" => "Taxon",
115
+ "document_type" => "taxon",
116
+ "links" => {
117
+ "parent_taxons" => parents,
118
+ },
119
+ }
120
+ end
121
+
122
+ def content_item_tagged_to_taxon(parents)
76
123
  {
124
+ "title" => "Some Content",
125
+ "document_type" => "guidance",
77
126
  "links" => {
78
127
  "taxons" => [
79
128
  {
80
129
  "content_id" => "30c1b93d-2553-47c9-bc3c-fc5b513ecc32",
81
130
  "locale" => "en",
82
131
  "title" => "Taxon",
83
- "base_path" => "/a-taxon",
132
+ "base_path" => "/taxon",
84
133
  "links" => {
85
134
  "parent_taxons" => parents
86
135
  },
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: 2.2.0
4
+ version: 2.3.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-02-10 00:00:00.000000000 Z
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler