Skip to content

Commit

Permalink
Add help_page controller and update content item model to support hel…
Browse files Browse the repository at this point in the history
…p_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/0fc5e6f8d6215c10f9a29795265f31fab526c0a5/test/integration/help_page_test.rb
- app/views/help_page/show.html.erb https://github.com/alphagov/government-frontend/blob/0fc5e6f8d6215c10f9a29795265f31fab526c0a5/app/views/content_items/help_page.html.erb
  • Loading branch information
georges1996 committed Oct 9, 2024
1 parent e0a2841 commit d4eccb5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/help_page_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class HelpPageController < ContentItemsController
end
4 changes: 3 additions & 1 deletion app/models/content_item.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/views/help_page/show.html.erb
Original file line number Diff line number Diff line change
@@ -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' %>
<meta name="robots" content="noindex">
<% end %>
<%= render 'shared/body_with_related_links' %>
29 changes: 29 additions & 0 deletions app/views/shared/_body_with_related_links.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% content_for :simple_header, true %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render 'govuk_publishing_components/components/title',
title: @content_item.title %>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="responsive-bottom-margin">

<%= 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 %>
</div>
</div>
<%= render 'shared/sidebar_navigation' %>
</div>

<%= render 'shared/footer_navigation' %>
9 changes: 6 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions spec/system/help_page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
RSpec.describe "HelpPage" do
let(:base_path) { "/help/about-govuk" }
let(:title) { "About GOV.UK" }
let(:body) { "<p>GOV.UK is the website for the UK government. It’s the best place to find government services and information.</p>" }

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
9 changes: 7 additions & 2 deletions spec/system/sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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")

Expand Down

0 comments on commit d4eccb5

Please sign in to comment.