File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+
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
2755end
You can’t perform that action at this time.
0 commit comments