diff --git a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js index 359c00f8fb..6dd0d63f8e 100644 --- a/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +++ b/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js @@ -61,7 +61,7 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics devolved_nations_banner: this.getElementAttribute('data-ga4-devolved-nations-banner') || undefined, cookie_banner: this.getBannerPresence('[data-ga4-cookie-banner]'), intervention: this.getBannerPresence('[data-ga4-intervention-banner]'), - global_bar: this.getBannerPresence('[data-ga4-global-bar]'), + global_bar: this.getBannerPresence('[data-ga4-global-banner]'), query_string: this.getQueryString(), search_term: this.getSearchTerm(), tool_name: this.getToolName(), diff --git a/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js b/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js index 37dbab4d64..a1b4f094b1 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +++ b/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js @@ -95,8 +95,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.$module.showConfirmationMessage() this.$module.cookieBannerConfirmationMessage.focus() - if (window.GOVUK.globalBarInit) { - window.GOVUK.globalBarInit.init() + if (window.GOVUK.globalBannerInit) { + window.GOVUK.globalBannerInit.init() } if (!window.GOVUK.useSingleConsentApi) { window.GOVUK.triggerEvent(window, 'cookie-consent') diff --git a/app/assets/javascripts/govuk_publishing_components/components/global-banner.js b/app/assets/javascripts/govuk_publishing_components/components/global-banner.js index 335184a884..f5c7322fbd 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/global-banner.js +++ b/app/assets/javascripts/govuk_publishing_components/components/global-banner.js @@ -9,26 +9,26 @@ window.GOVUK = window.GOVUK || {} window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { - function GlobalBar ($module) { + function GlobalBanner ($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') + GlobalBanner.prototype.init = function () { + var GLOBAL_BANNER_SEEN_COOKIE = 'global_banner_seen' + var alwaysOn = this.$module.getAttribute('data-global-banner-permanent') if (alwaysOn === 'false') { alwaysOn = false // in this situation we need to convert string to boolean } - var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BAR_SEEN_COOKIE) + var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BANNER_SEEN_COOKIE) var cookieConsent = window.GOVUK.getConsentCookie()[cookieCategory] if (cookieConsent) { // If the cookie is not set, let's set a basic one - if (window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) === null || window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)).count === undefined) { - window.GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 0, version: 0 }), { days: 84 }) + if (window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE) === null || window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE)).count === undefined) { + window.GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 0, version: 0 }), { days: 84 }) } - var currentCookie = window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)) + var currentCookie = window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE)) var currentCookieVersion = currentCookie.version var count = viewCount() } @@ -46,7 +46,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; } function hide (event) { - var currentCookie = window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE)) + var currentCookie = window.GOVUK.parseCookie(window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE)) var cookieVersion = currentCookieVersion if (currentCookie) { @@ -54,14 +54,14 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; } var cookieValue = JSON.stringify({ count: 999, version: cookieVersion }) - window.GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, cookieValue, { days: 84 }) - var additional = document.querySelector('.global-bar-additional') + window.GOVUK.setCookie(GLOBAL_BANNER_SEEN_COOKIE, cookieValue, { days: 84 }) + var additional = document.querySelector('.global-banner-additional') if (additional) { - additional.classList.remove('global-bar-additional--show') + additional.classList.remove('global-banner-additional--show') } - var dismiss = document.querySelector('.global-bar__dismiss') + var dismiss = document.querySelector('.global-banner__dismiss') if (dismiss) { - dismiss.classList.remove('global-bar__dismiss--show') + dismiss.classList.remove('global-banner__dismiss--show') } event.preventDefault() } @@ -69,11 +69,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; function incrementViewCount (count) { count = count + 1 var cookieValue = JSON.stringify({ count: count, version: currentCookieVersion }) - window.GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, cookieValue, { days: 84 }) + window.GOVUK.setCookie(GLOBAL_BANNER_SEEN_COOKIE, cookieValue, { days: 84 }) } function viewCount () { - var viewCountCookie = window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) + var viewCountCookie = window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE) var viewCount = parseInt(window.GOVUK.parseCookie(viewCountCookie).count, 10) if (isNaN(viewCount)) { @@ -84,5 +84,5 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; } } - Modules.GlobalBar = GlobalBar + Modules.GlobalBanner = GlobalBanner })(window.GOVUK.Modules) diff --git a/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js b/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js index f4ea74563f..8e8bed0920 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js @@ -22,7 +22,7 @@ govuk_contact_referrer: 'essential', multivariatetest_cohort_coronavirus_extremely_vulnerable_rate_limit: 'essential', dgu_beta_banner_dismissed: 'settings', - global_bar_seen: 'settings', + global_banner_seen: 'settings', user_nation: 'settings', 'JS-Detection': 'usage', TLSversion: 'usage', diff --git a/app/assets/javascripts/govuk_publishing_components/lib/global-banner-init.js b/app/assets/javascripts/govuk_publishing_components/lib/global-banner-init.js index cf18cf88e0..3effdbd8a7 100644 --- a/app/assets/javascripts/govuk_publishing_components/lib/global-banner-init.js +++ b/app/assets/javascripts/govuk_publishing_components/lib/global-banner-init.js @@ -6,15 +6,15 @@ 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 GLOBAL_BANNER_SEEN_COOKIE = 'global_banner_seen' -var globalBarInit = { +var globalBannerInit = { getBannerVersion: function () { return BANNER_VERSION }, getLatestCookie: function () { - var currentCookie = window.GOVUK.getCookie(GLOBAL_BAR_SEEN_COOKIE) + var currentCookie = window.GOVUK.getCookie(GLOBAL_BANNER_SEEN_COOKIE) return currentCookie }, @@ -38,74 +38,74 @@ var globalBarInit = { }, setBannerCookie: function () { - var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BAR_SEEN_COOKIE) + var cookieCategory = window.GOVUK.getCookieCategory(GLOBAL_BANNER_SEEN_COOKIE) var cookieConsent = window.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() }) + value = JSON.stringify({ count: 999, version: globalBannerInit.getBannerVersion() }) } else { - value = JSON.stringify({ count: 0, version: globalBarInit.getBannerVersion() }) + value = JSON.stringify({ count: 0, version: globalBannerInit.getBannerVersion() }) } - window.GOVUK.setCookie(GLOBAL_BAR_SEEN_COOKIE, value, { days: 84 }) + window.GOVUK.setCookie(GLOBAL_BANNER_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', '') + document.documentElement.className = document.documentElement.className.concat(' show-global-banner') + var globalBannerEl = document.querySelector('#global-banner') + if (globalBannerEl) { + globalBannerEl.setAttribute('data-ga4-global-banner', '') } }, init: function () { var currentCookieVersion - if (!globalBarInit.urlBlockList()) { - if (globalBarInit.getLatestCookie() === null) { - globalBarInit.setBannerCookie() - globalBarInit.makeBannerVisible() + if (!globalBannerInit.urlBlockList()) { + if (globalBannerInit.getLatestCookie() === null) { + globalBannerInit.setBannerCookie() + globalBannerInit.makeBannerVisible() } else { - currentCookieVersion = window.GOVUK.parseCookie(globalBarInit.getLatestCookie()).version + currentCookieVersion = window.GOVUK.parseCookie(globalBannerInit.getLatestCookie()).version - if (currentCookieVersion !== globalBarInit.getBannerVersion()) { - globalBarInit.setBannerCookie() + if (currentCookieVersion !== globalBannerInit.getBannerVersion()) { + globalBannerInit.setBannerCookie() } - var newCookieCount = window.GOVUK.parseCookie(globalBarInit.getLatestCookie()).count + var newCookieCount = window.GOVUK.parseCookie(globalBannerInit.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 globalBannerAdditional = document.querySelector('.global-banner-additional') + if (globalBannerAdditional) { + globalBannerAdditional.classList.remove('global-banner-additional--show') } - var globarBarDismiss = document.querySelector('.global-bar__dismiss') + var globarBarDismiss = document.querySelector('.global-banner__dismiss') if (globarBarDismiss) { - globarBarDismiss.classList.remove('global-bar__dismiss--show') + globarBarDismiss.classList.remove('global-banner__dismiss--show') } } - globalBarInit.makeBannerVisible() + globalBannerInit.makeBannerVisible() } } else { // If on a url in the blocklist, set cookie but don't show the banner - if (globalBarInit.getLatestCookie() === null) { - globalBarInit.setBannerCookie() + if (globalBannerInit.getLatestCookie() === null) { + globalBannerInit.setBannerCookie() } else { - currentCookieVersion = window.GOVUK.parseCookie(globalBarInit.getLatestCookie()).version + currentCookieVersion = window.GOVUK.parseCookie(globalBannerInit.getLatestCookie()).version - if (currentCookieVersion !== globalBarInit.getBannerVersion()) { - globalBarInit.setBannerCookie() + if (currentCookieVersion !== globalBannerInit.getBannerVersion()) { + globalBannerInit.setBannerCookie() } } } } } -window.GOVUK.globalBarInit = globalBarInit -window.GOVUK.globalBarInit.init() +window.GOVUK.globalBannerInit = globalBannerInit +window.GOVUK.globalBannerInit.init() diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_global-banner.scss b/app/assets/stylesheets/govuk_publishing_components/components/_global-banner.scss index 5786d4ec7d..c0932b7448 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_global-banner.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_global-banner.scss @@ -1,20 +1,20 @@ @import "govuk_publishing_components/individual_component_support"; // stylelint-disable selector-max-id -.show-global-bar #global-header-bar { +.show-global-banner #global-header-bar { display: none; } $covid-yellow: #fff500; $covid-grey: #262828; -.gem-c-global-bar { +.gem-c-global-banner { background-color: #d9e7f2; border-top: govuk-spacing(2) solid govuk-colour("blue"); display: none; @include govuk-font(19); - .show-global-bar & { + .show-global-banner & { display: block; } @@ -32,13 +32,13 @@ $covid-grey: #262828; } } -.gem-c-global-bar-message { +.gem-c-global-banner-message { margin-bottom: 0; margin-top: 0; padding: govuk-spacing(4) 0; } -.gem-c-global-bar-title { +.gem-c-global-banner-title { font-weight: 700; margin-right: govuk-spacing(2); margin-bottom: govuk-spacing(1); @@ -48,37 +48,37 @@ $covid-grey: #262828; } } -.gem-c-global-bar-title, -.gem-c-global-bar-text { +.gem-c-global-banner-title, +.gem-c-global-banner-text { color: govuk-colour("black"); } -.gem-c-global-bar-title__nowrap { +.gem-c-global-banner-title__nowrap { white-space: nowrap; } -.gem-c-global-bar-dismiss-wrapper { +.gem-c-global-banner-dismiss-wrapper { margin-top: govuk-spacing(4); } -.gem-c-global-bar__dismiss { +.gem-c-global-banner__dismiss { display: none; } -.gem-c-global-bar__dismiss--show { +.gem-c-global-banner__dismiss--show { display: inline-block; } -.gem-c-govspeak .gem-c-global-bar__heading { +.gem-c-govspeak .gem-c-global-banner__heading { margin-top: 0; margin-bottom: govuk-spacing(1); @include govuk-font(19, $weight: bold); } -.gem-c-govspeak .gem-c-global-bar__list { +.gem-c-govspeak .gem-c-global-banner__list { margin-top: 0; } -.gem-c-global-bar__list { +.gem-c-global-banner__list { margin-top: 0; } diff --git a/app/views/govuk_publishing_components/components/_global_banner.html.erb b/app/views/govuk_publishing_components/components/_global_banner.html.erb index 3fbe9e82cf..654c860705 100644 --- a/app/views/govuk_publishing_components/components/_global_banner.html.erb +++ b/app/views/govuk_publishing_components/components/_global_banner.html.erb @@ -1,5 +1,5 @@ <% - add_gem_component_stylesheet("global-bar") + add_gem_component_stylesheet("global-banner") title ||= nil title_href ||= nil @@ -10,9 +10,9 @@ # Regardless of value, banner is always manually dismissable by users always_visible ||= false - global_bar_classes = %w(gem-c-global-bar govuk-!-display-none-print) + global_banner_classes = %w(gem-c-global-banner govuk-!-display-none-print) - title_classes = %w(gem-c-global-bar-title) + title_classes = %w(gem-c-global-banner-title) title_classes << "js-call-to-action" if title_href title_classes << "govuk-link" if title_href @@ -23,8 +23,8 @@ }.to_json %> <% if title %> -
data-nosnippet> -

+

data-nosnippet> +

<% if title_href %> <%= title %> <% else %> @@ -32,7 +32,7 @@ <% end %> <% if text %> - + <%= text %> <% end %> diff --git a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb index a983ea10db..3bc41b90e7 100644 --- a/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +++ b/app/views/govuk_publishing_components/components/_layout_for_public.html.erb @@ -5,7 +5,7 @@ emergency_banner ||= nil full_width ||= false blue_bar ||= local_assigns.include?(:blue_bar) ? local_assigns[:blue_bar] : !full_width - global_bar ||= nil + global_banner ||= nil html_lang ||= "en" homepage ||= false layout_helper = GovukPublishingComponents::Presenters::PublicLayoutHelper.new(local_assigns) @@ -49,10 +49,10 @@ # height, making the two blue bars overlap and appear as one. The class is added # when a) there's content for the emergency or global banner *and* b) when using # the contrained width layout. - blue_bar_dedupe = !full_width && global_bar.present? + blue_bar_dedupe = !full_width && global_banner.present? body_css_classes = %w(gem-c-layout-for-public govuk-template__body) body_css_classes << "draft" if draft_watermark - body_css_classes << "global-bar-present" if global_bar.present? + body_css_classes << "global-banner-present" if global_banner.present? blue_bar_wrapper_classes = %w() blue_bar_wrapper_classes << "gem-c-layout-for-public__blue-bar-wrapper--#{blue_bar_background_colour}" if blue_bar_background_colour @@ -137,17 +137,17 @@ <%= raw(emergency_banner) %> - <% if (blue_bar && !global_bar.present? && !homepage) || (blue_bar_dedupe) %> + <% if (blue_bar && !global_banner.present? && !homepage) || (blue_bar_dedupe) %> <%= content_tag(:div, class: blue_bar_wrapper_classes) do %>

<% end %> <% end %> - <% if global_bar.present? %> + <% if global_banner.present? %> <%= content_tag("div", { class: blue_bar_dedupe ? "gem-c-layout-for-public__global-banner-wrapper" : nil, }) do %> - <%= raw(global_bar) %> + <%= raw(global_banner) %> <% end %> <% end %> diff --git a/app/views/govuk_publishing_components/components/docs/layout_for_public.yml b/app/views/govuk_publishing_components/components/docs/layout_for_public.yml index f06480f0f0..6b2ce0bb29 100644 --- a/app/views/govuk_publishing_components/components/docs/layout_for_public.yml +++ b/app/views/govuk_publishing_components/components/docs/layout_for_public.yml @@ -73,7 +73,7 @@ examples: with_global_banner: description: This allows the HTML for the global banner to be added to the page. This is only the slot for the global banner - the markup for the banner needs to be passed in. data: - global_bar:
This is the global bar slot
+ global_banner:
This is the global bar slot
with_emergency_banner: description: This allows the HTML for the emergency banner to be added to the page in the correct place. This is only the slot for the emergency banner - the markup for the banner needs to be passed in. data: @@ -82,7 +82,7 @@ examples: description: Both global banner and emergency banner should be usable together. data: emergency_banner:
This is the emergency banner slot
- global_bar:
This is the global bar slot
+ global_banner:
This is the global bar slot
with_account_layout_enabled: description: Adds account layout wrapper around the content passed in to the component data: diff --git a/spec/components/global_banner_spec.rb b/spec/components/global_banner_spec.rb index 5ec4f8b726..e716477413 100644 --- a/spec/components/global_banner_spec.rb +++ b/spec/components/global_banner_spec.rb @@ -2,7 +2,7 @@ describe "Global bar", type: :view do def component_name - "global_bar" + "global_banner" end it "renders nothing without a title" do @@ -11,17 +11,17 @@ def component_name it "renders with a title" do render_component(title: "Look here you") - assert_select ".gem-c-global-bar", text: "Look here you" + assert_select ".gem-c-global-banner", text: "Look here you" end it "renders with a title and a link" do render_component(title: "Look here you", title_href: "https://www.gov.uk") - assert_select ".gem-c-global-bar a.gem-c-global-bar-title", text: "Look here you" + assert_select ".gem-c-global-banner a.gem-c-global-banner-title", text: "Look here you" end it "renders with a title and text" do render_component(title: "Look here you", text: "This is important") - assert_select ".gem-c-global-bar .gem-c-global-bar-title", text: "Look here you" - assert_select ".gem-c-global-bar .gem-c-global-bar-text", text: "This is important" + assert_select ".gem-c-global-banner .gem-c-global-banner-title", text: "Look here you" + assert_select ".gem-c-global-banner .gem-c-global-banner-text", text: "This is important" end end diff --git a/spec/components/layout_for_public_spec.rb b/spec/components/layout_for_public_spec.rb index 4c52421abe..e9854064c4 100644 --- a/spec/components/layout_for_public_spec.rb +++ b/spec/components/layout_for_public_spec.rb @@ -101,7 +101,7 @@ def component_name it "can add a global bar" do render_component({ - global_bar: "
This is a global bar test
", + global_banner: "
This is a global bar test
", }) assert_select "#test-global-banner", text: "This is a global bar test" @@ -110,7 +110,7 @@ def component_name it "can add both an emergency banner and a global bar" do render_component({ emergency_banner: "
This is an emergency banner test
", - global_bar: "
This is a global bar test
", + global_banner: "
This is a global bar test
", }) assert_select "#test-emergency-banner", text: "This is an emergency banner test" @@ -293,16 +293,16 @@ def component_name assert_select ".gem-c-layout-for-public.govuk-template__body.draft" end - it "contains a global-bar-present class when the global bar is present" do - render_component({ global_bar: { present: true } }) + it "contains a global-banner-present class when the global bar is present" do + render_component({ global_banner: { present: true } }) - assert_select ".gem-c-layout-for-public.govuk-template__body.global-bar-present" + assert_select ".gem-c-layout-for-public.govuk-template__body.global-banner-present" end - it "does not contains a global-bar-present class when the global bar is not present" do - render_component({ global_bar: {} }) + it "does not contains a global-banner-present class when the global bar is not present" do + render_component({ global_banner: {} }) - assert_select ".gem-c-layout-for-public.govuk-template__body.global-bar-present", false + assert_select ".gem-c-layout-for-public.govuk-template__body.global-banner-present", false end it "has an Open Graph image with an absolute URL" do diff --git a/spec/dummy/app/views/layouts/dummy_public_layout.html.erb b/spec/dummy/app/views/layouts/dummy_public_layout.html.erb index 1fa82d1f59..52617c1cd8 100644 --- a/spec/dummy/app/views/layouts/dummy_public_layout.html.erb +++ b/spec/dummy/app/views/layouts/dummy_public_layout.html.erb @@ -1,6 +1,6 @@ <%= render 'govuk_publishing_components/components/layout_for_public', { emergency_banner: '

This is the emergency banner slot.

', - global_bar: '

This is the global bar slot.

', + global_banner: '

This is the global bar slot.

', title: "Example public page", for_static: true, show_explore_header: true, diff --git a/spec/javascripts/components/cookie-banner-spec.js b/spec/javascripts/components/cookie-banner-spec.js index b2ff260e66..03181bf0c9 100644 --- a/spec/javascripts/components/cookie-banner-spec.js +++ b/spec/javascripts/components/cookie-banner-spec.js @@ -153,13 +153,13 @@ describe('Cookie banner', function () { expect(GOVUK.getCookie('cookies_policy')).toEqual(ALL_COOKIE_CONSENT) }) - it('sets global_bar_seen cookie when accepting cookies', function () { - if (typeof GOVUK.globalBarInit === 'undefined') { - GOVUK.globalBarInit = { + it('sets global_banner_seen cookie when accepting cookies', function () { + if (typeof GOVUK.globalBannerInit === 'undefined') { + GOVUK.globalBannerInit = { init: function () {} } } - spyOn(GOVUK.globalBarInit, 'init') + spyOn(GOVUK.globalBannerInit, 'init') spyOn(GOVUK, 'setCookie').and.callThrough() var element = document.querySelector('[data-module="cookie-banner"]') @@ -175,7 +175,7 @@ describe('Cookie banner', function () { expect(GOVUK.setCookie).toHaveBeenCalledWith('cookies_preferences_set', 'true', { days: 365 }) expect(GOVUK.getCookie('cookies_preferences_set')).toEqual('true') expect(GOVUK.getCookie('cookies_policy')).toEqual(ALL_COOKIE_CONSENT) - expect(GOVUK.globalBarInit.init).toHaveBeenCalled() + expect(GOVUK.globalBannerInit.init).toHaveBeenCalled() }) it('shows a confirmation message when cookies have been accepted', function () { diff --git a/spec/javascripts/components/global-banner-init-spec.js b/spec/javascripts/components/global-banner-init-spec.js index c82faa152b..f77a4ceadf 100644 --- a/spec/javascripts/components/global-banner-init-spec.js +++ b/spec/javascripts/components/global-banner-init-spec.js @@ -1,100 +1,100 @@ /* eslint-env jasmine, jquery */ -/* global GOVUK, globalBarInit */ +/* global GOVUK, globalBannerInit */ describe('Global bar initialize', function () { - function expectGlobalBarToShow () { - expect($('html').hasClass('show-global-bar')).toBe(true) + function expectGlobalBannerToShow () { + expect($('html').hasClass('show-global-banner')).toBe(true) } - function expectGlobalBarToBeHidden () { - expect($('html').hasClass('show-global-bar')).toBe(false) + function expectGlobalBannerToBeHidden () { + expect($('html').hasClass('show-global-banner')).toBe(false) } function expectGa4AttributeToExist () { - expect($('#global-bar').attr('data-ga4-global-bar')).toBe('') + expect($('#global-banner').attr('data-ga4-global-banner')).toBe('') } function expectGa4AttributeToNotExist () { - expect($('#global-bar').attr('data-ga4-global-bar')).toBe(undefined) + expect($('#global-banner').attr('data-ga4-global-banner')).toBe(undefined) } // function expectAdditionalSectionToBeVisible () { - // expect($('.global-bar-additional').hasClass('global-bar-additional--show')).toBe(true) + // expect($('.global-banner-additional').hasClass('global-banner-additional--show')).toBe(true) // } beforeAll(function () { - $('html').append('
') + $('html').append('
') }) afterAll(function () { - $('#global-bar').remove() + $('#global-banner').remove() }) beforeEach(function () { deleteAllCookies() - spyOn(globalBarInit, 'getBannerVersion').and.returnValue(5) - $('html').removeClass('show-global-bar') - $('#global-bar').removeAttr('data-ga4-global-bar') + spyOn(globalBannerInit, 'getBannerVersion').and.returnValue(5) + $('html').removeClass('show-global-banner') + $('#global-banner').removeAttr('data-ga4-global-banner') 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() + spyOn(globalBannerInit, 'urlBlockList').and.returnValue(true) + GOVUK.globalBannerInit.init() // The cookie should still be set, but the banner should not be visible - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToBeHidden() + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(5) + expectGlobalBannerToBeHidden() expectGa4AttributeToNotExist() }) - it('sets global_bar_seen cookie', function () { - GOVUK.globalBarInit.init() + it('sets global_banner_seen cookie', function () { + GOVUK.globalBannerInit.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(5) + expectGlobalBannerToShow() 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() + GOVUK.setCookie('global_banner_seen', 1) + GOVUK.globalBannerInit.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(5) - expectGlobalBarToShow() + expectGlobalBannerToShow() 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() + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 1, version: 1 })) + GOVUK.globalBannerInit.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(5) + expectGlobalBannerToShow() 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() + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 10, version: 1 })) + GOVUK.globalBannerInit.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(5) - expectGlobalBarToShow() + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(5) + expectGlobalBannerToShow() 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() + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 1, version: 5 })) + GOVUK.globalBannerInit.init() - expectGlobalBarToShow() + expectGlobalBannerToShow() expectGa4AttributeToExist() }) }) diff --git a/spec/javascripts/components/global-banner-spec.js b/spec/javascripts/components/global-banner-spec.js index fa16b1c39e..c6793b82a8 100644 --- a/spec/javascripts/components/global-banner-spec.js +++ b/spec/javascripts/components/global-banner-spec.js @@ -3,147 +3,147 @@ describe('Global bar module', function () { 'use strict' - var globalBar + var globalBanner var element function expectAdditionalSectionToBeHidden () { - expect($('.global-bar-additional').hasClass('global-bar-additional--show')).toBe(false) + expect($('.global-banner-additional').hasClass('global-banner-additional--show')).toBe(false) } beforeEach(function () { window.GOVUK.setConsentCookie({ settings: true }) - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' + document.cookie = 'global_banner_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' }) afterEach(function () { window.GOVUK.setConsentCookie({ settings: null }) - $('#global-bar').remove() + $('#global-banner').remove() }) describe('global banner default', function () { beforeEach(function () { element = $( - '
' + + '
' + 'Register to Vote' + - 'Hide message' + - '
This is some additional content
' + + 'Hide message' + + '
This is some additional content
' + '
' ) - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' + document.cookie = 'global_banner_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() + it('sets basic global_banner_seen cookie if not already set', function () { + expect(GOVUK.getCookie('global_banner_seen')).toBeNull() - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) }) - it('sets basic global_bar_seen cookie if existing one is malformed', function () { - GOVUK.setCookie('global_bar_seen', 1) + it('sets basic global_banner_seen cookie if existing one is malformed', function () { + GOVUK.setCookie('global_banner_seen', 1) - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(0) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) }) }) describe('global banner interactions', function () { beforeEach(function () { element = $( - '
' + + '' ) $(document.body).append(element) - document.cookie = 'global_bar_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' + document.cookie = 'global_banner_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 })) + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 1, version: 0 })) - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(2) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(2) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) }) it('hides additional information section when dismiss link is clicked', function () { - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() $(element).find('.dismiss')[0].click() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(999) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(999) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) expectAdditionalSectionToBeHidden() }) it('hides dismiss link once dismiss link is clicked', function () { - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() $(element).find('.dismiss')[0].click() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(999) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(999) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) - expect($('.global-bar-dismiss').hasClass('global-bar-dismiss--show')).toBe(false) + expect($('.global-banner-dismiss').hasClass('global-banner-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;' + document.cookie = 'global_banner_seen=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;' }) it('does not increment view count when on', function () { element = $( - '
' + + '' ) $(document.body).append(element) - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 2, version: 0 })) + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 2, version: 0 })) - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(2) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(2) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) }) it('continues to increment view count when off', function () { element = $( - '
' + + '' ) $(document.body).append(element) - GOVUK.setCookie('global_bar_seen', JSON.stringify({ count: 2, version: 0 })) + GOVUK.setCookie('global_banner_seen', JSON.stringify({ count: 2, version: 0 })) - globalBar = new GOVUK.Modules.GlobalBar(element[0]) - globalBar.init() + globalBanner = new GOVUK.Modules.GlobalBanner(element[0]) + globalBanner.init() - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).count).toBe(3) - expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_bar_seen')).version).toBe(0) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).count).toBe(3) + expect(window.GOVUK.parseCookie(GOVUK.getCookie('global_banner_seen')).version).toBe(0) }) }) }) diff --git a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.spec.js b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.spec.js index 5c9b92d057..44f1e3b206 100644 --- a/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.spec.js +++ b/spec/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.spec.js @@ -570,9 +570,9 @@ describe('Google Tag Manager page view tracking', function () { }) }) - it('correctly sets the global_bar parameter', function () { + it('correctly sets the global_banner parameter', function () { var div = document.createElement('div') - div.setAttribute('data-ga4-global-bar', '') + div.setAttribute('data-ga4-global-banner', '') document.body.appendChild(div) expected.page_view.global_bar = 'true' GOVUK.analyticsGa4.analyticsModules.PageViewTracker.init()