TypeScript Convert MVP
This commit is contained in:
parent
6cc45c0735
commit
d79499a898
13
.babelrc
13
.babelrc
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"presets": ["react", ["env", {
|
||||
"test": {
|
||||
"plugins": [ "istanbul" ]
|
||||
}
|
||||
}]
|
||||
],
|
||||
"plugins": [
|
||||
"transform-class-properties",
|
||||
"transform-async-to-generator",
|
||||
"transform-object-rest-spread"
|
||||
]
|
||||
}
|
270
.eslintrc.js
270
.eslintrc.js
|
@ -1,270 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
// When adding items to this file please check for effects on sub-directories.
|
||||
"parser": "babel-eslint",
|
||||
"parserOptions": {"ecmaFeatures": {"jsx": true}, "sourceType": "module"},
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"mocha": true,
|
||||
"node": true,
|
||||
"webextensions": true
|
||||
},
|
||||
"globals": {"chrome": true},
|
||||
"plugins": [
|
||||
"json",
|
||||
"mocha",
|
||||
"promise",
|
||||
"react"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended"
|
||||
],
|
||||
"rules": {
|
||||
|
||||
"react/prop-types": 0,
|
||||
|
||||
"mocha/handle-done-callback": 2,
|
||||
"mocha/max-top-level-suites": 2,
|
||||
"mocha/no-exclusive-tests": 2,
|
||||
"mocha/no-global-tests": 2,
|
||||
"mocha/no-identical-title": 2,
|
||||
"mocha/no-mocha-arrows": 2,
|
||||
"mocha/no-return-and-callback": 2,
|
||||
"mocha/no-skipped-tests": 0,
|
||||
"mocha/no-sibling-hooks": 2,
|
||||
"mocha/no-top-level-hooks": 2,
|
||||
"mocha/valid-suite-description": 2,
|
||||
"mocha/valid-test-description": 2,
|
||||
|
||||
"promise/always-return": 2,
|
||||
"promise/catch-or-return": 2,
|
||||
"promise/param-names": 2,
|
||||
|
||||
"accessor-pairs": [2, {"setWithoutGet": true, "getWithoutSet": false}],
|
||||
"array-bracket-spacing": [2, "never"],
|
||||
"array-callback-return": 2,
|
||||
"arrow-body-style": [2, "as-needed"],
|
||||
"arrow-parens": [2, "always"],
|
||||
"arrow-spacing": 2,
|
||||
"block-scoped-var": 2,
|
||||
"block-spacing": [2, "never"],
|
||||
"brace-style": 0,
|
||||
"callback-return": 0,
|
||||
"camelcase": 0,
|
||||
"comma-dangle": [2, "never"],
|
||||
"comma-spacing": 2,
|
||||
"comma-style": 2,
|
||||
"complexity": [2, {"max": 20}],
|
||||
"computed-property-spacing": [2, "never"],
|
||||
"consistent-return": 2,
|
||||
"consistent-this": [2, "use-bind"],
|
||||
"constructor-super": 2,
|
||||
"curly": [2, "all"],
|
||||
"default-case": 0,
|
||||
"dot-location": [2, "property"],
|
||||
"dot-notation": 2,
|
||||
"eol-last": 2,
|
||||
"eqeqeq": 2,
|
||||
"func-names": 0,
|
||||
"func-style": 0,
|
||||
"generator-star-spacing": [2, {"before": false, "after": false}],
|
||||
"global-require": 0,
|
||||
"guard-for-in": 2,
|
||||
"handle-callback-err": 2,
|
||||
"id-blacklist": 0,
|
||||
"id-length": 0,
|
||||
"id-match": 0,
|
||||
"indent": ["error", "tab"],
|
||||
"init-declarations": 0,
|
||||
"jsx-quotes": [2, "prefer-double"],
|
||||
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
|
||||
"keyword-spacing": 2,
|
||||
"linebreak-style": [2, "unix"],
|
||||
"lines-around-comment": [2, {"beforeBlockComment": true, "allowObjectStart": true}],
|
||||
"max-depth": [2, 4],
|
||||
"max-len": 0,
|
||||
"max-lines": 0,
|
||||
"max-nested-callbacks": [2, 4],
|
||||
"max-params": [2, 6],
|
||||
"max-statements": [2, 50],
|
||||
"max-statements-per-line": [2, {"max": 2}],
|
||||
"multiline-ternary": 0,
|
||||
"new-cap": [2, {"newIsCap": true, "capIsNew": false}],
|
||||
"new-parens": 2,
|
||||
"newline-after-var": 0,
|
||||
"newline-before-return": 0,
|
||||
"newline-per-chained-call": [2, {"ignoreChainWithDepth": 3}],
|
||||
"no-alert": 2,
|
||||
"no-array-constructor": 2,
|
||||
"no-bitwise": 0,
|
||||
"no-caller": 2,
|
||||
"no-case-declarations": 2,
|
||||
"no-catch-shadow": 2,
|
||||
"no-class-assign": 2,
|
||||
"no-cond-assign": 2,
|
||||
"no-confusing-arrow": [2, {"allowParens": true}],
|
||||
"no-console": [1, { allow: ["error"] }],
|
||||
"no-const-assign": 2,
|
||||
"no-constant-condition": 2,
|
||||
"no-continue": 0,
|
||||
"no-control-regex": 2,
|
||||
"no-debugger": 2,
|
||||
"no-delete-var": 2,
|
||||
"no-div-regex": 2,
|
||||
"no-dupe-args": 2,
|
||||
"no-dupe-class-members": 2,
|
||||
"no-dupe-keys": 2,
|
||||
"no-duplicate-case": 2,
|
||||
"no-duplicate-imports": 2,
|
||||
"no-else-return": 2,
|
||||
"no-empty": 2,
|
||||
"no-empty-character-class": 2,
|
||||
"no-empty-function": 0,
|
||||
"no-empty-pattern": 2,
|
||||
"no-eq-null": 2,
|
||||
"no-eval": 2,
|
||||
"no-ex-assign": 2,
|
||||
"no-extend-native": 2,
|
||||
"no-extra-bind": 2,
|
||||
"no-extra-boolean-cast": 2,
|
||||
"no-extra-label": 2,
|
||||
"no-extra-parens": 0,
|
||||
"no-extra-semi": 2,
|
||||
"no-fallthrough": 2,
|
||||
"no-floating-decimal": 2,
|
||||
"no-func-assign": 2,
|
||||
"no-implicit-coercion": [2, {"allow": ["!!"]}],
|
||||
"no-implicit-globals": 2,
|
||||
"no-implied-eval": 2,
|
||||
"no-inline-comments": 0,
|
||||
"no-inner-declarations": 2,
|
||||
"no-invalid-regexp": 2,
|
||||
"no-invalid-this": 0,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-iterator": 2,
|
||||
"no-label-var": 2,
|
||||
"no-labels": 2,
|
||||
"no-lone-blocks": 2,
|
||||
"no-lonely-if": 2,
|
||||
"no-loop-func": 2,
|
||||
"no-magic-numbers": 0,
|
||||
"no-mixed-operators": [2, {"allowSamePrecedence": true, "groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["==", "!=", "===", "!==", ">", ">=", "<", "<="], ["&&", "||"], ["in", "instanceof"]]}],
|
||||
"no-mixed-requires": 2,
|
||||
"no-mixed-spaces-and-tabs": 2,
|
||||
"no-multi-spaces": 2,
|
||||
"no-multi-str": 2,
|
||||
"no-multiple-empty-lines": [2, {"max": 1, "maxBOF": 0, "maxEOF": 0}],
|
||||
"no-native-reassign": 2,
|
||||
"no-negated-condition": 0,
|
||||
"no-negated-in-lhs": 2,
|
||||
"no-nested-ternary": 2,
|
||||
"no-new": 2,
|
||||
"no-new-func": 2,
|
||||
"no-new-object": 2,
|
||||
"no-new-require": 2,
|
||||
"no-new-symbol": 2,
|
||||
"no-new-wrappers": 2,
|
||||
"no-obj-calls": 2,
|
||||
"no-octal": 2,
|
||||
"no-octal-escape": 2,
|
||||
"no-param-reassign": 2,
|
||||
"no-path-concat": 2,
|
||||
"no-plusplus": 0,
|
||||
"no-process-env": 0,
|
||||
"no-process-exit": 2,
|
||||
"no-proto": 2,
|
||||
"no-prototype-builtins": 2,
|
||||
"no-redeclare": 2,
|
||||
"no-regex-spaces": 2,
|
||||
"no-restricted-globals": 2,
|
||||
"no-restricted-imports": 2,
|
||||
"no-restricted-modules": 2,
|
||||
"no-restricted-syntax": 2,
|
||||
"no-return-assign": [2, "except-parens"],
|
||||
"no-script-url": 2,
|
||||
"no-self-assign": 2,
|
||||
"no-self-compare": 2,
|
||||
"no-sequences": 2,
|
||||
"no-shadow": 0, // TODO: Change to `1`?
|
||||
"no-shadow-restricted-names": 2,
|
||||
"no-spaced-func": 2,
|
||||
"no-sparse-arrays": 2,
|
||||
"no-sync": 2,
|
||||
"no-tabs": 0,
|
||||
"no-ternary": 0,
|
||||
"no-this-before-super": 2,
|
||||
"no-throw-literal": 2,
|
||||
"no-trailing-spaces": [2, {"skipBlankLines": false}],
|
||||
"no-undef": 2,
|
||||
"no-undef-init": 2,
|
||||
"no-undefined": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unexpected-multiline": 2,
|
||||
"no-unmodified-loop-condition": 2,
|
||||
"no-unneeded-ternary": 2,
|
||||
"no-unreachable": 2,
|
||||
"no-unsafe-finally": 2,
|
||||
"no-unused-expressions": 2,
|
||||
"no-unused-labels": 2,
|
||||
"no-unused-vars": [2, {"vars": "all", "args": "none"}],
|
||||
"no-use-before-define": 2,
|
||||
"no-useless-call": 2,
|
||||
"no-useless-computed-key": 2,
|
||||
"no-useless-concat": 2,
|
||||
"no-useless-constructor": 2,
|
||||
"no-useless-escape": 0,
|
||||
"no-useless-rename": 2,
|
||||
"no-var": 2,
|
||||
"no-void": 2,
|
||||
"no-warning-comments": 0, // TODO: Change to `1`?
|
||||
"no-whitespace-before-property": 2,
|
||||
"no-with": 2,
|
||||
"object-curly-newline": [2, {
|
||||
minProperties: 1
|
||||
}],
|
||||
"object-curly-spacing": [2, "never"],
|
||||
"object-property-newline": [2, {"allowMultiplePropertiesPerLine": true}],
|
||||
"object-shorthand": [2, "always"],
|
||||
"one-var": [2, "never"],
|
||||
"one-var-declaration-per-line": [2, "initializations"],
|
||||
"operator-assignment": [2, "always"],
|
||||
"operator-linebreak": [2, "after"],
|
||||
"padded-blocks": [2, "never"],
|
||||
"prefer-arrow-callback": ["error", {"allowNamedFunctions": true}],
|
||||
"prefer-const": 0, // TODO: Change to `1`?
|
||||
"prefer-reflect": 0,
|
||||
"prefer-rest-params": 2,
|
||||
"prefer-spread": 2,
|
||||
"prefer-template": 2,
|
||||
"quote-props": [2, "consistent"],
|
||||
"quotes": [2, "double", "avoid-escape"],
|
||||
"radix": [2, "always"],
|
||||
"require-jsdoc": 0,
|
||||
"require-yield": 2,
|
||||
"rest-spread-spacing": [2, "never"],
|
||||
"semi": [2, "always"],
|
||||
"semi-spacing": [2, {"before": false, "after": true}],
|
||||
"sort-imports": 0,
|
||||
"sort-vars": 2,
|
||||
"space-before-blocks": [2, "always"],
|
||||
"space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
|
||||
"space-in-parens": [2, "never"],
|
||||
"space-infix-ops": 2,
|
||||
"space-unary-ops": 2,
|
||||
"spaced-comment": [2, "always"],
|
||||
"strict": 0,
|
||||
"template-curly-spacing": [2, "never"],
|
||||
"unicode-bom": [2, "never"],
|
||||
"use-isnan": 2,
|
||||
"valid-jsdoc": [0, {"requireReturn": false, "requireParamDescription": false, "requireReturnDescription": false}],
|
||||
"valid-typeof": 2,
|
||||
"vars-on-top": 2,
|
||||
"wrap-iife": [2, "inside"],
|
||||
"wrap-regex": 0,
|
||||
"yield-star-spacing": [2, "after"],
|
||||
"yoda": [2, "never"]
|
||||
}
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"trailingComma": "all",
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true
|
||||
}
|
|
@ -0,0 +1,450 @@
|
|||
import { when } from 'jest-when';
|
||||
import { initialState } from '../src/redux/State';
|
||||
import {
|
||||
isSafeToClean,
|
||||
returnSetOfOpenTabDomains,
|
||||
} from '../src/services/CleanupService';
|
||||
import * as Lib from '../src/services/Libs';
|
||||
// ToDo: cleanCookiesOperation
|
||||
|
||||
jest.mock('../src/services/Libs');
|
||||
|
||||
const wildCardWhiteListGoogle: Expression = {
|
||||
expression: '*.google.com',
|
||||
id: '1',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const whiteListYoutube: Expression = {
|
||||
expression: 'youtube.com',
|
||||
id: '2',
|
||||
listType: ListType.WHITE,
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const wildCardGreyFacebook: Expression = {
|
||||
expression: '*.facebook.com',
|
||||
id: '3',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'firefox-container-1',
|
||||
};
|
||||
|
||||
const greyMessenger: Expression = {
|
||||
expression: 'messenger.com',
|
||||
id: '4',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'firefox-container-1',
|
||||
};
|
||||
|
||||
const sampleState: State = {
|
||||
...initialState,
|
||||
lists: {
|
||||
default: [wildCardWhiteListGoogle, whiteListYoutube],
|
||||
'firefox-container-1': [wildCardGreyFacebook, greyMessenger],
|
||||
},
|
||||
};
|
||||
|
||||
const mockCookie: CookiePropertiesCleanup = {
|
||||
domain: '',
|
||||
hostOnly: true,
|
||||
hostname: '',
|
||||
httpOnly: true,
|
||||
mainDomain: '',
|
||||
name: 'key',
|
||||
path: '/',
|
||||
secure: true,
|
||||
session: true,
|
||||
storeId: 'firefox-default',
|
||||
value: 'value',
|
||||
};
|
||||
|
||||
describe('CleanupService', () => {
|
||||
describe('returnSetOfOpenTabDomains()', () => {
|
||||
// const stub1 = sinon.stub(UsefulFunctions, 'getHostname');
|
||||
// stub1.withArgs('https://google.com/search').returns('google.com');
|
||||
// stub1.withArgs('http://facebook.com/search').returns('facebook.com');
|
||||
// stub1.withArgs('http://sub.domain.com').returns('sub.domain.com');
|
||||
|
||||
// const stub2 = sinon.stub(UsefulFunctions, 'extractMainDomain');
|
||||
// stub2.withArgs('google.com').returns('google.com');
|
||||
// stub2.withArgs('facebook.com').returns('facebook.com');
|
||||
// stub2.withArgs('sub.domain.com').returns('domain.com');
|
||||
|
||||
// const stub3 = sinon.stub(UsefulFunctions, 'isAWebpage');
|
||||
// stub3.withArgs('https://google.com/search').returns(true);
|
||||
// stub3.withArgs('http://facebook.com/search').returns(true);
|
||||
// stub3.withArgs('http://sub.domain.com').returns(true);
|
||||
// stub3
|
||||
// .withArgs('moz-extension://test/settings/settings.html')
|
||||
// .returns(false);
|
||||
|
||||
beforeAll(() => {
|
||||
global.browser = {
|
||||
tabs: {
|
||||
query: () => [
|
||||
{
|
||||
url: 'https://google.com/search',
|
||||
},
|
||||
{
|
||||
url: 'http://facebook.com/search',
|
||||
},
|
||||
{
|
||||
url: 'http://sub.domain.com',
|
||||
},
|
||||
{
|
||||
url: 'moz-extension://test/settings/settings.html',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
when(Lib.isAWebpage)
|
||||
.calledWith('https://google.com/search')
|
||||
.mockReturnValue(true);
|
||||
when(Lib.isAWebpage)
|
||||
.calledWith('http://facebook.com/search')
|
||||
.mockReturnValue(true);
|
||||
when(Lib.isAWebpage)
|
||||
.calledWith('http://sub.domain.com')
|
||||
.mockReturnValue(true);
|
||||
when(Lib.isAWebpage)
|
||||
.calledWith('moz-extension://test/settings/settings.html')
|
||||
.mockReturnValue(false);
|
||||
|
||||
when(Lib.getHostname)
|
||||
.calledWith('https://google.com/search')
|
||||
.mockReturnValue('google.com');
|
||||
when(Lib.getHostname)
|
||||
.calledWith('http://facebook.com/search')
|
||||
.mockReturnValue('facebook.com');
|
||||
when(Lib.getHostname)
|
||||
.calledWith('http://sub.domain.com')
|
||||
.mockReturnValue('sub.domain.com');
|
||||
|
||||
when(Lib.extractMainDomain)
|
||||
.calledWith('google.com')
|
||||
.mockReturnValue('google.com');
|
||||
when(Lib.extractMainDomain)
|
||||
.calledWith('facebook.com')
|
||||
.mockReturnValue('facebook.com');
|
||||
when(Lib.extractMainDomain)
|
||||
.calledWith('sub.domain.com')
|
||||
.mockReturnValue('domain.com');
|
||||
});
|
||||
|
||||
it('should have google.com in set', () => {
|
||||
return returnSetOfOpenTabDomains().then(results => {
|
||||
expect(results.has('google.com')).toBe(true);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have facebook.com in set', () => {
|
||||
return returnSetOfOpenTabDomains().then(results => {
|
||||
expect(results.has('facebook.com')).toBe(true);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have domain.com in set', () => {
|
||||
return returnSetOfOpenTabDomains().then(results => {
|
||||
expect(results.has('domain.com')).toBe(true);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
it('should have length 3 in set', () => {
|
||||
return returnSetOfOpenTabDomains().then(results => {
|
||||
expect(results.size).toBe(3);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not have youtube.com in set', () => {
|
||||
return returnSetOfOpenTabDomains().then(results => {
|
||||
expect(results.has('youtube.com')).toBe(false);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete global.browser;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSafeToClean()', () => {
|
||||
const cleanupProperties: CleanupPropertiesInternal = {
|
||||
// @ts-ignore
|
||||
cachedResults: {
|
||||
dateTime: '',
|
||||
recentlyCleaned: 0,
|
||||
},
|
||||
greyCleanup: false,
|
||||
hostnamesDeleted: new Set(),
|
||||
ignoreOpenTabs: false,
|
||||
openTabDomains: new Set(['example.com', 'mozilla.org']),
|
||||
setOfDeletedDomainCookies: new Set(),
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
global.browser = {
|
||||
i18n: {
|
||||
getMessage: () => '',
|
||||
},
|
||||
};
|
||||
when(Lib.returnMatchedExpressionObject)
|
||||
.calledWith(sampleState, 'default', 'youtube.com')
|
||||
.mockReturnValue(whiteListYoutube);
|
||||
when(Lib.returnMatchedExpressionObject)
|
||||
.calledWith(sampleState, 'default', 'google.com')
|
||||
.mockReturnValue(wildCardWhiteListGoogle);
|
||||
when(Lib.returnMatchedExpressionObject)
|
||||
.calledWith(sampleState, 'default', 'sub.google.com')
|
||||
.mockReturnValue(wildCardWhiteListGoogle);
|
||||
});
|
||||
|
||||
it('should return true for yahoo.com', () => {
|
||||
const cookieProperty: CookiePropertiesCleanup = {
|
||||
...mockCookie,
|
||||
hostname: 'yahoo.com',
|
||||
mainDomain: 'yahoo.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for youtube.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'youtube.com',
|
||||
mainDomain: 'youtube.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for sub.youtube.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'sub.youtube.com',
|
||||
mainDomain: 'youtube.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for google.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'google.com',
|
||||
mainDomain: 'google.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for google.com in Personal', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'google.com',
|
||||
mainDomain: 'google.com',
|
||||
storeId: 'firefox-container-1',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for sub.google.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'sub.google.com',
|
||||
mainDomain: 'google.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for example.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'example.com',
|
||||
mainDomain: 'example.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for sub.example.com', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'sub.example.com',
|
||||
mainDomain: 'example.com',
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true for Facebook in Personal onStartup with Facebook in the Greylist', () => {
|
||||
const cookieProperty = {
|
||||
...mockCookie,
|
||||
hostname: 'facebook.com',
|
||||
mainDomain: 'facebook.com',
|
||||
storeId: 'firefox-container-1',
|
||||
};
|
||||
|
||||
const result = isSafeToClean(sampleState, cookieProperty, {
|
||||
...cleanupProperties,
|
||||
greyCleanup: true,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete global.browser;
|
||||
});
|
||||
});
|
||||
|
||||
// describe('cleanCookies()', () => {
|
||||
// beforeAll(() => {
|
||||
// const cleanup = jest.genMockFromModule('../src/services/CleanupService');
|
||||
// // @ts-ignore
|
||||
// cleanup.isSafeToClean = jest.fn(() => false);
|
||||
// });
|
||||
// const googleCookie: CookiePropertiesCleanup = {
|
||||
// ...mockCookie,
|
||||
// domain: 'google.com',
|
||||
// name: 'NID',
|
||||
// path: '/',
|
||||
// secure: true,
|
||||
// storeId: 'firefox-default',
|
||||
// };
|
||||
// const youtubeCookie: CookiePropertiesCleanup = {
|
||||
// ...mockCookie,
|
||||
// domain: 'youtube.com',
|
||||
// name: 'SID',
|
||||
// path: '/',
|
||||
// secure: true,
|
||||
// storeId: 'firefox-default',
|
||||
// };
|
||||
// const yahooCookie: CookiePropertiesCleanup = {
|
||||
// ...mockCookie,
|
||||
// domain: 'yahoo.com',
|
||||
// name: 'BID',
|
||||
// path: '/login',
|
||||
// secure: false,
|
||||
// storeId: 'firefox-default',
|
||||
// };
|
||||
|
||||
// const personalGoogleCookie: CookiePropertiesCleanup = {
|
||||
// ...mockCookie,
|
||||
// domain: 'google.com',
|
||||
// name: 'NID',
|
||||
// path: '/',
|
||||
// secure: true,
|
||||
// storeId: 'firefox-container-1',
|
||||
// };
|
||||
|
||||
// const cookies = [
|
||||
// googleCookie,
|
||||
// youtubeCookie,
|
||||
// yahooCookie,
|
||||
// personalGoogleCookie,
|
||||
// ];
|
||||
|
||||
// beforeAll(() => {
|
||||
// global.browser = {
|
||||
// cookies: {
|
||||
// remove: jest.fn(),
|
||||
// },
|
||||
// i18n: {
|
||||
// getMessage: () => null,
|
||||
// },
|
||||
// };
|
||||
// });
|
||||
|
||||
// it('should be called twice for cookies.remove', () => {
|
||||
// const cleanupProperties: CleanupPropertiesInternal = {
|
||||
// cachedResults: {
|
||||
// dateTime: '',
|
||||
// recentlyCleaned: 0,
|
||||
// },
|
||||
// greyCleanup: false,
|
||||
// hostnamesDeleted: new Set(),
|
||||
// ignoreOpenTabs: false,
|
||||
// openTabDomains: new Set(['example.com', 'mozilla.org']),
|
||||
// setOfDeletedDomainCookies: new Set(),
|
||||
// };
|
||||
|
||||
// cleanCookies(sampleState, cookies, cleanupProperties);
|
||||
// expect(global.browser.cookies.remove).toBeCalledTimes(2);
|
||||
// });
|
||||
|
||||
// afterAll(() => {
|
||||
// delete global.browser;
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe("cleanCookiesOperation()", () => {
|
||||
//
|
||||
// let resolveStub = sinon.stub(browser.contextualIdentities, "query");
|
||||
// // let stub1;
|
||||
// // let stub2;
|
||||
// //
|
||||
// beforeEach(() => {
|
||||
// // stub1 = sinon.stub(cleanupService, "cleanCookies");
|
||||
// // stub1.resolves(new Set(["facebook.com", "amazon.com"]));
|
||||
// //
|
||||
// // stub2 = sinon.stub(cleanupService, "returnSetOfOpenTabDomains");
|
||||
// // stub2.resolves({});
|
||||
// browser.cookies.getAll.resolves({});
|
||||
// resolveStub.resolves([{cookieStoreId: "firefox-container-1"}, {cookieStoreId: "firefox-container-2"}, {cookieStoreId: "firefox-container-3"}, {cookieStoreId: "firefox-container-4"}]);
|
||||
// });
|
||||
//
|
||||
//
|
||||
// it("should return 5 for call count of browser.cookies.getAll with contextualIdentities enabled", () => {
|
||||
// return cleanCookiesOperation(sampleState, {greyCleanup: false, ignoreOpenTabs: false})
|
||||
// .then((setOfDeletedDomainCookies) => {
|
||||
// assert.strictEqual(browser.cookies.getAll.callCount, 5);
|
||||
// return Promise.resolve();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// // after(() => {
|
||||
// // stub1.restore();
|
||||
// // });
|
||||
// });
|
||||
|
||||
// afterEach(() => {
|
||||
// browser.flush();
|
||||
// });
|
||||
});
|
|
@ -0,0 +1,407 @@
|
|||
import { initialState } from '../src/redux/State';
|
||||
import {
|
||||
extractMainDomain,
|
||||
getHostname,
|
||||
getStoreId,
|
||||
globExpressionToRegExp,
|
||||
isAnIP,
|
||||
isAWebpage,
|
||||
prepareCookieDomain,
|
||||
returnOptionalCookieAPIAttributes,
|
||||
} from '../src/services/Libs';
|
||||
// ToDo: returnMatchedExpressionObject, getSetting
|
||||
|
||||
const mockCookie: browser.cookies.Cookie = {
|
||||
domain: 'domain.com',
|
||||
hostOnly: true,
|
||||
httpOnly: true,
|
||||
name: 'blah',
|
||||
path: '/',
|
||||
secure: true,
|
||||
session: true,
|
||||
storeId: 'default',
|
||||
value: 'test value',
|
||||
};
|
||||
|
||||
describe('Library Functions', () => {
|
||||
describe('extractMainDomain()', () => {
|
||||
it('should return domain.com from domain.com', () => {
|
||||
expect(extractMainDomain('domain.com')).toBe('domain.com');
|
||||
});
|
||||
|
||||
it('should return domain.com from sub.domain.com', () => {
|
||||
expect(extractMainDomain('sub.domain.com')).toBe('domain.com');
|
||||
});
|
||||
|
||||
it('should return domain.com from sub.sub.domain.com', () => {
|
||||
expect(extractMainDomain('sub.sub.domain.com')).toBe('domain.com');
|
||||
});
|
||||
|
||||
it('should return domain.com from sub.sub.sub.domain.com', () => {
|
||||
expect(extractMainDomain('sub.sub.sub.domain.com')).toBe('domain.com');
|
||||
});
|
||||
|
||||
it('should return example.co.uk from sub.example.co.uk', () => {
|
||||
expect(extractMainDomain('sub.example.co.uk')).toBe('example.co.uk');
|
||||
});
|
||||
|
||||
it('should return example.com.br from sub.example.com.br', () => {
|
||||
expect(extractMainDomain('sub.example.com.br')).toBe('example.com.br');
|
||||
});
|
||||
|
||||
it('should return the ip address from an ip address', () => {
|
||||
expect(extractMainDomain('127.0.0.1')).toBe('127.0.0.1');
|
||||
});
|
||||
|
||||
it('should return the srv-test01 from an srv-test01', () => {
|
||||
expect(extractMainDomain('srv-test01')).toBe('srv-test01');
|
||||
});
|
||||
|
||||
it('should return the test.i2p from an test.i2p', () => {
|
||||
expect(extractMainDomain('test.i2p')).toBe('test.i2p');
|
||||
});
|
||||
|
||||
it('should return domain.com from .domain.com.', () => {
|
||||
expect(extractMainDomain('domain.com.')).toBe('domain.com');
|
||||
});
|
||||
|
||||
it('should return nothing on empty string', () => {
|
||||
expect(extractMainDomain('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('prepareCookieDomain()', () => {
|
||||
it('should return https://google.com', () => {
|
||||
expect(
|
||||
prepareCookieDomain({
|
||||
...mockCookie,
|
||||
domain: 'google.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
}),
|
||||
).toBe('https://google.com/');
|
||||
});
|
||||
|
||||
it('should return http://google.com with a removed leading .', () => {
|
||||
expect(
|
||||
prepareCookieDomain({
|
||||
...mockCookie,
|
||||
domain: '.google.com',
|
||||
path: '/test',
|
||||
secure: false,
|
||||
}),
|
||||
).toBe('http://google.com/test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStoreId()', () => {
|
||||
const contextualIdentitiesFalseChrome = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Chrome',
|
||||
},
|
||||
settings: {
|
||||
contextualIdentities: {
|
||||
id: 7,
|
||||
name: 'contextualIdentities',
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const contextualIdentitiesFalseFF = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Firefox',
|
||||
},
|
||||
settings: {
|
||||
contextualIdentities: {
|
||||
id: 7,
|
||||
name: 'contextualIdentities',
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
const contextualIdentitiesTrue = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Firefox',
|
||||
},
|
||||
settings: {
|
||||
contextualIdentities: {
|
||||
id: 7,
|
||||
name: 'contextualIdentities',
|
||||
value: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Default storeIds
|
||||
it('should return default from firefox-default', () => {
|
||||
expect(getStoreId(contextualIdentitiesFalseFF, 'firefox-default')).toBe(
|
||||
'default',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return default from Chrome and storeId 0', () => {
|
||||
expect(getStoreId(contextualIdentitiesFalseChrome, '0')).toBe('default');
|
||||
});
|
||||
|
||||
// Private storeIds
|
||||
it('should return firefox-private from Firefox and storeId firefox-private (private)', () => {
|
||||
expect(getStoreId(contextualIdentitiesFalseFF, 'firefox-private')).toBe(
|
||||
'firefox-private',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return firefox-private from Firefox and storeId firefox-private (private) with containers', () => {
|
||||
expect(getStoreId(contextualIdentitiesTrue, 'firefox-private')).toBe(
|
||||
'firefox-private',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return private from Chrome and storeId 1 (private)', () => {
|
||||
expect(getStoreId(contextualIdentitiesFalseChrome, '1')).toBe('private');
|
||||
});
|
||||
|
||||
// Containers
|
||||
it('should return firefox-container-1 from Firefox and Containers on', () => {
|
||||
expect(getStoreId(contextualIdentitiesTrue, 'firefox-container-1')).toBe(
|
||||
'firefox-container-1',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return default from Firefox and storeId firefox-container-1 with Containers off', () => {
|
||||
expect(
|
||||
getStoreId(contextualIdentitiesFalseFF, 'firefox-container-1'),
|
||||
).toBe('default');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHostname()', () => {
|
||||
it('should return en.wikipedia.org from https://en.wikipedia.org/wiki/Cat', () => {
|
||||
expect(getHostname('https://en.wikipedia.org/wiki/Cat')).toBe(
|
||||
'en.wikipedia.org',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return yahoo.com from http://yahoo.com', () => {
|
||||
expect(getHostname('http://yahoo.com')).toBe('yahoo.com');
|
||||
});
|
||||
|
||||
it('should return scotiaonline.scotiabank.com from https://www1.scotiaonline.scotiabank.com/online/authentication/authentication.bns', () => {
|
||||
expect(
|
||||
getHostname(
|
||||
'https://www1.scotiaonline.scotiabank.com/online/authentication/authentication.bns',
|
||||
),
|
||||
).toBe('scotiaonline.scotiabank.com');
|
||||
});
|
||||
|
||||
it('should return mint.com from https://wwws.mint.com', () => {
|
||||
expect(getHostname('https://wwws.mint.com')).toBe('mint.com');
|
||||
});
|
||||
|
||||
it('should return an empty string from invalid URLs', () => {
|
||||
expect(getHostname('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAWebpage()', () => {
|
||||
it('should return true from https://en.wikipedia.org/wiki/Cat', () => {
|
||||
expect(isAWebpage('https://en.wikipedia.org/wiki/Cat')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true from http://yahoo.com', () => {
|
||||
expect(isAWebpage('http://yahoo.com')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false from random', () => {
|
||||
expect(isAWebpage('random')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false from extension page', () => {
|
||||
expect(isAWebpage('moz-extension://test/settings/settings.html')).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAnIP()', () => {
|
||||
it('should return false from https://en.wikipedia.org/wiki/Cat', () => {
|
||||
expect(isAnIP('https://en.wikipedia.org/wiki/Cat')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false from http://yahoo.com', () => {
|
||||
expect(isAnIP('http://yahoo.com')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false from random', () => {
|
||||
expect(isAnIP('random')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false from extension page', () => {
|
||||
expect(isAnIP('moz-extension://test/settings/settings.html')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true from http ip', () => {
|
||||
expect(isAnIP('http://192.168.1.1/')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true from https ip', () => {
|
||||
expect(isAnIP('https://192.168.1.1/')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('globExpressionToRegExp', () => {
|
||||
it('should match example.com for example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('example.com'));
|
||||
expect(regExp.test('example.com')).toBe(true);
|
||||
});
|
||||
it('should not match badexample.com for example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('example.com'));
|
||||
expect(regExp.test('badexample.com')).toBe(false);
|
||||
});
|
||||
it('should match example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('example.com')).toBe(true);
|
||||
});
|
||||
it('should match a.example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('a.example.com')).toBe(true);
|
||||
});
|
||||
it('should match a.b.example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('a.b.example.com')).toBe(true);
|
||||
});
|
||||
it('should match a.b-c.example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('a.b-c.example.com')).toBe(true);
|
||||
});
|
||||
it('should match a.b_c.example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('a.b_c.example.com')).toBe(true);
|
||||
});
|
||||
it('should match sub-with-strage_chars.example.another.sub.example.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(
|
||||
regExp.test('sub-with-strage_chars.example.another.sub.example.com'),
|
||||
).toBe(true);
|
||||
});
|
||||
it('should not match badexample.com for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('badexample.com')).toBe(false);
|
||||
});
|
||||
it('should not match bad.example.com.others.org for *.example.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.example.com'));
|
||||
expect(regExp.test('bad.example.com.others.org')).toBe(false);
|
||||
});
|
||||
it('should equal ^.*$ for just *', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*'));
|
||||
expect(regExp.toString()).toBe('/^.*$/');
|
||||
});
|
||||
it('should match github.com with git*b.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('git*b.com'));
|
||||
expect(regExp.test('github.com')).toBe(true);
|
||||
});
|
||||
it('should match sub.gitlab.com with *.git*b.com', () => {
|
||||
const regExp = new RegExp(globExpressionToRegExp('*.git*b.com'));
|
||||
expect(regExp.test('sub.gitlab.com')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('returnOptionalCookieAPIAttributes()', () => {
|
||||
it('should return an object with an undefined firstPartyDomain', () => {
|
||||
const state = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Firefox',
|
||||
firstPartyIsolateSetting: true,
|
||||
},
|
||||
};
|
||||
const cookieAPIAttributes = {
|
||||
...mockCookie,
|
||||
domain: 'example.com',
|
||||
};
|
||||
const results = returnOptionalCookieAPIAttributes(
|
||||
state,
|
||||
cookieAPIAttributes,
|
||||
);
|
||||
expect(results).toEqual(
|
||||
expect.objectContaining({
|
||||
domain: 'example.com',
|
||||
firstPartyDomain: undefined,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an object the same object with a firstPartyDomain', () => {
|
||||
const state = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Firefox',
|
||||
firstPartyIsolateSetting: true,
|
||||
},
|
||||
};
|
||||
const cookieAPIAttributes = {
|
||||
...mockCookie,
|
||||
domain: 'example.com',
|
||||
firstPartyDomain: 'example.com',
|
||||
};
|
||||
const results = returnOptionalCookieAPIAttributes(
|
||||
state,
|
||||
cookieAPIAttributes,
|
||||
);
|
||||
expect(results).toEqual(
|
||||
expect.objectContaining({
|
||||
domain: 'example.com',
|
||||
firstPartyDomain: 'example.com',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an object with no firstPartyDomain (Setting false)', () => {
|
||||
const state = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Firefox',
|
||||
firstPartyIsolateSetting: false,
|
||||
},
|
||||
};
|
||||
const cookieAPIAttributes = {
|
||||
...mockCookie,
|
||||
firstPartyDomain: '',
|
||||
};
|
||||
const results = returnOptionalCookieAPIAttributes(
|
||||
state,
|
||||
cookieAPIAttributes,
|
||||
);
|
||||
expect(results).toEqual(
|
||||
expect.not.objectContaining({
|
||||
firstPartyDomain: '',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return an object with no firstPartyDomain (Browser other than FF)', () => {
|
||||
const state = {
|
||||
...initialState,
|
||||
cache: {
|
||||
browserDetect: 'Chrome',
|
||||
firstPartyIsolateSetting: false,
|
||||
},
|
||||
};
|
||||
const cookieAPIAttributes = {
|
||||
...mockCookie,
|
||||
firstPartyDomain: '',
|
||||
};
|
||||
const results = returnOptionalCookieAPIAttributes(
|
||||
state,
|
||||
cookieAPIAttributes,
|
||||
);
|
||||
expect(results).toEqual(
|
||||
expect.not.objectContaining({
|
||||
firstPartyDomain: '',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,191 @@
|
|||
import { cookieDeletedCounterTotal, lists } from '../src/redux/Reducers';
|
||||
import { ReduxConstants } from '../src/typings/ReduxConstants';
|
||||
|
||||
const mockExpression: Expression = {
|
||||
expression: '',
|
||||
listType: ListType.WHITE,
|
||||
storeId: 'default',
|
||||
};
|
||||
|
||||
describe('Reducer', () => {
|
||||
describe('cookieDeletedCounterTotal', () => {
|
||||
const state = 5;
|
||||
|
||||
it('should return 0', () => {
|
||||
const newState = cookieDeletedCounterTotal(state, {
|
||||
type: ReduxConstants.RESET_COOKIE_DELETED_COUNTER,
|
||||
});
|
||||
expect(newState).toBe(0);
|
||||
});
|
||||
it('should return 6', () => {
|
||||
const newState = cookieDeletedCounterTotal(state, {
|
||||
type: ReduxConstants.INCREMENT_COOKIE_DELETED_COUNTER,
|
||||
});
|
||||
expect(newState).toBe(6);
|
||||
});
|
||||
it('should return 10', () => {
|
||||
const newState = cookieDeletedCounterTotal(state, {
|
||||
payload: 5,
|
||||
type: ReduxConstants.INCREMENT_COOKIE_DELETED_COUNTER,
|
||||
});
|
||||
expect(newState).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lists with no stuff', () => {
|
||||
const state = {};
|
||||
|
||||
it('should return google.com', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
...mockExpression,
|
||||
expression: 'google.com',
|
||||
listType: ListType.GREY,
|
||||
},
|
||||
type: ReduxConstants.ADD_EXPRESSION,
|
||||
});
|
||||
const firstExpression = newState.default[0];
|
||||
expect(firstExpression).toHaveProperty('expression', 'google.com');
|
||||
expect(firstExpression).toHaveProperty('listType', ListType.GREY);
|
||||
expect(firstExpression).toHaveProperty('id');
|
||||
});
|
||||
|
||||
it('should return youtube.com for firefox_container_2', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
expression: 'youtube.com',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'firefox_container_2',
|
||||
},
|
||||
type: ReduxConstants.ADD_EXPRESSION,
|
||||
});
|
||||
const firstExpression = newState.firefox_container_2[0];
|
||||
expect(firstExpression).toHaveProperty('expression', 'youtube.com');
|
||||
expect(firstExpression).toHaveProperty('listType', ListType.GREY);
|
||||
expect(firstExpression).toHaveProperty('id');
|
||||
});
|
||||
|
||||
it('should return google.com with a default listType of WHITE', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
...mockExpression,
|
||||
expression: 'google.com',
|
||||
},
|
||||
type: ReduxConstants.ADD_EXPRESSION,
|
||||
});
|
||||
const firstExpression = newState.default[0];
|
||||
expect(firstExpression).toHaveProperty('expression', 'google.com');
|
||||
expect(firstExpression).toHaveProperty('listType', ListType.WHITE);
|
||||
expect(firstExpression).toHaveProperty('id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('lists with stuff', () => {
|
||||
const state: StoreIdToExpressionList = {
|
||||
default: [
|
||||
{
|
||||
expression: 'messenger.com*',
|
||||
id: 'SyZbDbC1dW',
|
||||
listType: ListType.WHITE,
|
||||
storeId: 'default',
|
||||
},
|
||||
{
|
||||
expression: 'facebook.com*',
|
||||
id: 'B1eWwWRJOb',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'default',
|
||||
},
|
||||
],
|
||||
firefox_container_1: [
|
||||
{
|
||||
expression: 'messenger.com*',
|
||||
id: '456',
|
||||
listType: ListType.WHITE,
|
||||
storeId: 'firefox_container_1',
|
||||
},
|
||||
{
|
||||
expression: 'facebook.com*',
|
||||
id: '123',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'firefox_container_1',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
it('should return youtube.com on default', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
...mockExpression,
|
||||
expression: 'youtube.com',
|
||||
listType: ListType.WHITE,
|
||||
},
|
||||
type: ReduxConstants.ADD_EXPRESSION,
|
||||
});
|
||||
const newExpression = newState.default[1];
|
||||
expect(newExpression).toHaveProperty('expression', 'youtube.com');
|
||||
expect(newExpression).toHaveProperty('listType', ListType.WHITE);
|
||||
expect(newExpression).toHaveProperty('id');
|
||||
});
|
||||
|
||||
it('should return github.com on firefox_container_1', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
expression: 'github.com',
|
||||
listType: ListType.GREY,
|
||||
storeId: 'firefox_container_1',
|
||||
},
|
||||
type: ReduxConstants.ADD_EXPRESSION,
|
||||
});
|
||||
const newExpression = newState.firefox_container_1[2];
|
||||
expect(newExpression).toHaveProperty('expression', 'github.com');
|
||||
expect(newExpression).toHaveProperty('listType', ListType.GREY);
|
||||
expect(newExpression).toHaveProperty('id');
|
||||
});
|
||||
it('should return not return messenger.com on default', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
id: 'SyZbDbC1dW',
|
||||
storeId: 'default',
|
||||
},
|
||||
type: ReduxConstants.REMOVE_EXPRESSION,
|
||||
});
|
||||
expect(newState.default).not.toEqual(
|
||||
expect.arrayContaining(state.default as any[]),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return github.com and GREY for updated expression on default', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
...mockExpression,
|
||||
expression: 'github.com',
|
||||
id: 'SyZbDbC1dW',
|
||||
listType: ListType.GREY,
|
||||
},
|
||||
type: ReduxConstants.UPDATE_EXPRESSION,
|
||||
});
|
||||
|
||||
const newExpression = newState.default[1];
|
||||
expect(newExpression).toHaveProperty('expression', 'github.com');
|
||||
expect(newExpression).toHaveProperty('listType', ListType.GREY);
|
||||
expect(newExpression).toHaveProperty('id');
|
||||
});
|
||||
|
||||
it('should return google.com and WHITE for updated expression on firefox_container_1', () => {
|
||||
const newState = lists(state, {
|
||||
payload: {
|
||||
expression: 'google.com',
|
||||
id: '123',
|
||||
listType: ListType.WHITE,
|
||||
storeId: 'firefox_container_1',
|
||||
},
|
||||
type: ReduxConstants.UPDATE_EXPRESSION,
|
||||
});
|
||||
|
||||
const newExpression = newState.firefox_container_1[0];
|
||||
expect(newExpression).toHaveProperty('expression', 'google.com');
|
||||
expect(newExpression).toHaveProperty('listType', ListType.WHITE);
|
||||
expect(newExpression).toHaveProperty('id');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,176 @@
|
|||
// For a detailed explanation regarding each configuration property, visit:
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
|
||||
module.exports = {
|
||||
// All imported modules in your tests should be mocked automatically
|
||||
// automock: false,
|
||||
|
||||
// Stop running tests after the first failure
|
||||
// bail: false,
|
||||
|
||||
// Respect "browser" field in package.json when resolving modules
|
||||
// browser: false,
|
||||
|
||||
// The directory where Jest should store its cached dependency information
|
||||
// cacheDirectory: "/tmp/jest_0",
|
||||
|
||||
// Automatically clear mock calls and instances between every test
|
||||
clearMocks: true,
|
||||
|
||||
// Indicates whether the coverage information should be collected while executing the test
|
||||
// collectCoverage: false,
|
||||
|
||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
||||
// collectCoverageFrom: null,
|
||||
|
||||
// The directory where Jest should output its coverage files
|
||||
coverageDirectory: 'coverage',
|
||||
|
||||
// An array of regexp pattern strings used to skip coverage collection
|
||||
// coveragePathIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
// ],
|
||||
|
||||
// A list of reporter names that Jest uses when writing coverage reports
|
||||
// coverageReporters: [
|
||||
// "json",
|
||||
// "text",
|
||||
// "lcov",
|
||||
// "clover"
|
||||
// ],
|
||||
|
||||
// An object that configures minimum threshold enforcement for coverage results
|
||||
// coverageThreshold: null,
|
||||
|
||||
// Make calling deprecated APIs throw helpful error messages
|
||||
// errorOnDeprecated: false,
|
||||
|
||||
// Force coverage collection from ignored files usin a array of glob patterns
|
||||
// forceCoverageMatch: [],
|
||||
|
||||
// A path to a module which exports an async function that is triggered once before all test suites
|
||||
// globalSetup: null,
|
||||
|
||||
// A path to a module which exports an async function that is triggered once after all test suites
|
||||
// globalTeardown: null,
|
||||
|
||||
// A set of global variables that need to be available in all test environments
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsConfigFile: 'tsconfig.json',
|
||||
},
|
||||
},
|
||||
|
||||
// An array of directory names to be searched recursively up from the requiring module's location
|
||||
// moduleDirectories: [
|
||||
// "node_modules"
|
||||
// ],
|
||||
|
||||
// An array of file extensions your modules use
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js'],
|
||||
|
||||
// A map from regular expressions to module names that allow to stub out resources with a single module
|
||||
// moduleNameMapper: {},
|
||||
|
||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
||||
// modulePathIgnorePatterns: [],
|
||||
|
||||
// Activates notifications for test results
|
||||
// notify: false,
|
||||
|
||||
// An enum that specifies notification mode. Requires { notify: true }
|
||||
// notifyMode: "always",
|
||||
|
||||
// A preset that is used as a base for Jest's configuration
|
||||
// preset: ts-jest,
|
||||
|
||||
// Run tests from one or more projects
|
||||
// projects: null,
|
||||
|
||||
// Use this configuration option to add custom reporters to Jest
|
||||
// reporters: undefined,
|
||||
|
||||
// Automatically reset mock state between every test
|
||||
// resetMocks: false,
|
||||
|
||||
// Reset the module registry before running each individual test
|
||||
// resetModules: false,
|
||||
|
||||
// A path to a custom resolver
|
||||
// resolver: null,
|
||||
|
||||
// Automatically restore mock state between every test
|
||||
// restoreMocks: false,
|
||||
|
||||
// The root directory that Jest should scan for tests and modules within
|
||||
// rootDir: null,
|
||||
|
||||
// A list of paths to directories that Jest should use to search for files in
|
||||
// roots: [
|
||||
// "<rootDir>"
|
||||
// ],
|
||||
|
||||
// Allows you to use a custom runner instead of Jest's default test runner
|
||||
// runner: "jest-runner",
|
||||
|
||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
||||
// setupFiles: [],
|
||||
|
||||
// The path to a module that runs some code to configure or set up the testing framework before each test
|
||||
// setupTestFrameworkScriptFile: null,
|
||||
|
||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
||||
// snapshotSerializers: [],
|
||||
|
||||
// The test environment that will be used for testing
|
||||
testEnvironment: 'node',
|
||||
|
||||
// Options that will be passed to the testEnvironment
|
||||
// testEnvironmentOptions: {},
|
||||
|
||||
// Adds a location field to test results
|
||||
// testLocationInResults: false,
|
||||
|
||||
// The glob patterns Jest uses to detect test files
|
||||
testMatch: ['**/__tests__/*.+(ts|tsx|js)'],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
||||
// testPathIgnorePatterns: [
|
||||
// "/node_modules/"
|
||||
// ],
|
||||
|
||||
// The regexp pattern Jest uses to detect test files
|
||||
// testRegex: "",
|
||||
|
||||
// This option allows the use of a custom results processor
|
||||
// testResultsProcessor: null,
|
||||
|
||||
// This option allows use of a custom test runner
|
||||
// testRunner: "jasmine2",
|
||||
|
||||
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
||||
// testURL: "http://localhost",
|
||||
|
||||
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
||||
// timers: "real",
|
||||
|
||||
// A map from regular expressions to paths to transformers
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx)$': 'ts-jest',
|
||||
},
|
||||
|
||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
||||
transformIgnorePatterns: ['/node_modules/'],
|
||||
|
||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
||||
// unmockedModulePathPatterns: undefined,
|
||||
|
||||
// Indicates whether each individual test should be reported during the run
|
||||
// verbose: null,
|
||||
|
||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
||||
// watchPathIgnorePatterns: [],
|
||||
|
||||
// Whether to use watchman for file crawling
|
||||
// watchman: true,
|
||||
};
|
File diff suppressed because it is too large
Load Diff
68
package.json
68
package.json
|
@ -1,52 +1,46 @@
|
|||
{
|
||||
"name": "cookie-autodelete",
|
||||
"version": "1.4.2",
|
||||
"version": "3.0.0",
|
||||
"description": "Firefox and Chrome extension that manages Cookies",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"prop-types": "^15.6.0",
|
||||
"react": "^16.2.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-redux": "^5.0.6",
|
||||
"redux": "^3.7.2",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"react": "^16.6.3",
|
||||
"react-dom": "^16.6.3",
|
||||
"react-redux": "^6.0.0",
|
||||
"redux": "^4.0.1",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"redux-webext": "^1.1.2",
|
||||
"shortid": "^2.2.8"
|
||||
"shortid": "^2.2.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel |