diff --git a/app/components/layout/social_component.rb b/app/components/layout/social_component.rb index 1391bd76a..3dd944c0e 100644 --- a/app/components/layout/social_component.rb +++ b/app/components/layout/social_component.rb @@ -1,6 +1,10 @@ class Layout::SocialComponent < ApplicationComponent delegate :content_block, to: :helpers + def render? + sites.any? || footer_content_block.present? + end + private def sites @@ -10,7 +14,7 @@ class Layout::SocialComponent < ApplicationComponent youtube: "https://www.youtube.com", telegram: "https://www.telegram.me", instragram: "https://www.instagram.com" - }.select { |name, _| setting["#{name}_handle"] } + }.select { |name, _| setting["#{name}_handle"].present? } end def link_title(site_name) diff --git a/spec/components/layout/social_component_spec.rb b/spec/components/layout/social_component_spec.rb new file mode 100644 index 000000000..29d29aa81 --- /dev/null +++ b/spec/components/layout/social_component_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +describe Layout::SocialComponent, type: :component do + describe "#render?" do + it "renders when a social setting is present" do + Setting["twitter_handle"] = "myhandle" + + render_inline Layout::SocialComponent.new + + expect(page).to have_css "ul" + end + + it "renders when a content block is present" do + Setting["twitter_handle"] = "" + Setting["facebook_handle"] = "" + Setting["youtube_handle"] = "" + Setting["telegram_handle"] = "" + Setting["instagram_handle"] = "" + + create(:site_customization_content_block, name: "footer") + + render_inline Layout::SocialComponent.new + + expect(page).to have_css "ul" + end + + it "does not render with no settings present and no content block present" do + Setting["twitter_handle"] = "" + Setting["facebook_handle"] = "" + Setting["youtube_handle"] = "" + Setting["telegram_handle"] = "" + Setting["instagram_handle"] = "" + + render_inline Layout::SocialComponent.new + + expect(page).not_to have_css "ul" + end + end +end