mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-10 05:14:05 -05:00
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.
23 lines
642 B
JavaScript
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;
|