Skip to content

Commit 1f6acf7

Browse files
committed
Add map download file size to travel advice download link
1 parent 889ebb9 commit 1f6acf7

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

app/models/travel_advice.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def map_download_url
2020
content_store_response["details"].dig("document", "url")
2121
end
2222

23+
def map_download_file_size
24+
content_store_response["details"].dig("document", "file_size")
25+
end
26+
2327
def email_signup_link
2428
content_store_response["details"]["email_signup_link"]
2529
end

app/views/travel_advice/_first_part.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<% if content_item.map_download_url %>
1616
<figcaption>
1717
<%= render "components/download_link", {
18-
text: "Download a more detailed map (PDF)",
18+
text: "Download a more detailed map (PDF, #{number_to_human_size(content_item.map_download_file_size)})",
1919
href: content_item.map_download_url,
2020
} %>
2121
</figcaption>

spec/models/travel_advice_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@
2424
expect(alert_statuses).to be_empty
2525
end
2626
end
27+
28+
describe "#map_download_file_size" do
29+
it "returns the file size when present" do
30+
content_store_response["details"]["document"] = {
31+
"url" => "https://example.com/map.pdf",
32+
"file_size" => 201_672,
33+
}
34+
35+
travel_advice = described_class.new(content_store_response)
36+
expect(travel_advice.map_download_file_size).to eq(201_672)
37+
end
38+
end
2739
end

spec/system/travel_advice_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@
165165
end
166166
end
167167

168-
it "displays the map" do
169-
visit base_path
168+
context "with map download" do
169+
let(:content_store_response) do
170+
response = GovukSchemas::Example.find("travel_advice", example_name: "full-country")
171+
response["details"]["document"]["file_size"] = 201_672
172+
response
173+
end
174+
175+
it "displays the map" do
176+
visit base_path
170177

171-
expect(page).to have_css(".map img[src=\"#{content_store_response['details']['image']['url']}\"]")
172-
expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF)")
178+
expect(page).to have_css(".map img[src=\"#{content_store_response['details']['image']['url']}\"]")
179+
expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF, 197 KB)")
180+
end
173181
end
174182
end
175183

0 commit comments

Comments
 (0)