mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-09 19:04:33 -04:00
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.
This commit is contained in:
22
tests/javascripts/support/helpers/cookies.js
Normal file
22
tests/javascripts/support/helpers/cookies.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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;
|
||||
Reference in New Issue
Block a user