Skip to content
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

Merged
merged 4 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions app/presenters/consultation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,12 @@ def final_outcome_detail
content_item["details"]["final_outcome_detail"]
end

def final_outcome_documents?
final_outcome_documents_list.any?
end

def final_outcome_documents
final_outcome_documents_list.join("")
end

def public_feedback_documents?
public_feedback_documents_list.any?
content_item["details"]["final_outcome_documents"].to_a.join("")
end

def public_feedback_documents
public_feedback_documents_list.join("")
content_item["details"]["public_feedback_documents"].to_a.join("")
end

def public_feedback_detail
Expand All @@ -78,12 +70,8 @@ def held_on_another_website_url
content_item["details"]["held_on_another_website_url"]
end

def documents?
documents_list.any?
end

def documents
documents_list.join("")
content_item["details"]["documents"].to_a.join("")
end

def ways_to_respond?
Expand Down Expand Up @@ -111,7 +99,8 @@ def attachment_url
end

def add_margin?
final_outcome? || public_feedback_detail || public_feedback_documents?
final_outcome? || public_feedback_detail ||
public_feedback_documents.present?
end

private
Expand All @@ -133,16 +122,4 @@ def display_date_and_time(date, rollback_midnight = false)
def ways_to_respond
content_item["details"]["ways_to_respond"]
end

def final_outcome_documents_list
content_item["details"]["final_outcome_documents"] || []
end

def public_feedback_documents_list
content_item["details"]["public_feedback_documents"] || []
end

def documents_list
content_item["details"]["documents"] || []
end
end
12 changes: 1 addition & 11 deletions app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ def details
end

def documents
documents_list.join("")
end

def documents_count
documents_list.size
content_item["details"]["documents"].to_a.join("")
end

def national_statistics?
Expand All @@ -23,10 +19,4 @@ def national_statistics?
def dataset?
%(national_statistics official_statistics transparency).include? document_type
end

private

def documents_list
content_item["details"]["documents"]
end
end
14 changes: 14 additions & 0 deletions app/views/content_items/_attachments.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% attachment_title_id = "#{title.parameterize}-title" %>

<% if legacy_pre_rendered_documents.present? %>
<%= render 'govuk_publishing_components/components/heading',
id: attachment_title_id,
text: title,
mobile_top_margin: true %>

<div aria-labelledby="<%= attachment_title_id %>">
Copy link
Contributor

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):

<div aria-labelledby="<%= attachment_title_id %>">

  <%= render 'govuk_publishing_components/components/heading',
      id: attachment_title_id,
      text: title,
      mobile_top_margin: true %>

I'm sure Alex has already looked at this, I'm just not immediately clear on how this is an improvement 🤔

Copy link
Contributor Author

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?

<%= render 'govuk_publishing_components/components/govspeak',
content: legacy_pre_rendered_documents.html_safe,
direction: page_text_direction %>
</div>
<% end %>
33 changes: 9 additions & 24 deletions app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@
<% elsif @content_item.final_outcome? %>
<%= render 'govuk_publishing_components/components/notice', title: 'This consultation has concluded' %>

<% if @content_item.final_outcome_documents? %>
<%= render 'govuk_publishing_components/components/heading', text: "Download the full outcome", mobile_top_margin: true %>
<div class="consultation-outcome">
<%= render 'govuk_publishing_components/components/govspeak',
content: @content_item.final_outcome_documents.html_safe,
direction: page_text_direction %>
</div>
<% end %>
<%= render "attachments",
title: "Download the full outcome",
legacy_pre_rendered_documents: @content_item.final_outcome_documents %>

<%= render 'govuk_publishing_components/components/heading', text: "Detail of outcome", mobile_top_margin: true %>
<div class="consultation-outcome-detail">
Expand All @@ -57,14 +52,9 @@
</div>
<% end %>

<% if @content_item.public_feedback_documents? %>
<%= render 'govuk_publishing_components/components/heading', text: "Feedback received", mobile_top_margin: true %>
<div class="consultation-feedback-documents">
<%= render 'govuk_publishing_components/components/govspeak',
content: @content_item.public_feedback_documents.html_safe,
direction: page_text_direction %>
</div >
<% end %>
<%= render "attachments",
title: "Feedback received",
legacy_pre_rendered_documents: @content_item.public_feedback_documents %>

