OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Skip FlashComponent rendering if content is blank
Alexander Brandon Colesf5c28cc9d9a4
diff --git a/app/components/op_primer/flash_component.rb b/app/components/op_primer/flash_component.rbindex 15a445c0331..022a78245c8 100644--- a/app/components/op_primer/flash_component.rb+++ b/app/components/op_primer/flash_component.rb@@ -45,5 +45,11 @@ module OpPrimersuperend++ private++ def render?+ trimmed_content.present?+ endendenddiff --git a/spec/components/op_primer/flash_component_spec.rb b/spec/components/op_primer/flash_component_spec.rbnew file mode 100644index 00000000000..217f3ae6e65--- /dev/null+++ b/spec/components/op_primer/flash_component_spec.rb@@ -0,0 +1,63 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "rails_helper"++RSpec.describe OpPrimer::FlashComponent, type: :component do+ def render_component(content, ...)+ render_inline(described_class.new(...).with_content(content))+ end++ subject(:rendered_component) { render_component(content) }++ context "with content" do+ let(:content) { "Flash Text" }++ it "renders an x-banner" do+ expect(rendered_component).to have_element "x-banner"+ end++ it "renders the banner text" do+ expect(rendered_component).to have_css ".Banner-message .Banner-title", text: "Flash Text"+ end+ end++ context "with blank content" do+ let(:content) { " " }++ it "does not render an x-banner" do+ expect(rendered_component).to have_no_element "x-banner"+ end++ it "does not render the banner text" do+ expect(rendered_component).to have_no_css ".Banner-message .Banner-title"+ end+ end+enddiff --git a/spec/helpers/flash_messages_helper_spec.rb b/spec/helpers/flash_messages_helper_spec.rbindex 8f10fbb0971..cdf687e90f6 100644--- a/spec/helpers/flash_messages_helper_spec.rb+++ b/spec/helpers/flash_messages_helper_spec.rb@@ -82,6 +82,22 @@ RSpec.describe FlashMessagesHelper doit_behaves_like "rendering a banner", "flash-success", :"check-circle", "zu deiner Information"end+ context "with an empty flash message" do+ before do+ flash[:info] = "" # rubocop:disable Rails/I18nLocaleTexts+ end++ it_behaves_like "rendering nothing"+ end++ context "with a nil flash message" do+ before do+ flash[:info] = nil+ end++ it_behaves_like "rendering nothing"+ end+context "with an :info flash message" dobefore doflash[:info] = "zu deiner Information" # rubocop:disable Rails/I18nLocaleTexts