-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |