Skip to content

Commit

Permalink
Merge pull request #276 from co-cddo/cookie-banner-tweaks
Browse files Browse the repository at this point in the history
Tweaks to the cookie banner
  • Loading branch information
maxf authored Sep 3, 2024
2 parents 40b1355 + a50972c commit 2af17bc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cypress/e2e/cookie-banner.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,29 @@ describe('Cookie banner', () => {
it('lets the user change their mind from accept to reject', () => {
cy.acceptCookies()
cy.visit('/cookies')
cy.get('#success-banner').should('not.be.visible');
cy.get('#replaced-gtm-snippet').should('exist')
cy.get('#use-cookies').should('be.checked')
cy.get('#no-cookies').should('not.be.checked')
cy.get('#no-cookies').click()
cy.get('#save-cookies').click()
cy.getCookie('cookies_preference_set').should('have.property', 'value', 'true')
cy.getCookie('cookies_accepted').should('have.property', 'value', 'false')
cy.get('#success-banner').should('be.visible');
cy.visit('/')
cy.get('#replaced-gtm-snippet').should('not.exist')
})

it('lets the user change their mind from reject to accept', () => {
cy.refuseCookies()
cy.visit('/cookies')
cy.get('#success-banner').should('not.be.visible');
cy.get('#replaced-gtm-snippet').should('not.exist')
cy.get('#use-cookies').should('not.be.checked')
cy.get('#no-cookies').should('be.checked')
cy.get('#use-cookies').click()
cy.get('#save-cookies').click()
cy.get('#success-banner').should('be.visible');
cy.getCookie('cookies_preference_set').should('have.property', 'value', 'true')
cy.getCookie('cookies_accepted').should('have.property', 'value', 'true')
cy.visit('/')
Expand Down
3 changes: 3 additions & 0 deletions request_a_govuk_domain/request/static/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ if (cookiePageControls) {
Cookies.set('cookies_preference_set', 'true', { secure: true, sameSite: 'strict' });
Cookies.set('cookies_accepted', 'false', { secure: true, sameSite: 'strict' });
}
document.querySelector('#cookie-success-back-link').href = document.referrer;
document.querySelector('#success-banner').style.display = 'block';
window.scrollTo(0, 0);
});
}
}
3 changes: 1 addition & 2 deletions request_a_govuk_domain/request/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
{% gds_cookie_banner_message headingText="Cookies on Get approval to use a .gov.uk domain" %}
<p class="govuk-body">We use some essential cookies to make this website work.</p>
<p class="govuk-body">We’d also like to use analytics cookies so we can understand how you use the service and make improvements.</p>
<p class="govuk-body"><a class="govuk-link--no-visited-state" href="/cookies">View cookies</a></p>

{% gds_cookie_banner_message_action text="Accept analytics cookies" %}
{% gds_cookie_banner_message_action text="Reject analytics cookies" %}
{% gds_cookie_banner_message_action text="View cookies" href="/cookies" %}
{% endgds_cookie_banner_message %}
{% endgds_cookie_banner %}
</div>
Expand Down
22 changes: 22 additions & 0 deletions request_a_govuk_domain/request/templates/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

{% if GOOGLE_ANALYTICS_ID %}
<style>#success-banner { display: none }</style>
<div id="success-banner" class="govuk-notification-banner govuk-notification-banner--success" 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">
Success
</h2>
</div>
<div class="govuk-notification-banner__content">
<h3 class="govuk-notification-banner__heading">
Your cookie settings were saved
</h3>
<div class="govuk-body">
Government services may set additional cookies and, if so, will have their own cookie policy and banner.
</div>
<div class="govuk-body">
<a href="govuk-notification-banner__link" id="cookie-success-back-link">Go back to the page you were looking at</a>
</div>
</div>
</div>
{% endif %}

<h1 class="govuk-heading-xl">
Cookies on the Get approval to use a .gov.uk domain name service
</h1>
Expand Down

0 comments on commit 2af17bc

Please sign in to comment.