Files
notifications-admin/tests/javascripts/support/helpers/cookies.js
Tom Byers 900aa19bd3 Add JS tests for analytics & cookies JS
Includes:
- tests for the analytics interface ported from
  GOVUK Frontend Toolkit
- tests for the cookie banner that appears on all
  pages except the cookies page
- tests for the cookies page JS
- tests for the hasConsentFor function
- adding a deleteCookie helper to remove
  cookies during tests
- polyfill for insertAdjacentText

The last one is because JSDOM doesn't support
insertAdjacentText but our target browsers
do. This polyfill also includes one for
insertAdjacentHTML.
2020-01-06 13:38:34 +00:00

23 lines
642 B
JavaScript

// Helper for deleting a cookie
function deleteCookie (cookieName) {
document.cookie = cookieName + '=; path=/; expires=' + (new Date());
};
function setCookie (name, value, options) {
if (typeof options === 'undefined') {
options = {};
}
var cookieString = name + '=' + value + '; path=/;domain=' + window.location.hostname;
if (options.days) {
var date = new Date();
date.setTime(date.getTime() + (options.days * 24 * 60 * 60 * 1000));
cookieString = cookieString + '; expires=' + date.toGMTString();
}
document.cookie = cookieString;
};
exports.deleteCookie = deleteCookie;
exports.setCookie = setCookie;