Skip to content

Commit

Permalink
General improvements
Browse files Browse the repository at this point in the history
- expand feed link test to check for toggle module
- improve template readability
- test modules are not added unless needed
- make test for data modules more specific
- make id for feed box unique
  • Loading branch information
andysellick committed May 9, 2018
1 parent bfdfbe6 commit a2a0684
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@
email_signup_link ||= false
email_signup_link_text ||= t("govuk_component.subscription_links.email_signup_link_text", default: "Get email alerts")
email_signup_link_data_attributes ||= false

feed_link ||= false
feed_link_text ||= t("govuk_component.subscription_links.feed_link_text", default: "Subscribe to feed")
feed_link_box_value ||= false
feed_link_data_attributes ||= {}

tracking_is_present = true if email_signup_link_data_attributes || !feed_link_data_attributes.empty?
tracking_is_present = true if email_signup_link_data_attributes || feed_link_data_attributes.any?

brand ||= false
brand_helper = GovukPublishingComponents::Presenters::BrandHelper.new(brand)

if feed_link_box_value
feed_link = "#"
feed_link_data_attributes[:controls] = "feed-reader"
feed_box_id = SecureRandom.hex(2)
feed_link_data_attributes[:controls] = "feed-reader-#{feed_box_id}"
feed_link_data_attributes[:expanded] = "false"
end
%>
<% if email_signup_link || feed_link || feed_link_box_value %>
<section class="gem-c-subscription-links <%= brand_helper.get_brand %>"
<section
class="gem-c-subscription-links <%= brand_helper.get_brand %>"
<%= "data-module=gem-toggle" if feed_link_box_value %>
>
<h2 class="visuallyhidden"><%= t("govuk_component.subscription_links.subscriptions", default: "Subscriptions") %></h2>
<ul class="gem-c-subscription-links__list"
<ul
class="gem-c-subscription-links__list"
<%= "data-module=track-click" if tracking_is_present %>
>
<% if email_signup_link.present? %>
Expand All @@ -46,7 +50,7 @@
</ul>

<% if feed_link_box_value %>
<div class="gem-c-subscription-links__feed-box js-hidden" id="feed-reader">
<div class="gem-c-subscription-links__feed-box js-hidden" id="feed-reader-<%= feed_box_id %>">
<p class="gem-c-subscription-links__feed-description js-hidden"><%= feed_link_text %></p>
<%= render "govuk_publishing_components/components/input", {
label: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ examples:
with_tracking:
description: Data attributes can be passed for each link as shown.
data:
brand: 'attorney-generals-office'
email_signup_link: '/foreign-travel-advice/singapore/email-signup'
email_signup_link_data_attributes: {
track_category: 'email_link_category',
Expand Down
3 changes: 3 additions & 0 deletions spec/components/subscription_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def component_name

it "renders both email signup and feed links" do
render_component(email_signup_link: 'email-signup', feed_link: 'singapore.atom')
assert_select ".gem-c-subscription-links[data-module='gem-toggle']", false
assert_select ".gem-c-subscription-links__list[data-module='track-click']", false
assert_select ".gem-c-subscription-links__link--email-alerts[href=\"email-signup\"]", text: "Get email alerts"
assert_select ".gem-c-subscription-links__link--feed[href=\"singapore.atom\"]", text: "Subscribe to feed"
end
Expand All @@ -33,6 +35,7 @@ def component_name

it "renders with a feed link box" do
render_component(feed_link_box_value: 'http://www.gov.uk', feed_link: 'singapore.atom')
assert_select ".gem-c-subscription-links[data-module=\"gem-toggle\"]"
assert_select ".gem-c-subscription-links__link--feed[href=\"singapore.atom\"]", false
assert_select ".gem-c-subscription-links__feed-box input[name='feed-reader-box'][value='http://www.gov.uk']"
end
Expand Down

0 comments on commit a2a0684

Please sign in to comment.