Skip to content

Commit

Permalink
Display GOV.UK Chat promo on certain pages
Browse files Browse the repository at this point in the history
We want to show a promo to the new GOV.UK Chat application on certain pages
on GOV.UK.

The list of URLs is quite short and cover only `answer` and `guide`
content types.

The CTA is to be shown in the sidebar on the right of the relevant
pages.
  • Loading branch information
jackbot committed Aug 28, 2024
1 parent e6e7044 commit abd4912
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/helpers/govuk_chat_promo_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module GovukChatPromoHelper
GOVUK_CHAT_PROMO_BASE_PATHS = %w[
/business-support-helpline
/company-tax-returns
/corporation-tax
/pay-corporation-tax
/pay-vat
/search-for-trademark
/set-up-business
/submit-vat-return
/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)
end
end
4 changes: 4 additions & 0 deletions app/views/shared/_sidebar_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% content_item = @content_item.content_item.parsed_content %>

<div class="govuk-grid-column-one-third">
<% if show_govuk_chat_promo?(@content_item.base_path) %>
<%= render "govuk_publishing_components/components/chat_entry", { border_top: true } %>
<% end %>
<%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: content_item %>
</div>
19 changes: 19 additions & 0 deletions test/helpers/govuk_chat_promo_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "test_helper"

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)
end

test "show_govuk_chat_promo? when base_path not in configuration" do
ClimateControl.modify GOVUK_CHAT_PROMO_ENABLED: "true" do
assert_not show_govuk_chat_promo?("/non-matching-path")
end
end

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)
end
end
end
15 changes: 15 additions & 0 deletions test/integration/govuk_chat_promo_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "test_helper"

class GovukChatPromoTest < ActionDispatch::IntegrationTest
test "renders GOV.UK chat promo for matching content type and base 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)

assert page.has_css?(".gem-c-chat-entry")
end
end

def schema_type
"answer"
end
end

0 comments on commit abd4912

Please sign in to comment.