-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render featured attachments directly #1709
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.attachment { | ||
margin-bottom: govuk-spacing(6); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ContentItem | ||
module Attachments | ||
def attachment_details(attachment_id) | ||
content_item["details"]["attachments"].find do |attachment| | ||
attachment["id"] == attachment_id | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
<% attachment_title_id = "#{title.parameterize}-title" %> | ||
|
||
<% if legacy_pre_rendered_documents.present? %> | ||
<% if legacy_pre_rendered_documents.present? || attachments.any? %> | ||
<%= render 'govuk_publishing_components/components/heading', | ||
id: attachment_title_id, | ||
text: title, | ||
mobile_top_margin: true %> | ||
|
||
<div aria-labelledby="<%= attachment_title_id %>"> | ||
<%= render 'govuk_publishing_components/components/govspeak', | ||
content: legacy_pre_rendered_documents.html_safe, | ||
direction: page_text_direction %> | ||
<% if legacy_pre_rendered_documents.present? %> | ||
<%= render 'govuk_publishing_components/components/govspeak', | ||
content: legacy_pre_rendered_documents.html_safe, | ||
direction: page_text_direction %> | ||
<% else %> | ||
<% attachments.each do |attachment_id| %> | ||
<div class="attachment"> | ||
<%= render 'govuk_publishing_components/components/attachment', | ||
attachment: @content_item.attachment_details(attachment_id) %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,20 @@ class ConsultationTest < ActionDispatch::IntegrationTest | |
end | ||
end | ||
|
||
test "consultation documents render" do | ||
test "renders document attachments (as-is and directly)" do | ||
setup_and_visit_content_item("closed_consultation") | ||
|
||
assert page.has_text?("Documents") | ||
within '[aria-labelledby="documents-title"]' do | ||
assert page.has_text?("Museums Review Terms of Reference") | ||
end | ||
|
||
setup_and_visit_content_item("consultation_outcome_with_featured_attachments") | ||
|
||
assert page.has_text?("Documents") | ||
within '[aria-labelledby="documents-title"]' do | ||
assert page.has_text?("Setting the grade standards of new GCSEs in England – part 2") | ||
end | ||
end | ||
|
||
test "link to external consultations" do | ||
|
@@ -87,21 +95,36 @@ class ConsultationTest < ActionDispatch::IntegrationTest | |
end | ||
end | ||
|
||
test "consultation outcome documents render" do | ||
test "renders consultation outcome attachments (as-is and directly)" do | ||
setup_and_visit_content_item("consultation_outcome") | ||
|
||
assert page.has_text?("Download the full outcome") | ||
within '[aria-labelledby="download-the-full-outcome-title"]' do | ||
assert page.has_text?("Employee Share Schemes: NIC elections - consulation response") | ||
end | ||
|
||
setup_and_visit_content_item("consultation_outcome_with_featured_attachments") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each of these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I agree they could be split up, I think that would decrease the readability of the rest of the test file, as there is indeed no way of grouping them, and they are effectively testing the same thing. One of the commit messages says this, somewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I would find it that much harder to delete the lines within the test, when we (finally) disable the legacy functionality. |
||
|
||
assert page.has_text?("Download the full outcome") | ||
within '[aria-labelledby="download-the-full-outcome-title"]' do | ||
assert page.has_text?("Equalities impact assessment: setting the grade standards of new GCSEs in England – part 2") | ||
end | ||
end | ||
|
||
test "public feedback documents render" do | ||
test "renders public feedback attachments (as-is and directly)" do | ||
setup_and_visit_content_item("consultation_outcome_with_feedback") | ||
|
||
assert page.has_text?("Feedback received") | ||
within '[aria-labelledby="feedback-received-title"]' do | ||
assert page.has_text?("Analysis of responses to our consultation on setting the grade standards of new GCSEs in England – part 2") | ||
end | ||
|
||
setup_and_visit_content_item("consultation_outcome_with_featured_attachments") | ||
|
||
assert page.has_text?("Feedback received") | ||
within '[aria-labelledby="feedback-received-title"]' do | ||
assert page.has_text?("Analysis of responses to our consultation on setting the grade standards of new GCSEs in England – part 2") | ||
end | ||
end | ||
|
||
test "consultation that only applies to a set of nations" do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "test_helper" | ||
|
||
class ContentItemsAttachmentsTest < ActionView::TestCase | ||
test "it shows pre-rendered attachments by default" do | ||
render(partial: "content_items/attachments", | ||
locals: { title: "Documents", | ||
legacy_pre_rendered_documents: "some html" }) | ||
|
||
assert_includes rendered, "gem-c-govspeak" | ||
assert_includes rendered, "some html" | ||
end | ||
|
||
test "can render attachments using their metadata" do | ||
@content_item = PublicationPresenter.new( | ||
"details" => { | ||
"attachments" => [{ "id" => "attachment_id", | ||
"title" => "Some title", | ||
"url" => "some/url" }], | ||
}, | ||
) | ||
|
||
render(partial: "content_items/attachments", | ||
locals: { title: "Documents", | ||
legacy_pre_rendered_documents: "", | ||
attachments: %w(attachment_id) }) | ||
|
||
assert_includes rendered, "gem-c-attachment" | ||
assert_includes rendered, "Some title" | ||
end | ||
|
||
test "it prioritises pre-rendered attachments" do | ||
render(partial: "content_items/attachments", | ||
locals: { title: "Documents", | ||
legacy_pre_rendered_documents: "some html", | ||
attachments: %w(attachment_id) }) | ||
|
||
assert_includes rendered, "gem-c-govspeak" | ||
assert_includes rendered, "some html" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this have the effect of reading the heading out twice (once on the heading itself, and once immediately afterwards)? (NB, the examples I've seen on MDN tend to show the heading inside the div):
I'm sure Alex has already looked at this, I'm just not immediately clear on how this is an improvement 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is a case of me assuming we were doing a good thing in the first place 🤦♂. This is replicating a behaviour that previously applied only to publication documents, and applying it to all lists of attachments (with a title).
Apparently it was introduced here, but with no explanation. I've added another commit so it conforms to the spec. Removing it makes the tests harder, as there's nothing to 'grab hold of', so I've gone with fixing it, instead.
How does it look now?