From 46690cfb215309b46cd275fd0e966a93b70f8f82 Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Thu, 31 Oct 2024 12:12:55 +0000 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. - We replace the call to TitleHelper in the view with a direct call, as it didn't add much and it's not clear whether it's worth copying that helper across yet. Commit audit trail: - https://github.com/alphagov/government-frontend/blob/6523741691ddfb9551967311a3f79775e9403ecf/app/views/content_items/take_part.html.erb - https://github.com/alphagov/government-frontend/blob/6523741691ddfb9551967311a3f79775e9403ecf/test/integration/take_part_test.rb --- app/controllers/take_part_controller.rb | 2 ++ app/views/take_part/show.html.erb | 42 +++++++++++++++++++++++++ config/routes.rb | 10 ++++-- spec/requests/take_part_spec.rb | 13 ++++++++ spec/system/take_part_spec.rb | 27 ++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 app/controllers/take_part_controller.rb create mode 100644 app/views/take_part/show.html.erb create mode 100644 spec/requests/take_part_spec.rb 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..bea2e4a245 --- /dev/null +++ b/app/controllers/take_part_controller.rb @@ -0,0 +1,2 @@ +class TakePartController < ContentItemsController +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..63449b84e5 --- /dev/null +++ b/app/views/take_part/show.html.erb @@ -0,0 +1,42 @@ +<% content_for :title do %> + <%= @content_item.title %> - GOV.UK +<% end %> + +<% content_for :extra_headers do %> + <%= render "govuk_publishing_components/components/machine_readable_metadata", { content_item: @content_item.to_h, schema: :article } %> + +<% end %> + + +
+
+ <%= render "govuk_publishing_components/components/title", { + title: @content_item.title, + context: I18n.t("formats.#{@content_item.document_type}", count: 1), + context_locale: t_locale_fallback("formats.#{@content_item.document_type}", count: 1), + } + %> + <%= 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 0f675570fb..38344997fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,8 +70,14 @@ # Media previews get "/media/:id/:filename/preview", to: "csv_preview#show", filename: /[^\/]+/ - # Placeholder for attachments being virus-scanned - get "/government/placeholder", to: "placeholder#show" + scope "/government" do + # Placeholder for attachments being virus-scanned + get "/placeholder", to: "placeholder#show" + + scope "/get-involved" do + get "/take-part/:slug", to: "take_part#show" + end + end # Simple Smart Answer pages constraints FormatRoutingConstraint.new("simple_smart_answer") do diff --git a/spec/requests/take_part_spec.rb b/spec/requests/take_part_spec.rb new file mode 100644 index 0000000000..68cec2e2a0 --- /dev/null +++ b/spec/requests/take_part_spec.rb @@ -0,0 +1,13 @@ +RSpec.describe "Take Part" do + before do + content_store_has_example_item("/government/get-involved/take-part/tp1", schema: :take_part) + end + + context "GET index" do + it "returns 200" do + get "/government/get-involved/take-part/tp1" + + expect(response).to have_http_status(:ok) + end + end +end diff --git a/spec/system/take_part_spec.rb b/spec/system/take_part_spec.rb new file mode 100644 index 0000000000..026b92db65 --- /dev/null +++ b/spec/system/take_part_spec.rb @@ -0,0 +1,27 @@ +RSpec.describe "TakePart" do + it_behaves_like "it has meta tags", "take_part", "/government/get-involved/take-part" + it_behaves_like "it has meta tags for images", "take_part", "/government/get-involved/take-part" + + before do + content_store_has_example_item("/government/get-involved/take-part/tp1", schema: :take_part) + end + + context "when visiting a Take Part page" 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