Skip to content

Commit 2b8eb45

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

3 files changed

Lines changed: 40 additions & 1 deletion

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414
<img src="<%= content_item.map["url"] %>" alt="<%= content_item.map["alt_text"] %>" class="map-image">
1515
<% if content_item.map_download_url %>
1616
<figcaption>
17+
<%
18+
download_text = "Download a more detailed map (PDF"
19+
if content_item.map_download_file_size
20+
download_text += ", #{number_to_human_size(content_item.map_download_file_size)}"
21+
end
22+
download_text += ")"
23+
%>
1724
<%= render "components/download_link", {
18-
text: "Download a more detailed map (PDF)",
25+
text: download_text,
1926
href: content_item.map_download_url,
2027
} %>
2128
</figcaption>

spec/models/travel_advice_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,32 @@
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" => 201672,
33+
}
34+
35+
travel_advice = described_class.new(content_store_response)
36+
expect(travel_advice.map_download_file_size).to eq(201672)
37+
end
38+
39+
it "returns nil when file size is not present" do
40+
content_store_response["details"]["document"] = {
41+
"url" => "https://example.com/map.pdf",
42+
}
43+
44+
travel_advice = described_class.new(content_store_response)
45+
expect(travel_advice.map_download_file_size).to be_nil
46+
end
47+
48+
it "returns nil when document is not present" do
49+
content_store_response["details"].delete("document")
50+
51+
travel_advice = described_class.new(content_store_response)
52+
expect(travel_advice.map_download_file_size).to be_nil
53+
end
54+
end
2755
end

0 commit comments

Comments
 (0)