From 5a3fef736557d8968a880994de80d8d9c87957fb Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Thu, 18 Apr 2024 14:51:28 +0100 Subject: [PATCH] Fix publication external links - some attachments are simply links to another website - for these we need to identify the type as 'external' and pass the right option to the attachment component - added test for this --- app/presenters/publication_presenter.rb | 1 + test/integration/publication_test.rb | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index 84c9aadce..2bbb092af 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -20,6 +20,7 @@ def documents docs = content_item["details"]["attachments"].select { |a| !a.key?("locale") || a["locale"] == locale } docs.each do |doc| doc["type"] = "html" unless doc["content_type"] + doc["type"] = "external" if doc["attachment_type"] == "external" doc["alternative_format_contact_email"] = nil if doc["accessible"] == true end end diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb index 9ddafa5dd..90eb6c49b 100644 --- a/test/integration/publication_test.rb +++ b/test/integration/publication_test.rb @@ -168,6 +168,37 @@ class PublicationTest < ActionDispatch::IntegrationTest end end + test "renders external links correctly" do + overrides = { + "details" => { + "attachments" => [{ + "accessible" => true, + "alternative_format_contact_email" => "ddc-modinternet@mod.gov.uk", + "attachment_type" => "external", + "id" => "PUBLIC_1392629965.pdf", + "title" => "Number of ex-regular service personnel now part of FR20", + "url" => "https://not-a-real-website-hopefully", + "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?("https://not-a-real-website-hopefully") + assert page.has_no_text?("HTML") + end + end + test "withdrawn publication" do setup_and_visit_content_item("withdrawn_publication") assert page.has_css?("title", text: "[Withdrawn]", visible: false)