From 1cfc9cdc8520efbff1c07532aee86788965adf4e Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Mon, 10 Feb 2025 15:49:19 +0000 Subject: [PATCH] Add govuk_web_banners gem - Add JS used by global banners, and banner dependencies - Add global/emergency banner support in layouts - Add initializer for emergency banner REDIS support - Mock redis client in all tests (we're not explicitly testing emergency banner support here, since we assume that's tested adequately in the gem). --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/assets/javascripts/application.js | 3 +++ app/views/layouts/account.html.erb | 2 ++ app/views/layouts/application.html.erb | 2 ++ config/initializers/govuk_web_banners.rb | 4 ++++ spec/spec_helper.rb | 1 + 7 files changed, 19 insertions(+) create mode 100644 config/initializers/govuk_web_banners.rb diff --git a/Gemfile b/Gemfile index 7e28a11b..a8f4ae7f 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,7 @@ gem "gds-api-adapters" gem "govuk_app_config" gem "govuk_personalisation" gem "govuk_publishing_components" +gem "govuk_web_banners" gem "jwt" gem "plek" gem "ratelimit" diff --git a/Gemfile.lock b/Gemfile.lock index c6beb4eb..99defadb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -169,6 +169,11 @@ GEM capybara (>= 3.36) puma selenium-webdriver (>= 4.0) + govuk_web_banners (1.0.1) + govuk_app_config + govuk_publishing_components + rails (>= 7) + redis hashdiff (1.1.2) http-accept (1.7.0) http-cookie (1.0.8) @@ -656,6 +661,7 @@ DEPENDENCIES govuk_publishing_components govuk_schemas govuk_test + govuk_web_banners jwt plek pry-byebug diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5b136e2b..d3f400bb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -3,4 +3,7 @@ //= require govuk_publishing_components/components/error-summary //= require govuk_publishing_components/components/radio //= require govuk_publishing_components/components/feedback +//= require govuk_publishing_components/components/global-banner //= require govuk_publishing_components/components/layout-super-navigation-header + +//= require govuk_web_banners/dependencies diff --git a/app/views/layouts/account.html.erb b/app/views/layouts/account.html.erb index 5148174c..c2d92287 100644 --- a/app/views/layouts/account.html.erb +++ b/app/views/layouts/account.html.erb @@ -21,6 +21,8 @@ <%= render "govuk_publishing_components/components/layout_for_public", { title: yield(:title), blue_bar: false, + emergency_banner: render("govuk_web_banners/emergency_banner"), + global_banner: render("govuk_web_banners/global_banner"), omit_feedback_form: true, omit_footer_border: true, omit_global_banner: true, diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9628ff02..b97571fd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -31,6 +31,8 @@ <%= render "govuk_publishing_components/components/layout_for_public", { title: yield(:title), show_explore_header: true, + emergency_banner: render("govuk_web_banners/emergency_banner"), + global_banner: render("govuk_web_banners/global_banner"), } do %> <%= yield :body %> <% end %> diff --git a/config/initializers/govuk_web_banners.rb b/config/initializers/govuk_web_banners.rb new file mode 100644 index 00000000..ae35e075 --- /dev/null +++ b/config/initializers/govuk_web_banners.rb @@ -0,0 +1,4 @@ +Rails.application.config.emergency_banner_redis_client = Redis.new( + url: ENV["EMERGENCY_BANNER_REDIS_URL"], + reconnect_attempts: [0, 0.1, 0.25], +) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fe7c25c7..67bec7b9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,5 +30,6 @@ config.before :each do rate_limiter = instance_double(Ratelimit, add: nil, exceeded?: false) allow(Ratelimit).to receive(:new).and_return(rate_limiter) + Rails.application.config.emergency_banner_redis_client = instance_double(Redis, hgetall: {}) end end