From 51e92f8f73bf2c05ad68a3e169654ee14e21e9e1 Mon Sep 17 00:00:00 2001 From: chao-xian Date: Fri, 4 Mar 2022 16:25:18 +0000 Subject: [PATCH 1/3] Add test helper to generate pages with specific base_path This is useful for testing against specific pages when we needed. --- test/test_helper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 7f9ddaac8..e605b8897 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -201,6 +201,15 @@ def setup_and_visit_notification_exempt_page(name) end end + def setup_and_visit_a_page_with_specific_base_path(name, base_path, content_id = nil) + @content_item = get_content_example(name).tap do |item| + item["content_id"] = content_id if content_id.present? + item["base_path"] = base_path + stub_content_store_has_item(item["base_path"], item.to_json) + visit_with_cachebust(item["base_path"]) + end + end + def brexit_citizen_id ContentItem::BrexitTaxons::BREXIT_CITIZEN_PAGE_CONTENT_ID end From a669604b0316978ba22d660b176e0ca4166a2cf3 Mon Sep 17 00:00:00 2001 From: chao-xian Date: Fri, 4 Mar 2022 16:32:09 +0000 Subject: [PATCH 2/3] Add intervention banner javascript and style tweak --- app/assets/javascripts/application.js | 1 + app/assets/stylesheets/components/_banner.scss | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 510b9e758..9b276cddd 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -4,6 +4,7 @@ //= require govuk_publishing_components/components/error-summary //= require govuk_publishing_components/components/feedback //= require govuk_publishing_components/components/govspeak +//= require govuk_publishing_components/components/intervention //= require govuk_publishing_components/components/metadata //= require govuk_publishing_components/components/print-link //= require govuk_publishing_components/components/radio diff --git a/app/assets/stylesheets/components/_banner.scss b/app/assets/stylesheets/components/_banner.scss index 55c773b78..5349b2e4c 100644 --- a/app/assets/stylesheets/components/_banner.scss +++ b/app/assets/stylesheets/components/_banner.scss @@ -34,3 +34,7 @@ max-width: 30em; padding-top: govuk-spacing(2); } + +.gem-c-intervention { + margin-top: govuk-spacing(4); +} From 7596e60f36d778c7669f216c2f078ae2e5f622fc Mon Sep 17 00:00:00 2001 From: chao-xian Date: Fri, 4 Mar 2022 16:32:39 +0000 Subject: [PATCH 3/3] Add logic to display intervention banner on specific pages --- app/presenters/content_item_presenter.rb | 6 ++++++ app/views/layouts/application.html.erb | 9 ++++++++- test/integration/guide_test.rb | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb index 0a3e8ef5d..f307f3c77 100644 --- a/app/presenters/content_item_presenter.rb +++ b/app/presenters/content_item_presenter.rb @@ -20,6 +20,8 @@ class ContentItemPresenter attr_accessor :include_collections_in_other_publisher_metadata + USER_RESEARCH_PAGES = %w[register-for-self-assessment self-employed-records income-tax-rates].freeze + def initialize(content_item, requested_path, view_context) @content_item = content_item @requested_path = requested_path @@ -87,6 +89,10 @@ def show_phase_banner? phase.in?(%w[alpha beta]) end + def show_study_banner? + USER_RESEARCH_PAGES.include?(slug) + end + def render_guide_as_single_page? # /how-to-vote content_id == "9315bc67-33e7-42e9-8dea-e022f56dabfa" && voting_is_open? diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c6ce899fc..ac96400fe 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,7 +31,14 @@
- <% if @content_item.show_phase_banner? %> + <% if @content_item.show_study_banner? %> + <%= render "govuk_publishing_components/components/intervention", { + suggestion_text: "Help improve GOV.UK", + suggestion_link_text: "Take part in user research", + suggestion_link_url: "https://GDSUserResearch.optimalworkshop.com/treejack/lb5eu75l", + new_tab: true, + } %> + <% elsif @content_item.show_phase_banner? %> <%= render 'govuk_publishing_components/components/phase_banner', phase: @content_item.phase %> <% end %> diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index 8bee5aa18..bc15a4356 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -169,6 +169,22 @@ class GuideTest < ActionDispatch::IntegrationTest assert_not page.has_css?(".gem-c-single-page-notification-button") end + test "does not render intervention banner by default" do + setup_and_visit_content_item("guide") + + assert_not page.has_css?(".gem-c-intervention") + end + + test "renders intervention banner on specific page" do + user_research_pages = %w[register-for-self-assessment self-employed-records income-tax-rates] + + user_research_pages.each do |banner_page| + setup_and_visit_a_page_with_specific_base_path("guide", "/#{banner_page}") + end + + assert page.has_css?(".gem-c-intervention") + end + def once_voting_has_closed Timecop.freeze(Time.zone.local(2021, 5, 6, 22, 0, 0)) yield