Skip to content

Commit

Permalink
Migrate the Reports page to GOV.UK Design System
Browse files Browse the repository at this point in the history
- Adds use of the
  [Page Title](https://components.publishing.service.gov.uk/component-guide/title)
  component to `app/views/layouts/design_system.html.erb` to ensure
  transitioned pages use consistent formatting for the page title.
- Updates the reports index view to use the
  [Document List](https://components.publishing.service.gov.uk/component-guide/document_list)
  component.
- Improves the test coverage around the reports controller.

Since the transitioned design splits the generated message into two
 separate pieces of metadata (one for the time and one for the date),
 there will now be twice the calls to S3 to fetch that data. This could
 be optimised if it becomes a problem, but this page is not used much so
 that is left as a potential future optimisation.
  • Loading branch information
mtaylorgds authored and patrickpatrickpatrick committed Jan 29, 2024
1 parent 931b5b9 commit a9b4f12
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 57 deletions.
14 changes: 10 additions & 4 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ def all_urls
private

def report_last_updated(report_name)
last_updated = ::Report.new(report_name).last_updated
::Report.new(report_name).last_updated
end
helper_method :report_last_updated

def report_generated_time_message(report_name)
last_updated = report_last_updated(report_name)
if last_updated
tag.span "Generated #{last_updated.to_fs(:govuk_date)}", class: "text-muted"
"Generated #{last_updated.strftime('%-l:%M%#p')}".strip
else
tag.span "Report currently unavailable", class: "text-muted"
"Report currently unavailable"
end
end
helper_method :report_last_updated
helper_method :report_generated_time_message

Check failure on line 54 in app/controllers/reports_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end. (https://rubystyle.guide#empty-lines-around-bodies)
end
17 changes: 16 additions & 1 deletion app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@

<div class="govuk-width-container">
<main class="govuk-main-wrapper" id="main-content" role="main">
<%= yield %>

<% if yield(:title).present? %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/title", {
title: yield(:title),
margin_top: 0,
margin_bottom: 6,
} %>
</div>
</div>
<% end %>

<div class="govuk-grid-row">
<%= yield %>
</div>
</main>
</div>

Expand Down
117 changes: 84 additions & 33 deletions app/views/reports/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,35 +1,86 @@
<div class="page-header">
<h1>CSV Reports</h1>
<p>These reports are updated every hour.</p>
</div>
<% content_for :page_title, "Reports" %>
<% content_for :title, "CSV Reports" %>

<p>
<strong><%= link_to 'All documents for departmental distribution', organisation_content_report_path(format: :csv) %></strong><br />
<%= report_last_updated("organisation_content")%>
</p>
<p>
<strong><%= link_to 'Churn in non-archived editions', edition_churn_report_path(format: :csv) %></strong><br />
<%= report_last_updated("edition_churn")%>
</p>
<p>
<strong><%= link_to 'Churn in all editions', all_edition_churn_report_path(format: :csv) %></strong><br />
<%= report_last_updated("all_edition_churn")%>
</p>
<p>
<strong><%= link_to 'Progress on all non-archived editions', progress_report_path(format: :csv) %></strong><br />
<%= report_last_updated("editorial_progress")%>
</p>
<p>
<strong><%= link_to 'Content summary and workflow history for all published editions', content_workflow_report_path(format: :csv) %></strong><br />
<%= report_last_updated("content_workflow")%>
</p>
<p>
<strong><%= link_to 'Content summary and workflow history for all editions', all_content_workflow_report_path(format: :csv) %></strong><br />
<%= report_last_updated("all_content_workflow")%>
</p>
<p>
<strong><%= link_to 'All URLs', all_urls_report_path(format: :csv) %></strong><br />
<%= report_last_updated("all_urls")%>
</p>
<div class="govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/lead_paragraph", {
text: "These reports are updated every hour.",
margin_bottom: 6
} %>

<% content_for :page_title, "Reports" %>
<%= render "govuk_publishing_components/components/document_list", {
margin_bottom: 6,
items: [
{
link: {
text: "All documents for departmental distribution",
path: organisation_content_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("organisation_content"),
public_updated_at: report_last_updated("organisation_content"),
}
},
{
link: {
text: "Churn in non-archived editions",
path: edition_churn_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("edition_churn"),
public_updated_at: report_last_updated("edition_churn"),
}
},
{
link: {
text: "Churn in all editions",
path: all_edition_churn_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("all_edition_churn"),
public_updated_at: report_last_updated("all_edition_churn"),
}
},
{
link: {
text: "Progress on all non-archived editions",
path: progress_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("editorial_progress"),
public_updated_at: report_last_updated("editorial_progress"),
}
},
{
link: {
text: "Content summary and workflow history for all published editions",
path: content_workflow_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("content_workflow"),
public_updated_at: report_last_updated("content_workflow"),
}
},
{
link: {
text: "Content summary and workflow history for all editions",
path: all_content_workflow_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("all_content_workflow"),
public_updated_at: report_last_updated("all_content_workflow"),
}
},
{
link: {
text: "All URLs",
path: all_urls_report_path(format: :csv)
},
metadata: {
updated_at_time: report_generated_time_message("all_urls"),
public_updated_at: report_last_updated("all_urls"),
}
},
]
} %>

</div>
80 changes: 61 additions & 19 deletions test/functional/reports_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,75 @@
require "test_helper"

class ReportsControllerTest < ActionController::TestCase
setup do
login_as_stub_user

Check failure on line 4 in test/functional/reports_controller_test.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning. (https://rubystyle.guide#empty-lines-around-bodies)
last_modified = Time.zone.local(2023, 12, 12, 1, 1, 1)
context "When reports are available" do
setup do
login_as_stub_user

Aws.config[:s3] = {
stub_responses: {
head_object: { last_modified: },
},
}
last_modified = Time.zone.local(2023, 12, 12, 1, 2, 3)

ENV["REPORTS_S3_BUCKET_NAME"] = "example"
end
Aws.config[:s3] = {
stub_responses: {
head_object: { last_modified: },
},
}

teardown do
ENV["REPORTS_S3_BUCKET_NAME"] = nil
end
ENV["REPORTS_S3_BUCKET_NAME"] = "example"
end

teardown do
ENV["REPORTS_S3_BUCKET_NAME"] = nil
end

should "redirect the user to S3 when following report links" do
[

Check failure on line 25 in test/functional/reports_controller_test.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/SymbolArray: Use `%i` or `%I` for an array of symbols. (https://rubystyle.guide#percent-i)
:progress,
:organisation_content,
:edition_churn,
:all_edition_churn,
:content_workflow,
:all_content_workflow,
:all_urls,
].each do |action|
get action

assert_equal 302, response.status
end
end

test "it redirects the user to S3" do
get :progress
should "show the last updated time on the index page" do
get :index

assert_equal 302, response.status
assert_select "ul.gem-c-document-list__item-metadata" do
assert_select "li.gem-c-document-list__attribute", { count: 7, text: "Generated 1:02am" }
assert_select "li.gem-c-document-list__attribute", { count: 7, text: "12 December 2023" }
end
end
end

test "shows the last updated time on the index page" do
get :index
context "When reports are not available" do
setup do
login_as_stub_user

Aws.config[:s3] = {
stub_responses: {
head_object: 'NotFound',

Check failure on line 56 in test/functional/reports_controller_test.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. (https://rubystyle.guide#consistent-string-literals)
},
}

ENV["REPORTS_S3_BUCKET_NAME"] = "example"
end

teardown do
ENV["REPORTS_S3_BUCKET_NAME"] = nil
end

should "indicate that reports are not available on the index page" do
get :index

assert_match(/Generated 1:01am, 12 December 2023/, response.body)
assert_select "ul.gem-c-document-list__item-metadata" do
assert_select "li.gem-c-document-list__attribute", { count: 7, text: "Report currently unavailable" }
end
end
end
end

0 comments on commit a9b4f12

Please sign in to comment.