From fead04aa627bc50ddd47b74e614a0a631d767bbb Mon Sep 17 00:00:00 2001 From: hannako Date: Mon, 14 Mar 2022 17:40:17 +0000 Subject: [PATCH 1/3] Move recruitment banner logic into its own module --- app/lib/recruitment_helper.rb | 7 +++++++ app/presenters/content_item/recruitment_banner.rb | 9 +++++++++ app/presenters/content_item_presenter.rb | 8 +------- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 app/lib/recruitment_helper.rb create mode 100644 app/presenters/content_item/recruitment_banner.rb diff --git a/app/lib/recruitment_helper.rb b/app/lib/recruitment_helper.rb new file mode 100644 index 000000000..b33714765 --- /dev/null +++ b/app/lib/recruitment_helper.rb @@ -0,0 +1,7 @@ +module RecruitmentHelper + USER_RESEARCH_PAGES = %w[register-for-self-assessment self-employed-records income-tax-rates].freeze + + def self.show_banner?(slug) + USER_RESEARCH_PAGES.include?(slug) + end +end diff --git a/app/presenters/content_item/recruitment_banner.rb b/app/presenters/content_item/recruitment_banner.rb new file mode 100644 index 000000000..f9b581e32 --- /dev/null +++ b/app/presenters/content_item/recruitment_banner.rb @@ -0,0 +1,9 @@ +module ContentItem + module RecruitmentBanner + USER_RESEARCH_PAGES = %w[register-for-self-assessment self-employed-records income-tax-rates].freeze + + def show_study_banner? + USER_RESEARCH_PAGES.include?(slug) + end + end +end diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb index f307f3c77..b89336d0a 100644 --- a/app/presenters/content_item_presenter.rb +++ b/app/presenters/content_item_presenter.rb @@ -2,7 +2,7 @@ class ContentItemPresenter include ContentItem::Withdrawable include ContentItem::BrexitTaxons include ContentItem::SinglePageNotificationButton - + include ContentItem::RecruitmentBanner attr_reader :content_item, :requested_path, :view_context, @@ -20,8 +20,6 @@ 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 @@ -89,10 +87,6 @@ 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? From 899dd9f529056d493d5380ee93c316a9466f3e4c Mon Sep 17 00:00:00 2001 From: hannako Date: Mon, 14 Mar 2022 16:31:42 +0000 Subject: [PATCH 2/3] Render the intervention banner on any page tagged to "browse/tax" --- .../content_item/recruitment_banner.rb | 20 +++++++++++-- app/views/layouts/application.html.erb | 4 +-- test/integration/guide_test.rb | 16 ---------- test/integration/recruitment_banner_test.rb | 30 +++++++++++++++++++ 4 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 test/integration/recruitment_banner_test.rb diff --git a/app/presenters/content_item/recruitment_banner.rb b/app/presenters/content_item/recruitment_banner.rb index f9b581e32..d7b609e9c 100644 --- a/app/presenters/content_item/recruitment_banner.rb +++ b/app/presenters/content_item/recruitment_banner.rb @@ -1,9 +1,23 @@ module ContentItem module RecruitmentBanner - USER_RESEARCH_PAGES = %w[register-for-self-assessment self-employed-records income-tax-rates].freeze + SURVEY_URLS = { "/browse/tax" => "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1" }.freeze - def show_study_banner? - USER_RESEARCH_PAGES.include?(slug) + def recruitment_survey_url + key = SURVEY_URLS.keys.find{ |k| content_tagged_to(k).present? } + SURVEY_URLS[key] + end + + private + + def mainstream_browse_pages + content_item["links"]["mainstream_browse_pages"] if content_item["links"] + end + + def content_tagged_to(browse_base_path) + return [] unless mainstream_browse_pages + mainstream_browse_pages.find do |mainstream_browse_page| + mainstream_browse_page["base_path"].starts_with? browse_base_path + end end end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ac96400fe..3be836a81 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,11 +31,11 @@
- <% if @content_item.show_study_banner? %> + <% if @content_item.recruitment_survey_url %> <%= 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", + suggestion_link_url: @content_item.recruitment_survey_url, new_tab: true, } %> <% elsif @content_item.show_phase_banner? %> diff --git a/test/integration/guide_test.rb b/test/integration/guide_test.rb index bc15a4356..8bee5aa18 100644 --- a/test/integration/guide_test.rb +++ b/test/integration/guide_test.rb @@ -169,22 +169,6 @@ 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 diff --git a/test/integration/recruitment_banner_test.rb b/test/integration/recruitment_banner_test.rb new file mode 100644 index 000000000..d072b433b --- /dev/null +++ b/test/integration/recruitment_banner_test.rb @@ -0,0 +1,30 @@ +require "test_helper" + +class RecruitmentBannerTest < ActionDispatch::IntegrationTest + test "Recruitment Banner is displayed for any page tagged to Money and Tax" do + @money_and_tax_browse_page = { + "content_id" => "123", + "title" => "Self Assessment", + "base_path" => "/browse/tax/self-assessment", + } + + guide = GovukSchemas::Example.find("guide", example_name: "guide") + guide["links"]["mainstream_browse_pages"] = [] + guide["links"]["mainstream_browse_pages"] << @money_and_tax_browse_page + + stub_content_store_has_item(guide["base_path"], guide.to_json) + visit guide["base_path"] + + assert page.has_css?(".gem-c-intervention") + assert page.has_link?("Take part in user research (opens in a new tab)", href: "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1") + end + + test "Recruitment Banner is not displayed for pages not tagged to Money and Tax" do + guide = GovukSchemas::Example.find("guide", example_name: "guide") + stub_content_store_has_item(guide["base_path"], guide.to_json) + visit_with_cachebust guide["base_path"] + + assert_not page.has_css?(".gem-c-intervention") + assert_not page.has_link?("Take part in user research", href: "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1") + end +end From c7d5cd09d042a98bfa5d30fa3d531742d1d94449 Mon Sep 17 00:00:00 2001 From: hannako Date: Mon, 14 Mar 2022 17:22:43 +0000 Subject: [PATCH 3/3] Render the intervention banner on any page tagged to "browse/business" At this time, we are only using a single survey URL, but this might change in the coming weeks so that different topic pages require links to different surveys. --- .../content_item/recruitment_banner.rb | 9 ++++-- test/integration/recruitment_banner_test.rb | 28 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/presenters/content_item/recruitment_banner.rb b/app/presenters/content_item/recruitment_banner.rb index d7b609e9c..592821b4f 100644 --- a/app/presenters/content_item/recruitment_banner.rb +++ b/app/presenters/content_item/recruitment_banner.rb @@ -1,9 +1,13 @@ module ContentItem module RecruitmentBanner - SURVEY_URLS = { "/browse/tax" => "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1" }.freeze + SURVEY_URL_ONE = "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1".freeze + SURVEY_URLS = { + "/browse/tax" => SURVEY_URL_ONE, + "/browse/business" => SURVEY_URL_ONE, + }.freeze def recruitment_survey_url - key = SURVEY_URLS.keys.find{ |k| content_tagged_to(k).present? } + key = SURVEY_URLS.keys.find { |k| content_tagged_to(k).present? } SURVEY_URLS[key] end @@ -15,6 +19,7 @@ def mainstream_browse_pages def content_tagged_to(browse_base_path) return [] unless mainstream_browse_pages + mainstream_browse_pages.find do |mainstream_browse_page| mainstream_browse_page["base_path"].starts_with? browse_base_path end diff --git a/test/integration/recruitment_banner_test.rb b/test/integration/recruitment_banner_test.rb index d072b433b..cd58bca92 100644 --- a/test/integration/recruitment_banner_test.rb +++ b/test/integration/recruitment_banner_test.rb @@ -19,8 +19,34 @@ class RecruitmentBannerTest < ActionDispatch::IntegrationTest assert page.has_link?("Take part in user research (opens in a new tab)", href: "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1") end - test "Recruitment Banner is not displayed for pages not tagged to Money and Tax" do + test "Recruitment Banner is displayed for any page tagged to Business and Self-employed" do + @business_browse_page = { + "content_id" => "123", + "title" => "Self Assessment", + "base_path" => "/browse/business", + } + + guide = GovukSchemas::Example.find("guide", example_name: "guide") + guide["links"]["mainstream_browse_pages"] = [] + guide["links"]["mainstream_browse_pages"] << @business_browse_page + + stub_content_store_has_item(guide["base_path"], guide.to_json) + visit guide["base_path"] + + assert page.has_css?(".gem-c-intervention") + assert page.has_link?("Take part in user research (opens in a new tab)", href: "https://GDSUserResearch.optimalworkshop.com/treejack/724268fr-1") + end + + test "Recruitment Banner is not displayed unless page is tagged to a topic of interest" do + @not_of_interest = { + "content_id" => "123", + "title" => "I am not interesting", + "base_path" => "/browse/boring", + } + guide = GovukSchemas::Example.find("guide", example_name: "guide") + guide["links"]["mainstream_browse_pages"] = [] + guide["links"]["mainstream_browse_pages"] << @not_of_interest stub_content_store_has_item(guide["base_path"], guide.to_json) visit_with_cachebust guide["base_path"]