Skip to content

Commit 0b829ce

Browse files
committed
Fix GOV.UK Chat promo on pages with multiple path segments
We have an allow list of URLs on which we want to render the GOV.UK Chat promo, which we compare the content item's `base_path` against to determine whether to show the promo or not. This results in a bug in some guide pages where we only want to show the promo on certain steps of the guide. Let's consider the "/contracted-out" URL. This guide has 3 steps, and so 3 URLs 1. /contracted-out 2. /contracted-out/how-contracting-out-affects-your-amount 3. /contracted-out/check-if-you-were-contracted-out We only want to show the promo on URL 1 and 3 in the list above, but not the second one. With the current logic, we're showing the promo on all of these URLs. That's because we're looking at the `content_item.base_path` property, which is "/contracted-out" for all of those URLs. Instead we should do the comparison on the `requested_path` method, which is the full path. It also fixes a bug in a similar vein where we want to show the promo on only one of the sub-pages in a guide (e.g. URL 2 above), but because we're comparing against the `base_path`, we end up showing it on all pages of the guide.
1 parent 1f09217 commit 0b829ce

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

app/helpers/govuk_chat_promo_helper.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module GovukChatPromoHelper
2-
GOVUK_CHAT_PROMO_BASE_PATHS = %w[
2+
GOVUK_CHAT_PROMO_PATHS = %w[
33
/business-asset-disposal-relief
44
/business-support-service
55
/capital-gains-tax
@@ -65,7 +65,7 @@ module GovukChatPromoHelper
6565
/write-business-plan
6666
].freeze
6767

68-
def show_govuk_chat_promo?(base_path)
69-
ENV["GOVUK_CHAT_PROMO_ENABLED"] == "true" && GOVUK_CHAT_PROMO_BASE_PATHS.include?(base_path)
68+
def show_govuk_chat_promo?(path)
69+
ENV["GOVUK_CHAT_PROMO_ENABLED"] == "true" && GOVUK_CHAT_PROMO_PATHS.include?(path)
7070
end
7171
end

app/views/shared/_sidebar_navigation.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% content_item = @content_item.content_item.parsed_content %>
22

33
<div class="govuk-grid-column-one-third">
4-
<% if show_govuk_chat_promo?(@content_item.base_path) %>
4+
<% if show_govuk_chat_promo?(@content_item.requested_path) %>
55
<%= render "govuk_publishing_components/components/chat_entry", { margin_top_until_tablet: true } %>
66
<% end %>
77

test/helpers/govuk_chat_promo_helper_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class GovukChatPromoHelperTest < ActionView::TestCase
44
test "show_govuk_chat_promo? when configuration disabled" do
5-
assert_not show_govuk_chat_promo?(GOVUK_CHAT_PROMO_BASE_PATHS.first)
5+
assert_not show_govuk_chat_promo?(GOVUK_CHAT_PROMO_PATHS.first)
66
end
77

88
test "show_govuk_chat_promo? when base_path not in configuration" do
@@ -13,7 +13,7 @@ class GovukChatPromoHelperTest < ActionView::TestCase
1313

1414
test "show_govuk_chat_promo? when base_path is in configuration" do
1515
ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do
16-
assert show_govuk_chat_promo?(GOVUK_CHAT_PROMO_BASE_PATHS.first)
16+
assert show_govuk_chat_promo?(GOVUK_CHAT_PROMO_PATHS.first)
1717
end
1818
end
1919
end
+19-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
require "test_helper"
22

33
class GovukChatPromoTest < ActionDispatch::IntegrationTest
4-
test "renders GOV.UK chat promo for matching content type and base path" do
4+
test "renders GOV.UK chat promo for matching content type and requested path" do
55
ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do
6-
setup_and_visit_a_page_with_specific_base_path("answer", GovukChatPromoHelper::GOVUK_CHAT_PROMO_BASE_PATHS.first)
6+
setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out")
77

88
assert page.has_css?(".gem-c-chat-entry")
99
end
1010
end
1111

12+
test "renders GOV.UK chat promo when requested path contains multiple parts" do
13+
ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do
14+
setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out/how-contracting-out-affects-your-amount")
15+
16+
assert page.has_css?(".gem-c-chat-entry")
17+
end
18+
end
19+
20+
test "does not render GOV.UK chat promo when base path is in allow list but actual path is not" do
21+
ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do
22+
setup_and_visit_a_page_with_specific_base_path("guide", "/contracted-out/check-if-you-were-contracted-out")
23+
24+
assert_not page.has_css?(".gem-c-chat-entry")
25+
end
26+
end
27+
1228
def schema_type
13-
"answer"
29+
"guide"
1430
end
1531
end

0 commit comments

Comments
 (0)