Skip to content

Commit a7819b1

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

4 files changed

Lines changed: 22 additions & 2 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,15 @@
165165
end
166166
end
167167

168+
before do
169+
content_store_response["details"]["document"]["file_size"] = 201_672
170+
end
171+
168172
it "displays the map" do
169173
visit base_path
170174

171175
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)")
176+
expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF, 197 KB)")
173177
end
174178
end
175179

0 commit comments

Comments
 (0)