Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GOV.UK Chat promo on pages with multiple path segments #3440

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading