-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from alphagov/travel-advice-print
Add print view for travel advice
- Loading branch information
Showing
9 changed files
with
147 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<% | ||
content_for :title, "Print #{@content_item.page_title}" | ||
content_for :simple_header, true | ||
content_for :extra_head_content do %> | ||
<meta name="robots" content="noindex, nofollow"> | ||
<script>window.onload = function() { window.print(); }</script> | ||
<% end %> | ||
|
||
<div class="grid-row travel-advice-print"> | ||
<div class="column-two-thirds"> | ||
<%= render 'govuk_component/title', @content_item.title_and_context %> | ||
|
||
<section> | ||
<h1 class="part-title"> | ||
<%= @content_item.current_part_title %> | ||
</h1> | ||
<%= render 'shared/travel_advice_summary', content_item: @content_item %> | ||
<%= render 'govuk_component/govspeak', | ||
content: @content_item.current_part_body, | ||
direction: page_text_direction %> | ||
</section> | ||
|
||
<% @content_item.parts.each do |part| %> | ||
<section> | ||
<h1 class="part-title"> | ||
<%= part['title'] %> | ||
</h1> | ||
<%= render 'govuk_component/govspeak', | ||
content: part['body'], | ||
direction: page_text_direction %> | ||
</section> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% if content_item.alert_status.present? %> | ||
<% alert_body = capture do %> | ||
<div class="help-notice"> | ||
<%= content_item.alert_status %> | ||
</div> | ||
<% end %> | ||
<%= render 'govuk_component/govspeak', | ||
content: alert_body, | ||
direction: page_text_direction %> | ||
<% end %> | ||
|
||
<%= render 'govuk_component/metadata', content_item.metadata %> | ||
<% if content_item.map %> | ||
<figure class="map"> | ||
<img src="<%= content_item.map["url"] %>" alt="<%= content_item.map["alt_text"] %>"> | ||
<% if content_item.map_download_url %> | ||
<figcaption class="map-download"> | ||
<a href="<%= content_item.map_download_url %>">Download map (PDF)</a> | ||
</figcaption> | ||
<% end %> | ||
</figure> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'test_helper' | ||
|
||
class TravelAdvicePrint < ActionDispatch::IntegrationTest | ||
test "it renders the print view" do | ||
setup_and_visit_travel_advice_print('full-country') | ||
assert page.has_css?(".travel-advice-print") | ||
end | ||
|
||
test "it is not indexable by search engines" do | ||
setup_and_visit_travel_advice_print('full-country') | ||
assert page.has_css?("meta[name='robots'][content='noindex, nofollow']", visible: false) | ||
end | ||
|
||
test "it renders the summary and all parts in the print view" do | ||
setup_and_visit_travel_advice_print('full-country') | ||
parts = @content_item['details']['parts'] | ||
|
||
assert_has_component_metadata_pair("Still current at", Date.today.strftime("%-d %B %Y")) | ||
assert_has_component_metadata_pair("Updated", Date.parse(@content_item["details"]["reviewed_at"]).strftime("%-d %B %Y")) | ||
|
||
within shared_component_selector("metadata") do | ||
component_args = JSON.parse(page.text) | ||
latest_update = component_args["other"].fetch("Latest update") | ||
|
||
assert latest_update.include?('<p>') | ||
assert latest_update.include?(@content_item['details']['change_description'].gsub('Latest update: ', '')) | ||
end | ||
|
||
assert page.has_css?("h1", text: 'Current travel advice') | ||
parts.each do |part| | ||
assert page.has_css?("h1", text: part['title']) | ||
end | ||
|
||
page.all(shared_component_selector("govspeak")).each_with_index do |govspeak_component, i| | ||
within(govspeak_component) do | ||
content_passed_to_component = JSON.parse(page.text).fetch("content").gsub(/\s+/, ' ') | ||
if i == 0 | ||
assert_equal @content_item["details"]["summary"].gsub(/\s+/, ' '), content_passed_to_component | ||
else | ||
assert_equal parts[i - 1]['body'].gsub(/\s+/, ' '), content_passed_to_component | ||
end | ||
end | ||
end | ||
end | ||
|
||
def setup_and_visit_travel_advice_print(name) | ||
example = get_content_example_by_format_and_name('travel_advice', name) | ||
@content_item = JSON.parse(example).tap do |item| | ||
content_store_has_item(item["base_path"], item.to_json) | ||
visit "#{item['base_path']}/print" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters