From f61f705186099ab477e3f2af2258491ca5c39c49 Mon Sep 17 00:00:00 2001 From: hannako Date: Thu, 27 May 2021 16:30:14 +0100 Subject: [PATCH 1/4] Create helper to check if content item is a brexit hub page --- app/controllers/content_items_controller.rb | 1 - .../content_item/brexit_hub_page.rb | 29 +++++++++++++++++++ app/presenters/content_item_presenter.rb | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/presenters/content_item/brexit_hub_page.rb diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 3dcbd998d..e09d428d1 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -87,7 +87,6 @@ def set_guide_draft_access_token def load_content_item content_item = Services.content_store.content_item(content_item_path) - if Services.feature_toggler.use_recommended_related_links?(content_item["links"], request.headers) content_item["links"]["ordered_related_items"] = content_item["links"].fetch("suggested_ordered_related_items", []) end diff --git a/app/presenters/content_item/brexit_hub_page.rb b/app/presenters/content_item/brexit_hub_page.rb new file mode 100644 index 000000000..5dbd42912 --- /dev/null +++ b/app/presenters/content_item/brexit_hub_page.rb @@ -0,0 +1,29 @@ +module ContentItem + module BrexitHubPage + BREXIT_BUSINESS_PAGE_CONTENT_ID = "91cd6143-69d5-4f27-99ff-a52fb0d51c78".freeze + BREXIT_CITIZEN_PAGE_CONTENT_ID = "6555e0bf-c270-4cf9-a0c5-d20b95fab7f1".freeze + BREXIT_HUB_PAGE_CONTENT_IDS = [BREXIT_BUSINESS_PAGE_CONTENT_ID, BREXIT_CITIZEN_PAGE_CONTENT_ID].freeze + BREXIT_BUSINESS_PAGE_PATH = "/guidance/brexit-guidance-for-businesses".freeze + BREXIT_CITIZEN_PAGE_PATH = "/guidance/brexit-guidance-for-individuals-and-families".freeze + + def brexit_hub_page? + BREXIT_HUB_PAGE_CONTENT_IDS.include?(content_item.dig("content_id")) + end + + def brexit_business_page? + BREXIT_BUSINESS_PAGE_CONTENT_ID == content_item.dig("content_id") + end + + def brexit_citizen_page? + BREXIT_CITIZEN_PAGE_CONTENT_ID == content_item.dig("content_id") + end + + def brexit_citizen_page + BREXIT_CITIZEN_PAGE_PATH + end + + def brexit_business_page + BREXIT_BUSINESS_PAGE_PATH + end + end +end diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb index 8919f445f..f160748d0 100644 --- a/app/presenters/content_item_presenter.rb +++ b/app/presenters/content_item_presenter.rb @@ -1,5 +1,6 @@ class ContentItemPresenter include ContentItem::Withdrawable + include ContentItem::BrexitHubPage attr_reader :content_item, :requested_path, From fa11d218fd8a1e152be8b2dc219a8d72191adeec Mon Sep 17 00:00:00 2001 From: hannako Date: Thu, 27 May 2021 16:31:07 +0100 Subject: [PATCH 2/4] Customise how we display a detailed guide if its a brexit hub Further modifications - Hide publisher metadata and print link - Render description field as a link - Hide print link at bottom of page - Hide the context field ("Guidance") from above the title - Replace the superbreadcrumb with a standard breadcrumb. - Reduce description size and hide published date --- .../content_items/detailed_guide.html.erb | 23 ++++++++++++++----- app/views/layouts/application.html.erb | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/views/content_items/detailed_guide.html.erb b/app/views/content_items/detailed_guide.html.erb index 4520e58b9..6f04f2dc4 100644 --- a/app/views/content_items/detailed_guide.html.erb +++ b/app/views/content_items/detailed_guide.html.erb @@ -6,15 +6,26 @@
- <%= render 'govuk_publishing_components/components/title', @content_item.title_and_context %> + <% title_and_context = @content_item.brexit_hub_page? ? { title: @content_item.title } : @content_item.title_and_context %> + <%= render 'govuk_publishing_components/components/title', title_and_context %>
<%= render 'shared/translations' %>
- <%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %> + <% if @content_item.brexit_hub_page? %> +
+ <% link_text = @content_item.brexit_citizen_page? ? "Brexit guidance for businesses" : "Brexit guidance for individuals and families" %> + <% link_path = @content_item.brexit_citizen_page? ? @content_item.brexit_business_page : @content_item.brexit_citizen_page %> +

+ There's different <%= link_to link_text, link_path %>. +

