-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are needed to render the new accessible form link from GOVUK Publishing Components. This is dependant on the component being updated first [1]. This change will apply to publications and consultations, which use the attachments partial. Initially, the new flow of requesting accessible formats will be a pilot and only available for documents, owned by a few organisations. This code will not need to be changed when the change is released to all orgs. [1]: alphagov/govuk_publishing_components#2636
- Loading branch information
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
module ContentItem | ||
module Attachments | ||
def attachment_details(attachment_id) | ||
content_item.dig("details", "attachments")&.find do |attachment| | ||
found_attachment = content_item.dig("details", "attachments")&.find do |attachment| | ||
attachment["id"] == attachment_id | ||
end | ||
|
||
return unless found_attachment | ||
|
||
found_attachment["attachment_id"] = found_attachment.delete("id") | ||
found_attachment["owning_document_content_id"] = content_item["content_id"] | ||
found_attachment | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "test_helper" | ||
|
||
class ContentItemAttachmentsTest < ActiveSupport::TestCase | ||
class DummyContentItem | ||
include ContentItem::Attachments | ||
attr_reader :content_item, :attachment_id, :content_id | ||
|
||
def initialize | ||
@attachment_id = 1234 | ||
@content_id = SecureRandom.uuid | ||
@content_item = { | ||
"content_id" => content_id, | ||
"details" => { | ||
"attachments" => [ | ||
{ | ||
"id" => attachment_id, | ||
"title" => "Some title", | ||
"url" => "some/url", | ||
"alternative_format_contact_email" => "[email protected]", | ||
}, | ||
], | ||
}, | ||
} | ||
end | ||
end | ||
|
||
test "returns attachment details for found attachment" do | ||
dummy = DummyContentItem.new | ||
|
||
details = dummy.attachment_details(dummy.attachment_id) | ||
|
||
assert_equal details, { | ||
"title" => "Some title", | ||
"url" => "some/url", | ||
"alternative_format_contact_email" => "[email protected]", | ||
"attachment_id" => dummy.attachment_id, | ||
"owning_document_content_id" => dummy.content_id, | ||
} | ||
end | ||
|
||
test "returns nil if no attachment found" do | ||
attachment_id = 4321 | ||
dummy = DummyContentItem.new | ||
|
||
details = dummy.attachment_details(attachment_id) | ||
|
||
assert_equal details, nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,17 @@ class ContentItemsAttachmentsTest < ActionView::TestCase | |
|
||
test "can render attachments using their metadata" do | ||
@content_item = PublicationPresenter.new( | ||
{ "details" => { "attachments" => [{ "id" => "attachment_id", | ||
"title" => "Some title", | ||
"url" => "some/url" }] } }, | ||
{ | ||
"content_id" => "doc_content_id", | ||
"details" => { | ||
"attachments" => [ | ||
{ "id" => "attachment_id", | ||
"title" => "Some title", | ||
"url" => "some/url", | ||
"alternative_format_contact_email" => "[email protected]" }, | ||
], | ||
}, | ||
}, | ||
"/publication", | ||
ApplicationController.new.view_context, | ||
) | ||
|
@@ -30,6 +38,7 @@ class ContentItemsAttachmentsTest < ActionView::TestCase | |
|
||
assert_includes rendered, "gem-c-attachment" | ||
assert_includes rendered, "Some title" | ||
assert_includes rendered, "href=\"/contact/govuk/request-accessible-format?content_id=doc_content_id&attachment_id=attachment_id" | ||
end | ||
|
||
test "it prioritises pre-rendered attachments" do | ||
|