From 6f7e30f3b958a5334b2138a0add7138dd1062c15 Mon Sep 17 00:00:00 2001 From: hannako Date: Thu, 10 Jun 2021 12:08:55 +0100 Subject: [PATCH 1/3] Amend track_label value for the header section tracking on brexit hubs. Previously it was picking up the link text, but we want it to send "Guidance nav link" instead. --- app/views/content_items/detailed_guide.html.erb | 2 +- test/integration/detailed_guide_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/content_items/detailed_guide.html.erb b/app/views/content_items/detailed_guide.html.erb index 6eface360..8b56be063 100644 --- a/app/views/content_items/detailed_guide.html.erb +++ b/app/views/content_items/detailed_guide.html.erb @@ -23,7 +23,7 @@ data: { track_action: brexit_link[:path], track_category: brexit_link[:track_category], - track_label: brexit_link[:text], + track_label: "Guidance nav link", module: 'gem-track-click', }) %>.

diff --git a/test/integration/detailed_guide_test.rb b/test/integration/detailed_guide_test.rb index db23a9a18..73c23f5c2 100644 --- a/test/integration/detailed_guide_test.rb +++ b/test/integration/detailed_guide_test.rb @@ -128,6 +128,6 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest assert_equal ContentItem::BrexitHubPage::BREXIT_BUSINESS_PAGE_PATH, track_action assert_equal "brexit-citizen-page", track_category - assert_equal "Brexit guidance for businesses", track_label + assert_equal "Guidance nav link", track_label end end From f80686d7a6355aa99b2513bff2c13dfdf0ec15a2 Mon Sep 17 00:00:00 2001 From: hannako Date: Fri, 11 Jun 2021 11:59:44 +0100 Subject: [PATCH 2/3] Small refactor of link parsing method --- app/lib/body_parser.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/lib/body_parser.rb b/app/lib/body_parser.rb index b2ec8d0f8..270af1e46 100644 --- a/app/lib/body_parser.rb +++ b/app/lib/body_parser.rb @@ -42,19 +42,21 @@ def raw_title_and_link_sections end def parsed_links(section) - raw_links = section.present? ? section.css("a") : [] + raw_links = section.css("a") if section.present? if raw_links.any? - raw_links.map do |link| - { - path: format_path(link["href"]), - text: link.content, - } - end + raw_links.map { |link| parse_link(link) } else [] end end + def parse_link(raw_link) + { + path: format_path(raw_link["href"]), + text: raw_link.content, + } + end + def parsed_title(section) raw_title = section.present? ? section.at_css("h2") : "" raw_title.present? ? raw_title.content : "" From 029ea0cdeed3c73981421a235edfb27ab604071a Mon Sep 17 00:00:00 2001 From: hannako Date: Fri, 11 Jun 2021 12:08:33 +0100 Subject: [PATCH 3/3] Fix broken anchor links on brexit child taxon pages The section headings need ID's so that the anchor links in the content list can find them. --- app/lib/body_parser.rb | 11 +++++++++-- .../detailed_guide/_brexit_links.html.erb | 7 ++++--- test/unit/body_parser_test.rb | 15 ++++++++++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/lib/body_parser.rb b/app/lib/body_parser.rb index 270af1e46..7fcc56c5a 100644 --- a/app/lib/body_parser.rb +++ b/app/lib/body_parser.rb @@ -58,8 +58,15 @@ def parse_link(raw_link) end def parsed_title(section) - raw_title = section.present? ? section.at_css("h2") : "" - raw_title.present? ? raw_title.content : "" + parsed = { text: "", id: "" } + + raw_header = section.at_css("h2") if section.present? + if raw_header.present? + id = raw_header.attribute("id") + parsed[:text] = raw_header.content + parsed[:id] = id.value if id.present? + end + parsed end def format_path(raw_url) diff --git a/app/views/content_items/detailed_guide/_brexit_links.html.erb b/app/views/content_items/detailed_guide/_brexit_links.html.erb index 9157d92a7..392789dac 100644 --- a/app/views/content_items/detailed_guide/_brexit_links.html.erb +++ b/app/views/content_items/detailed_guide/_brexit_links.html.erb @@ -1,10 +1,11 @@ <% @content_item.title_and_link_sections.each do |section| %> - <% if section[:title].present? %> + <% if section[:title][:text].present? %> <%= render "govuk_publishing_components/components/heading", { - text: section[:title], + text: section[:title][:text], heading_level: 2, font_size: "m", margin_bottom: 6, + id: section[:title][:id], } %> <% end %> <% if section[:links].present? %> @@ -13,7 +14,7 @@ link_to(link[:text], link[:path], class: "govuk-link", data: { track_action: link[:path], track_category: track_category, - track_label: section[:title] || "", + track_label: section[:title][:text] || "", module: 'gem-track-click', }) end diff --git a/test/unit/body_parser_test.rb b/test/unit/body_parser_test.rb index 2c02e899e..0d0bc1e33 100644 --- a/test/unit/body_parser_test.rb +++ b/test/unit/body_parser_test.rb @@ -44,7 +44,10 @@ def subject test "#title_and_link_sections" do expected = [ { - title: "Travel to the EU", + title: { + text: "Travel to the EU", + id: "travel-to-the-eu", + }, links: [ { path: "/foreign-travel-advice", @@ -57,7 +60,10 @@ def subject ], }, { - title: "Travel to the UK", + title: { + text: "Travel to the UK", + id: "travel-to-the-uk", + }, links: [ { path: "/local-travel-advice", @@ -78,7 +84,10 @@ def subject subject = BodyParser.new(html_missing_section_headings) expected = [ { - title: "", + title: { + text: "", + id: "", + }, links: [ { path: "/foreign-travel-advice",