aboutsummaryrefslogtreecommitdiff
path: root/test/content
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-21 21:17:27 +0900
committerGitHub <noreply@github.com>2017-10-21 21:17:27 +0900
commit7639e99b755e372712dca36e077a85d9a025cd9f (patch)
tree177a523e5996e302d647853cf4b11767e669de3c /test/content
parent941073404b534d7f79e90f29b514a5f06fb8080d (diff)
parent6ad143d294df0a0cc2dfb775ecab9f8b12ee7be5 (diff)
Merge pull request #86 from ueokande/10-disable-temporary
Disable add-on temporary
Diffstat (limited to 'test/content')
-rw-r--r--test/content/actions/addon.test.js26
-rw-r--r--test/content/actions/input.test.js8
-rw-r--r--test/content/components/common/input.test.js102
-rw-r--r--test/content/reducers/addon.test.js38
4 files changed, 167 insertions, 7 deletions
diff --git a/test/content/actions/addon.test.js b/test/content/actions/addon.test.js
new file mode 100644
index 0000000..7f244dc
--- /dev/null
+++ b/test/content/actions/addon.test.js
@@ -0,0 +1,26 @@
+import { expect } from "chai";
+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/actions/input.test.js b/test/content/actions/input.test.js
index 6031829..30705d2 100644
--- a/test/content/actions/input.test.js
+++ b/test/content/actions/input.test.js
@@ -5,16 +5,10 @@ import * as inputActions from 'content/actions/input';
describe("input actions", () => {
describe("keyPress", () => {
it('create INPUT_KEY_PRESS action', () => {
- let action = inputActions.keyPress('a', false);
+ let action = inputActions.keyPress('a');
expect(action.type).to.equal(actions.INPUT_KEY_PRESS);
expect(action.key).to.equal('a');
});
-
- it('create INPUT_KEY_PRESS action from key with ctrl', () => {
- let action = inputActions.keyPress('b', true);
- expect(action.type).to.equal(actions.INPUT_KEY_PRESS);
- expect(action.key).to.equal('<C-B>');
- });
});
describe("clearKeys", () => {
diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.js
new file mode 100644
index 0000000..912ac34
--- /dev/null
+++ b/test/content/components/common/input.test.js
@@ -0,0 +1,102 @@
+import InputComponent from 'content/components/common/input';
+import { expect } from "chai";
+
+describe('InputComponent', () => {
+ it('register callbacks', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect(key).is.equals('a');
+ });
+ component.onKeyDown({ key: 'a' });
+ });
+
+ it('invoke callback once', () => {
+ let component = new InputComponent(window.document);
+ let a = 0, b = 0;
+ component.onKey((key) => {
+ if (key == 'a') {
+ ++a;
+ } else {
+ key == 'b'
+ ++b;
+ }
+ });
+ component.onKeyDown({ key: 'a' });
+ component.onKeyDown({ key: 'b' });
+ component.onKeyPress({ key: 'a' });
+ component.onKeyUp({ key: 'a' });
+ component.onKeyPress({ key: 'b' });
+ component.onKeyUp({ key: 'b' });
+
+ expect(a).is.equals(1);
+ expect(b).is.equals(1);
+ })
+
+ it('add prefix when ctrl pressed', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect(key).is.equals('<C-A>');
+ });
+ component.onKeyDown({ key: 'a', ctrlKey: true });
+ })
+
+ it('press X', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect(key).is.equals('X');
+ });
+ component.onKeyDown({ key: 'X', shiftKey: true });
+ })
+
+ it('press <Shift> + <Esc>', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect(key).is.equals('<S-Esc>');
+ });
+ component.onKeyDown({ key: 'Escape', shiftKey: true });
+ })
+
+ it('press <Ctrl> + <Esc>', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect(key).is.equals('<C-Esc>');
+ });
+ component.onKeyDown({ key: 'Escape', ctrlKey: true });
+ })
+
+ it('does not invoke only meta keys', () => {
+ let component = new InputComponent(window.document);
+ component.onKey((key) => {
+ expect.fail();
+ });
+ component.onKeyDown({ key: 'Shift' });
+ component.onKeyDown({ key: 'Control' });
+ component.onKeyDown({ key: 'Alt' });
+ component.onKeyDown({ key: 'OS' });
+ })
+
+ it('ignores events from input elements', () => {
+ ['input', 'textarea', 'select'].forEach((name) => {
+ let target = window.document.createElement(name);
+ let component = new InputComponent(target);
+ component.onKey((key) => {
+ expect.fail();
+ });
+ component.onKeyDown({ key: 'x', target });
+ });
+ });
+
+ it('ignores events from contenteditable elements', () => {
+ let target = window.document.createElement('div');
+ let component = new InputComponent(target);
+ component.onKey((key) => {
+ expect.fail();
+ });
+
+ target.setAttribute('contenteditable', '');
+ component.onKeyDown({ key: 'x', target });
+
+ target.setAttribute('contenteditable', 'true');
+ component.onKeyDown({ key: 'x', target });
+ })
+});
diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.js
new file mode 100644
index 0000000..93f97e8
--- /dev/null
+++ b/test/content/reducers/addon.test.js
@@ -0,0 +1,38 @@
+import { expect } from "chai";
+import actions from 'content/actions';
+import addonReducer from 'content/reducers/addon';
+
+describe("addon reducer", () => {
+ it('return the initial state', () => {
+ let state = addonReducer(undefined, {});
+ expect(state).to.have.property('enabled', true);
+ });
+
+ it('return next state for ADDON_ENABLE', () => {
+ let action = { type: actions.ADDON_ENABLE};
+ 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);
+ });
+
+});