Skip to content

Commit

Permalink
Merge pull request #772 from alphagov/transaction-done-register-to-vote
Browse files Browse the repository at this point in the history
Add register-to-vote promo on transaction done pages
  • Loading branch information
dsingleton committed Apr 19, 2016
2 parents 4c341a8 + 4eb245f commit e124f28
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
29 changes: 27 additions & 2 deletions app/views/root/related.raw.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
<%# Whilst they are both in use, this and the test copy in slimmer should be kept in sync %>
<% if artefact and (artefact.related_artefacts.any? or (artefact.related_external_links and artefact.related_external_links.any?)) %>

<%
promo_target_formats = ['completed_transaction', 'transaction']
promo_excluded_regex = /register-to-vote/

has_promo_callout = (artefact and promo_target_formats.include?(artefact.format) and not promo_excluded_regex.match(URI.decode(artefact.slug)))
%>
<%# Whilst they are both in use, this and the test copy in slimmer should be kept in sync %>
<% if artefact and (artefact.related_artefacts.any? or (artefact.related_external_links and artefact.related_external_links.any?) or has_promo_callout) %>
<!-- related -->
<div class="related-container">

<aside class="related" id="related">
<% artefact.related_artefacts.group_by(&:group).each do |group, related_artefacts| %>

<% if has_promo_callout %>
<div class="inner group related-callout">
<h2 id="parent-promo">Register to vote</h2>
<p>You need to register if you want to vote in elections and referendums.</p>
<p>You can <a href="/register-to-vote?source=related">register online</a> in less than 5 minutes.</p>
</div>
<% end %>

<% related_artefacts = artefact.related_artefacts || [] %>

<%# Exclude '/register-to-vote', only if we're adding it manually (its easier to do by `content_id` than full `web_url`) %>
<% related_artefacts = related_artefacts.reject { |artefact|
artefact.content_id == "834a7921-260b-4061-9de1-edda3e998c68" and has_promo_callout
} %>

<% related_artefacts.group_by(&:group).each do |group, related_artefacts| %>
<%
section = case group
when 'subsection' then artefact.primary_section
when 'section' then artefact.primary_root_section
when 'other' then { "title" => "Elsewhere on GOV.UK" }
end
section = section['parent'] if artefact.format == "travel-advice" and group == "subsection"

%>
<div class="inner group related-<%= group %>">
<% if section %>
Expand Down
45 changes: 30 additions & 15 deletions test/integration/related_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def get_template

context "with related artefacts" do
setup do
@related1 = stub("Artefact", :web_url => "http://www.example.com/foo", :title => "Foo", :group => "subsection")
@related2 = stub("Artefact", :web_url => "http://www.example.com/bar", :title => "Bar", :group => "section")
@related3 = stub("Artefact", :web_url => "http://www.example.com/baz", :title => "Baz", :group => "other")
@related1 = stub("Artefact", web_url: "http://www.example.com/foo", title: "Foo", group: "subsection", content_id: 1)
@related2 = stub("Artefact", web_url: "http://www.example.com/bar", title: "Bar", group: "section", content_id: 2)
@related3 = stub("Artefact", web_url: "http://www.example.com/baz", title: "Baz", group: "other", content_id: 3)
@artefact = stub("Artefact",
:related_artefacts => [@related1, @related2, @related3],
:related_external_links => [],
:primary_root_section => { "title" => "Section", "content_with_tag" => { "web_url" => "/browse/section" }},
:primary_section => { "title" => "Sub-section", "content_with_tag" => { "web_url" => "/browse/section/subsection" } },
:format => "guide"
related_artefacts: [@related1, @related2, @related3],
related_external_links: [],
primary_root_section: { "title" => "Section", "content_with_tag" => { "web_url" => "/browse/section" } },
primary_section: { "title" => "Sub-section", "content_with_tag" => { "web_url" => "/browse/section/subsection" } },
format: "guide"
)
end

Expand Down Expand Up @@ -148,11 +148,11 @@ def get_template
context "adding related_external_links with no internal related links" do
setup do
@artefact = stub("Artefact",
:related_artefacts => [],
:related_external_links => [],
:primary_root_section => { "title" => "Section", "content_with_tag" => { "web_url" => "/browse/section" }},
:primary_section => { "title" => "Sub-section", "content_with_tag" => { "web_url" => "/browse/section/subsection" } },
:format => "guide"
related_artefacts: [],
related_external_links: [],
primary_root_section: { "title" => "Section", "content_with_tag" => { "web_url" => "/browse/section" } },
primary_section: { "title" => "Sub-section", "content_with_tag" => { "web_url" => "/browse/section/subsection" } },
format: "guide"
)
end

Expand Down Expand Up @@ -207,7 +207,7 @@ def get_template
should "be blank with an artefact with no related_artefacts or related_external_links" do
template = get_template

artefact = stub("Artefact", :related_artefacts => [], :related_external_links => [])
artefact = stub("Artefact", related_artefacts: [], related_external_links: [], format: "smart_answer")
result = ERB.new(template).result(binding)

assert_match /\A\s+\z/, result
Expand All @@ -216,9 +216,24 @@ def get_template
should "be blank with no related_artefacts and nil related_external_links" do
template = get_template

artefact = stub("Artefact", :related_artefacts => [], :related_external_links => nil)
artefact = stub("Artefact", related_artefacts: [], related_external_links: nil, format: "smart_answer")
result = ERB.new(template).result(binding)

assert_match /\A\s+\z/, result
end

context "adding promo block to related links" do
should "have promo block for target formats" do
artefact = stub("Artefact", related_artefacts: [], related_external_links: nil, format: "completed_transaction", slug: "book-theory-test")
result = ERB.new(get_template).result(binding)
doc = Nokogiri::HTML.parse(result)
assert doc.at_css("h2#parent-promo")
end

should "not have promo block for artefact with excluded path" do
artefact = stub("Artefact", related_artefacts: [], related_external_links: nil, format: "completed_transaction", slug: "done/register-to-vote")
result = ERB.new(get_template).result(binding)
assert_match(/\A\s+\z/, result)
end
end
end

0 comments on commit e124f28

Please sign in to comment.