diff --git a/tests/helpers.js b/tests/helpers.js index 8ed45f9f..bfda7624 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -59,4 +59,12 @@ export const runRedirect = (name, verbose = true) => { evalWrapper(resultString); }; +/** + * Clear cookie by name + * @param {string} cName + */ +export const clearCookie = (cName) => { + document.cookie = `${cName}=; max-age=0`; +}; + export const isSafariBrowser = () => navigator.vendor === 'Apple Computer, Inc.'; diff --git a/tests/scriptlets/set-cookie-reload.test.js b/tests/scriptlets/set-cookie-reload.test.js index 0f6dd04a..6075424d 100644 --- a/tests/scriptlets/set-cookie-reload.test.js +++ b/tests/scriptlets/set-cookie-reload.test.js @@ -1,5 +1,9 @@ /* eslint-disable no-underscore-dangle */ -import { runScriptlet, clearGlobalProps } from '../helpers'; +import { + runScriptlet, + clearGlobalProps, + clearCookie, +} from '../helpers'; const { test, module } = QUnit; const name = 'set-cookie-reload'; @@ -14,10 +18,6 @@ const afterEach = () => { clearGlobalProps('hit', '__debug'); }; -const clearCookie = (cName) => { - document.cookie = `${cName}=; max-age=0`; -}; - module(name, { beforeEach, afterEach }); test('Set cookie with valid value', (assert) => { diff --git a/tests/scriptlets/set-cookie.test.js b/tests/scriptlets/set-cookie.test.js index 869e70cf..31c4338b 100644 --- a/tests/scriptlets/set-cookie.test.js +++ b/tests/scriptlets/set-cookie.test.js @@ -1,5 +1,9 @@ /* eslint-disable no-underscore-dangle */ -import { runScriptlet, clearGlobalProps } from '../helpers'; +import { + runScriptlet, + clearGlobalProps, + clearCookie, +} from '../helpers'; const { test, module } = QUnit; const name = 'set-cookie'; @@ -16,10 +20,6 @@ const afterEach = () => { module(name, { beforeEach, afterEach }); -const clearCookie = (cName) => { - document.cookie = `${cName}=; max-age=0`; -}; - test('Set cookie with valid value', (assert) => { let cName = '__test-cookie_OK'; let cValue = 'OK'; diff --git a/tests/scriptlets/trusted-click-element.test.js b/tests/scriptlets/trusted-click-element.test.js index 5ef0464d..663f6062 100644 --- a/tests/scriptlets/trusted-click-element.test.js +++ b/tests/scriptlets/trusted-click-element.test.js @@ -1,6 +1,6 @@ /* eslint-disable no-underscore-dangle, no-console */ import { runScriptlet, clearGlobalProps } from '../helpers'; -import { prepareLimitedCookieString } from '../../src/helpers'; +import { concatCookieNameValuePath } from '../../src/helpers'; const { test, module } = QUnit; const name = 'trusted-click-element'; @@ -162,7 +162,7 @@ test('Multiple elements clicked, non-ordered render', (assert) => { test('extraMatch - single cookie match, matched', (assert) => { const cookieKey1 = 'first'; - const cookieData = prepareLimitedCookieString(cookieKey1, 'true'); + const cookieData = concatCookieNameValuePath(cookieKey1, 'true', '/'); document.cookie = cookieData; const EXTRA_MATCH_STR = `cookie:${cookieKey1}`; @@ -190,7 +190,7 @@ test('extraMatch - single cookie match, matched', (assert) => { test('extraMatch - single cookie match, not matched', (assert) => { const cookieKey1 = 'first'; const cookieKey2 = 'second'; - const cookieData = prepareLimitedCookieString(cookieKey1, 'true'); + const cookieData = concatCookieNameValuePath(cookieKey1, 'true', '/'); document.cookie = cookieData; const EXTRA_MATCH_STR = `cookie:${cookieKey2}`; @@ -218,7 +218,7 @@ test('extraMatch - single cookie match, not matched', (assert) => { test('extraMatch - string+regex cookie input, matched', (assert) => { const cookieKey1 = 'first'; const cookieVal1 = 'true'; - const cookieData1 = prepareLimitedCookieString(cookieKey1, cookieVal1); + const cookieData1 = concatCookieNameValuePath(cookieKey1, cookieVal1, '/'); document.cookie = cookieData1; const EXTRA_MATCH_STR = 'cookie:/firs/=true'; @@ -299,13 +299,13 @@ test('extraMatch - single localStorage match, not matched', (assert) => { test('extraMatch - complex string+regex cookie input & whitespaces & comma in regex, matched', (assert) => { const cookieKey1 = 'first'; const cookieVal1 = 'true'; - const cookieData1 = prepareLimitedCookieString(cookieKey1, cookieVal1); + const cookieData1 = concatCookieNameValuePath(cookieKey1, cookieVal1, '/'); const cookieKey2 = 'sec'; const cookieVal2 = '1-1'; - const cookieData2 = prepareLimitedCookieString(cookieKey2, cookieVal2); + const cookieData2 = concatCookieNameValuePath(cookieKey2, cookieVal2, '/'); const cookieKey3 = 'third'; const cookieVal3 = 'true'; - const cookieData3 = prepareLimitedCookieString(cookieKey3, cookieVal3); + const cookieData3 = concatCookieNameValuePath(cookieKey3, cookieVal3, '/'); document.cookie = cookieData1; document.cookie = cookieData2; diff --git a/tests/scriptlets/trusted-set-cookie.test.js b/tests/scriptlets/trusted-set-cookie.test.js index 38d26901..3fecbf39 100644 --- a/tests/scriptlets/trusted-set-cookie.test.js +++ b/tests/scriptlets/trusted-set-cookie.test.js @@ -1,5 +1,9 @@ /* eslint-disable no-underscore-dangle */ -import { runScriptlet, clearGlobalProps } from '../helpers'; +import { + runScriptlet, + clearGlobalProps, + clearCookie, +} from '../helpers'; const { test, module } = QUnit; const name = 'trusted-set-cookie'; @@ -16,10 +20,6 @@ const afterEach = () => { module(name, { beforeEach, afterEach }); -const clearCookie = (cName) => { - document.cookie = `${cName}=; max-age=0`; -}; - test('Set cookie string', (assert) => { let cName = '__test-cookie_OK'; let cValue = 'OK';