From d04f2ee3aca5bbe3c63d12603359aa40e2738fce Mon Sep 17 00:00:00 2001 From: George Schena Date: Fri, 4 Oct 2024 07:29:26 +0100 Subject: [PATCH] Add help_page controller and update content item model to support help_page - Add new route - Add help_page controller - Update content item model - Add help_page views - Add system spec for the new help_page Commit audit trail: - spec/system/help_page_spec.rb https://github.com/alphagov/government-frontend/blob/af54031948650448b965ac274c3248d23658c4f6/test/integration/help_page_test.rb - app/views/help_page/show.html.erb https://github.com/alphagov/government-frontend/blob/af54031948650448b965ac274c3248d23658c4f6/app/views/content_items/help_page.html.erb --- app/controllers/content_items_controller.rb | 2 +- app/controllers/help_page_controller.rb | 2 + app/models/content_item.rb | 4 +- app/views/help_page/show.html.erb | 9 ++++ .../shared/_body_with_related_links.html.erb | 29 +++++++++++++ config/routes.rb | 9 ++-- spec/system/help_page_spec.rb | 43 +++++++++++++++++++ spec/system/sessions_spec.rb | 9 +++- 8 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 app/controllers/help_page_controller.rb create mode 100644 app/views/help_page/show.html.erb create mode 100644 app/views/shared/_body_with_related_links.html.erb create mode 100644 spec/system/help_page_spec.rb diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index fb95e76af0..a25fe7f442 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -26,7 +26,7 @@ def content_item end def content_item_slug - nil # set to override content item fetched from Content Store + request.path end def content_item_hash diff --git a/app/controllers/help_page_controller.rb b/app/controllers/help_page_controller.rb new file mode 100644 index 0000000000..4dd50e7ee7 --- /dev/null +++ b/app/controllers/help_page_controller.rb @@ -0,0 +1,2 @@ +class HelpPageController < ContentItemsController +end diff --git a/app/models/content_item.rb b/app/models/content_item.rb index 500659d61d..974ba6aaab 100644 --- a/app/models/content_item.rb +++ b/app/models/content_item.rb @@ -1,5 +1,5 @@ class ContentItem - attr_reader :content_store_response, :body, :image, :description, :document_type, :title, :base_path, :locale + attr_reader :content_store_response, :body, :image, :description, :document_type, :title, :base_path, :locale, :last_updated, :schema_name def initialize(content_store_response) @content_store_response = content_store_response @@ -10,6 +10,8 @@ def initialize(content_store_response) @title = content_store_response["title"] @base_path = content_store_response["base_path"] @locale = content_store_response["locale"] + @last_updated = content_store_response["public_updated_at"] + @schema_name = content_store_response["schema_name"] end delegate :to_h, to: :content_store_response diff --git a/app/views/help_page/show.html.erb b/app/views/help_page/show.html.erb new file mode 100644 index 0000000000..7ca2b1c10c --- /dev/null +++ b/app/views/help_page/show.html.erb @@ -0,0 +1,9 @@ +<% content_for :extra_head_content do %> + <%= render "govuk_publishing_components/components/machine_readable_metadata", { content_item: @content_item.to_h, schema: :article } %> +<% end %> + +<% if @content_item.base_path == '/help/cookie-details' %> + +<% end %> + +<%= render 'shared/body_with_related_links' %> diff --git a/app/views/shared/_body_with_related_links.html.erb b/app/views/shared/_body_with_related_links.html.erb new file mode 100644 index 0000000000..7062f839f8 --- /dev/null +++ b/app/views/shared/_body_with_related_links.html.erb @@ -0,0 +1,29 @@ +<% content_for :simple_header, true %> +
+
+ <%= render 'govuk_publishing_components/components/title', + title: @content_item.title %> +
+
+
+
+
+ + <%= render 'govuk_publishing_components/components/govspeak', { + direction: page_text_direction, + disable_youtube_expansions: true, + } do %> + <%= raw(@content_item.body) %> + <% end %> + + <% if @content_item.last_updated && @content_item.schema_name == "help_page" %> + <%= render "components/published_dates", { + last_updated: display_date(@content_item.last_updated) + } %> + <% end %> +
+
+ <%= render 'shared/sidebar_navigation' %> +
+ +<%= render 'shared/footer_navigation' %> diff --git a/config/routes.rb b/config/routes.rb index f13c08aea9..ca712cf6bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,9 +41,12 @@ end # Help pages - get "/help", to: "help#index" - get "/help/ab-testing", to: "help#ab_testing" - get "/help/cookies", to: "help#cookie_settings" + scope "/help" do + get "/:slug", to: "help_page#show", constraints: { slug: /(?!(ab-testing|cookies)$).*/ } + get "/", to: "help#index", as: :help + get "/ab-testing", to: "help#ab_testing" + get "/cookies", to: "help#cookie_settings" + end # GOVUK Public Roadmap get "/roadmap", to: "roadmap#index" diff --git a/spec/system/help_page_spec.rb b/spec/system/help_page_spec.rb new file mode 100644 index 0000000000..44226fd5af --- /dev/null +++ b/spec/system/help_page_spec.rb @@ -0,0 +1,43 @@ +RSpec.describe "HelpPage" do + let(:base_path) { "/help/about-govuk" } + let(:title) { "About GOV.UK" } + let(:body) { "

GOV.UK is the website for the UK government. It’s the best place to find government services and information.

" } + + let(:payload) do + { + base_path:, + format: "help_page", + title:, + details: { body: }, + } + end + + before do + stub_content_store_has_item(base_path, payload) + end + + it "displays the help page" do + visit base_path + + expect(page).to have_title("#{title} - GOV.UK") + expect(page).to have_css("h1", text: title) + expect(page).to have_text("GOV.UK is the website for the UK government. It’s the best place to find government services and information.") + end + + context "when visiting '/help/cookie-details'" do + let(:base_path) { "/help/cookie-details" } + let(:title) { "Details about cookies on GOV.UK" } + + it "sets noindex meta tag" do + visit base_path + + expect(page).to have_css('meta[name="robots"][content="noindex"]', visible: false) + end + + it "does not render with the single page notification button" do + visit base_path + + expect(page).not_to have_css(".gem-c-single-page-notification-button") + end + end +end diff --git a/spec/system/sessions_spec.rb b/spec/system/sessions_spec.rb index 7ba0e4d1d6..ee5fa85a07 100644 --- a/spec/system/sessions_spec.rb +++ b/spec/system/sessions_spec.rb @@ -6,7 +6,12 @@ include GdsApi::TestHelpers::EmailAlertApi include GovukPersonalisation::TestHelpers::Features + path = "/email/subscriptions/account/confirm" + before do + stub_request(:get, "http://content-store.dev.gov.uk/content#{path}") + .to_return(status: 200, body: { details: { body: "" }, links: {} }.to_json, headers: {}) + stub_content_store_has_item("/", schema: "special_route", links: {}) # The redirect test needs a route to actually exist to redirect to @@ -16,7 +21,7 @@ Rails.application.routes.disable_clear_and_finalize = true Rails.application.routes.draw do - get "/email/subscriptions/account/confirm", to: "homepage#index" + get path, to: "homepage#index" end end @@ -31,7 +36,7 @@ end it "Logs the user in and send them to a redirect path if supplied" do - redirect_path = "/email/subscriptions/account/confirm?frequency=immediately&return_to_url=true&topic_id=some-page-with-notifications" + redirect_path = "#{path}?frequency=immediately&return_to_url=true&topic_id=some-page-with-notifications" given_a_successful_login_attempt(redirect_path:) visit new_govuk_session_callback_path(code: "code", state: "state")