Skip to content

Commit

Permalink
Merge pull request #3219 from alphagov/cfe-use-components
Browse files Browse the repository at this point in the history
Use components for calls for evidence
  • Loading branch information
andysellick authored Jun 12, 2024
2 parents 5b81c7e + fdd3a8b commit 2ef9e5e
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 104 deletions.
40 changes: 31 additions & 9 deletions app/presenters/call_for_evidence_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,50 @@ def outcome_detail
content_item["details"]["outcome_detail"]
end

# Read the full outcome, top of page
def outcome_documents
content_item["details"]["outcome_documents"]&.join("")
# content_item["details"]["outcome_documents"]&.join("")
documents.select { |doc| outcome_attachments.include? doc["id"] }
end

# Documents, bottom of page
def general_documents
documents.select { |doc| featured_attachments.include? doc["id"] }
end

def attachments_with_details
items = [].push(*outcome_documents)
items.push(*general_documents)
items.select { |doc| doc["accessible"] == false && doc["alternative_format_contact_email"] }.count
end

def outcome_attachments
content_item["details"]["outcome_attachments"]
end

def held_on_another_website?
held_on_another_website_url.present?
def featured_attachments
content_item["details"]["featured_attachments"]
end

def held_on_another_website_url
content_item["details"]["held_on_another_website_url"]
def documents
# content_item["details"]["documents"]&.join("")
return [] unless content_item["details"]["attachments"]

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["preview_url"] = "#{doc['url']}/preview" if doc["preview_url"]
doc["alternative_format_contact_email"] = nil if doc["accessible"] == true
end
end

def documents
content_item["details"]["documents"]&.join("")
def held_on_another_website?
held_on_another_website_url.present?
end

def featured_attachments
content_item["details"]["featured_attachments"]
def held_on_another_website_url
content_item["details"]["held_on_another_website_url"]
end

def ways_to_respond?
Expand Down
27 changes: 0 additions & 27 deletions app/views/content_items/_attachments.html.erb

This file was deleted.

16 changes: 8 additions & 8 deletions app/views/content_items/call_for_evidence.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
<% elsif @content_item.outcome? %>
<%= render 'govuk_publishing_components/components/notice', title: t("call_for_evidence.closed") %>

<%= render "attachments",
title: t("call_for_evidence.download_outcome"),
legacy_pre_rendered_documents: @content_item.outcome_documents,
attachments: @content_item.outcome_attachments %>
<%= render "attachments_list",
title: t("call_for_evidence.download_outcome"),
attachments_for_components: @content_item.outcome_documents
%>

<%= render 'govuk_publishing_components/components/heading', text: t("call_for_evidence.detail_of_outcome"), mobile_top_margin: true %>
<div class="call-for-evidence-outcome-detail">
Expand Down Expand Up @@ -116,10 +116,10 @@
<%= raw(@content_item.govspeak_body[:content]) %>
<% end %>

<%= render "attachments",
title: t("call_for_evidence.documents"),
legacy_pre_rendered_documents: @content_item.documents,
attachments: @content_item.featured_attachments %>
<%= render "attachments_list",
title: t("call_for_evidence.documents"),
attachments_for_components: @content_item.general_documents
%>
</div>

<% if @content_item.ways_to_respond? %>
Expand Down
6 changes: 0 additions & 6 deletions app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@
title: t("consultation.documents"),
attachments_for_components: @content_item.documents_attachments_for_components
%>
<% if false %>
<%= render "attachments",
title: t("consultation.documents"),
legacy_pre_rendered_documents: @content_item.documents,
attachments: @content_item.featured_attachments %>
<% end %>
</div>

<% if @content_item.ways_to_respond? %>
Expand Down
219 changes: 215 additions & 4 deletions test/integration/call_for_evidence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,81 @@ def teardown
Timecop.return
end

general_overrides = {
"details" => {
"attachments" => [
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"command_paper_number" => "",
"content_type" => "application/pdf",
"file_size" => 803,
"filename" => "Setting_grade_standards_part_2.pdf",
"hoc_paper_number" => "",
"id" => "01",
"isbn" => "",
"number_of_pages" => 33,
"title" => "Setting the grade standards of new GCSEs in England – part 2",
"unique_reference" => "Ofqual/16/5939",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"url" => "https://assets.publishing.service.gov.uk/media/5a7f7b63ed915d74e33f6b3d/Setting_grade_standards_part_2.pdf",
},
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"command_paper_number" => "",
"content_type" => "application/pdf",
"file_size" => 365,
"filename" => "Decisions_-_setting_GCSE_grade_standards_-_part_2.pdf",
"hoc_paper_number" => "",
"id" => "02",
"isbn" => "",
"number_of_pages" => 10,
"title" => "Decisions on setting the grade standards of new GCSEs in England - part 2",
"unique_reference" => "Ofqual/16/6102",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"url" => "https://assets.publishing.service.gov.uk/media/5a817d87ed915d74e62328cf/Decisions_-_setting_GCSE_grade_standards_-_part_2.pdf",
},
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"command_paper_number" => "",
"content_type" => "application/pdf",
"file_size" => 646,
"filename" => "Grading-consulation-Equalities-Impact-Assessment.pdf",
"hoc_paper_number" => "",
"id" => "03",
"isbn" => "",
"number_of_pages" => 5,
"title" => "Equalities impact assessment: setting the grade standards of new GCSEs in England – part 2",
"unique_reference" => "Ofqual/16/6104",
"unnumbered_command_paper" => false,
"unnumbered_hoc_paper" => false,
"url" => "https://assets.publishing.service.gov.uk/media/5a8014d6ed915d74e622c5af/Grading-consulation-Equalities-Impact-Assessment.pdf",
},
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"content_type" => "application/pdf",
"file_size" => 175,
"filename" => "Grading-consultation-analysis-of-responses.pdf",
"id" => "04",
"number_of_pages" => 24,
"title" => "Analysis of responses to our consultation on setting the grade standards of new GCSEs in England – part 2",
"url" => "https://assets.publishing.service.gov.uk/media/5a819d85ed915d74e6233377/Grading-consultation-analysis-of-responses.pdf",
},
],
"outcome_attachments" => %w[01],
"featured_attachments" => %w[02],
},
}

