From 7c71da9cfe7884ba11756e276633eee4c9d280b3 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Wed, 17 Apr 2024 16:48:29 +0100 Subject: [PATCH] Correctly display 'request accessible format' option - attachments on publications should only show this option when 'accessible' is false and email address is supplied - including tests accordingly --- app/presenters/publication_presenter.rb | 5 +- test/integration/publication_test.rb | 89 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index f042be7e1..98c7e575f 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -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 diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb index c0406ed3f..48c43bf53 100644 --- a/test/integration/publication_test.rb +++ b/test/integration/publication_test.rb @@ -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" => "ddc-modinternet@mod.gov.uk", + "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" => "ddc-modinternet@mod.gov.uk", + "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)