+
+ <% else %> + <%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %> + <% end %>
-<%= render 'shared/publisher_metadata_with_logo' %> +<%= render 'shared/publisher_metadata_with_logo' unless @content_item.brexit_hub_page? %> <%= render 'shared/history_notice', content_item: @content_item %> <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %> @@ -26,7 +37,7 @@ <%= render "govuk_publishing_components/components/print_link", { margin_top: 0, margin_bottom: 6, - } %> + } unless @content_item.brexit_hub_page? %> <%= render 'govuk_publishing_components/components/govspeak', {} do %> <%= raw(@content_item.govspeak_body[:content]) %> @@ -37,13 +48,13 @@ published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history - } %> + } unless @content_item.brexit_hub_page? %> <% end %> <%= render "govuk_publishing_components/components/print_link", { margin_top: 0, margin_bottom: 6, - } %> + } unless @content_item.brexit_hub_page? %> <%= render 'shared/sidebar_navigation' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 312c8dcd3..76cbefdfb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -42,6 +42,8 @@ <% unless @do_not_show_breadcrumbs %> <% if @content_item.try(:back_link) %> <%= render 'govuk_publishing_components/components/back_link', href: @content_item.back_link %> + <% elsif @content_item.brexit_hub_page? %> + <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: [ { url: "/", title: "Home" } , { url: "/transition", title: "Brexit" } ] %> <% else %> <%= render 'govuk_publishing_components/components/contextual_breadcrumbs', content_item: @content_item.content_item.parsed_content %> <% end %> From 7a4380664984015e42858689f83d98d1f2a3c4cf Mon Sep 17 00:00:00 2001 From: hannako Date: Thu, 27 May 2021 21:26:18 +0100 Subject: [PATCH 3/4] Add an integration test --- test/integration/detailed_guide_test.rb | 22 ++++++++++++++++++++++ test/test_helper.rb | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/test/integration/detailed_guide_test.rb b/test/integration/detailed_guide_test.rb index 370d3365f..166f1bef1 100644 --- a/test/integration/detailed_guide_test.rb +++ b/test/integration/detailed_guide_test.rb @@ -90,4 +90,26 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest assert_equal faq_schema["name"], @content_item["title"] assert_not_equal faq_schema["mainEntity"], [] end + + test "renders brexit child taxon pages in special ways" do + setup_and_visit_brexit_child_taxon("business") + + # hides the print links + assert_not page.has_css?(".gem-c-print-link") + assert_not page.has_content?("Print this page") + + # hides published by metadata + assert_not page.has_css?(".gem-c-metadata") + + # renders description field as a custom link + assert_not page.has_text?(@content_item["description"]) + link_text = "Brexit guidance for individuals and families" + assert page.has_link?(link_text, href: ContentItem::BrexitHubPage::BREXIT_CITIZEN_PAGE_PATH) + + setup_and_visit_brexit_child_taxon("citizen") + + assert_not page.has_text?(@content_item["description"]) + link_text = "Brexit guidance for businesses" + assert page.has_link?(link_text, href: ContentItem::BrexitHubPage::BREXIT_BUSINESS_PAGE_PATH) + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index ffac52fc5..1b0f5f6ef 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -176,6 +176,22 @@ def setup_and_visit_content_item_with_taxons(name, taxons) end end + def setup_and_visit_brexit_child_taxon(type = nil) + @content_item = get_content_example("detailed_guide").tap do |item| + item["content_id"] = type == "business" ? brexit_business_id : brexit_citizen_id + stub_content_store_has_item(item["base_path"], item.to_json) + visit_with_cachebust((item["base_path"]).to_s) + end + end + + def brexit_citizen_id + ContentItem::BrexitHubPage::BREXIT_CITIZEN_PAGE_CONTENT_ID + end + + def brexit_business_id + ContentItem::BrexitHubPage::BREXIT_BUSINESS_PAGE_CONTENT_ID + end + def setup_and_visit_random_content_item(document_type: nil) content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: schema_type) do |payload| payload.merge!("document_type" => document_type) unless document_type.nil? From d526d58ae331eb7fd2040be36f8cb499657cbb58 Mon Sep 17 00:00:00 2001 From: hannako Date: Fri, 28 May 2021 19:39:40 +0100 Subject: [PATCH 4/4] Move text into locale files - english only at this point - simplify brexit_hub_page presenter --- .../content_item/brexit_hub_page.rb | 29 +++++++++---------- .../content_items/detailed_guide.html.erb | 16 +++++----- app/views/layouts/application.html.erb | 2 +- config/locales/en.yml | 4 +++ 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app/presenters/content_item/brexit_hub_page.rb b/app/presenters/content_item/brexit_hub_page.rb index 5dbd42912..e52737b3b 100644 --- a/app/presenters/content_item/brexit_hub_page.rb +++ b/app/presenters/content_item/brexit_hub_page.rb @@ -6,24 +6,21 @@ module BrexitHubPage BREXIT_BUSINESS_PAGE_PATH = "/guidance/brexit-guidance-for-businesses".freeze BREXIT_CITIZEN_PAGE_PATH = "/guidance/brexit-guidance-for-individuals-and-families".freeze - def brexit_hub_page? - BREXIT_HUB_PAGE_CONTENT_IDS.include?(content_item.dig("content_id")) + def brexit_links + { + ContentItem::BrexitHubPage::BREXIT_BUSINESS_PAGE_CONTENT_ID => { + text: I18n.t("brexit.citizen_link"), + path: BREXIT_CITIZEN_PAGE_PATH, + }, + ContentItem::BrexitHubPage::BREXIT_CITIZEN_PAGE_CONTENT_ID => { + text: I18n.t("brexit.business_link"), + path: BREXIT_BUSINESS_PAGE_PATH, + }, + } end - def brexit_business_page? - BREXIT_BUSINESS_PAGE_CONTENT_ID == content_item.dig("content_id") - end - - def brexit_citizen_page? - BREXIT_CITIZEN_PAGE_CONTENT_ID == content_item.dig("content_id") - end - - def brexit_citizen_page - BREXIT_CITIZEN_PAGE_PATH - end - - def brexit_business_page - BREXIT_BUSINESS_PAGE_PATH + def brexit_link + brexit_links[content_item.dig("content_id")] end end end diff --git a/app/views/content_items/detailed_guide.html.erb b/app/views/content_items/detailed_guide.html.erb index 6f04f2dc4..25484c57d 100644 --- a/app/views/content_items/detailed_guide.html.erb +++ b/app/views/content_items/detailed_guide.html.erb @@ -6,17 +6,15 @@
- <% title_and_context = @content_item.brexit_hub_page? ? { title: @content_item.title } : @content_item.title_and_context %> + <% title_and_context = @content_item.brexit_link ? { title: @content_item.title } : @content_item.title_and_context %> <%= render 'govuk_publishing_components/components/title', title_and_context %>
<%= render 'shared/translations' %>
- <% if @content_item.brexit_hub_page? %> + <% if @content_item.brexit_link %>
- <% link_text = @content_item.brexit_citizen_page? ? "Brexit guidance for businesses" : "Brexit guidance for individuals and families" %> - <% link_path = @content_item.brexit_citizen_page? ? @content_item.brexit_business_page : @content_item.brexit_citizen_page %>

- There's different <%= link_to link_text, link_path %>. + <%= I18n.t("brexit.heading_prefix") %> <%= link_to @content_item.brexit_link[:text], @content_item.brexit_link[:path] %>.

<% else %> @@ -25,7 +23,7 @@
-<%= render 'shared/publisher_metadata_with_logo' unless @content_item.brexit_hub_page? %> +<%= render 'shared/publisher_metadata_with_logo' unless @content_item.brexit_link %> <%= render 'shared/history_notice', content_item: @content_item %> <%= render 'govuk_publishing_components/components/notice', @content_item.withdrawal_notice_component %> @@ -37,7 +35,7 @@ <%= render "govuk_publishing_components/components/print_link", { margin_top: 0, margin_bottom: 6, - } unless @content_item.brexit_hub_page? %> + } unless @content_item.brexit_link %> <%= render 'govuk_publishing_components/components/govspeak', {} do %> <%= raw(@content_item.govspeak_body[:content]) %> @@ -48,13 +46,13 @@ published: @content_item.published, last_updated: @content_item.updated, history: @content_item.history - } unless @content_item.brexit_hub_page? %> + } unless @content_item.brexit_link %> <% end %> <%= render "govuk_publishing_components/components/print_link", { margin_top: 0, margin_bottom: 6, - } unless @content_item.brexit_hub_page? %> + } unless @content_item.brexit_link %> <%= render 'shared/sidebar_navigation' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 76cbefdfb..661ad7551 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -42,7 +42,7 @@ <% unless @do_not_show_breadcrumbs %> <% if @content_item.try(:back_link) %> <%= render 'govuk_publishing_components/components/back_link', href: @content_item.back_link %> - <% elsif @content_item.brexit_hub_page? %> + <% elsif @content_item.brexit_link %> <%= render 'govuk_publishing_components/components/breadcrumbs', breadcrumbs: [ { url: "/", title: "Home" } , { url: "/transition", title: "Brexit" } ] %> <% else %> <%= render 'govuk_publishing_components/components/contextual_breadcrumbs', content_item: @content_item.content_item.parsed_content %> diff --git a/config/locales/en.yml b/config/locales/en.yml index b2c70f981..56a698f59 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -281,6 +281,10 @@ en: written_statement: one: Written statement to Parliament other: Written statements to Parliament + brexit: + heading_prefix: There’s different + business_link: Brexit guidance for businesses + citizen_link: Brexit guidance for individuals and families corporate_information_page: about_our_services_html: Find out %{link}. corporate_information: Corporate information