Skip to content

Commit

Permalink
Implement notification button exemption list
Browse files Browse the repository at this point in the history
Change single page notification button allow list to an exemption list.

Add tests to verify that pages whose content item is on the exemption
list do not display with the single page notification button.

Ensure that the button appears only on detailed_guides, publications and
consultations and update tests for all other types of publications to
check that the button is not included on those types.
  • Loading branch information
danacotoran committed Mar 1, 2022
1 parent b31ee67 commit 6ecd50c
Show file tree
Hide file tree
Showing 26 changed files with 156 additions and 33 deletions.
34 changes: 1 addition & 33 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def render_template
end

# use these and `@content_item.base_path` in the template
@notification_button_visible = in_single_page_notifications_trial? && !@content_item.brexit_child_taxon
@notification_button_visible = @content_item.has_single_page_notifications? && !@content_item.brexit_child_taxon
@include_single_page_notification_button_js = account_session_header.present?

request.variant = :print if params[:variant] == "print"
Expand Down Expand Up @@ -211,36 +211,4 @@ def set_account_vary_header
# variation, rather than caching pages per user
response.headers["Vary"] = [response.headers["Vary"], "GOVUK-Account-Session-Exists", "GOVUK-Account-Session-Flash"].compact.join(", ")
end

def in_single_page_notifications_trial?
%w[
/government/publications/open-standards-for-government
/government/publications/identity-proofing-and-verification-of-an-individual
/guidance/travel-to-england-from-another-country-during-coronavirus-covid-19
/guidance/covid-19-coronavirus-restrictions-what-you-can-and-cannot-do
/government/publications/face-coverings-when-to-wear-one-and-how-to-make-your-own
/guidance/commercial-court-hearing-and-trial-dates
/guidance/london-circuit-commercial-court-hearing-and-trial-dates
/guidance/united-kingdom-single-issuing-authority-uksia
/government/publications/current-catch-limits-over-10-metre-non-sector-pool
/government/publications/current-catch-limits-10-metres-and-under-pool
/government/publications/fishing-vessel-licence-variations
/guidance/check-if-youre-eligible-for-making-tax-digital-for-income-tax
/guidance/check-when-to-sign-up-for-making-tax-digital-for-income-tax
/guidance/find-software-thats-compatible-with-making-tax-digital-for-income-tax
/guidance/using-making-tax-digital-for-income-tax
/guidance/sign-up-your-business-for-making-tax-digital-for-income-tax
/guidance/list-of-customs-agents-and-fast-parcel-operators
/guidance/check-if-you-need-to-register-for-plastic-packaging-tax
/guidance/work-out-which-packaging-is-subject-to-plastic-packaging-tax
/guidance/check-which-plastic-packaging-is-exempt-from-plastic-packaging-tax
/guidance/examples-of-tests-and-calculations-for-plastic-packaging-tax
/guidance/register-for-plastic-packaging-tax
/guidance/claim-a-credit-or-defer-paying-plastic-packaging-tax
/guidance/completing-your-plastic-packaging-tax-return
/guidance/register-a-group-of-companies-for-plastic-packaging-tax
/guidance/decide-if-you-need-to-register-for-plastic-packaging-tax
/guidance/uk-trade-agreements-with-non-eu-countries
].include? @content_item.base_path
end
end
21 changes: 21 additions & 0 deletions app/presenters/content_item/single_page_notification_button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ContentItem
module SinglePageNotificationButton
# Add the content id of the publication, detailed_guide or consultation that should be exempt from having the single page notification button
EXEMPTION_LIST = %w[
c5c8d3cd-0dc2-4ca3-8672-8ca0a6e92165
70bd3a76-6606-45dd-9fb5-2b95f8667b4d
a457220c-915c-4cb1-8e41-9191fba42540
5f9c6c15-7631-11e4-a3cb-005056011aef
].freeze

ALLOWED_DOCUMENT_TYPES = %w[
publication
detailed_guide
consultation
].freeze

def has_single_page_notifications?
(!EXEMPTION_LIST.include? content_item["content_id"]) && (ALLOWED_DOCUMENT_TYPES.include? content_item["schema_name"])
end
end
end
1 change: 1 addition & 0 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ContentItemPresenter
include ContentItem::Withdrawable
include ContentItem::BrexitTaxons
include ContentItem::SinglePageNotificationButton

attr_reader :content_item,
:requested_path,
Expand Down
5 changes: 5 additions & 0 deletions test/integration/answer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ class AnswerTest < ActionDispatch::IntegrationTest
assert_equal faq_schema["name"], @content_item["title"]
assert_not_equal faq_schema["mainEntity"], []
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("answer")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/case_study_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class CaseStudyTest < ActionDispatch::IntegrationTest
assert page.has_css?("time[datetime='#{@content_item['withdrawn_notice']['withdrawn_at']}']")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("translated")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
10 changes: 10 additions & 0 deletions test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ class ConsultationTest < ActionDispatch::IntegrationTest
assert page.has_css?("a", text: "Facebook")
assert page.has_css?("a", text: "Twitter")
end

test "renders with the single page notification button" do
setup_and_visit_content_item("open_consultation")
assert page.has_css?(".gem-c-single-page-notification-button")
end

