From cecf7e41a54c3fb1dd132b5ff7a24f768aeb5de4 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Fri, 17 Jan 2025 13:23:28 +0000 Subject: [PATCH 1/2] Remove global bar and all references --- Gemfile | 1 - Gemfile.lock | 2 - app/assets/javascripts/application.js | 3 - app/assets/javascripts/global-bar-init.js | 114 -------------- .../javascripts/libs/GlobalBarHelper.js | 10 -- app/assets/javascripts/modules/global-bar.js | 91 ----------- app/assets/javascripts/surveys.js | 8 +- app/assets/stylesheets/application.scss | 1 - .../stylesheets/components/_global-bar.scss | 82 ---------- app/helpers/timed_update_helper.rb | 5 - app/views/components/_global_bar.html.erb | 68 --------- app/views/components/docs/global_bar.yml | 10 -- app/views/root/_gem_base.html.erb | 6 - .../root/gem_layout_account_manager.html.erb | 1 - docs/slimmer_templates.md | 4 +- spec/javascripts/global-bar-init.spec.js | 86 ----------- spec/javascripts/helpers/GlobalBarHelper.js | 26 ---- spec/javascripts/modules/global-bar.spec.js | 144 ------------------ spec/javascripts/surveys.spec.js | 2 - test/unit/helpers/timed_update_helper_test.rb | 20 --- 20 files changed, 3 insertions(+), 681 deletions(-) delete mode 100644 app/assets/javascripts/global-bar-init.js delete mode 100644 app/assets/javascripts/libs/GlobalBarHelper.js delete mode 100644 app/assets/javascripts/modules/global-bar.js delete mode 100644 app/assets/stylesheets/components/_global-bar.scss delete mode 100644 app/helpers/timed_update_helper.rb delete mode 100644 app/views/components/_global_bar.html.erb delete mode 100644 app/views/components/docs/global_bar.yml delete mode 100644 spec/javascripts/global-bar-init.spec.js delete mode 100644 spec/javascripts/helpers/GlobalBarHelper.js delete mode 100644 spec/javascripts/modules/global-bar.spec.js delete mode 100644 test/unit/helpers/timed_update_helper_test.rb diff --git a/Gemfile b/Gemfile index 88b27e6df..098ecf0ff 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,5 @@ group :test do gem "mocha", require: false gem "shoulda-context" gem "simplecov" - gem "timecop" gem "webmock" end diff --git a/Gemfile.lock b/Gemfile.lock index fa1779a62..7f4289836 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -591,7 +591,6 @@ GEM terser (1.2.5) execjs (>= 0.3.0, < 3) thor (1.3.2) - timecop (0.9.10) timeout (0.4.3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -645,7 +644,6 @@ DEPENDENCIES simplecov sprockets-rails terser - timecop webmock RUBY VERSION diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0a912af3b..0fb9de7dd 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,7 +21,4 @@ //= require govuk_publishing_components/components/skip-link //= require govuk_publishing_components/components/search-with-autocomplete -//= require modules/global-bar - -//= require global-bar-init //= require surveys diff --git a/app/assets/javascripts/global-bar-init.js b/app/assets/javascripts/global-bar-init.js deleted file mode 100644 index e92535ddd..000000000 --- a/app/assets/javascripts/global-bar-init.js +++ /dev/null @@ -1,114 +0,0 @@ -//= require libs/GlobalBarHelper.js -//= require govuk_publishing_components/lib/cookie-functions - -/* global parseCookie */ - -'use strict' -window.GOVUK = window.GOVUK || {} - -// Bump this if you are releasing a major change to the banner -// This will reset the view count so all users will see the banner, even if previously seen -var BANNER_VERSION = 8 -var GLOBAL_BAR_SEEN_COOKIE = 'global_bar_seen' - -var globalBarInit = { - getBannerVersion: function () { - return BANNER_VERSION - }, - - getLatestCookie: function () { - var currentCookie = window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) - - return currentCookie - }, - - urlBlockList: function () { - var paths = [ - '^/coronavirus/.*$', - '^/brexit(.cy)?$', - '^/transition-check/.*$', - '^/eubusiness(\\..*)?$', - '^/account/.*$' - ] - - var ctaLink = document.querySelector('.js-call-to-action') - if (ctaLink) { - var ctaPath = '^' + ctaLink.getAttribute('href') + '$' - paths.push(ctaPath) - } - - return new RegExp(paths.join('|')).test(window.location.pathname) - }, - - setBannerCookie: function () { - var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BAR_SEEN_COOKIE) - var cookieConsent = GOVUK.getConsentCookie() - var value - - if (cookieConsent && cookieConsent[cookieCategory]) { - // Coronavirus banner - auto hide after user has been on landing page - if (window.location.pathname === '/coronavirus') { - value = JSON.stringify({ count: 999, version: globalBarInit.getBannerVersion() }) - } else { - value = JSON.stringify({ count: 0, version: globalBarInit.getBannerVersion() }) - } - - window.GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, value, { days: 84 }) - } - }, - - makeBannerVisible: function () { - document.documentElement.className = document.documentElement.className.concat(' show-global-bar') - var globalBarEl = document.querySelector('#global-bar') - if (globalBarEl) { - globalBarEl.setAttribute('data-ga4-global-bar', '') - } - }, - - init: function () { - var currentCookieVersion - - if (!globalBarInit.urlBlockList()) { - if (globalBarInit.getLatestCookie() === null) { - globalBarInit.setBannerCookie() - globalBarInit.makeBannerVisible() - } else { - currentCookieVersion = parseCookie(globalBarInit.getLatestCookie()).version - - if (currentCookieVersion !== globalBarInit.getBannerVersion()) { - globalBarInit.setBannerCookie() - } - - var newCookieCount = parseCookie(globalBarInit.getLatestCookie()).count - - // If banner has been manually dismissed, hide the additional info - if (newCookieCount === 999) { - var globalBarAdditional = document.querySelector('.global-bar-additional') - if (globalBarAdditional) { - globalBarAdditional.classList.remove('global-bar-additional--show') - } - var globarBarDismiss = document.querySelector('.global-bar__dismiss') - if (globarBarDismiss) { - globarBarDismiss.classList.remove('global-bar__dismiss--show') - } - } - - globalBarInit.makeBannerVisible() - } - } else { - // If on a url in the blocklist, set cookie but don't show the banner - if (globalBarInit.getLatestCookie() === null) { - globalBarInit.setBannerCookie() - } else { - currentCookieVersion = parseCookie(globalBarInit.getLatestCookie()).version - - if (currentCookieVersion !== globalBarInit.getBannerVersion()) { - globalBarInit.setBannerCookie() - } - } - } - } -} - -window.GOVUK.globalBarInit = globalBarInit -window.GOVUK.globalBarInit.init() diff --git a/app/assets/javascripts/libs/GlobalBarHelper.js b/app/assets/javascripts/libs/GlobalBarHelper.js deleted file mode 100644 index 05b860d8a..000000000 --- a/app/assets/javascripts/libs/GlobalBarHelper.js +++ /dev/null @@ -1,10 +0,0 @@ -function parseCookie(cookie) { - var parsedCookie = JSON.parse(cookie) - - // Tests seem to run differently on CI, and require an extra parse - if (typeof parsedCookie !== "object") { - parsedCookie = JSON.parse(parsedCookie) - } - - return parsedCookie -} diff --git a/app/assets/javascripts/modules/global-bar.js b/app/assets/javascripts/modules/global-bar.js deleted file mode 100644 index b39fd37ce..000000000 --- a/app/assets/javascripts/modules/global-bar.js +++ /dev/null @@ -1,91 +0,0 @@ -//= require libs/GlobalBarHelper.js - -/* global parseCookie */ - -/* - Global bar - - Manages count of how many times a global bar has been seen - using cookies. -*/ -window.GOVUK = window.GOVUK || {} -window.GOVUK.Modules = window.GOVUK.Modules || {}; - -(function (Modules) { - function GlobalBar ($module) { - this.$module = $module - } - - GlobalBar.prototype.init = function () { - var GLOBAL_BAR_SEEN_COOKIE = 'global_bar_seen' - var alwaysOn = this.$module.getAttribute('data-global-bar-permanent') - if (alwaysOn === 'false') { - alwaysOn = false // in this situation we need to convert string to boolean - } - var cookieCategory = GOVUK.getCookieCategory(GLOBAL_BAR_SEEN_COOKIE) - var cookieConsent = GOVUK.getConsentCookie()[cookieCategory] - - if (cookieConsent) { - // If the cookie is not set, let's set a basic one - if (GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) === null || parseCookie(GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)).count === undefined) { - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 0, version: 0 }), { days: 84 }) - } - - var currentCookie = parseCookie(GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)) - var currentCookieVersion = currentCookie.version - var count = viewCount() - } - - this.$module.addEventListener('click', function (e) { - var target = e.target - if (target.classList.contains('dismiss')) { - hide(e) - } - }) - - // if the element is visible - if (this.$module.offsetParent !== null && !alwaysOn) { - incrementViewCount(count) - } - - function hide (event) { - var currentCookie = parseCookie(GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)) - var cookieVersion = currentCookieVersion - - if (currentCookie) { - cookieVersion = currentCookie.version - } - - var cookieValue = JSON.stringify({ count: 999, version: cookieVersion }) - GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, cookieValue, { days: 84 }) - var additional = document.querySelector('.global-bar-additional') - if (additional) { - additional.classList.remove('global-bar-additional--show') - } - var dismiss = document.querySelector('.global-bar__dismiss') - if (dismiss) { - dismiss.classList.remove('global-bar__dismiss--show') - } - event.preventDefault() - } - - function incrementViewCount (count) { - count = count + 1 - var cookieValue = JSON.stringify({ count: count, version: currentCookieVersion }) - GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, cookieValue, { days: 84 }) - } - - function viewCount () { - var viewCountCookie = GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) - var viewCount = parseInt(parseCookie(viewCountCookie).count, 10) - - if (isNaN(viewCount)) { - viewCount = 0 - } - - return viewCount - } - } - - Modules.GlobalBar = GlobalBar -})(window.GOVUK.Modules) diff --git a/app/assets/javascripts/surveys.js b/app/assets/javascripts/surveys.js index 897d1b6ea..863479008 100644 --- a/app/assets/javascripts/surveys.js +++ b/app/assets/javascripts/surveys.js @@ -88,11 +88,6 @@ if (userSurveys.canShowAnySurvey()) { var activeSurvey = userSurveys.getActiveSurvey(userSurveys.defaultSurvey, userSurveys.smallSurveys) if (activeSurvey !== undefined) { - // Hide global bar if one is showing - var globalBar = document.getElementById('global-bar') - if (globalBar) { - globalBar.style.display = 'none' - } userSurveys.displaySurvey(activeSurvey) } } @@ -434,8 +429,7 @@ } var notificationIds = [ '.emergency-banner', - '#taxonomy-survey', - '#global-bar' // Currently about Coronavirus + '#taxonomy-survey' ] var count = 0 for (var i = 0; i < notificationIds.length; i++) { diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6c0833039..0a4139ca9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -29,7 +29,6 @@ @import "govuk_publishing_components/components/layout-header"; @import "govuk_publishing_components/components/layout-super-navigation-header"; -@import "components/global-bar"; @import "components/survey"; @import "helpers/draft"; diff --git a/app/assets/stylesheets/components/_global-bar.scss b/app/assets/stylesheets/components/_global-bar.scss deleted file mode 100644 index bb4345974..000000000 --- a/app/assets/stylesheets/components/_global-bar.scss +++ /dev/null @@ -1,82 +0,0 @@ -// stylelint-disable selector-max-id -.show-global-bar #global-header-bar { - display: none; -} - -$covid-yellow: #fff500; -$covid-grey: #262828; - -.global-bar { - @include govuk-font(19); - background-color: #d9e7f2; - border-top: govuk-spacing(2) solid govuk-colour("blue"); - display: none; - - .show-global-bar & { - display: block; - } - - .govuk-link, - .govuk-link:link { - color: govuk-colour("black"); - - &:visited { - color: govuk-colour("black"); - } - - &:focus { - color: govuk-colour("black"); - } - } -} - -.global-bar-message { - margin-bottom: 0; - margin-top: 0; - padding: govuk-spacing(4) 0; -} - -.global-bar-title { - font-weight: 700; - margin-right: govuk-spacing(2); - margin-bottom: govuk-spacing(1); - - &:only-child { - margin: 0; - } -} - -.global-bar-title, -.global-bar-text { - color: govuk-colour("black"); -} - -.global-bar-title__nowrap { - white-space: nowrap; -} - -.global-bar-dismiss-wrapper { - margin-top: govuk-spacing(4); -} - -.global-bar__dismiss { - display: none; -} - -.global-bar__dismiss--show { - display: inline-block; -} - -.gem-c-govspeak .global-bar__heading { - @include govuk-font(19, $weight: bold); - margin-top: 0; - margin-bottom: govuk-spacing(1); -} - -.gem-c-govspeak .global-bar__list { - margin-top: 0; -} - -.global-bar__list { - margin-top: 0; -} diff --git a/app/helpers/timed_update_helper.rb b/app/helpers/timed_update_helper.rb deleted file mode 100644 index 3dbc6a37b..000000000 --- a/app/helpers/timed_update_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module TimedUpdateHelper - def before_update_time?(year:, month:, day:, hour:, minute:) - Time.zone.now.before? Time.zone.local(year, month, day, hour, minute) - end -end diff --git a/app/views/components/_global_bar.html.erb b/app/views/components/_global_bar.html.erb deleted file mode 100644 index 6826980ac..000000000 --- a/app/views/components/_global_bar.html.erb +++ /dev/null @@ -1,68 +0,0 @@ -<% - if before_update_time?(year: 2024, month: 7, day: 4, hour: 22, minute: 0) - show_global_bar ||= true # Toggles the appearance of the global bar - title = "Bring photo ID to vote" - title_href = "/how-to-vote/photo-id-youll-need" - link_text = "Check what photo ID you'll need to vote in person in the General Election on 4 July." - else - show_global_bar = false - title = nil - title_href = nil - link_text = nil - end - - link_href = false - - # Toggles banner being permanently visible - # If true, banner is always_visible & does not disappear automatically after 3 pageviews - # Regardless of value, banner is always manually dismissable by users - always_visible = true - - global_bar_classes = %w(global-bar govuk-!-display-none-print) - - title_classes = %w(global-bar-title) - title_classes << "js-call-to-action" if title_href - title_classes << "govuk-link" if title_href - - ga4_data = { - event_name: "navigation", - type: "global bar", - section: title, - }.to_json - --%> - -<% if show_global_bar %> - -
data-nosnippet> -

- <% if title %> - <% if title_href %> - <%= title %> - <% else %> - <%= title %> - <% end %> - <% end %> - - <% if link_text %> - - <% if link_href %> - <%= link_to( - link_text, - link_href, - rel: "external noreferrer", - class: "govuk-link js-call-to-action", - data: { - module: "ga4-link-tracker", - ga4_link: ga4_data, - }, - ) %> - <% else %> - <%= link_text %> - <% end %> - - <% end %> -

-
- -<% end %> diff --git a/app/views/components/docs/global_bar.yml b/app/views/components/docs/global_bar.yml deleted file mode 100644 index 5b5735437..000000000 --- a/app/views/components/docs/global_bar.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Global banner -description: A site-wide banner used to convey important information -body: | - See the [opsmanual](https://docs.publishing.service.gov.uk/apps/static/global-banner.html) for information about what the Global banner is and when it should be activated. -accessibility_criteria: | - The link must: - - * be keyboard focusable -examples: - default: {} diff --git a/app/views/root/_gem_base.html.erb b/app/views/root/_gem_base.html.erb index 42265b299..21d386885 100644 --- a/app/views/root/_gem_base.html.erb +++ b/app/views/root/_gem_base.html.erb @@ -4,7 +4,6 @@ omit_feedback_form ||= nil omit_footer_navigation ||= nil omit_footer_border ||= nil - omit_global_banner ||= nil omit_account_navigation ||= nil product_name ||= nil navigation_items ||= [] @@ -16,10 +15,6 @@ footer_meta ||= nil draft_environment ||= ENV["DRAFT_ENVIRONMENT"].present? homepage ||= false - - global_bar = '' - global_banner = render "components/global_bar" unless omit_global_banner - global_bar << global_banner if global_banner %> <%= render "govuk_publishing_components/components/layout_for_public", { @@ -29,7 +24,6 @@ draft_watermark: draft_environment, emergency_banner: render("govuk_web_banners/emergency_banner", homepage:), full_width: full_width, - global_banner: global_bar, homepage: homepage, logo_link: logo_link, navigation_items: navigation_items, diff --git a/app/views/root/gem_layout_account_manager.html.erb b/app/views/root/gem_layout_account_manager.html.erb index 9c6c9ba40..ae4ae0ff6 100644 --- a/app/views/root/gem_layout_account_manager.html.erb +++ b/app/views/root/gem_layout_account_manager.html.erb @@ -6,7 +6,6 @@ blue_bar: false, omit_feedback_form: true, omit_footer_border: true, - omit_global_banner: true, omit_footer_navigation: true, product_name: "GOV.UK email subscriptions", show_account_layout: true, diff --git a/docs/slimmer_templates.md b/docs/slimmer_templates.md index 23638e8be..aabfc6618 100644 --- a/docs/slimmer_templates.md +++ b/docs/slimmer_templates.md @@ -2,7 +2,7 @@ ## `gem_layout` (default) -This template uses the [public layout component] from the GOV.UK Publishing Components gem. It supplies the header and footer only - this includes the cookie banner, skip to content link, header bar, emergency banner, survey banner, global bar, feedback, and footer. The content is constrained and centred. +This template uses the [public layout component] from the GOV.UK Publishing Components gem. It supplies the header and footer only - this includes the cookie banner, skip to content link, header bar, emergency banner, survey banner, feedback, and footer. The content is constrained and centred. ## `gem_layout_full_width` @@ -18,6 +18,6 @@ Same as the `gem_layout_full_width` template, except this layout is only used on This is intended as a skeleton wrapper for account pages. It is intended to be used when we need a page rendered by another frontend app to look like a GOV.UK account page. -This layout omits the default feedback component for GOVUK as the account pages use a different one from the rest of GOV.UK. Instead it introduces an account-specific phase banner. It also purposefully omits the global bar and user satisfaction survey bar. +This layout omits the default feedback component for GOVUK as the account pages use a different one from the rest of GOV.UK. Instead it introduces an account-specific phase banner. It also purposefully omits the user satisfaction survey bar. [public layout component]: https://components.publishing.service.gov.uk/component-guide/layout_for_public diff --git a/spec/javascripts/global-bar-init.spec.js b/spec/javascripts/global-bar-init.spec.js deleted file mode 100644 index 13e72ae0a..000000000 --- a/spec/javascripts/global-bar-init.spec.js +++ /dev/null @@ -1,86 +0,0 @@ -/* global globalBarInit, parseCookie, expectGlobalBarToShow, expectGlobalBarToBeHidden, expectGa4AttributeToExist, expectGa4AttributeToNotExist */ - -xdescribe('Global bar initialize', function () { - beforeAll(function () { - $('html').append('
') - }) - - beforeEach(function () { - deleteAllCookies() - spyOn(globalBarInit, 'getBannerVersion').and.returnValue(5) - $('html').removeClass('show-global-bar') - $('#global-bar').removeAttr('data-ga4-global-bar') - - window.GOVUK.setConsentCookie({ settings: true }) - }) - - it('does not show the banner on a blocked URL', function () { - spyOn(globalBarInit, 'urlBlockList').and.returnValue(true) - GOVUK.globalBarInit.init() - - // The cookie should still be set, but the banner should not be visible - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToBeHidden() - expectGa4AttributeToNotExist() - }) - - it('sets global_bar_seen cookie', function () { - GOVUK.globalBarInit.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() - expectGa4AttributeToExist() - }) - - it('sets cookie to default value if current cookie is old (prior to versioning mechanism)', function () { - GOVUK.setCookie('global_bar_seen', 1) - GOVUK.globalBarInit.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - - expectGlobalBarToShow() - expectGa4AttributeToExist() - }) - - it('resets cookie if version number is out of date, if count below 3', function () { - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 1, version: 1 })) - GOVUK.globalBarInit.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() - expectGa4AttributeToExist() - }) - - it('resets cookie if version number is out of date, if count above 3', function () { - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 10, version: 1 })) - GOVUK.globalBarInit.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() - expectGa4AttributeToExist() - }) - - it('makes banner visible if view count is less than 3', function () { - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 1, version: 5 })) - GOVUK.globalBarInit.init() - - expectGlobalBarToShow() - expectGa4AttributeToExist() - }) -}) - -function deleteAllCookies () { - var cookies = document.cookie.split(';') - - for (var i = 0; i < cookies.length; i++) { - var cookie = cookies[i] - var eqPos = cookie.indexOf('=') - var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie - document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT' - } -} diff --git a/spec/javascripts/helpers/GlobalBarHelper.js b/spec/javascripts/helpers/GlobalBarHelper.js deleted file mode 100644 index 60d08bbf2..000000000 --- a/spec/javascripts/helpers/GlobalBarHelper.js +++ /dev/null @@ -1,26 +0,0 @@ -//= require libs/GlobalBarHelper.js - -/* eslint-disable no-unused-vars */ -function expectGlobalBarToShow () { - expect($('html').hasClass('show-global-bar')).toBe(true) -} - -function expectGlobalBarToBeHidden () { - expect($('html').hasClass('show-global-bar')).toBe(false) -} - -function expectGa4AttributeToExist () { - expect($('#global-bar').attr('data-ga4-global-bar')).toBe('') -} - -function expectGa4AttributeToNotExist () { - expect($('#global-bar').attr('data-ga4-global-bar')).toBe(undefined) -} - -function expectAdditionalSectionToBeVisible () { - expect($('.global-bar-additional').hasClass('global-bar-additional--show')).toBe(true) -} - -function expectAdditionalSectionToBeHidden () { - expect($('.global-bar-additional').hasClass('global-bar-additional--show')).toBe(false) -} diff --git a/spec/javascripts/modules/global-bar.spec.js b/spec/javascripts/modules/global-bar.spec.js deleted file mode 100644 index 325db1345..000000000 --- a/spec/javascripts/modules/global-bar.spec.js +++ /dev/null @@ -1,144 +0,0 @@ -/* global parseCookie, expectAdditionalSectionToBeHidden */ -xdescribe('Global bar module', function () { - 'use strict' - - var globalBar - var element - - beforeEach(function () { - window.GOVUK.setConsentCookie({ settings: true }) - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' - }) - - afterEach(function () { - window.GOVUK.setConsentCookie({ settings: null }) - $('#global-bar').remove() - }) - - describe('global banner default', function () { - beforeEach(function () { - element = $( - '
' + - 'Register to Vote' + - 'Hide message' + - '
This is some additional content
' + - '
' - ) - - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' - }) - - it('sets basic global_bar_seen cookie if not already set', function () { - expect(GOVUK.getCookie('global_bar_seen')).toBeNull() - - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - }) - - it('sets basic global_bar_seen cookie if existing one is malformed', function () { - GOVUK.setCookie('global_bar_seen', 1) - - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - }) - }) - - describe('global banner interactions', function () { - beforeEach(function () { - element = $( - '
' + - 'Register to Vote' + - 'Hide message' + - '
' - ) - - $(document.body).append(element) - - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' - }) - - it('increments view count', function () { - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 1, version: 0 })) - - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(2) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - }) - - it('hides additional information section when dismiss link is clicked', function () { - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - $(element).find('.dismiss')[0].click() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(999) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - - expectAdditionalSectionToBeHidden() - }) - - it('hides dismiss link once dismiss link is clicked', function () { - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - $(element).find('.dismiss')[0].click() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(999) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - - expect($('.global-bar-dismiss').hasClass('global-bar-dismiss--show')).toBe(false) - }) - }) - - describe('always on', function () { - beforeEach(function () { - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' - }) - - it('does not increment view count when on', function () { - element = $( - '
' + - 'Register to Vote' + - 'Hide message' + - '
' - ) - - $(document.body).append(element) - - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 2, version: 0 })) - - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(2) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - }) - - it('continues to increment view count when off', function () { - element = $( - '
' + - 'Register to Vote' + - 'Hide message' + - '
' - ) - - $(document.body).append(element) - - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 2, version: 0 })) - - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() - - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(3) - expect(parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) - }) - }) -}) diff --git a/spec/javascripts/surveys.spec.js b/spec/javascripts/surveys.spec.js index 161cd1c43..3b0caff1b 100644 --- a/spec/javascripts/surveys.spec.js +++ b/spec/javascripts/surveys.spec.js @@ -50,7 +50,6 @@ describe('Surveys', function () { GOVUK.cookie(surveys.surveySeenCookieName(survey), null) }) $block.remove() - $('#global-bar').remove() window.GOVUK.setConsentCookie({ settings: null }) }) @@ -492,7 +491,6 @@ describe('Surveys', function () { $('#global-cookie-message').css('display', 'none') $('.emergency-banner').css('display', 'none') $('#taxonomy-survey').css('display', 'none') - $('#global-bar').css('display', 'none') }) it('returns true if the global cookie banner is visible', function () { diff --git a/test/unit/helpers/timed_update_helper_test.rb b/test/unit/helpers/timed_update_helper_test.rb deleted file mode 100644 index 3e971f8f3..000000000 --- a/test/unit/helpers/timed_update_helper_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "test_helper" - -class TimedUpdateHelperTest < ActiveSupport::TestCase - include TimedUpdateHelper - - test "#before_update_time? returns true if we haven't reached the requested time yet" do - Timecop.freeze(2024, 6, 17, 23, 59) - assert before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0) - end - - test "#before_update_time? returns false if we've reached the requested time" do - Timecop.freeze(2024, 6, 18, 0, 0) - assert_not before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0) - end - - test "#before_update_time? returns false if we've passed the requested time" do - Timecop.freeze(2024, 6, 20, 10, 10) - assert_not before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0) - end -end From fb7fdd7eb489db7036bf2904c7b26f6258336729 Mon Sep 17 00:00:00 2001 From: Keith Lawrence Date: Tue, 4 Feb 2025 13:26:31 +0000 Subject: [PATCH 2/2] Add global banner from gem - reinstate the omit_global_banner flag. - Until email-alert-frontend can be moved entirely off static, we still need to maintain the omit_global_banner flag for the account manager layout. email-alert-frontend is the only user of this template, so once that app is off static we can remove that template and this shim. --- app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 1 + app/views/root/_gem_base.html.erb | 2 ++ app/views/root/gem_layout_account_manager.html.erb | 1 + 4 files changed, 5 insertions(+) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0fb9de7dd..c7abecd50 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,6 +16,7 @@ //= require govuk_publishing_components/components/cookie-banner //= require govuk_publishing_components/components/cross-service-header //= require govuk_publishing_components/components/feedback +//= require govuk_publishing_components/components/global-banner //= require govuk_publishing_components/components/layout-header //= require govuk_publishing_components/components/layout-super-navigation-header //= require govuk_publishing_components/components/skip-link diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 0a4139ca9..6f2ca1ccf 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -24,6 +24,7 @@ @import "govuk_publishing_components/components/cross-service-header"; @import "govuk_publishing_components/components/feedback"; @import "govuk_publishing_components/components/emergency-banner"; +@import "govuk_publishing_components/components/global-banner"; @import "govuk_publishing_components/components/layout-footer"; @import "govuk_publishing_components/components/layout-for-public"; @import "govuk_publishing_components/components/layout-header"; diff --git a/app/views/root/_gem_base.html.erb b/app/views/root/_gem_base.html.erb index 21d386885..3d4836d64 100644 --- a/app/views/root/_gem_base.html.erb +++ b/app/views/root/_gem_base.html.erb @@ -4,6 +4,7 @@ omit_feedback_form ||= nil omit_footer_navigation ||= nil omit_footer_border ||= nil + omit_global_banner ||= false omit_account_navigation ||= nil product_name ||= nil navigation_items ||= [] @@ -23,6 +24,7 @@ **(defined?(blue_bar) ? {blue_bar: blue_bar,} : {}), draft_watermark: draft_environment, emergency_banner: render("govuk_web_banners/emergency_banner", homepage:), + global_banner: omit_global_banner ? nil : render("govuk_web_banners/global_banner"), full_width: full_width, homepage: homepage, logo_link: logo_link, diff --git a/app/views/root/gem_layout_account_manager.html.erb b/app/views/root/gem_layout_account_manager.html.erb index ae4ae0ff6..530e73e24 100644 --- a/app/views/root/gem_layout_account_manager.html.erb +++ b/app/views/root/gem_layout_account_manager.html.erb @@ -7,6 +7,7 @@ omit_feedback_form: true, omit_footer_border: true, omit_footer_navigation: true, + omit_global_banner: true, product_name: "GOV.UK email subscriptions", show_account_layout: true, show_cross_service_header: true,