aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/background/actions/find.test.js12
-rw-r--r--test/background/actions/tab.test.js13
-rw-r--r--test/background/reducers/find.test.js18
-rw-r--r--test/background/reducers/setting.test.js2
-rw-r--r--test/background/reducers/tab.test.js22
-rw-r--r--test/console/actions/console.test.js7
-rw-r--r--test/console/reducers/console.test.js7
-rw-r--r--test/content/actions/addon.test.js1
-rw-r--r--test/content/actions/follow-controller.test.js1
-rw-r--r--test/content/actions/input.test.js1
-rw-r--r--test/content/actions/setting.test.js3
-rw-r--r--test/content/components/common/follow.test.js1
-rw-r--r--test/content/components/common/hint.test.js1
-rw-r--r--test/content/components/common/input.test.js1
-rw-r--r--test/content/hint-key-producer.test.js1
-rw-r--r--test/content/navigates.test.js1
-rw-r--r--test/content/reducers/addon.test.js1
-rw-r--r--test/content/reducers/find.test.js3
-rw-r--r--test/content/reducers/follow-controller.test.js1
-rw-r--r--test/content/reducers/input.test.js1
-rw-r--r--test/content/reducers/setting.test.js1
-rw-r--r--test/main.js6
-rw-r--r--test/settings/components/form/blacklist-form.test.jsx1
-rw-r--r--test/settings/components/form/keymaps-form.test.jsx1
-rw-r--r--test/settings/components/form/properties-form.test.jsx1
-rw-r--r--test/settings/components/form/search-engine-form.test.jsx1
-rw-r--r--test/settings/components/ui/input.test.jsx1
-rw-r--r--test/settings/reducers/setting.test.js1
-rw-r--r--test/shared/commands/parsers.test.js1
-rw-r--r--test/shared/settings/validator.test.js1
-rw-r--r--test/shared/settings/values.test.js1
-rw-r--r--test/shared/store/index.test.js1
-rw-r--r--test/shared/utils/keys.test.js1
-rw-r--r--test/shared/utils/re.test.js1
-rw-r--r--test/shared/versions/index.test.js55
-rw-r--r--test/shared/versions/storage.test.js39
36 files changed, 180 insertions, 31 deletions
diff --git a/test/background/actions/find.test.js b/test/background/actions/find.test.js
new file mode 100644
index 0000000..6b0b846
--- /dev/null
+++ b/test/background/actions/find.test.js
@@ -0,0 +1,12 @@
+import actions from 'background/actions';
+import * as findActions from 'background/actions/find';
+
+describe("find actions", () => {
+ describe("setKeyword", () => {
+ it('create FIND_SET_KEYWORD action', () => {
+ let action = findActions.setKeyword('banana');
+ expect(action.type).to.equal(actions.FIND_SET_KEYWORD);
+ expect(action.keyword).to.equal('banana');
+ });
+ });
+});
diff --git a/test/background/actions/tab.test.js b/test/background/actions/tab.test.js
new file mode 100644
index 0000000..ab57374
--- /dev/null
+++ b/test/background/actions/tab.test.js
@@ -0,0 +1,13 @@
+import actions from 'background/actions';
+import * as tabActions from 'background/actions/tab';
+
+describe("tab actions", () => {
+ describe("selected", () => {
+ it('create TAB_SELECTED action', () => {
+ let action = tabActions.selected(123);
+ expect(action.type).to.equal(actions.TAB_SELECTED);
+ expect(action.tabId).to.equal(123);
+ });
+ });
+});
+
diff --git a/test/background/reducers/find.test.js b/test/background/reducers/find.test.js
new file mode 100644
index 0000000..c366223
--- /dev/null
+++ b/test/background/reducers/find.test.js
@@ -0,0 +1,18 @@
+import actions from 'background/actions';
+import findReducer from 'background/reducers/find';
+
+describe("find reducer", () => {
+ it('return the initial state', () => {
+ let state = findReducer(undefined, {});
+ expect(state).to.have.deep.property('keyword', null);
+ });
+
+ it('return next state for FIND_SET_KEYWORD', () => {
+ let action = {
+ type: actions.FIND_SET_KEYWORD,
+ keyword: 'cherry',
+ };
+ let state = findReducer(undefined, action);
+ expect(state).to.have.deep.property('keyword', 'cherry')
+ });
+});
diff --git a/test/background/reducers/setting.test.js b/test/background/reducers/setting.test.js
index 2ef98cb..24d02ea 100644
--- a/test/background/reducers/setting.test.js
+++ b/test/background/reducers/setting.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'background/actions';
import settingReducer from 'background/reducers/setting';
@@ -30,7 +29,6 @@ describe("setting reducer", () => {
};
state = settingReducer(state, action);
- console.log(state);
expect(state.value.properties).to.have.property('smoothscroll', true);
expect(state.value.properties).to.have.property('encoding', 'utf-8');
});
diff --git a/test/background/reducers/tab.test.js b/test/background/reducers/tab.test.js
new file mode 100644
index 0000000..09fa8a7
--- /dev/null
+++ b/test/background/reducers/tab.test.js
@@ -0,0 +1,22 @@
+import actions from 'background/actions';
+import tabReducer from 'background/reducers/tab';
+
+describe("tab reducer", () => {
+ it('return the initial state', () => {
+ let state = tabReducer(undefined, {});
+ expect(state.previousSelected).to.equal(-1);
+ expect(state.currentSelected).to.equal(-1);
+ });
+
+ it('return next state for TAB_SELECTED', () => {
+ let state = undefined;
+
+ state = tabReducer(state, { type: actions.TAB_SELECTED, tabId: 123 });
+ expect(state.previousSelected).to.equal(-1);
+ expect(state.currentSelected).to.equal(123);
+
+ state = tabReducer(state, { type: actions.TAB_SELECTED, tabId: 456 });
+ expect(state.previousSelected).to.equal(123);
+ expect(state.currentSelected).to.equal(456);
+ });
+});
diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.js
index 9af13d4..77855cd 100644
--- a/test/console/actions/console.test.js
+++ b/test/console/actions/console.test.js
@@ -1,8 +1,13 @@
-import { expect } from "chai";
import actions from 'console/actions';
import * as consoleActions from 'console/actions/console';
describe("console actions", () => {
+ describe('hide', () => {
+ it('create CONSOLE_HIDE action', () => {
+ let action = consoleActions.hide();
+ expect(action.type).to.equal(actions.CONSOLE_HIDE);
+ });
+ });
describe("showCommand", () => {
it('create CONSOLE_SHOW_COMMAND action', () => {
let action = consoleActions.showCommand('hello');
diff --git a/test/console/reducers/console.test.js b/test/console/reducers/console.test.js
index 438d513..db40088 100644
--- a/test/console/reducers/console.test.js
+++ b/test/console/reducers/console.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'console/actions';
import reducer from 'console/reducers';
@@ -13,6 +12,12 @@ describe("console reducer", () => {
expect(state).to.have.property('itemSelection', -1);
});
+ it('return next state for CONSOLE_HIDE', () => {
+ let action = { type: actions.CONSOLE_HIDE };
+ let state = reducer({ mode: 'error' }, action);
+ expect(state).to.have.property('mode', '');
+ })
+
it('return next state for CONSOLE_SHOW_COMMAND', () => {
let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
let state = reducer({}, action);
diff --git a/test/content/actions/addon.test.js b/test/content/actions/addon.test.js
index 7f244dc..5f96372 100644
--- a/test/content/actions/addon.test.js
+++ b/test/content/actions/addon.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import * as addonActions from 'content/actions/addon';
diff --git a/test/content/actions/follow-controller.test.js b/test/content/actions/follow-controller.test.js
index 298abf2..718a90a 100644
--- a/test/content/actions/follow-controller.test.js
+++ b/test/content/actions/follow-controller.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import * as followControllerActions from 'content/actions/follow-controller';
diff --git a/test/content/actions/input.test.js b/test/content/actions/input.test.js
index 30705d2..fe9db5f 100644
--- a/test/content/actions/input.test.js
+++ b/test/content/actions/input.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import * as inputActions from 'content/actions/input';
diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.js
index 1248edf..10f6807 100644
--- a/test/content/actions/setting.test.js
+++ b/test/content/actions/setting.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import * as settingActions from 'content/actions/setting';
@@ -23,6 +22,8 @@ describe("setting actions", () => {
let map = new Map(keymaps);
expect(map).to.have.deep.all.keys(
[
+ [{ key: 'Esc', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }],
+ [{ key: '[', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }],
[{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }],
[{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
diff --git a/test/content/components/common/follow.test.js b/test/content/components/common/follow.test.js
index 1fc935e..4fc11d0 100644
--- a/test/content/components/common/follow.test.js
+++ b/test/content/components/common/follow.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import FollowComponent from 'content/components/common/follow';
describe('FollowComponent', () => {
diff --git a/test/content/components/common/hint.test.js b/test/content/components/common/hint.test.js
index ced2fde..42d571f 100644
--- a/test/content/components/common/hint.test.js
+++ b/test/content/components/common/hint.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import Hint from 'content/components/common/hint';
describe('Hint class', () => {
diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.js
index a346cf6..2ba5507 100644
--- a/test/content/components/common/input.test.js
+++ b/test/content/components/common/input.test.js
@@ -1,5 +1,4 @@
import InputComponent from 'content/components/common/input';
-import { expect } from "chai";
describe('InputComponent', () => {
it('register callbacks', () => {
diff --git a/test/content/hint-key-producer.test.js b/test/content/hint-key-producer.test.js
index b2171ba..dcf477d 100644
--- a/test/content/hint-key-producer.test.js
+++ b/test/content/hint-key-producer.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import HintKeyProducer from 'content/hint-key-producer';
describe('HintKeyProducer class', () => {
diff --git a/test/content/navigates.test.js b/test/content/navigates.test.js
index f1f0741..1d73344 100644
--- a/test/content/navigates.test.js
+++ b/test/content/navigates.test.js
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import * as navigates from 'content/navigates';
const testRel = (done, rel, html) => {
diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.js
index 93f97e8..8c546d2 100644
--- a/test/content/reducers/addon.test.js
+++ b/test/content/reducers/addon.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import addonReducer from 'content/reducers/addon';
diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.js
index 93625da..a8c30d7 100644
--- a/test/content/reducers/find.test.js
+++ b/test/content/reducers/find.test.js
@@ -1,11 +1,10 @@
-import { expect } from "chai";
import actions from 'content/actions';
import findReducer from 'content/reducers/find';
describe("find reducer", () => {
it('return the initial state', () => {
let state = findReducer(undefined, {});
- expect(state).to.have.property('keyword', '');
+ expect(state).to.have.property('keyword', null);
expect(state).to.have.property('found', false);
});
diff --git a/test/content/reducers/follow-controller.test.js b/test/content/reducers/follow-controller.test.js
index f4b91d2..8a4c2d4 100644
--- a/test/content/reducers/follow-controller.test.js
+++ b/test/content/reducers/follow-controller.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import followControllerReducer from 'content/reducers/follow-controller';
diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.js
index d0b5655..0011943 100644
--- a/test/content/reducers/input.test.js
+++ b/test/content/reducers/input.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import inputReducer from 'content/reducers/input';
diff --git a/test/content/reducers/setting.test.js b/test/content/reducers/setting.test.js
index 634b299..4e4c095 100644
--- a/test/content/reducers/setting.test.js
+++ b/test/content/reducers/setting.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'content/actions';
import settingReducer from 'content/reducers/setting';
diff --git a/test/main.js b/test/main.js
new file mode 100644
index 0000000..3aeae69
--- /dev/null
+++ b/test/main.js
@@ -0,0 +1,6 @@
+import chai from 'chai';
+const browserFake = require('webextensions-api-fake');
+const browser = browserFake();
+
+global.expect = chai.expect;
+global.browser = browser;
diff --git a/test/settings/components/form/blacklist-form.test.jsx b/test/settings/components/form/blacklist-form.test.jsx
index 95f5cde..1c46943 100644
--- a/test/settings/components/form/blacklist-form.test.jsx
+++ b/test/settings/components/form/blacklist-form.test.jsx
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import { h, render } from 'preact';
import BlacklistForm from 'settings/components/form/blacklist-form'
diff --git a/test/settings/components/form/keymaps-form.test.jsx b/test/settings/components/form/keymaps-form.test.jsx
index e9f9359..55edf8c 100644
--- a/test/settings/components/form/keymaps-form.test.jsx
+++ b/test/settings/components/form/keymaps-form.test.jsx
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import { h, render } from 'preact';
import KeymapsForm from 'settings/components/form/keymaps-form'
diff --git a/test/settings/components/form/properties-form.test.jsx b/test/settings/components/form/properties-form.test.jsx
index 4807361..0efe382 100644
--- a/test/settings/components/form/properties-form.test.jsx
+++ b/test/settings/components/form/properties-form.test.jsx
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import { h, render } from 'preact';
import PropertiesForm from 'settings/components/form/properties-form'
diff --git a/test/settings/components/form/search-engine-form.test.jsx b/test/settings/components/form/search-engine-form.test.jsx
index 9600cae..c52419d 100644
--- a/test/settings/components/form/search-engine-form.test.jsx
+++ b/test/settings/components/form/search-engine-form.test.jsx
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import { h, render } from 'preact';
import SearchForm from 'settings/components/form/search-form'
diff --git a/test/settings/components/ui/input.test.jsx b/test/settings/components/ui/input.test.jsx
index 98f2cef..0711bba 100644
--- a/test/settings/components/ui/input.test.jsx
+++ b/test/settings/components/ui/input.test.jsx
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import { h, render } from 'preact';
import Input from 'settings/components/ui/input'
diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.js
index 3468d4b..b9579cf 100644
--- a/test/settings/reducers/setting.test.js
+++ b/test/settings/reducers/setting.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import actions from 'settings/actions';
import settingReducer from 'settings/reducers/setting';
diff --git a/test/shared/commands/parsers.test.js b/test/shared/commands/parsers.test.js
index 0a1960c..1910f07 100644
--- a/test/shared/commands/parsers.test.js
+++ b/test/shared/commands/parsers.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import * as parsers from 'shared/commands/parsers';
describe("shared/commands/parsers", () => {
diff --git a/test/shared/settings/validator.test.js b/test/shared/settings/validator.test.js
index 61d976a..9bbfa3e 100644
--- a/test/shared/settings/validator.test.js
+++ b/test/shared/settings/validator.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import { validate } from 'shared/settings/validator';
describe("setting validator", () => {
diff --git a/test/shared/settings/values.test.js b/test/shared/settings/values.test.js
index 62cfb5f..c72824d 100644
--- a/test/shared/settings/values.test.js
+++ b/test/shared/settings/values.test.js
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import * as values from 'shared/settings/values';
describe("settings values", () => {
diff --git a/test/shared/store/index.test.js b/test/shared/store/index.test.js
index 133033b..5b69b40 100644
--- a/test/shared/store/index.test.js
+++ b/test/shared/store/index.test.js
@@ -1,4 +1,3 @@
-import { expect } from "chai";
import { createStore } from 'shared/store';
describe("Store class", () => {
diff --git a/test/shared/utils/keys.test.js b/test/shared/utils/keys.test.js
index 5ca8b54..770b530 100644
--- a/test/shared/utils/keys.test.js
+++ b/test/shared/utils/keys.test.js
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import * as keys from 'shared/utils/keys';
describe("keys util", () => {
diff --git a/test/shared/utils/re.test.js b/test/shared/utils/re.test.js
index 9ed6521..d12ceb7 100644
--- a/test/shared/utils/re.test.js
+++ b/test/shared/utils/re.test.js
@@ -1,4 +1,3 @@
-import { expect } from 'chai';
import * as re from 'shared/utils/re';
describe("re util", () => {
diff --git a/test/shared/versions/index.test.js b/test/shared/versions/index.test.js
new file mode 100644
index 0000000..3bb307a
--- /dev/null
+++ b/test/shared/versions/index.test.js
@@ -0,0 +1,55 @@
+import * as versions from 'shared/versions';
+import manifest from '../../../manifest.json';
+
+describe("shared/versions/storage", () => {
+ describe('#checkUpdated', () => {
+ beforeEach(() => {
+ return browser.storage.local.remove('version');
+ });
+
+ it('return true if no previous versions', () => {
+ return Promise.resolve().then(() => {
+ return versions.checkUpdated();
+ }).then((updated) => {
+ expect(updated).to.be.true;
+ });
+ });
+
+ it('return true if updated', () => {
+ return Promise.resolve().then(() => {
+ return browser.storage.local.set({ version: '0.001' });
+ }).then(() => {
+ return versions.checkUpdated();
+ }).then((updated) => {
+ expect(updated).to.be.true;
+ });
+ });
+
+ it('return false if not updated', () => {
+ return Promise.resolve().then(() => {
+ return browser.storage.local.set({ version: manifest.version });
+ }).then(() => {
+ return versions.checkUpdated();
+ }).then((updated) => {
+ expect(updated).to.be.false;
+ });
+ });
+ });
+
+ describe('#commit', () => {
+ beforeEach(() => {
+ return browser.storage.local.remove('version');
+ });
+
+ it('saves current version from manifest.json', () => {
+ return Promise.resolve().then(() => {
+ return versions.commit();
+ }).then(() => {
+ return browser.storage.local.get('version');
+ }).then(({version}) => {
+ expect(version).to.be.a('string');
+ expect(version).to.equal(manifest.version);
+ });
+ });
+ });
+});
diff --git a/test/shared/versions/storage.test.js b/test/shared/versions/storage.test.js
new file mode 100644
index 0000000..bcfa259
--- /dev/null
+++ b/test/shared/versions/storage.test.js
@@ -0,0 +1,39 @@
+import * as storage from 'shared/versions/storage';
+
+describe("shared/versions/storage", () => {
+ describe('#load', () => {
+ beforeEach(() => {
+ return browser.storage.local.remove('version');
+ });
+
+ it('loads saved version', () => {
+ return Promise.resolve().then(() => {
+ return browser.storage.local.set({ version: '1.2.3' });
+ }).then(() => {
+ return storage.load();
+ }).then((version) => {
+ expect(version).to.equal('1.2.3');
+ });
+ });
+
+ it('returns undefined if no versions in storage', () => {
+ return Promise.resolve().then(() => {
+ return storage.load();
+ }).then((version) => {
+ expect(version).to.be.a('undefined');
+ });
+ });
+ });
+
+ describe('#save', () => {
+ it('saves version string', () => {
+ return Promise.resolve().then(() => {
+ return storage.save('2.3.4');
+ }).then(() => {
+ return browser.storage.local.get('version');
+ }).then(({version}) => {
+ expect(version).to.equal('2.3.4');
+ });
+ });
+ });
+});