Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/assets/stylesheets/tables-report.css.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@forward 'uswds-core';
@forward 'usa-prose';
@forward 'usa-table';
@forward 'usa-alert';

.table-number {
font-variant-numeric: tabular-nums;
Expand Down
22 changes: 19 additions & 3 deletions app/jobs/reports/monthly_key_metrics_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,30 @@ def perform(date = Time.zone.yesterday)

# Explanatory text to go before the report in the email
# @return [String]
def preamble
<<~HTML.html_safe # rubocop:disable Rails/OutputSafety
def preamble(env: Identity::Hostdata.env || 'local')
ERB.new(<<~ERB).result(binding).html_safe # rubocop:disable Rails/OutputSafety
<% if env != 'prod' %>
<div class="usa-alert usa-alert--info">
<div class="usa-alert__body">
<%#
NOTE: our AlertComponent doesn't support heading content like this uses,
so for a one-off outside the Rails pipeline it was easier to inline the HTML here.
%>
<h2 class="usa-alert__heading">
Non-Production Report
</h2>
<p class="usa-alert__text">
This was generated in the <strong><%= env %></strong> environment.
</p>
</div>
</div>
<% end %>
<p>
For more information on how each of these metrics are calculated, take a look at our
<a href="https://handbook.login.gov/articles/monthly-key-metrics-explainer.html">
Monthly Key Metrics Report Explainer document</a>.
</p>
HTML
ERB
end

def reports
Expand Down
16 changes: 15 additions & 1 deletion spec/jobs/reports/monthly_key_metrics_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,26 @@
end

describe '#preamble' do
subject(:preamble) { report.preamble }
let(:env) { 'prod' }
subject(:preamble) { report.preamble(env:) }

it 'has a preamble that is valid HTML' do
expect(preamble).to be_html_safe

expect { Nokogiri::XML(preamble) { |config| config.strict } }.to_not raise_error
end

context 'in a non-prod environment' do
let(:env) { 'staging' }

it 'has an alert with the environment name' do
expect(preamble).to be_html_safe

doc = Nokogiri::XML(preamble)

alert = doc.at_css('.usa-alert')
expect(alert.text).to include(env)
end
end
end
end