Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/travel_advice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/travel_advice/_first_part.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<% if content_item.map_download_url %>
<figcaption>
<%= 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,
} %>
</figcaption>
Expand Down
12 changes: 12 additions & 0 deletions spec/models/travel_advice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 12 additions & 4 deletions spec/system/travel_advice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down