diff --git a/app/models/travel_advice.rb b/app/models/travel_advice.rb index 6bc862a6da..7fd693ea4b 100644 --- a/app/models/travel_advice.rb +++ b/app/models/travel_advice.rb @@ -20,6 +20,10 @@ def map_download_url content_store_response["details"].dig("document", "url") end + def map_download_file_size + content_store_response["details"].dig("document", "file_size") + end + def email_signup_link content_store_response["details"]["email_signup_link"] end diff --git a/app/views/travel_advice/_first_part.html.erb b/app/views/travel_advice/_first_part.html.erb index 0502b3812d..b428c51f43 100644 --- a/app/views/travel_advice/_first_part.html.erb +++ b/app/views/travel_advice/_first_part.html.erb @@ -15,7 +15,7 @@ <% if content_item.map_download_url %>
<%= render "components/download_link", { - text: "Download a more detailed map (PDF)", + text: "Download a more detailed map (PDF, #{number_to_human_size(content_item.map_download_file_size)})", href: content_item.map_download_url, } %>
diff --git a/spec/models/travel_advice_spec.rb b/spec/models/travel_advice_spec.rb index 8f4c29b5c1..a524f64026 100644 --- a/spec/models/travel_advice_spec.rb +++ b/spec/models/travel_advice_spec.rb @@ -24,4 +24,16 @@ expect(alert_statuses).to be_empty end end + + describe "#map_download_file_size" do + it "returns the file size when present" do + content_store_response["details"]["document"] = { + "url" => "https://example.com/map.pdf", + "file_size" => 201_672, + } + + travel_advice = described_class.new(content_store_response) + expect(travel_advice.map_download_file_size).to eq(201_672) + end + end end diff --git a/spec/system/travel_advice_spec.rb b/spec/system/travel_advice_spec.rb index 4e338acd14..645cce7213 100644 --- a/spec/system/travel_advice_spec.rb +++ b/spec/system/travel_advice_spec.rb @@ -165,11 +165,19 @@ end end - it "displays the map" do - visit base_path + context "with map download" do + let(:content_store_response) do + response = GovukSchemas::Example.find("travel_advice", example_name: "full-country") + response["details"]["document"]["file_size"] = 201_672 + response + end + + it "displays the map" do + visit base_path - expect(page).to have_css(".map img[src=\"#{content_store_response['details']['image']['url']}\"]") - expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF)") + expect(page).to have_css(".map img[src=\"#{content_store_response['details']['image']['url']}\"]") + expect(page).to have_css(".map figcaption a[href=\"#{content_store_response['details']['document']['url']}\"]", text: "Download a more detailed map (PDF, 197 KB)") + end end end