From abd491249b0af2bfe05126903fe250c02c8ea08d Mon Sep 17 00:00:00 2001 From: Jack Weeden Date: Mon, 19 Aug 2024 09:54:58 +0100 Subject: [PATCH] Display GOV.UK Chat promo on certain pages We want to show a promo to the new GOV.UK Chat application on certain pages on GOV.UK. The list of URLs is quite short and cover only `answer` and `guide` content types. The CTA is to be shown in the sidebar on the right of the relevant pages. --- app/helpers/govuk_chat_promo_helper.rb | 17 +++++++++++++++++ app/views/shared/_sidebar_navigation.html.erb | 4 ++++ test/helpers/govuk_chat_promo_helper_test.rb | 19 +++++++++++++++++++ test/integration/govuk_chat_promo_test.rb | 15 +++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 app/helpers/govuk_chat_promo_helper.rb create mode 100644 test/helpers/govuk_chat_promo_helper_test.rb create mode 100644 test/integration/govuk_chat_promo_test.rb diff --git a/app/helpers/govuk_chat_promo_helper.rb b/app/helpers/govuk_chat_promo_helper.rb new file mode 100644 index 000000000..b116e99b1 --- /dev/null +++ b/app/helpers/govuk_chat_promo_helper.rb @@ -0,0 +1,17 @@ +module GovukChatPromoHelper + GOVUK_CHAT_PROMO_BASE_PATHS = %w[ + /business-support-helpline + /company-tax-returns + /corporation-tax + /pay-corporation-tax + /pay-vat + /search-for-trademark + /set-up-business + /submit-vat-return + /write-business-plan + ].freeze + + def show_govuk_chat_promo?(base_path) + ENV["GOVUK_CHAT_PROMO_ENABLED"] == "true" && GOVUK_CHAT_PROMO_BASE_PATHS.include?(base_path) + end +end diff --git a/app/views/shared/_sidebar_navigation.html.erb b/app/views/shared/_sidebar_navigation.html.erb index 9919b08a0..797a6d943 100644 --- a/app/views/shared/_sidebar_navigation.html.erb +++ b/app/views/shared/_sidebar_navigation.html.erb @@ -1,5 +1,9 @@ <% content_item = @content_item.content_item.parsed_content %>
+ <% if show_govuk_chat_promo?(@content_item.base_path) %> + <%= render "govuk_publishing_components/components/chat_entry", { border_top: true } %> + <% end %> + <%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: content_item %>
diff --git a/test/helpers/govuk_chat_promo_helper_test.rb b/test/helpers/govuk_chat_promo_helper_test.rb new file mode 100644 index 000000000..60dc9fff3 --- /dev/null +++ b/test/helpers/govuk_chat_promo_helper_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +class GovukChatPromoHelperTest < ActionView::TestCase + test "show_govuk_chat_promo? when configuration disabled" do + assert_not show_govuk_chat_promo?(GOVUK_CHAT_PROMO_BASE_PATHS.first) + end + + test "show_govuk_chat_promo? when base_path not in configuration" do + ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do + assert_not show_govuk_chat_promo?("/non-matching-path") + end + end + + test "show_govuk_chat_promo? when base_path is in configuration" do + ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do + assert show_govuk_chat_promo?(GOVUK_CHAT_PROMO_BASE_PATHS.first) + end + end +end diff --git a/test/integration/govuk_chat_promo_test.rb b/test/integration/govuk_chat_promo_test.rb new file mode 100644 index 000000000..37d0f138e --- /dev/null +++ b/test/integration/govuk_chat_promo_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class GovukChatPromoTest < ActionDispatch::IntegrationTest + test "renders GOV.UK chat promo for matching content type and base path" do + ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do + setup_and_visit_a_page_with_specific_base_path("answer", GovukChatPromoHelper::GOVUK_CHAT_PROMO_BASE_PATHS.first) + + assert page.has_css?(".gem-c-chat-entry") + end + end + + def schema_type + "answer" + end +end