diff --git a/packages/cookie-banner/__tests__/analytics/index.js b/packages/cookie-banner/__tests__/analytics/index.js deleted file mode 100644 index 54a146db..00000000 --- a/packages/cookie-banner/__tests__/analytics/index.js +++ /dev/null @@ -1,61 +0,0 @@ -import cookieBanner from '../../src'; -import sampleTemplates from '../../example/src/js/sample-templates'; -import defaults from '../../src/lib/defaults'; -let instance; - -const init = () => { - // Set up our document body - document.body.innerHTML = `
`; - instance = cookieBanner({ - ...sampleTemplates, - secure: false, - hideBannerOnFormPage: false, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); -}; - -describe(`Cookie banner > Analytics > Data layer additions`, () => { - beforeAll(init); - - it('It should add to the dataLayer when the banner is shown', async () => { - expect(dataLayer.find(e => e.event === "stormcb_display")).toBeDefined(); - }); - - it('It should add to the datalayer when accept all is clicked', async () => { - document.querySelector(`.${defaults.classNames.acceptBtn}`).click(); - expect(dataLayer.find(e => e.event === "stormcb_accept_all")).toBeDefined(); - expect(dataLayer.find(e => e.stormcb_performance === 1)).toBeDefined(); - expect(dataLayer.find(e => e.stormcb_test === 1)).toBeDefined(); - }); - - it('It should add to the datalayer when reject all is clicked', async () => { - instance.showBanner(); - document.querySelector(`.${defaults.classNames.rejectBtn}`).click(); - expect(dataLayer.find(e => e.event === "stormcb_reject_all")).toBeDefined(); - expect(dataLayer.find(e => e.stormcb_performance === 0)).toBeDefined(); - expect(dataLayer.find(e => e.stormcb_test === 0)).toBeDefined(); - }); -}); diff --git a/packages/cookie-banner/__tests__/banner/index.js b/packages/cookie-banner/__tests__/banner/index.js deleted file mode 100644 index e8e0f74c..00000000 --- a/packages/cookie-banner/__tests__/banner/index.js +++ /dev/null @@ -1,99 +0,0 @@ -import sampleTemplates from '../../example/src/js/sample-templates'; -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; - -const init = () => { - // Set up our document body - document.body.innerHTML = ``; - cookieBanner({ - ...sampleTemplates, - secure: false, - hideBannerOnFormPage: false, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); -}; - - -describe(`Cookie banner > DOM > render`, () => { - beforeAll(init); - - it('It should render the banner', async () => { - expect(document.querySelector(`.${defaults.classNames.banner}`)).not.toBeNull(); - }); -}); - -describe(`Cookie banner > DOM > not render`, () => { - - it('It should not render the banner if hideBannerOnFormPage setting is true and on consent form page', async () => { - document.body.innerHTML = ``; - cookieBanner({ - secure: false, - hideBannerOnFormPage: true, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); - expect(document.querySelector(`.${defaults.classNames.banner}`)).toBeNull(); - }); -}); - - -describe(`Cookie banner > DOM > accessibility`, () => { - beforeAll(init); - it('The banner should be a region', async () => { - expect(document.querySelector(`.${defaults.classNames.banner}`).getAttribute('role')).toEqual('region'); - }); - - it('The banner should be a polite aria live region', async () => { - expect(document.querySelector(`.${defaults.classNames.banner}`).getAttribute('aria-live')).toEqual('polite'); - }); - - it('The banner should have an aria label', async () => { - expect(document.querySelector(`.${defaults.classNames.banner}`).getAttribute('aria-label')).toBeDefined(); - }); - -}); - -describe(`Cookie banner > DOM > interactions`, () => { - beforeAll(init); - - it('Hides the banner', async () => { - document.querySelector(`.${defaults.classNames.acceptBtn}`).click(); - expect(document.querySelector(`.${defaults.classNames.banner}`)).toBeNull(); - }); - -}); - diff --git a/packages/cookie-banner/__tests__/cookies.js b/packages/cookie-banner/__tests__/cookies.js deleted file mode 100644 index 46ea343a..00000000 --- a/packages/cookie-banner/__tests__/cookies.js +++ /dev/null @@ -1,55 +0,0 @@ -import sampleTemplates from '../example/src/js/sample-templates'; -import cookieBanner from '../src'; -import defaults from '../src/lib/defaults'; - -const init = () => { - // Set up our document body - document.body.innerHTML = ``; - window.__cb__ = cookieBanner({ - ...sampleTemplates, - secure: false, - hideBannerOnFormPage: false, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); -}; - - -describe(`Cookie banner > cookies > update`, () => { - beforeAll(init); - - it('Sets a cookie based on preferences form', async () => { - document.querySelector(`.${defaults.classNames.acceptBtn}`).click(); - expect(document.cookie).toEqual(`${defaults.name}=${btoa(`{"consent":{"test":1,"performance":1}}`)}`); - - const fields = Array.from(document.querySelectorAll(`.${defaults.classNames.field}`)); - fields[1].checked = true; - fields[3].checked = true; - document.querySelector(`.${defaults.classNames.submitBtn}`).click(); - expect(document.cookie).toEqual(`${defaults.name}=${btoa(`{"consent":{"test":0,"performance":0}}`)}`); - }); - -}); - diff --git a/packages/cookie-banner/__tests__/form/interactions.js b/packages/cookie-banner/__tests__/form/interactions.js deleted file mode 100644 index 96e22402..00000000 --- a/packages/cookie-banner/__tests__/form/interactions.js +++ /dev/null @@ -1,66 +0,0 @@ -import sampleTemplates from '../../example/src/js/sample-templates'; -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; - -const dispatchSyntheticEvent = (node, eventType) => { - let event = document.createEvent('Event'); - event.initEvent(eventType, true, true); - node.dispatchEvent(event); -}; - -describe(`Cookie banner > DOM > form interactions`, () => { - beforeAll(() => { - document.body.innerHTML = ``; - window.__cb__ = cookieBanner({ - ...sampleTemplates, - secure: false, - hideBannerOnFormPage: false, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Test yes label', - no: 'Test no label' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); - }); - - it('Submit button should be disabled', async () => { - expect(document.querySelector(`.${defaults.classNames.submitBtn}`).getAttribute('disabled')).not.toBeNull(); - }); - - it('Submit button should be enabled if both field groups have values', async () => { - const fields = Array.from(document.querySelectorAll(`.${defaults.classNames.field}`)); - - fields[0].checked = true; - dispatchSyntheticEvent(fields[0], 'change');//for JSDOM - expect(document.querySelector(`.${defaults.classNames.submitBtn}`).getAttribute('disabled')).not.toBeNull(); - - fields[2].checked = true; - dispatchSyntheticEvent(fields[2], 'change');//for JSDOM - expect(document.querySelector(`.${defaults.classNames.submitBtn}`).getAttribute('disabled')).toEqual(null); - }); - - it('Submit button should set the cookie and hide the banner', async () => { - document.querySelector(`.${defaults.classNames.acceptBtn}`).click(); - expect(document.cookie).toEqual(`${defaults.name}=${btoa(`{"consent":{"test":1,"performance":1}}`)}`); - expect(document.querySelector(`.${defaults.classNames.banner}`)).toBeNull(); - }); -}); \ No newline at end of file diff --git a/packages/cookie-banner/__tests__/form/not-render.js b/packages/cookie-banner/__tests__/form/not-render.js deleted file mode 100644 index c7b7ebcc..00000000 --- a/packages/cookie-banner/__tests__/form/not-render.js +++ /dev/null @@ -1,28 +0,0 @@ -import sampleTemplates from '../../example/src/js/sample-templates'; -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; - -describe(`Cookie banner > DOM > form > not render`, () => { - document.body.innerHTML = ``; - cookieBanner({ - ...sampleTemplates, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); - - it('Should return if there is no form container', async () => { - expect(document.querySelector(`.${defaults.classNames.form}`)).toBeNull(); - }); - -}); \ No newline at end of file diff --git a/packages/cookie-banner/__tests__/form/render.js b/packages/cookie-banner/__tests__/form/render.js deleted file mode 100644 index 33f371be..00000000 --- a/packages/cookie-banner/__tests__/form/render.js +++ /dev/null @@ -1,56 +0,0 @@ -import sampleTemplates from '../../example/src/js/sample-templates'; -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; - -describe(`Cookie banner > DOM > form > render`, () => { - beforeAll(() => { - document.body.innerHTML = ``; - cookieBanner({ - ...sampleTemplates, - secure: false, - hideBannerOnFormPage: false, - types: { - test: { - suggested: true, - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Test yes label', - no: 'Test no label' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); - }); - - it('Should render the form', async () => { - expect(document.querySelector(`.${defaults.classNames.form}`)).not.toBeNull(); - }); - - it('Should render a fieldset for each type', async () => { - const fieldset = Array.from(document.querySelectorAll(`.${defaults.classNames.fieldset}`)); - const fields = Array.from(document.querySelectorAll(`.${defaults.classNames.field}`)); - expect(fieldset.length).toEqual(2); - expect(fields.length).toEqual(4); - }); - - it('Should set the default values if any are set and no there is no user consent preferences', async () => { - const fields = Array.from(document.querySelectorAll(`.${defaults.classNames.field}`)); - expect(fields[0].checked).toEqual(true); - }); - -}); \ No newline at end of file diff --git a/packages/cookie-banner/__tests__/google-eu-consent/index.js b/packages/cookie-banner/__tests__/google-eu-consent/index.js deleted file mode 100644 index 0e8acfa8..00000000 --- a/packages/cookie-banner/__tests__/google-eu-consent/index.js +++ /dev/null @@ -1,67 +0,0 @@ -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; -import sampleTemplates from '../../example/src/js/sample-templates'; - -/* eslint-disable camelcase */ -const init = () => { - // Set up our document body - document.body.innerHTML = ``; - window.__cb__ = cookieBanner({ - ...sampleTemplates, - secure: false, - euConsentTypes: { - ad_storage: 'test', - ad_user_data: 'test', - ad_personalization: 'test', - analytics_storage: 'performance' - }, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); -}; - - -describe(`Cookie banner > cookies > Google EU consent > default event`, () => { - beforeAll(init); - - it('must set a default consent event with all categories denied', async () => { - const banner = document.querySelector(`.${defaults.classNames.banner}`); - expect(banner).not.toBeNull(); - - //These assertions break Jest because of the use 'arguments' in the gtag implementation - //They have been manually validated in the browser - // expect(window.dataLayer).toEqual([ - // ['consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied' }] - // ]); - // const acceptAllBtn = document.querySelector(`.${defaults.classNames.acceptBtn}`); - // acceptAllBtn.click(); - - // expect(window.dataLayer).toEqual([ - // ['consent', 'default', { ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied' }], - // ['consent', 'update', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted', analytics_storage: 'granted' }] - // ]); - }); - -}); \ No newline at end of file diff --git a/packages/cookie-banner/__tests__/google-eu-consent/no-eu-consent-config.js b/packages/cookie-banner/__tests__/google-eu-consent/no-eu-consent-config.js deleted file mode 100644 index 76637377..00000000 --- a/packages/cookie-banner/__tests__/google-eu-consent/no-eu-consent-config.js +++ /dev/null @@ -1,47 +0,0 @@ -import cookieBanner from '../../src'; -import defaults from '../../src/lib/defaults'; -import sampleTemplates from '../../example/src/js/sample-templates'; - -const init = () => { - // Set up our document body - document.body.innerHTML = ``; - window.__cb__ = cookieBanner({ - ...sampleTemplates, - secure: false, - types: { - test: { - title: 'Test title', - description: 'Test description', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - }, - performance: { - title: 'Performance preferences', - description: 'Performance cookies are used to measure the performance of our website and make improvements. Your personal data is not identified.', - labels: { - yes: 'Pages you visit and actions you take will be measured and used to improve the service', - no: 'Pages you visit and actions you take will not be measured and used to improve the service' - }, - fns: [ - () => { } - ] - } - } - }); -}; - - -describe(`Cookie banner > cookies > Google EU consent > no EU consent settings`, () => { - beforeAll(init); - - it('No errors if no consent options configured', async () => { - const banner = document.querySelector(`.${defaults.classNames.banner}`); - expect(banner).not.toBeNull(); - }); - -}); \ No newline at end of file diff --git a/packages/cookie-banner/__tests__/consent.js b/packages/cookie-banner/__tests__/jest/consent.js similarity index 96% rename from packages/cookie-banner/__tests__/consent.js rename to packages/cookie-banner/__tests__/jest/consent.js index 4d971c43..764cada6 100644 --- a/packages/cookie-banner/__tests__/consent.js +++ b/packages/cookie-banner/__tests__/jest/consent.js @@ -1,4 +1,4 @@ -import { applyEffects } from '../src/lib/consent'; +import { applyEffects } from '../../src/lib/consent'; describe(`Cookie banner > consent > callback`, () => { document.body.innerHTML = `Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded + onto a device to allow a website to recognise it and to store some information about your preferences.
+We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our + sites, recognising and remembering your preferences and showing you personalised ads. Learn more about + cookies and how we use them.
+ + +