diff --git a/app/helpers/govuk_chat_promo_helper.rb b/app/helpers/govuk_chat_promo_helper.rb index bb90c0bac..d49efe665 100644 --- a/app/helpers/govuk_chat_promo_helper.rb +++ b/app/helpers/govuk_chat_promo_helper.rb @@ -1,5 +1,5 @@ module GovukChatPromoHelper - GOVUK_CHAT_PROMO_BASE_PATHS = %w[ + GOVUK_CHAT_PROMO_PATHS = %w[ /business-asset-disposal-relief /business-support-service /capital-gains-tax @@ -65,7 +65,7 @@ module GovukChatPromoHelper /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) + def show_govuk_chat_promo?(path) + ENV["GOVUK_CHAT_PROMO_ENABLED"] == "true" && GOVUK_CHAT_PROMO_PATHS.include?(path) end end diff --git a/app/views/shared/_sidebar_navigation.html.erb b/app/views/shared/_sidebar_navigation.html.erb index ac4885fff..89ae0688e 100644 --- a/app/views/shared/_sidebar_navigation.html.erb +++ b/app/views/shared/_sidebar_navigation.html.erb @@ -1,7 +1,7 @@ <% content_item = @content_item.content_item.parsed_content %>
- <% if show_govuk_chat_promo?(@content_item.base_path) %> + <% if show_govuk_chat_promo?(@content_item.requested_path) %> <%= render "govuk_publishing_components/components/chat_entry", { margin_top_until_tablet: true } %> <% end %> diff --git a/test/helpers/govuk_chat_promo_helper_test.rb b/test/helpers/govuk_chat_promo_helper_test.rb index 60dc9fff3..beabb3ce3 100644 --- a/test/helpers/govuk_chat_promo_helper_test.rb +++ b/test/helpers/govuk_chat_promo_helper_test.rb @@ -2,7 +2,7 @@ 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) + assert_not show_govuk_chat_promo?(GOVUK_CHAT_PROMO_PATHS.first) end test "show_govuk_chat_promo? when base_path not in configuration" do @@ -13,7 +13,7 @@ class GovukChatPromoHelperTest < ActionView::TestCase 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) + assert show_govuk_chat_promo?(GOVUK_CHAT_PROMO_PATHS.first) end end end diff --git a/test/integration/govuk_chat_promo_test.rb b/test/integration/govuk_chat_promo_test.rb index 37d0f138e..d1199aa91 100644 --- a/test/integration/govuk_chat_promo_test.rb +++ b/test/integration/govuk_chat_promo_test.rb @@ -1,15 +1,31 @@ require "test_helper" class GovukChatPromoTest < ActionDispatch::IntegrationTest - test "renders GOV.UK chat promo for matching content type and base path" do + test "renders GOV.UK chat promo for matching content type and requested 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) + setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out") assert page.has_css?(".gem-c-chat-entry") end end + test "renders GOV.UK chat promo when requested path contains multiple parts" do + ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do + setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out/how-contracting-out-affects-your-amount") + + assert page.has_css?(".gem-c-chat-entry") + end + end + + test "does not render GOV.UK chat promo when base path is in allow list but actual path is not" do + ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do + setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out/check-if-you-were-contracted-out") + + assert_not page.has_css?(".gem-c-chat-entry") + end + end + def schema_type - "answer" + "guide" end end