Skip to content

Commit

Permalink
move clearCookie to test/helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 3, 2022
1 parent 9f1f0d4 commit 69367ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
8 changes: 8 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
10 changes: 5 additions & 5 deletions tests/scriptlets/set-cookie-reload.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand Down
10 changes: 5 additions & 5 deletions tests/scriptlets/set-cookie.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down
14 changes: 7 additions & 7 deletions tests/scriptlets/trusted-click-element.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}`;

Expand Down Expand Up @@ -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}`;

Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions tests/scriptlets/trusted-set-cookie.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down

0 comments on commit 69367ab

Please sign in to comment.