<% if @content_item.public_feedback_detail %>
<%= render 'govuk_publishing_components/components/heading', text: "Detail of feedback received", mobile_top_margin: true %>
Expand Down Expand Up @@ -115,14 +105,9 @@
<%= render 'govuk_publishing_components/components/heading', text: "Consultation description", mobile_top_margin: true %>
<%= render 'govuk_publishing_components/components/govspeak', @content_item.govspeak_body %>

<% if @content_item.documents? %>
<%= render 'govuk_publishing_components/components/heading', text: "Documents", mobile_top_margin: true %>
<div class="consultation-documents">
<%= render 'govuk_publishing_components/components/govspeak',
content: @content_item.documents.html_safe,
direction: page_text_direction %>
</div>
<% end %>
<%= render "attachments",
title: "Documents",
legacy_pre_rendered_documents: @content_item.documents %>
</div>

<% if @content_item.ways_to_respond? %>
Expand Down
13 changes: 3 additions & 10 deletions app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,9 @@
<div class="govuk-grid-column-two-thirds responsive-bottom-margin">
<%= render 'components/important-metadata', items: @content_item.important_metadata %>
<div class="responsive-bottom-margin">
<%= render 'govuk_publishing_components/components/heading',
text: t("publication.documents", count: 5), # This should always be pluralised.
id: "documents-title",
mobile_top_margin: true %>

<div aria-labelledby="documents-title">
<%= render 'govuk_publishing_components/components/govspeak',
content: @content_item.documents.html_safe,
direction: page_text_direction %>
</div>
<%= render "attachments",
title: t("publication.documents", count: 5), # This should always be pluralised.
legacy_pre_rendered_documents: @content_item.documents %>

<%= render 'govuk_publishing_components/components/heading',
text: t("publication.details"),
Expand Down
6 changes: 3 additions & 3 deletions test/integration/consultation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest
test "consultation documents render" do
setup_and_visit_content_item("closed_consultation")

within ".consultation-documents" do
within '[aria-labelledby="documents-title"]' do
assert page.has_text?("Museums Review Terms of Reference")
end
end
Expand Down Expand Up @@ -90,7 +90,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest
test "consultation outcome documents render" do
setup_and_visit_content_item("consultation_outcome")

within ".consultation-outcome" do
within '[aria-labelledby="download-the-full-outcome-title"]' do
assert page.has_text?("Employee Share Schemes: NIC elections - consulation response")
end
end
Expand All @@ -99,7 +99,7 @@ class ConsultationTest < ActionDispatch::IntegrationTest
setup_and_visit_content_item("consultation_outcome_with_feedback")

assert page.has_text?("Feedback received")
within ".consultation-feedback-documents" do
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
Expand Down
3 changes: 0 additions & 3 deletions test/presenters/consultation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@ def schema_name
presented = presented_item("closed_consultation")
schema = schema_item("closed_consultation")

assert presented.documents?
assert_equal schema["details"]["documents"].join(""), presented.documents
end

test "presents final outcome documents" do
presented = presented_item("consultation_outcome")
schema = schema_item("consultation_outcome")

assert presented.final_outcome_documents?
assert_equal schema["details"]["final_outcome_documents"].join(""), presented.final_outcome_documents
end

test "presents public feedback documents" do
presented = presented_item("consultation_outcome_with_feedback")
schema = schema_item("consultation_outcome_with_feedback")

assert presented.public_feedback_documents?
assert_equal schema["details"]["public_feedback_documents"].join(""), presented.public_feedback_documents
end

Expand Down
4 changes: 0 additions & 4 deletions test/presenters/publication_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def schema_name
assert_equal "3 May 2016", presented_item.published
end

test "counts documents attached to publication" do
assert_equal 2, presented_item.documents_count
end

test "presents the title of the publishing government" do
assert_equal schema_item["links"]["government"][0]["title"], presented_item.publishing_government
end
Expand Down