test "call for evidence" do
setup_and_visit_content_item("open_call_for_evidence", {
"public_updated_at" => "2022-05-15T15:52:59.000+00:00",
Expand Down Expand Up @@ -41,11 +116,11 @@ def teardown
end

test "renders document attachments" do
setup_and_visit_content_item("closed_call_for_evidence")
setup_and_visit_content_item("closed_call_for_evidence", general_overrides)

assert page.has_text?("Documents")
within "#documents" do
assert page.has_text?("Net Zero Review: Call for evidence")
assert page.has_text?("Decisions on setting the grade standards of new GCSEs in England - part 2")
end
end

Expand All @@ -58,6 +133,142 @@ def teardown
end
end

test "renders accessible format option when accessible is false and email is supplied" do
overrides = {
"details" => {
"attachments" => [
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"id" => "01",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
],
"featured_attachments" => %w[01],
},
}
setup_and_visit_content_item("call_for_evidence_outcome_with_featured_attachments", overrides)
within "#documents" do
assert page.has_text?("Request an accessible format")
end
end

test "doesn't render accessible format option when accessible is true and email is supplied" do
overrides = {
"details" => {
"attachments" => [
{
"accessible" => true,
"alternative_format_contact_email" => "[email protected]",
"attachment_type" => "file",
"id" => "01",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
],
"featured_attachments" => %w[01],
},
}
setup_and_visit_content_item("call_for_evidence_outcome_with_featured_attachments", overrides)
within "#documents" do
assert page.has_no_text?("Request an accessible format")
end
end

test "doesn't render accessible format option when accessible is false and email is not supplied" do
overrides = {
"details" => {
"attachments" => [
{
"accessible" => false,
"attachment_type" => "file",
"id" => "01",
"title" => "Number of ex-regular service personnel now part of FR20",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
],
"featured_attachments" => %w[01],
},
}
setup_and_visit_content_item("call_for_evidence_outcome_with_featured_attachments", overrides)
within "#documents" do
assert page.has_no_text?("Request an accessible format")
end
end

test "tracks details elements in attachments correctly" do
overrides = {
"details" => {
"attachments" => [
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"id" => "01",
"title" => "Attachment 1 - should have details element",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
{
"accessible" => true,
"alternative_format_contact_email" => "[email protected]",
"id" => "02",
"title" => "Attachment 2",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
{
"accessible" => true,
"alternative_format_contact_email" => nil,
"id" => "03",
"title" => "Attachment 3",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
{
"accessible" => false,
"alternative_format_contact_email" => "[email protected]",
"id" => "04",
"title" => "Attachment 4 - should have details element",
"url" => "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/315163/PUBLIC_1392629965.pdf",
"content_type" => "application/pdf",
"filename" => "PUBLIC_1392629965.pdf",
"locale" => "en",
},
],
"outcome_attachments" => %w[01 02],
"featured_attachments" => %w[03 04],
},
}
setup_and_visit_content_item("call_for_evidence_outcome_with_featured_attachments", overrides)
attachments = page.find_all(".gem-c-attachment")
assert_equal attachments.length, overrides["details"]["attachments"].length

attachments.each do |attachment|
next unless attachment.has_css?(".govuk-details__summary")

details = attachment.find(".govuk-details__summary")["data-ga4-event"]
actual_tracking = JSON.parse(details)
assert_equal actual_tracking["index_section_count"], 2
end
end

test "link to external calls for evidence" do
setup_and_visit_content_item("open_call_for_evidence")

Expand Down Expand Up @@ -117,12 +328,12 @@ def teardown
end

test "renders call for evidence outcome attachments" do
setup_and_visit_content_item("call_for_evidence_outcome")
setup_and_visit_content_item("call_for_evidence_outcome", general_overrides)

assert page.has_text?("This call for evidence has closed")
assert page.has_text?("Read the full outcome")
within "#read-the-full-outcome" do
assert page.has_text?("Employee Share Schemes: NIC elections - consulation response")
assert page.has_text?("Setting the grade standards of new GCSEs in England – part 2")
end
end

Expand Down
Loading

0 comments on commit 2ef9e5e

Please sign in to comment.