mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-10 03:14:58 -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:
55
tests/javascripts/consent.test.js
Normal file
55
tests/javascripts/consent.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const helpers = require('./support/helpers');
|
||||
|
||||
beforeAll(() => {
|
||||
|
||||
require('../../app/assets/javascripts/govuk/cookie-functions.js');
|
||||
require('../../app/assets/javascripts/consent.js');
|
||||
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
require('./support/teardown.js');
|
||||
|
||||
});
|
||||
|
||||
describe("Cookie consent", () => {
|
||||
|
||||
describe("hasConsentFor", () => {
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
// remove cookie set by tests
|
||||
helpers.deleteCookie('cookies_policy');
|
||||
|
||||
});
|
||||
|
||||
test("If there is no consent cookie, return false", () => {
|
||||
|
||||
expect(window.GOVUK.hasConsentFor('analytics')).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
describe("If a consent cookie is set", () => {
|
||||
|
||||
test("If the category is not saved in the cookie, return false", () => {
|
||||
|
||||
window.GOVUK.setConsentCookie({ 'usage': true });
|
||||
|
||||
expect(window.GOVUK.hasConsentFor('analytics')).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
test("If the category is saved in the cookie, return its value", () => {
|
||||
|
||||
window.GOVUK.setConsentCookie({ 'analytics': true });
|
||||
|
||||
expect(window.GOVUK.hasConsentFor('analytics')).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user