Skip to content

Commit

Permalink
Merge pull request #1463 from DFE-Digital/feature/161271-information-…
Browse files Browse the repository at this point in the history
…banner

Add an Information banner
  • Loading branch information
mec authored Mar 27, 2024
2 parents e312257 + a25f08f commit 4483c5b
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- for some projects, an MP name could not be located which caused some views and
exports to fail, this has been resolved

### Changed

- the maintenance banner has been repurposed as a more generic information
banner that can be switched on and off.

## [Release-61][release-61]

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ code straight forward for those that would like to use them.
- [Infrastructure and Terraform](/doc/infrastructure-and-terraform.md)
- [Developer scripts](/doc/developer-scripts.md)
- [GOV.UK Notify](/doc/govuk-notify.md)
- [Information banner](/doc/information-banner.md)

## Errors and monitoring

Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<div class="govuk-width-container ">
<%= yield :pre_content_nav %>
<main class="govuk-main-wrapper app-content" id="main-content" role="main">
<%= render partial: "/shared/information_banner" if ENV["SHOW_INFORMATION_BANNER"].eql?("true") %>
<%= render(NotificationBanner.new(flashes: flash)) %>
<%= yield %>
Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_information_banner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="govuk-notification-banner" id="information-banner" role="region" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Important
</h2>
</div>
<div class="govuk-notification-banner__content">
<h3 class="govuk-notification-banner__heading">
<%= t("information_banner.title") %>
</h3>
<%= t("information_banner.body.html") %>
</div>
</div>
15 changes: 0 additions & 15 deletions app/views/shared/_maintenance_banner.html.erb

This file was deleted.

8 changes: 8 additions & 0 deletions config/locales/information_banner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
en:
information_banner:
title: Scheduled maintenance, 5pm on 5 April
body:
html:
<p class="govuk-body">We will carry out maintenance on Complete from 5pm to 6pm on Friday 5 April 2024.</p>
<p class="govuk-body">Project changes will not be saved during the maintenance.</p>
<p class="govuk-body">Make sure you save your changes before the work starts.</p>
5 changes: 5 additions & 0 deletions doc/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ the `/healthcheck` endpoint to confirm the app is up & running.
`APPLICATION_INSIGHTS_KEY`

The instrumentation key for Microsoft Application Insights.

`SHOW_INFORMATION_BANNER`

Turns the [information banner](./information_banner.md) on across the
application.
18 changes: 18 additions & 0 deletions doc/information-banner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Information Banner

We sometimes want to inform all users of something important, scheduled downtime
for example.

To do so we have an Information banner that can be enabled and is then shown
across the application.

To set the content of the banner:

- locate the `config/locales/information_banner.yml` locale file
- update the `title`
- update the HTML used for the `body`
- commit, merge and deploy this change

Then:

- set the `SHOW_INFORMATION_BANNER` environment variable to `true`
52 changes: 52 additions & 0 deletions spec/features/information_banner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "rails_helper"

RSpec.feature "Users can see an information banner" do
let(:user) { create(:user, :regional_delivery_officer) }

before do
sign_in_with_user(user)
end

context "with the environment variable present and set to true" do
it "shows the banner on all pages" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "true" do
visit in_progress_your_projects_path

expect(page).to have_selector("#information-banner")

visit all_in_progress_projects_path

expect(page).to have_selector("#information-banner")
end
end

it "shows the title and body" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "true" do
visit in_progress_your_projects_path

within("#information-banner") do
expect(page).to have_content(I18n.t("information_banner.title"))
expect(page.html).to include(I18n.t("information_banner.body.html"))
end
end
end
end

context "with the environment variable present and set to false" do
it "does not show the banner" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "false" do
visit in_progress_your_projects_path

expect(page).not_to have_selector("#information-banner")
end
end
end

context "without the environment variable set" do
it "does not show the banner" do
visit in_progress_your_projects_path

expect(page).not_to have_selector("#information-banner")
end
end
end

0 comments on commit 4483c5b

Please sign in to comment.