Skip to content

Commit

Permalink
Merge pull request #3440 from alphagov/fix-govuk-chat-promo-link
Browse files Browse the repository at this point in the history
Fix GOV.UK Chat promo on pages with multiple path segments
  • Loading branch information
jackbot authored Nov 26, 2024
2 parents 1f09217 + 0b829ce commit 7407b35
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/helpers/govuk_chat_promo_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/shared/_sidebar_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% content_item = @content_item.content_item.parsed_content %>

<div class="govuk-grid-column-one-third">
<% 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 %>

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/govuk_chat_promo_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 19 additions & 3 deletions test/integration/govuk_chat_promo_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7407b35

Please sign in to comment.