Skip to content

Commit

Permalink
Correctly display 'request accessible format' option
Browse files Browse the repository at this point in the history
- attachments on publications should only show this option when 'accessible' is false and email address is supplied
- including tests accordingly
  • Loading branch information
andysellick committed Apr 17, 2024
1 parent 4e69bf9 commit 7c71da9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def documents
return [] unless content_item["details"]["attachments"]

docs = content_item["details"]["attachments"].select { |a| a["locale"] == locale }
docs.each { |t| t["type"] = "html" unless t["content_type"] }
docs.each do |doc|
doc["type"] = "html" unless doc["content_type"]
doc["alternative_format_contact_email"] = nil if doc["accessible"] == true
end
end

def featured_attachments
Expand Down
89 changes: 89 additions & 0 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,95 @@ class PublicationTest < ActionDispatch::IntegrationTest
end
end

test "renders accessible format option when accessible is false and email is supplied" do
overrides = {
"details" => {
"attachments" => [{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"id" => "PUBLIC_1392629965.pdf",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"command_paper_number" => "",
"hoc_paper_number" => "",
"isbn" => "",
"unique_reference" => "",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"content_type" => "application/pdf",
"file_size" => 932,
"filename" => "PUBLIC_1392629965.pdf",
"number_of_pages" => 2,
"locale" => "en",
}],
},
}
setup_and_visit_content_item("publication-with-featured-attachments", overrides)
within "#documents" do
assert page.has_text?("Request an accessible format")
end
end

test "doesn't render accessible format option when accessible is false and email is not supplied" do
overrides = {
"details" => {
"attachments" => [{
"accessible" => false,
"attachment_type" => "file",
"id" => "PUBLIC_1392629965.pdf",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"command_paper_number" => "",
"hoc_paper_number" => "",
"isbn" => "",
"unique_reference" => "",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"content_type" => "application/pdf",
"file_size" => 932,
"filename" => "PUBLIC_1392629965.pdf",
"number_of_pages" => 2,
"locale" => "en",
}],
},
}
setup_and_visit_content_item("publication-with-featured-attachments", overrides)
within "#documents" do
assert page.has_no_text?("Request an accessible format")
end
end

test "doesn't render accessible format option when accessible is true and email is supplied" do
overrides = {
"details" => {
"attachments" => [{
"accessible" => true,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"id" => "PUBLIC_1392629965.pdf",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"command_paper_number" => "",
"hoc_paper_number" => "",
"isbn" => "",
"unique_reference" => "",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"content_type" => "application/pdf",
"file_size" => 932,
"filename" => "PUBLIC_1392629965.pdf",
"number_of_pages" => 2,
"locale" => "en",
}],
},
}
setup_and_visit_content_item("publication-with-featured-attachments", overrides)
within "#documents" do
assert page.has_no_text?("Request an accessible format")
end
end

test "withdrawn publication" do
setup_and_visit_content_item("withdrawn_publication")
assert page.has_css?("title", text: "[Withdrawn]", visible: false)
Expand Down

0 comments on commit 7c71da9

Please sign in to comment.