Skip to content

Commit

Permalink
Merge pull request #3058 from alphagov/tracking-details
Browse files Browse the repository at this point in the history
Convert publications to local rendering
  • Loading branch information
andysellick authored Apr 17, 2024
2 parents 408932d + 2f5cdec commit 538128a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def details
end

def documents
content_item["details"]["documents"].to_a.join("")
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"] }
end

def featured_attachments
Expand Down
21 changes: 21 additions & 0 deletions app/views/content_items/_attachments_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%
attachments ||= nil
featured_attachments ||= []
attachment_details = featured_attachments.filter_map { |id| @content_item&.attachment_details(id) }
%>
<section id="<%= title.parameterize %>">
<%= render 'govuk_publishing_components/components/heading',
text: title,
mobile_top_margin: true
%>
<% if attachment_details.length > 0 %>
<% add_gem_component_stylesheet("details") %>
<% attachment_details.each do |details| %>
<%= render 'govuk_publishing_components/components/attachment', {
heading_level: 3,
attachment: details,
margin_bottom: 6
} %>
<% end %>
<% end %>
</section>
6 changes: 3 additions & 3 deletions app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
<% end %>

<div class="responsive-bottom-margin">
<%= render "attachments",
<%= render "attachments_list",
title: t("publication.documents", count: 5), # This should always be pluralised.
legacy_pre_rendered_documents: @content_item.documents,
attachments: @content_item.featured_attachments
attachments: @content_item.documents,
featured_attachments: @content_item.featured_attachments
%>

<section id="details">
Expand Down
32 changes: 29 additions & 3 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,38 @@ class PublicationTest < ActionDispatch::IntegrationTest
assert_footer_has_published_dates("Published 3 May 2016")
end

test "renders document attachments (as-is and directly)" do
setup_and_visit_content_item("publication")
test "does not render non-featured attachments" do
overrides = {
"details" => {
"attachments" => [{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"command_paper_number" => "",
"content_type" => "application/pdf",
"file_size" => 123_456,
"filename" => "veolia-permit.pdf",
"hoc_paper_number" => "",
"id" => "violia-permit",
"isbn" => "",
"locale" => "en",
"title" => "Permit: Veolia ES (UK) Limited",
"unique_reference" => "",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"url" => "https://assets.publishing.service.gov.uk/media/123abc/veolia-permit.zip",
}],
"featured_attachments" => [],
},
}

setup_and_visit_content_item("publication", overrides)
within "#documents" do
assert page.has_text?("Permit: Veolia ES (UK) Limited")
assert page.has_no_text?("Permit: Veolia ES (UK) Limited")
end
end

test "renders featured document attachments using components" do
setup_and_visit_content_item("publication-with-featured-attachments")
within "#documents" do
assert page.has_text?("Number of ex-regular service personnel now part of FR20")
Expand Down
1 change: 0 additions & 1 deletion test/presenters/publication_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def schema_name
assert_equal schema_item["schema_name"], presented_item.schema_name
assert_equal schema_item["title"], presented_item.title
assert_equal schema_item["details"]["body"], presented_item.details
assert_equal schema_item["details"]["documents"].join(""), presented_item.documents
end

test "#published returns a formatted date of the day the content item became public" do
Expand Down

0 comments on commit 538128a

Please sign in to comment.