Do not show link content section when links fields are not defined.

This commit is contained in:
taitus
2021-06-25 13:15:11 +02:00
parent 108de86da5
commit db23d536dd
2 changed files with 34 additions and 4 deletions

View File

@@ -1,13 +1,17 @@
<% if header.present? %> <% if header.present? %>
<div class="jumbo highlight"> <div class="header-card jumbo highlight">
<div class="row"> <div class="row">
<div class="small-12 medium-6 column <%= "medium-9 small-centered text-center" unless header.image.present? %>"> <div class="small-12 medium-6 column <%= "medium-9 small-centered text-center" unless header.image.present? %>">
<span><%= header.label %></span> <span><%= header.label %></span>
<h1><%= header.title %></h1> <h1><%= header.title %></h1>
<p class="lead"><%= header.description %></p> <p class="lead"><%= header.description %></p>
<div class="small-12 medium-6 large-4 <%= "small-centered" unless header.image.present? %>">
<%= link_to header.link_text, header.link_url, class: "button expanded large" %> <% if header.link_text.present? && header.link_url.present? %>
</div> <div class="small-12 medium-6 large-4 <%= "small-centered" unless header.image.present? %>">
<%= link_to header.link_text, header.link_url, class: "button expanded large" %>
</div>
<% end %>
</div> </div>
<% if header.image.present? %> <% if header.image.present? %>

View File

@@ -174,4 +174,30 @@ describe "Home" do
expect(page).not_to have_css(".title", text: "Featured") expect(page).not_to have_css(".title", text: "Featured")
end end
describe "Header Card" do
scenario "if there is header card with link, the link content is rendered" do
create(:widget_card, :header, link_text: "Link text", link_url: "consul.dev")
visit root_path
expect(page).to have_link "Link text", href: "consul.dev"
end
scenario "if there is header card without link, the link content is not rendered" do
create(:widget_card, :header, link_text: nil, link_url: nil)
visit root_path
within(".header-card") { expect(page).not_to have_link }
end
scenario "if there is header card without link and with text, the link content is not rendered" do
create(:widget_card, :header, link_text: "", link_url: "", link_text_es: "Link ES", title_es: "ES")
visit root_path(locale: :es)
within(".header-card") { expect(page).not_to have_link }
end
end
end end