govuk_navigation_helpers 3.1.1 → 3.2.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: d12b3bb1dd94ca92627a1eab3cf9fcf1fa393db0
4
- data.tar.gz: 5137482b6cc5dc6bc5406541d8ba7605e506bd44
3
+ metadata.gz: 19f91260ea75a1db921c4b82de4aff1cceb0ed68
4
+ data.tar.gz: 28253a57bee243f566f2588bf70325a44134f76b
5
5
  SHA512:
6
- metadata.gz: 398630f553c56a3a4a037051b8894adc827f88f5de217318f425c35b8bd28c624fb69ac956ccb176b2e3b4532922442dba2bcce1adea8430f9599c27b85fefc4
7
- data.tar.gz: 0a076531e1979a9bbaef6144d0c4e29bec55117a4f76076e9e74c8a331bf7cc804accf7fa68662edb6e24bdce64d63bfa66b814c54fa041bec1d690f04efce68
6
+ metadata.gz: c2406adc6eb2b21a485c910f05fcb9c531a3b82b96c631bfea410e377e2df028c164ac5bf4b9ce6ac00744a540eee47aae9589e98d6edb25d1486dda5d97dea8
7
+ data.tar.gz: 00664e1d2ecce5b360899b158a1645d8c507519b2a1b80c2d5513ad4e81eefadbc4f91d64f856acc43655310e49888e18da5d39e5037f818fd704848e0a1e3bd
@@ -1,3 +1,7 @@
1
+ ## 3.2.0
2
+
3
+ * Alphabetically sort taxons and related links in the taxonomy sidebar.
4
+
1
5
  ## 3.1.1
2
6
 
3
7
  * Remove `notice` from list of guidance document types.
@@ -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.map do |result|
53
- {
54
- title: result['title'],
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
  []
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "3.1.1".freeze
2
+ VERSION = "3.2.0".freeze
3
3
  end
@@ -6,19 +6,7 @@ include GdsApi::TestHelpers::Rummager
6
6
 
7
7
  RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
8
8
  describe '#sidebar' do
9
- before(:each) do
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
- it 'returns a sidebar hash containing a list of parent taxons and related content' do
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 1",
56
- url: "/taxon-1",
57
- description: "The 1st taxon.",
56
+ title: "Taxon A",
57
+ url: "/taxon-a",
58
+ description: "The A taxon.",
58
59
  related_content: [
59
- {
60
- title: 'Result Content',
61
- link: '/result-content',
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 2",
67
- url: "/taxon-2",
68
- description: "The 2nd taxon.",
66
+ title: "Taxon B",
67
+ url: "/taxon-b",
68
+ description: "The B taxon.",
69
69
  related_content: [
70
- {
71
- title: 'Result Content',
72
- link: '/result-content',
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 1",
126
- "base_path" => "/taxon-1",
127
- "content_id" => "taxon1",
128
- "description" => "The 1st taxon.",
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 2",
132
- "base_path" => "/taxon-2",
133
- "content_id" => "taxon2",
134
- "description" => "The 2nd taxon.",
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
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_navigation_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev