From a1f8cbfc1cb863363685e1b671b4b9bdd59cdffa Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Thu, 5 Sep 2024 11:23:52 +0100 Subject: [PATCH] Add TakePartController - add view and helpers - convert test suite to RSpec on move - note that we explicitly remove the content-bottom-margin div class that was immediately inside the 2/3rds column. This is a style used in a handful of government-frontend document types which (on review with frontend developers) does not really fix the problem it's trying to fix (insufficient bottom margin on some tablet-sized devices). This has been captured as https://github.com/alphagov/govuk_publishing_components/issues/4220 to be fixed properly in the components gem. Commit audit trail: - app/views/take_part/show.html.erb https://github.com/alphagov/government-frontend/commit/e858440960d68b6484855507e9e347dc53f9ca1c - app/helpers/machine_readable_metadata_helper.rb https://github.com/alphagov/government-frontend/commit/5fb924ed7152a699816b0f3d5c9c685139015b79 - app/helpers/title_helper.rb https://github.com/alphagov/government-frontend/commit/08db76d1931e67eec6cce67c2017cf0847c300f3 - spec/system/take_part_spec.rb https://github.com/alphagov/government-frontend/commit/6ecd50c198565dc9bafdb72cb42b15411e795ad2 FIX - remove unnecessary div --- app/controllers/take_part_controller.rb | 5 +++ .../machine_readable_metadata_helper.rb | 6 ++++ app/helpers/title_helper.rb | 10 ++++++ app/views/take_part/show.html.erb | 35 +++++++++++++++++++ config/routes.rb | 7 +++- spec/system/take_part_spec.rb | 24 +++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 app/controllers/take_part_controller.rb create mode 100644 app/helpers/machine_readable_metadata_helper.rb create mode 100644 app/helpers/title_helper.rb create mode 100644 app/views/take_part/show.html.erb create mode 100644 spec/system/take_part_spec.rb diff --git a/app/controllers/take_part_controller.rb b/app/controllers/take_part_controller.rb new file mode 100644 index 0000000000..18717202e7 --- /dev/null +++ b/app/controllers/take_part_controller.rb @@ -0,0 +1,5 @@ +class TakePartController < ContentItemsController + def content_item_slug + request.path + end +end diff --git a/app/helpers/machine_readable_metadata_helper.rb b/app/helpers/machine_readable_metadata_helper.rb new file mode 100644 index 0000000000..9c35a2af1c --- /dev/null +++ b/app/helpers/machine_readable_metadata_helper.rb @@ -0,0 +1,6 @@ +module MachineReadableMetadataHelper + def machine_readable_metadata(content_item, args) + locals = { content_item: content_item.to_h }.merge(args) + render("govuk_publishing_components/components/machine_readable_metadata", locals) + end +end diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb new file mode 100644 index 0000000000..665332b0b8 --- /dev/null +++ b/app/helpers/title_helper.rb @@ -0,0 +1,10 @@ +module TitleHelper + def title_and_context(title, document_type) + { + title:, + context: I18n.t("content_item.schema_name.#{document_type}", count: 1), + context_locale: t_locale_fallback("content_item.schema_name.#{document_type}", count: 1), + average_title_length: "long", + } + end +end diff --git a/app/views/take_part/show.html.erb b/app/views/take_part/show.html.erb new file mode 100644 index 0000000000..54c327de98 --- /dev/null +++ b/app/views/take_part/show.html.erb @@ -0,0 +1,35 @@ +<% content_for :title do %> + <%= @content_item.title %> - GOV.UK +<% end %> + +<% content_for :extra_head_content do %> + <%= machine_readable_metadata(@content_item, schema: :article) %> +<% end %> + +
+
+ <%= render 'govuk_publishing_components/components/title', title_and_context(@content_item.title, @content_item.document_type).except(:average_title_length) %> + <%= render 'govuk_publishing_components/components/lead_paragraph', text: @content_item.description %> +
+ + <%= render 'shared/translations' %> +
+ +
+
+ <%= render 'components/figure', + src: @content_item.image["url"], + alt: @content_item.image["alt_text"], + credit: @content_item.image["credit"], + caption: @content_item.image["caption"] if @content_item.image %> + + <%= render "govuk_publishing_components/components/govspeak", { + direction: page_text_direction + } do %> + <%= raw(@content_item.body) %> + <% end %> +
+ <%= render 'shared/sidebar_navigation' %> +
+ +<%= render 'shared/footer_navigation' %> diff --git a/config/routes.rb b/config/routes.rb index 413826a98f..6b6ea20d18 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,7 +98,12 @@ get "/media/:id/:filename/preview", to: "csv_preview#show", filename: /[^\/]+/ - get "/government/placeholder", to: "placeholder#show" + scope "/government" do + get "/placeholder", to: "placeholder#show" + scope "/get-involved" do + get "/take-part/:slug", to: "take_part#show" + end + end # route API errors to the error handler constraints ApiErrorRoutingConstraint.new do diff --git a/spec/system/take_part_spec.rb b/spec/system/take_part_spec.rb new file mode 100644 index 0000000000..f848706c1e --- /dev/null +++ b/spec/system/take_part_spec.rb @@ -0,0 +1,24 @@ +RSpec.describe "TakePart" do + before do + content_store_has_example_item("/government/get-involved/take-part/tp1", schema: :take_part) + end + + context "/government/get-involved/take-part/:slug" do + it "displays the take_part page" do + visit "/government/get-involved/take-part/tp1" + + expect(page).to have_title("Become a councillor - GOV.UK") + + expect(page).to have_css("h1", text: "Become a councillor") + expect(page).to have_text("All councils are led by democratically elected councillors who set the vision and direction, and represent their local community.") + + assert page.has_text?("There are roughly 20,000 local councillors in England. Councillors are elected to the local council to represent their own local community, so they must either live or work in the area.") + end + + it "does not display a single page notification button" do + visit "/government/get-involved/take-part/tp1" + + expect(page).not_to have_css(".gem-c-single-page-notification-button") + end + end +end