Skip to content

Commit

Permalink
Add logic to display intervention banner on specific pages
Browse files Browse the repository at this point in the history
  • Loading branch information
chao-xian committed Mar 4, 2022
1 parent a669604 commit 7596e60
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ContentItemPresenter

attr_accessor :include_collections_in_other_publisher_metadata

USER_RESEARCH_PAGES = %w[register-for-self-assessment self-employed-records income-tax-rates].freeze

def initialize(content_item, requested_path, view_context)
@content_item = content_item
@requested_path = requested_path
Expand Down Expand Up @@ -87,6 +89,10 @@ def show_phase_banner?
phase.in?(%w[alpha beta])
end

def show_study_banner?
USER_RESEARCH_PAGES.include?(slug)
end

def render_guide_as_single_page?
# /how-to-vote
content_id == "9315bc67-33e7-42e9-8dea-e022f56dabfa" && voting_is_open?
Expand Down
9 changes: 8 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
</head>
<body>
<div id="wrapper" class="<%= wrapper_class %>">
<% if @content_item.show_phase_banner? %>
<% if @content_item.show_study_banner? %>
<%= render "govuk_publishing_components/components/intervention", {
suggestion_text: "Help improve GOV.UK",
suggestion_link_text: "Take part in user research",
suggestion_link_url: "https://GDSUserResearch.optimalworkshop.com/treejack/lb5eu75l",
new_tab: true,
} %>
<% elsif @content_item.show_phase_banner? %>
<%= render 'govuk_publishing_components/components/phase_banner', phase: @content_item.phase %>
<% end %>

Expand Down
16 changes: 16 additions & 0 deletions test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ class GuideTest < ActionDispatch::IntegrationTest
assert_not page.has_css?(".gem-c-single-page-notification-button")
end

test "does not render intervention banner by default" do
setup_and_visit_content_item("guide")

assert_not page.has_css?(".gem-c-intervention")
end

test "renders intervention banner on specific page" do
user_research_pages = %w[register-for-self-assessment self-employed-records income-tax-rates]

user_research_pages.each do |banner_page|
setup_and_visit_a_page_with_specific_base_path("guide", "/#{banner_page}")
end

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

def once_voting_has_closed
Timecop.freeze(Time.zone.local(2021, 5, 6, 22, 0, 0))
yield
Expand Down

0 comments on commit 7596e60

Please sign in to comment.