From c9cd58e3f86037db5ec1734ef105b1bcf54c38af Mon Sep 17 00:00:00 2001 From: Peter Yates Date: Wed, 10 Mar 2021 16:54:45 +0000 Subject: [PATCH] Make render? check for content as well as headings This allows the notification banner to be used in a more-flexible manner but still prevents an empty one from being rendered. Fixes #119 --- .../govuk_component/notification_banner.rb | 2 +- .../govuk_component/notification_banner_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/components/govuk_component/notification_banner.rb b/app/components/govuk_component/notification_banner.rb index e1964f90..d7d301b1 100644 --- a/app/components/govuk_component/notification_banner.rb +++ b/app/components/govuk_component/notification_banner.rb @@ -24,7 +24,7 @@ def success? end def render? - headings.any? + headings.any? || content.present? end def title_tag diff --git a/spec/components/govuk_component/notification_banner_spec.rb b/spec/components/govuk_component/notification_banner_spec.rb index 950698cf..8fd4f9b8 100644 --- a/spec/components/govuk_component/notification_banner_spec.rb +++ b/spec/components/govuk_component/notification_banner_spec.rb @@ -15,7 +15,7 @@ let(:kwargs) { { title: title } } - describe "rendering a notification banner" do + describe "rendering a notification banner with headings" do before do render_inline(GovukComponent::NotificationBanner.new(**kwargs)) do |nb| nb.slot(:heading, text: "omg") @@ -196,4 +196,19 @@ let(:block) { ->(banner) { banner.add_heading(text: "What a nice heading!") } } end end + + describe "rendering a notification banner with arbitrary content" do + before do + render_inline(GovukComponent::NotificationBanner.new(**kwargs)) { additional_content } + end + + let(:subject) { page } + + specify "the extra banner with extra content is rendered" do + expect(subject).to have_css(".govuk-notification-banner > .govuk-notification-banner__content") do |content| + expect(content).to have_css("p", text: "The quick brown fox") + expect(content).to have_css("blockquote", text: "Jumped over the lazy dog") + end + end + end end