test "does not render the single page notification button on exempt pages" do
setup_and_visit_notification_exempt_page("open_consultation")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class ContactTest < ActionDispatch::IntegrationTest
assert page.has_css?("h2#post-title")
assert page.has_css?(".street-address")
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("contact")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/corporate_information_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ class CorporateInformationPageTest < ActionDispatch::IntegrationTest
assert page.has_css?(".gem-c-notice__title", text: "This information page was withdrawn on 9 August 2014")
assert page.has_css?(".gem-c-notice", text: "This is out of date")
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("corporate_information_page")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
10 changes: 10 additions & 0 deletions test/integration/detailed_guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,14 @@ class DetailedGuideTest < ActionDispatch::IntegrationTest
assert_equal "brexit-citizen-page", track_category
assert_equal "Guidance nav link", track_label
end

test "renders with the single page notification button" do
setup_and_visit_content_item("detailed_guide")
assert page.has_css?(".gem-c-single-page-notification-button")
end

test "does not render the single page notification button on exempt pages" do
setup_and_visit_notification_exempt_page("detailed_guide")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,9 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("document_collection")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/fatality_notice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest
assert page.has_text?("This content is not factually correct. For current information please go to")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("fatality_notice")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/guide_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class GuideTest < ActionDispatch::IntegrationTest
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("guide")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end

def once_voting_has_closed
Timecop.freeze(Time.zone.local(2021, 5, 6, 22, 0, 0))
yield
Expand Down
5 changes: 5 additions & 0 deletions test/integration/help_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class HelpPageTest < ActionDispatch::IntegrationTest

assert page.has_css?('meta[name="robots"][content="noindex"]', visible: false)
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("help_page")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/html_publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ def assert_has_component_organisation_logo_with_brand(brand, index = 1)

assert page.has_css?(".gem-c-notice__title", text: "This publication was withdrawn on 9 August 2014")
end

test "does not render with the single page notification button" do
setup_and_visit_html_publication("published")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/news_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ class NewsArticleTest < ActionDispatch::IntegrationTest
assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("news_article")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
10 changes: 10 additions & 0 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ class PublicationTest < ActionDispatch::IntegrationTest
},
])
end

test "renders with the single page notification button" do
setup_and_visit_content_item("publication")
assert page.has_css?(".gem-c-single-page-notification-button")
end

test "does not render the single page notification button on exempt pages" do
setup_and_visit_notification_exempt_page("publication")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/specialist_document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,9 @@ def assert_nested_content_item(heading)
text: "See all EU Withdrawal Act 2018 statutory instruments",
)
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("aaib-reports")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/speech_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ class SpeechTest < ActionDispatch::IntegrationTest

assert_footer_has_published_dates("Published 8 March 2016")
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("speech")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/statistical_data_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ class StatisticalDataSetTest < ActionDispatch::IntegrationTest

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

test "does not render with the single page notification button" do
setup_and_visit_content_item("statistical_data_set")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/statistics_announcement_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ class StatisticsAnnouncementTest < ActionDispatch::IntegrationTest

assert_not page.has_text?(StatisticsAnnouncementPresenter::FORTHCOMING_NOTICE)
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("official_statistics")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/take_part_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ class TakePartTest < ActionDispatch::IntegrationTest

assert page.has_text?("There are roughly 20,000 local councillors in England. Councillors are elected to the local council to represent their own local community, so they must either live or work in the area.")
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("take_part")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/topical_event_about_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class TopicalEventAboutPageTest < ActionDispatch::IntegrationTest
assert page.has_css?(".gem-c-contents-list")
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("topical_event_about_page")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end

private

def topical_event_end_date
Expand Down
5 changes: 5 additions & 0 deletions test/integration/travel_advice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class TravelAdviceTest < ActionDispatch::IntegrationTest
assert page.has_css?("link[type*='atom'][href='#{@content_item['base_path']}.atom']", visible: false)
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("full-country")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end

def setup_and_visit_travel_advice_part(name, part)
@content_item = get_content_example(name).tap do |item|
stub_content_store_has_item("#{item['base_path']}/#{part}", item.to_json)
Expand Down
5 changes: 5 additions & 0 deletions test/integration/working_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ class WorkingGroupTest < ActionDispatch::IntegrationTest

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

test "does not render with the single page notification button" do
setup_and_visit_content_item("long")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
5 changes: 5 additions & 0 deletions test/integration/world_location_news_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ class WorldLocationNewsArticleTest < ActionDispatch::IntegrationTest
assert page.has_text?("This was published under the 2010 to 2015 Conservative and Liberal Democrat coalition government")
end
end

test "does not render with the single page notification button" do
setup_and_visit_content_item("world_location_news_article")
assert_not page.has_css?(".gem-c-single-page-notification-button")
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ def setup_and_visit_brexit_child_taxon(type = nil)
end
end

def setup_and_visit_notification_exempt_page(name)
@content_item = get_content_example(name).tap do |item|
item["content_id"] = ContentItem::SinglePageNotificationButton::EXEMPTION_LIST[0]
stub_content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust((item["base_path"]).to_s)
end
end

def brexit_citizen_id
ContentItem::BrexitTaxons::BREXIT_CITIZEN_PAGE_CONTENT_ID
end
Expand Down

0 comments on commit 6ecd50c

Please sign in to comment.