aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/background/shared/versions/index.test.js (renamed from test/shared/versions/index.test.js)4
-rw-r--r--test/background/shared/versions/storage.test.js (renamed from test/shared/versions/storage.test.js)2
-rw-r--r--test/console/actions/console.test.js25
-rw-r--r--test/content/actions/addon.test.js25
-rw-r--r--test/content/reducers/addon.test.js24
-rw-r--r--test/settings/reducers/setting.test.js42
-rw-r--r--test/shared/blacklists.test.js42
-rw-r--r--test/shared/store/index.test.js110
8 files changed, 93 insertions, 181 deletions
diff --git a/test/shared/versions/index.test.js b/test/background/shared/versions/index.test.js
index d90f04c..d65dd9a 100644
--- a/test/shared/versions/index.test.js
+++ b/test/background/shared/versions/index.test.js
@@ -1,5 +1,5 @@
-import * as versions from 'shared/versions';
-import manifest from '../../../manifest.json';
+import * as versions from 'background/shared/versions';
+import manifest from '../../../../manifest.json';
describe("shared/versions/storage", () => {
describe('#checkUpdated', () => {
diff --git a/test/shared/versions/storage.test.js b/test/background/shared/versions/storage.test.js
index f541abf..f452516 100644
--- a/test/shared/versions/storage.test.js
+++ b/test/background/shared/versions/storage.test.js
@@ -1,4 +1,4 @@
-import * as storage from 'shared/versions/storage';
+import * as storage from 'background/shared/versions/storage';
describe("shared/versions/storage", () => {
describe('#load', () => {
diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.js
index 77855cd..10cd9fe 100644
--- a/test/console/actions/console.test.js
+++ b/test/console/actions/console.test.js
@@ -23,14 +23,6 @@ describe("console actions", () => {
});
});
- describe("showInfo", () => {
- it('create CONSOLE_SHOW_INFO action', () => {
- let action = consoleActions.showInfo('an info');
- expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO);
- expect(action.text).to.equal('an info');
- });
- });
-
describe("showError", () => {
it('create CONSOLE_SHOW_ERROR action', () => {
let action = consoleActions.showError('an error');
@@ -39,6 +31,14 @@ describe("console actions", () => {
});
});
+ describe("showInfo", () => {
+ it('create CONSOLE_SHOW_INFO action', () => {
+ let action = consoleActions.showInfo('an info');
+ expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO);
+ expect(action.text).to.equal('an info');
+ });
+ });
+
describe("hideCommand", () => {
it('create CONSOLE_HIDE_COMMAND action', () => {
let action = consoleActions.hideCommand();
@@ -54,15 +54,6 @@ describe("console actions", () => {
});
});
- describe("setCompletions", () => {
- it('create CONSOLE_SET_COMPLETIONS action', () => {
- let action = consoleActions.setCompletions('query', [1, 2, 3]);
- expect(action.type).to.equal(actions.CONSOLE_SET_COMPLETIONS);
- expect(action.completionSource).to.deep.equal('query');
- expect(action.completions).to.deep.equal([1, 2, 3]);
- });
- });
-
describe("completionPrev", () => {
it('create CONSOLE_COMPLETION_PREV action', () => {
let action = consoleActions.completionPrev();
diff --git a/test/content/actions/addon.test.js b/test/content/actions/addon.test.js
deleted file mode 100644
index 5f96372..0000000
--- a/test/content/actions/addon.test.js
+++ /dev/null
@@ -1,25 +0,0 @@
-import actions from 'content/actions';
-import * as addonActions from 'content/actions/addon';
-
-describe("addon actions", () => {
- describe("enable", () => {
- it('create ADDON_ENABLE action', () => {
- let action = addonActions.enable();
- expect(action.type).to.equal(actions.ADDON_ENABLE);
- });
- });
-
- describe("disable", () => {
- it('create ADDON_DISABLE action', () => {
- let action = addonActions.disable();
- expect(action.type).to.equal(actions.ADDON_DISABLE);
- });
- });
-
- describe("toggle", () => {
- it('create ADDON_TOGGLE_ENABLED action', () => {
- let action = addonActions.toggleEnabled();
- expect(action.type).to.equal(actions.ADDON_TOGGLE_ENABLED);
- });
- });
-});
diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.js
index 8c546d2..d4eb845 100644
--- a/test/content/reducers/addon.test.js
+++ b/test/content/reducers/addon.test.js
@@ -7,31 +7,11 @@ describe("addon reducer", () => {
expect(state).to.have.property('enabled', true);
});
- it('return next state for ADDON_ENABLE', () => {
- let action = { type: actions.ADDON_ENABLE};
+ it('return next state for ADDON_SET_ENABLED', () => {
+ let action = { type: actions.ADDON_SET_ENABLED, enabled: true };
let prev = { enabled: false };
let state = addonReducer(prev, action);
expect(state.enabled).is.equal(true);
});
-
- it('return next state for ADDON_DISABLE', () => {
- let action = { type: actions.ADDON_DISABLE};
- let prev = { enabled: true };
- let state = addonReducer(prev, action);
-
- expect(state.enabled).is.equal(false);
- });
-
- it('return next state for ADDON_TOGGLE_ENABLED', () => {
- let action = { type: actions.ADDON_TOGGLE_ENABLED };
- let state = { enabled: false };
-
- state = addonReducer(state, action);
- expect(state.enabled).is.equal(true);
-
- state = addonReducer(state, action);
- expect(state.enabled).is.equal(false);
- });
-
});
diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.js
index b9579cf..d800394 100644
--- a/test/settings/reducers/setting.test.js
+++ b/test/settings/reducers/setting.test.js
@@ -1,21 +1,55 @@
import actions from 'settings/actions';
import settingReducer from 'settings/reducers/setting';
-describe("setting reducer", () => {
+describe("settings setting reducer", () => {
it('return the initial state', () => {
let state = settingReducer(undefined, {});
expect(state).to.have.deep.property('json', '');
- expect(state).to.have.deep.property('value', {});
+ expect(state).to.have.deep.property('form', null);
+ expect(state).to.have.deep.property('error', '');
});
it('return next state for SETTING_SET_SETTINGS', () => {
let action = {
type: actions.SETTING_SET_SETTINGS,
+ source: 'json',
json: '{ "key": "value" }',
- value: { key: 123 },
+ form: {},
};
let state = settingReducer(undefined, action);
+ expect(state).to.have.deep.property('source', 'json');
expect(state).to.have.deep.property('json', '{ "key": "value" }');
- expect(state).to.have.deep.property('value', { key: 123 });
+ expect(state).to.have.deep.property('form', {});
+ });
+
+ it('return next state for SETTING_SHOW_ERROR', () => {
+ let action = {
+ type: actions.SETTING_SHOW_ERROR,
+ text: 'bad value',
+ json: '{}',
+ };
+ let state = settingReducer(undefined, action);
+ expect(state).to.have.deep.property('error', 'bad value');
+ expect(state).to.have.deep.property('json', '{}');
+ });
+
+ it('return next state for SETTING_SWITCH_TO_FORM', () => {
+ let action = {
+ type: actions.SETTING_SWITCH_TO_FORM,
+ form: {},
+ };
+ let state = settingReducer(undefined, action);
+ expect(state).to.have.deep.property('form', {});
+ expect(state).to.have.deep.property('source', 'form');
+ });
+
+ it('return next state for SETTING_SWITCH_TO_JSON', () => {
+ let action = {
+ type: actions.SETTING_SWITCH_TO_JSON,
+ json: '{}',
+ };
+ let state = settingReducer(undefined, action);
+ expect(state).to.have.deep.property('json', '{}');
+ expect(state).to.have.deep.property('source', 'json');
});
});
diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.js
new file mode 100644
index 0000000..87e89c5
--- /dev/null
+++ b/test/shared/blacklists.test.js
@@ -0,0 +1,42 @@
+import { includes } from 'shared/blacklists';
+
+describe("shared/blacklist", () => {
+ it('matches by *', () => {
+ let blacklist = ['*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ })
+
+ it('matches by hostname', () => {
+ let blacklist = ['github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.false;
+ expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true;
+ expect(includes(blacklist, 'https://github.org')).to.be.false;
+ expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false;
+ })
+
+ it('matches by hostname with wildcard', () => {
+ let blacklist = ['*.github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.true;
+ })
+
+ it('matches by path', () => {
+ let blacklist = ['github.com/abc'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches by path with wildcard', () => {
+ let blacklist = ['github.com/abc*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+});
diff --git a/test/shared/store/index.test.js b/test/shared/store/index.test.js
deleted file mode 100644
index 5b69b40..0000000
--- a/test/shared/store/index.test.js
+++ /dev/null
@@ -1,110 +0,0 @@
-import { createStore } from 'shared/store';
-
-describe("Store class", () => {
- const reducer = (state, action) => {
- if (state == undefined) {
- return 0;
- }
- return state + action;
- };
-
- describe("#dispatch", () => {
- it('transit status by immediate action', () => {
- let store = createStore(reducer);
- store.dispatch(10);
- expect(store.getState()).to.equal(10);
-
- store.dispatch(-20);
- expect(store.getState()).to.equal(-10);
- });
-
- it('returns next state by immediate action', () => {
- let store = createStore(reducer);
- let dispatchedAction = store.dispatch(11);
- expect(dispatchedAction).to.equal(11);
- });
-
- it('transit status by Promise action', () => {
- let store = createStore(reducer);
- let p1 = Promise.resolve(10);
-
- return store.dispatch(p1).then(() => {
- expect(store.getState()).to.equal(10);
- }).then(() => {
- store.dispatch(Promise.resolve(-20));
- }).then(() => {
- expect(store.getState()).to.equal(-10);
- });
- });
-
- it('returns next state by promise action', () => {
- let store = createStore(reducer);
- let dispatchedAction = store.dispatch(Promise.resolve(11));
- return dispatchedAction.then((value) => {
- expect(value).to.equal(11);
- });
- });
- });
-
- describe("#subscribe", () => {
- it('invoke callback', (done) => {
- let store = createStore(reducer);
- store.subscribe(() => {
- expect(store.getState()).to.equal(15);
- done();
- });
- store.dispatch(15);
- });
-
- it('propagate sender object', (done) => {
- let store = createStore(reducer);
- store.subscribe((sender) => {
- expect(sender).to.equal('sender');
- done();
- });
- store.dispatch(15, 'sender');
- });
- })
-
- describe("catcher", () => {
- it('catch an error in reducer on initializing by immediate action', (done) => {
- let store = createStore(() => {
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- });
-
- it('catch an error in reducer on initializing by immediate action', (done) => {
- let store = createStore((state, action) => {
- if (state === undefined) return 0;
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(20);
- });
-
- it('catch an error in reducer on initializing by promise action', (done) => {
- let store = createStore((state, action) => {
- if (state === undefined) return 0;
- throw new Error();
- }, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(Promise.resolve(20));
- });
-
- it('catch an error in promise action', (done) => {
- let store = createStore((state, action) => 0, (e) => {
- expect(e).to.be.an('error');
- done();
- });
- store.dispatch(new Promise(() => { throw new Error() }));
- });
- })
-});
-