Skip to content

Commit

Permalink
Merge pull request #1638 from alphagov/no-deal-notice-no-links
Browse files Browse the repository at this point in the history
Show no deal notice with no links
  • Loading branch information
Vanita Barrett authored Jan 29, 2020
2 parents e73875c + 3e9b4eb commit 512c9f8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 17 deletions.
11 changes: 10 additions & 1 deletion app/assets/stylesheets/components/_header-notice.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
padding: govuk-spacing(4);
}

.app-c-header-notice__text {
margin-bottom: govuk-spacing(2);
}

.app-c-header-notice__links {
margin-bottom: govuk-spacing(2);
}

.app-c-header-notice__list {
margin-top: -5px;
margin-bottom: 0;
}

.app-c-header-notice__link-intro {
margin-bottom: govuk-spacing(1);
margin-bottom: govuk-spacing(2);
}

.app-c-header-notice__link {
Expand Down
23 changes: 19 additions & 4 deletions app/presenters/content_item/no_deal_notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NoDealNotice
include ActionView::Context

def has_no_deal_notice?
no_deal_notice.present?
content_item.dig("details").has_key?("brexit_no_deal_notice")
end

def no_deal_notice_component
Expand All @@ -15,13 +15,14 @@ def no_deal_notice_component
description: no_deal_notice_description,
link_intro: no_deal_notice_link_intro,
links: no_deal_links,
featured_link: no_deal_landing_page_cta,
}
end
end

private

def no_deal_notice
def no_deal_notice_links
content_item.dig("details", "brexit_no_deal_notice")
end

Expand All @@ -30,15 +31,29 @@ def no_deal_notice_title
end

def no_deal_notice_description
"This page tells you what you will need to do from January 2021. <a class='govuk-link' href='/email-signup?topic=%2Ftransition'>Sign up for email alerts</a> to find out when it is updated.".html_safe
"This page tells you what you'll need to do from 1 January 2021. It'll be updated if anything changes. "
end

def no_deal_notice_link_intro
"For current information, read: "
end

def no_deal_landing_page_cta
data_attributes = {
"module": "track-click",
"track-category": "no_deal_notice",
"track-action": "/transition",
"track-label": "the transition period",
}

featured_link = link_to("the transition period", "/transition", data: data_attributes, class: "govuk-link")
featured_link_intro = no_deal_notice_links.any? ? "You can also read about" : "You can read about"

(featured_link_intro + " " + featured_link + ".").html_safe
end

def no_deal_links
no_deal_notice.map do |link|
no_deal_notice_links.map do |link|
{
title: link["title"],
href: link["href"],
Expand Down
33 changes: 21 additions & 12 deletions app/views/components/_header-notice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
description ||= false
link_intro ||= false
links ||= []
featured_link ||= false
%>
<% if title && description %>
<section class="app-c-header-notice" aria-label="notice" role="region">
Expand All @@ -11,19 +12,27 @@
</div>

<div class="app-c-header-notice__content">
<p class="govuk-body"><%= description %></p>
<% if links.count == 1 %>
<p class="govuk-body">
<% if link_intro %><%= link_intro %><% end %>
<%= link_to(links[0][:title], links[0][:href], data: links[0][:data_attributes], class: "app-c-header-notice__link") %>
</p>
<% else %>
<% if link_intro %><p class="govuk-body app-c-header-notice__link-intro"><%= link_intro %></p><% end %>
<ul class="app-c-header-notice__list govuk-list">
<% links.each do |link| %>
<li><%= link_to(link[:title], link[:href], data: link[:data_attributes], class: "app-c-header-notice__link") %></li>
<p class="app-c-header-notice__text govuk-body"><%= description %></p>
<% if links.any? %>
<div class="app-c-header-notice__links">
<% if links.count == 1 %>
<p class="govuk-body app-c-header-notice__link-intro">
<% if link_intro %><%= link_intro %><% end %>
<%= link_to(links[0][:title], links[0][:href], data: links[0][:data_attributes], class: "app-c-header-notice__link") %>
</p>
<% else %>
<% if link_intro %><p class="govuk-body app-c-header-notice__link-intro"><%= link_intro %></p><% end %>
<ul class="app-c-header-notice__list govuk-list">
<% links.each do |link| %>
<li><%= link_to(link[:title], link[:href], data: link[:data_attributes], class: "app-c-header-notice__link") %></li>
<% end %>
</ul>
<% end %>
</ul>
</div>
<% end %>

<% if featured_link %>
<p class="app-c-header-notice__text govuk-body"><%= featured_link %></p>
<% end %>
</div>
</section>
Expand Down
10 changes: 10 additions & 0 deletions app/views/components/docs/header-notice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ examples:
data:
title: "This is an important notice"
description: "Here is a message about this notice"
featured_link: "You can also read about <a class='govuk-link' href='/transition'>the transition period</a>"
link_intro: "Look at these links: "
links:
- title: "This is a link"
Expand All @@ -15,10 +16,19 @@ examples:
data:
title: "This is an important notice"
description: "Here is a message about this notice"
featured_link: "You can also read about <a class='govuk-link' href='/transition'>the transition period</a>"
link_intro: "Look at these links: "
links:
- title: "This is a link"
href: "/this-is-a-link"
- title: "This is a second link"
href: "/this-is-a-link"
without_links:
description: The link intro does not render if there are no links, even if it has been provided
data:
title: "This is an important notice"
description: "Here is a message about this notice"
link_intro: "Look at these links: "
featured_link: "You can also read about <a class='govuk-link' href='/transition'>the transition period</a>"


8 changes: 8 additions & 0 deletions test/components/header_notice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def component_name
assert_select "section[aria-label=notice]"
end

test "renders a header notice with no link" do
render_component(title: "This is an important notice", description: "This is a description", link_intro: "This should not be shown", links: [])

assert_select ".app-c-header-notice__title", text: "This is an important notice"
assert_select ".app-c-header-notice__content p", text: "This is a description"
assert_select ".app-c-header-notice__link-intro", false, "A link intro shouldn't be shown when no links are provided"
end

test "renders a header notice with one link" do
render_component(title: "This is an important notice", description: "This is a description", links: [{ title: "test", href: "/test" }])

Expand Down

0 comments on commit 512c9f8

Please sign in to comment.