From c60d0e7392fc708e961614d6b756a045de74f458 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:00:07 +0900 Subject: Rename .js/.jsx to .ts/.tsx --- test/content/actions/follow-controller.test.js | 34 ------ test/content/actions/follow-controller.test.ts | 34 ++++++ test/content/actions/input.test.js | 19 ---- test/content/actions/input.test.ts | 19 ++++ test/content/actions/mark.test.js | 35 ------ test/content/actions/mark.test.ts | 35 ++++++ test/content/actions/setting.test.js | 35 ------ test/content/actions/setting.test.ts | 35 ++++++ test/content/components/common/follow.test.js | 25 ----- test/content/components/common/follow.test.ts | 25 +++++ test/content/components/common/hint.test.js | 57 ---------- test/content/components/common/hint.test.ts | 57 ++++++++++ test/content/components/common/input.test.js | 70 ------------ test/content/components/common/input.test.ts | 70 ++++++++++++ test/content/hint-key-producer.test.js | 24 ----- test/content/hint-key-producer.test.ts | 24 +++++ test/content/navigates.test.js | 137 ------------------------ test/content/navigates.test.ts | 137 ++++++++++++++++++++++++ test/content/reducers/addon.test.js | 17 --- test/content/reducers/addon.test.ts | 17 +++ test/content/reducers/find.test.js | 22 ---- test/content/reducers/find.test.ts | 22 ++++ test/content/reducers/follow-controller.test.js | 47 -------- test/content/reducers/follow-controller.test.ts | 47 ++++++++ test/content/reducers/input.test.js | 25 ----- test/content/reducers/input.test.ts | 25 +++++ test/content/reducers/mark.test.js | 41 ------- test/content/reducers/mark.test.ts | 41 +++++++ test/content/reducers/setting.test.js | 17 --- test/content/reducers/setting.test.ts | 17 +++ 30 files changed, 605 insertions(+), 605 deletions(-) delete mode 100644 test/content/actions/follow-controller.test.js create mode 100644 test/content/actions/follow-controller.test.ts delete mode 100644 test/content/actions/input.test.js create mode 100644 test/content/actions/input.test.ts delete mode 100644 test/content/actions/mark.test.js create mode 100644 test/content/actions/mark.test.ts delete mode 100644 test/content/actions/setting.test.js create mode 100644 test/content/actions/setting.test.ts delete mode 100644 test/content/components/common/follow.test.js create mode 100644 test/content/components/common/follow.test.ts delete mode 100644 test/content/components/common/hint.test.js create mode 100644 test/content/components/common/hint.test.ts delete mode 100644 test/content/components/common/input.test.js create mode 100644 test/content/components/common/input.test.ts delete mode 100644 test/content/hint-key-producer.test.js create mode 100644 test/content/hint-key-producer.test.ts delete mode 100644 test/content/navigates.test.js create mode 100644 test/content/navigates.test.ts delete mode 100644 test/content/reducers/addon.test.js create mode 100644 test/content/reducers/addon.test.ts delete mode 100644 test/content/reducers/find.test.js create mode 100644 test/content/reducers/find.test.ts delete mode 100644 test/content/reducers/follow-controller.test.js create mode 100644 test/content/reducers/follow-controller.test.ts delete mode 100644 test/content/reducers/input.test.js create mode 100644 test/content/reducers/input.test.ts delete mode 100644 test/content/reducers/mark.test.js create mode 100644 test/content/reducers/mark.test.ts delete mode 100644 test/content/reducers/setting.test.js create mode 100644 test/content/reducers/setting.test.ts (limited to 'test/content') diff --git a/test/content/actions/follow-controller.test.js b/test/content/actions/follow-controller.test.js deleted file mode 100644 index 718a90a..0000000 --- a/test/content/actions/follow-controller.test.js +++ /dev/null @@ -1,34 +0,0 @@ -import actions from 'content/actions'; -import * as followControllerActions from 'content/actions/follow-controller'; - -describe('follow-controller actions', () => { - describe('enable', () => { - it('creates FOLLOW_CONTROLLER_ENABLE action', () => { - let action = followControllerActions.enable(true); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_ENABLE); - expect(action.newTab).to.equal(true); - }); - }); - - describe('disable', () => { - it('creates FOLLOW_CONTROLLER_DISABLE action', () => { - let action = followControllerActions.disable(true); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_DISABLE); - }); - }); - - describe('keyPress', () => { - it('creates FOLLOW_CONTROLLER_KEY_PRESS action', () => { - let action = followControllerActions.keyPress(100); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_KEY_PRESS); - expect(action.key).to.equal(100); - }); - }); - - describe('backspace', () => { - it('creates FOLLOW_CONTROLLER_BACKSPACE action', () => { - let action = followControllerActions.backspace(100); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_BACKSPACE); - }); - }); -}); diff --git a/test/content/actions/follow-controller.test.ts b/test/content/actions/follow-controller.test.ts new file mode 100644 index 0000000..718a90a --- /dev/null +++ b/test/content/actions/follow-controller.test.ts @@ -0,0 +1,34 @@ +import actions from 'content/actions'; +import * as followControllerActions from 'content/actions/follow-controller'; + +describe('follow-controller actions', () => { + describe('enable', () => { + it('creates FOLLOW_CONTROLLER_ENABLE action', () => { + let action = followControllerActions.enable(true); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_ENABLE); + expect(action.newTab).to.equal(true); + }); + }); + + describe('disable', () => { + it('creates FOLLOW_CONTROLLER_DISABLE action', () => { + let action = followControllerActions.disable(true); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_DISABLE); + }); + }); + + describe('keyPress', () => { + it('creates FOLLOW_CONTROLLER_KEY_PRESS action', () => { + let action = followControllerActions.keyPress(100); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_KEY_PRESS); + expect(action.key).to.equal(100); + }); + }); + + describe('backspace', () => { + it('creates FOLLOW_CONTROLLER_BACKSPACE action', () => { + let action = followControllerActions.backspace(100); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_BACKSPACE); + }); + }); +}); diff --git a/test/content/actions/input.test.js b/test/content/actions/input.test.js deleted file mode 100644 index fe9db5f..0000000 --- a/test/content/actions/input.test.js +++ /dev/null @@ -1,19 +0,0 @@ -import actions from 'content/actions'; -import * as inputActions from 'content/actions/input'; - -describe("input actions", () => { - describe("keyPress", () => { - it('create INPUT_KEY_PRESS action', () => { - let action = inputActions.keyPress('a'); - expect(action.type).to.equal(actions.INPUT_KEY_PRESS); - expect(action.key).to.equal('a'); - }); - }); - - describe("clearKeys", () => { - it('create INPUT_CLEAR_KEYSaction', () => { - let action = inputActions.clearKeys(); - expect(action.type).to.equal(actions.INPUT_CLEAR_KEYS); - }); - }); -}); diff --git a/test/content/actions/input.test.ts b/test/content/actions/input.test.ts new file mode 100644 index 0000000..fe9db5f --- /dev/null +++ b/test/content/actions/input.test.ts @@ -0,0 +1,19 @@ +import actions from 'content/actions'; +import * as inputActions from 'content/actions/input'; + +describe("input actions", () => { + describe("keyPress", () => { + it('create INPUT_KEY_PRESS action', () => { + let action = inputActions.keyPress('a'); + expect(action.type).to.equal(actions.INPUT_KEY_PRESS); + expect(action.key).to.equal('a'); + }); + }); + + describe("clearKeys", () => { + it('create INPUT_CLEAR_KEYSaction', () => { + let action = inputActions.clearKeys(); + expect(action.type).to.equal(actions.INPUT_CLEAR_KEYS); + }); + }); +}); diff --git a/test/content/actions/mark.test.js b/test/content/actions/mark.test.js deleted file mode 100644 index adbf06b..0000000 --- a/test/content/actions/mark.test.js +++ /dev/null @@ -1,35 +0,0 @@ -import actions from 'content/actions'; -import * as markActions from 'content/actions/mark'; - -describe('mark actions', () => { - describe('startSet', () => { - it('create MARK_START_SET action', () => { - let action = markActions.startSet(); - expect(action.type).to.equal(actions.MARK_START_SET); - }); - }); - - describe('startJump', () => { - it('create MARK_START_JUMP action', () => { - let action = markActions.startJump(); - expect(action.type).to.equal(actions.MARK_START_JUMP); - }); - }); - - describe('cancel', () => { - it('create MARK_CANCEL action', () => { - let action = markActions.cancel(); - expect(action.type).to.equal(actions.MARK_CANCEL); - }); - }); - - describe('setLocal', () => { - it('create setLocal action', () => { - let action = markActions.setLocal('a', 20, 30); - expect(action.type).to.equal(actions.MARK_SET_LOCAL); - expect(action.key).to.equal('a'); - expect(action.x).to.equal(20); - expect(action.y).to.equal(30); - }); - }); -}); diff --git a/test/content/actions/mark.test.ts b/test/content/actions/mark.test.ts new file mode 100644 index 0000000..adbf06b --- /dev/null +++ b/test/content/actions/mark.test.ts @@ -0,0 +1,35 @@ +import actions from 'content/actions'; +import * as markActions from 'content/actions/mark'; + +describe('mark actions', () => { + describe('startSet', () => { + it('create MARK_START_SET action', () => { + let action = markActions.startSet(); + expect(action.type).to.equal(actions.MARK_START_SET); + }); + }); + + describe('startJump', () => { + it('create MARK_START_JUMP action', () => { + let action = markActions.startJump(); + expect(action.type).to.equal(actions.MARK_START_JUMP); + }); + }); + + describe('cancel', () => { + it('create MARK_CANCEL action', () => { + let action = markActions.cancel(); + expect(action.type).to.equal(actions.MARK_CANCEL); + }); + }); + + describe('setLocal', () => { + it('create setLocal action', () => { + let action = markActions.setLocal('a', 20, 30); + expect(action.type).to.equal(actions.MARK_SET_LOCAL); + expect(action.key).to.equal('a'); + expect(action.x).to.equal(20); + expect(action.y).to.equal(30); + }); + }); +}); diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.js deleted file mode 100644 index 10f6807..0000000 --- a/test/content/actions/setting.test.js +++ /dev/null @@ -1,35 +0,0 @@ -import actions from 'content/actions'; -import * as settingActions from 'content/actions/setting'; - -describe("setting actions", () => { - describe("set", () => { - it('create SETTING_SET action', () => { - let action = settingActions.set({ red: 'apple', yellow: 'banana' }); - expect(action.type).to.equal(actions.SETTING_SET); - expect(action.value.red).to.equal('apple'); - expect(action.value.yellow).to.equal('banana'); - expect(action.value.keymaps).to.be.empty; - }); - - it('converts keymaps', () => { - let action = settingActions.set({ - keymaps: { - 'dd': 'remove current tab', - 'z': 'increment', - } - }); - let keymaps = action.value.keymaps; - 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 }, - { key: 'a', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], - ] - ); - }); - }); -}); diff --git a/test/content/actions/setting.test.ts b/test/content/actions/setting.test.ts new file mode 100644 index 0000000..10f6807 --- /dev/null +++ b/test/content/actions/setting.test.ts @@ -0,0 +1,35 @@ +import actions from 'content/actions'; +import * as settingActions from 'content/actions/setting'; + +describe("setting actions", () => { + describe("set", () => { + it('create SETTING_SET action', () => { + let action = settingActions.set({ red: 'apple', yellow: 'banana' }); + expect(action.type).to.equal(actions.SETTING_SET); + expect(action.value.red).to.equal('apple'); + expect(action.value.yellow).to.equal('banana'); + expect(action.value.keymaps).to.be.empty; + }); + + it('converts keymaps', () => { + let action = settingActions.set({ + keymaps: { + 'dd': 'remove current tab', + 'z': 'increment', + } + }); + let keymaps = action.value.keymaps; + 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 }, + { key: 'a', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], + ] + ); + }); + }); +}); diff --git a/test/content/components/common/follow.test.js b/test/content/components/common/follow.test.js deleted file mode 100644 index 90d6cf5..0000000 --- a/test/content/components/common/follow.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import FollowComponent from 'content/components/common/follow'; - -describe('FollowComponent', () => { - describe('#getTargetElements', () => { - beforeEach(() => { - document.body.innerHTML = __html__['test/content/components/common/follow.html']; - }); - - it('returns visible links', () => { - let targets = FollowComponent.getTargetElements( - window, - { width: window.innerWidth, height: window.innerHeight }, - { x: 0, y: 0 }); - expect(targets).to.have.lengthOf(4); - - let ids = Array.prototype.map.call(targets, (e) => e.id); - expect(ids).to.include.members([ - 'visible_a', - 'editable_div_1', - 'editable_div_2', - 'summary_1', - ]); - }); - }); -}); diff --git a/test/content/components/common/follow.test.ts b/test/content/components/common/follow.test.ts new file mode 100644 index 0000000..90d6cf5 --- /dev/null +++ b/test/content/components/common/follow.test.ts @@ -0,0 +1,25 @@ +import FollowComponent from 'content/components/common/follow'; + +describe('FollowComponent', () => { + describe('#getTargetElements', () => { + beforeEach(() => { + document.body.innerHTML = __html__['test/content/components/common/follow.html']; + }); + + it('returns visible links', () => { + let targets = FollowComponent.getTargetElements( + window, + { width: window.innerWidth, height: window.innerHeight }, + { x: 0, y: 0 }); + expect(targets).to.have.lengthOf(4); + + let ids = Array.prototype.map.call(targets, (e) => e.id); + expect(ids).to.include.members([ + 'visible_a', + 'editable_div_1', + 'editable_div_2', + 'summary_1', + ]); + }); + }); +}); diff --git a/test/content/components/common/hint.test.js b/test/content/components/common/hint.test.js deleted file mode 100644 index 42d571f..0000000 --- a/test/content/components/common/hint.test.js +++ /dev/null @@ -1,57 +0,0 @@ -import Hint from 'content/components/common/hint'; - -describe('Hint class', () => { - beforeEach(() => { - document.body.innerHTML = __html__['test/content/components/common/hint.html']; - }); - - describe('#constructor', () => { - it('creates a hint element with tag name', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - expect(hint.element.textContent.trim()).to.be.equal('abc'); - }); - - it('throws an exception when non-element given', () => { - expect(() => new Hint(window, 'abc')).to.throw(TypeError); - }); - }); - - describe('#show', () => { - it('shows an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - hint.hide(); - hint.show(); - - expect(hint.element.style.display).to.not.equal('none'); - }); - }); - - describe('#hide', () => { - it('hides an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - hint.hide(); - - expect(hint.element.style.display).to.equal('none'); - }); - }); - - describe('#remove', () => { - it('removes an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - - expect(hint.element.parentElement).to.not.be.null; - hint.remove(); - expect(hint.element.parentElement).to.be.null; - }); - }); - - describe('#activate', () => { - // TODO test activations - }); -}); - - diff --git a/test/content/components/common/hint.test.ts b/test/content/components/common/hint.test.ts new file mode 100644 index 0000000..42d571f --- /dev/null +++ b/test/content/components/common/hint.test.ts @@ -0,0 +1,57 @@ +import Hint from 'content/components/common/hint'; + +describe('Hint class', () => { + beforeEach(() => { + document.body.innerHTML = __html__['test/content/components/common/hint.html']; + }); + + describe('#constructor', () => { + it('creates a hint element with tag name', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + expect(hint.element.textContent.trim()).to.be.equal('abc'); + }); + + it('throws an exception when non-element given', () => { + expect(() => new Hint(window, 'abc')).to.throw(TypeError); + }); + }); + + describe('#show', () => { + it('shows an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + hint.hide(); + hint.show(); + + expect(hint.element.style.display).to.not.equal('none'); + }); + }); + + describe('#hide', () => { + it('hides an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + hint.hide(); + + expect(hint.element.style.display).to.equal('none'); + }); + }); + + describe('#remove', () => { + it('removes an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + + expect(hint.element.parentElement).to.not.be.null; + hint.remove(); + expect(hint.element.parentElement).to.be.null; + }); + }); + + describe('#activate', () => { + // TODO test activations + }); +}); + + diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.js deleted file mode 100644 index 2ba5507..0000000 --- a/test/content/components/common/input.test.js +++ /dev/null @@ -1,70 +0,0 @@ -import InputComponent from 'content/components/common/input'; - -describe('InputComponent', () => { - it('register callbacks', () => { - let component = new InputComponent(window.document); - let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false }; - component.onKey((key) => { - expect(key).to.deep.equal(key); - }); - component.onKeyDown(key); - }); - - it('invoke callback once', () => { - let component = new InputComponent(window.document); - let a = 0, b = 0; - component.onKey((key) => { - if (key.key == 'a') { - ++a; - } else { - key.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('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/components/common/input.test.ts b/test/content/components/common/input.test.ts new file mode 100644 index 0000000..2ba5507 --- /dev/null +++ b/test/content/components/common/input.test.ts @@ -0,0 +1,70 @@ +import InputComponent from 'content/components/common/input'; + +describe('InputComponent', () => { + it('register callbacks', () => { + let component = new InputComponent(window.document); + let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false }; + component.onKey((key) => { + expect(key).to.deep.equal(key); + }); + component.onKeyDown(key); + }); + + it('invoke callback once', () => { + let component = new InputComponent(window.document); + let a = 0, b = 0; + component.onKey((key) => { + if (key.key == 'a') { + ++a; + } else { + key.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('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/hint-key-producer.test.js b/test/content/hint-key-producer.test.js deleted file mode 100644 index dcf477d..0000000 --- a/test/content/hint-key-producer.test.js +++ /dev/null @@ -1,24 +0,0 @@ -import HintKeyProducer from 'content/hint-key-producer'; - -describe('HintKeyProducer class', () => { - describe('#constructor', () => { - it('throws an exception on empty charset', () => { - expect(() => new HintKeyProducer([])).to.throw(TypeError); - }); - }); - - describe('#produce', () => { - it('produce incremented keys', () => { - let charset = 'abc'; - let sequences = [ - 'a', 'b', 'c', - 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', - 'aaa', 'aab', 'aac', 'aba'] - - let producer = new HintKeyProducer(charset); - for (let i = 0; i < sequences.length; ++i) { - expect(producer.produce()).to.equal(sequences[i]); - } - }); - }); -}); diff --git a/test/content/hint-key-producer.test.ts b/test/content/hint-key-producer.test.ts new file mode 100644 index 0000000..dcf477d --- /dev/null +++ b/test/content/hint-key-producer.test.ts @@ -0,0 +1,24 @@ +import HintKeyProducer from 'content/hint-key-producer'; + +describe('HintKeyProducer class', () => { + describe('#constructor', () => { + it('throws an exception on empty charset', () => { + expect(() => new HintKeyProducer([])).to.throw(TypeError); + }); + }); + + describe('#produce', () => { + it('produce incremented keys', () => { + let charset = 'abc'; + let sequences = [ + 'a', 'b', 'c', + 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', + 'aaa', 'aab', 'aac', 'aba'] + + let producer = new HintKeyProducer(charset); + for (let i = 0; i < sequences.length; ++i) { + expect(producer.produce()).to.equal(sequences[i]); + } + }); + }); +}); diff --git a/test/content/navigates.test.js b/test/content/navigates.test.js deleted file mode 100644 index 1d73344..0000000 --- a/test/content/navigates.test.js +++ /dev/null @@ -1,137 +0,0 @@ -import * as navigates from 'content/navigates'; - -const testRel = (done, rel, html) => { - const method = rel === 'prev' ? 'linkPrev' : 'linkNext'; - document.body.innerHTML = html; - navigates[method](window); - setTimeout(() => { - expect(document.location.hash).to.equal(`#${rel}`); - done(); - }, 0); -}; - -const testPrev = html => done => testRel(done, 'prev', html); -const testNext = html => done => testRel(done, 'next', html); - -describe('navigates module', () => { - describe('#linkPrev', () => { - it('navigates to elements whose rel attribute is "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute starts with "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute ends with "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute contains "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute is "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute starts with "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose rel attribute ends with "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose rel attribute contains "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose text matches "prev"', testPrev( - 'previewgo to prev' - )); - - it('navigates to elements whose text matches "previous"', testPrev( - 'previouslyprevious page' - )); - - it('navigates to elements whose decoded text matches "<<"', testPrev( - 'click me<<' - )); - - it('navigates to matching elements by clicking', testPrev( - `` - )); - - it('prefers link[rel~=prev] to a[rel~=prev]', testPrev( - '' - )); - - it('prefers a[rel~=prev] to a::text(pattern)', testPrev( - 'go to prev' - )); - }); - - describe('#linkNext', () => { - it('navigates to elements whose rel attribute is "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute starts with "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute ends with "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute contains "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute is "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute starts with "next"', testNext( - 'click me' - )); - - it('navigates to elements whose rel attribute ends with "next"', testNext( - 'click me' - )); - - it('navigates to elements whose rel attribute contains "next"', testNext( - 'click me' - )); - - it('navigates to elements whose text matches "next"', testNext( - 'inextricablego to next' - )); - - it('navigates to elements whose decoded text matches ">>"', testNext( - 'click me>>' - )); - - it('navigates to matching elements by clicking', testNext( - `` - )); - - it('prefers link[rel~=next] to a[rel~=next]', testNext( - '' - )); - - it('prefers a[rel~=next] to a::text(pattern)', testNext( - 'next page' - )); - }); - - describe('#parent', () => { - // NOTE: not able to test location - it('removes hash', () => { - window.location.hash = '#section-1'; - navigates.parent(window); - expect(document.location.hash).to.be.empty; - }); - }); -}); diff --git a/test/content/navigates.test.ts b/test/content/navigates.test.ts new file mode 100644 index 0000000..1d73344 --- /dev/null +++ b/test/content/navigates.test.ts @@ -0,0 +1,137 @@ +import * as navigates from 'content/navigates'; + +const testRel = (done, rel, html) => { + const method = rel === 'prev' ? 'linkPrev' : 'linkNext'; + document.body.innerHTML = html; + navigates[method](window); + setTimeout(() => { + expect(document.location.hash).to.equal(`#${rel}`); + done(); + }, 0); +}; + +const testPrev = html => done => testRel(done, 'prev', html); +const testNext = html => done => testRel(done, 'next', html); + +describe('navigates module', () => { + describe('#linkPrev', () => { + it('navigates to elements whose rel attribute is "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute starts with "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute ends with "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute contains "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute is "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute starts with "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose rel attribute ends with "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose rel attribute contains "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose text matches "prev"', testPrev( + 'previewgo to prev' + )); + + it('navigates to elements whose text matches "previous"', testPrev( + 'previouslyprevious page' + )); + + it('navigates to elements whose decoded text matches "<<"', testPrev( + 'click me<<' + )); + + it('navigates to matching elements by clicking', testPrev( + `` + )); + + it('prefers link[rel~=prev] to a[rel~=prev]', testPrev( + '' + )); + + it('prefers a[rel~=prev] to a::text(pattern)', testPrev( + 'go to prev' + )); + }); + + describe('#linkNext', () => { + it('navigates to elements whose rel attribute is "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute starts with "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute ends with "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute contains "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute is "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute starts with "next"', testNext( + 'click me' + )); + + it('navigates to elements whose rel attribute ends with "next"', testNext( + 'click me' + )); + + it('navigates to elements whose rel attribute contains "next"', testNext( + 'click me' + )); + + it('navigates to elements whose text matches "next"', testNext( + 'inextricablego to next' + )); + + it('navigates to elements whose decoded text matches ">>"', testNext( + 'click me>>' + )); + + it('navigates to matching elements by clicking', testNext( + `` + )); + + it('prefers link[rel~=next] to a[rel~=next]', testNext( + '' + )); + + it('prefers a[rel~=next] to a::text(pattern)', testNext( + 'next page' + )); + }); + + describe('#parent', () => { + // NOTE: not able to test location + it('removes hash', () => { + window.location.hash = '#section-1'; + navigates.parent(window); + expect(document.location.hash).to.be.empty; + }); + }); +}); diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.js deleted file mode 100644 index d4eb845..0000000 --- a/test/content/reducers/addon.test.js +++ /dev/null @@ -1,17 +0,0 @@ -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_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); - }); -}); diff --git a/test/content/reducers/addon.test.ts b/test/content/reducers/addon.test.ts new file mode 100644 index 0000000..d4eb845 --- /dev/null +++ b/test/content/reducers/addon.test.ts @@ -0,0 +1,17 @@ +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_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); + }); +}); diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.js deleted file mode 100644 index a8c30d7..0000000 --- a/test/content/reducers/find.test.js +++ /dev/null @@ -1,22 +0,0 @@ -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', null); - expect(state).to.have.property('found', false); - }); - - it('return next state for FIND_SET_KEYWORD', () => { - let action = { - type: actions.FIND_SET_KEYWORD, - keyword: 'xyz', - found: true, - }; - let state = findReducer({}, action); - - expect(state.keyword).is.equal('xyz'); - expect(state.found).to.be.true; - }); -}); diff --git a/test/content/reducers/find.test.ts b/test/content/reducers/find.test.ts new file mode 100644 index 0000000..a8c30d7 --- /dev/null +++ b/test/content/reducers/find.test.ts @@ -0,0 +1,22 @@ +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', null); + expect(state).to.have.property('found', false); + }); + + it('return next state for FIND_SET_KEYWORD', () => { + let action = { + type: actions.FIND_SET_KEYWORD, + keyword: 'xyz', + found: true, + }; + let state = findReducer({}, action); + + expect(state.keyword).is.equal('xyz'); + expect(state.found).to.be.true; + }); +}); diff --git a/test/content/reducers/follow-controller.test.js b/test/content/reducers/follow-controller.test.js deleted file mode 100644 index 8a4c2d4..0000000 --- a/test/content/reducers/follow-controller.test.js +++ /dev/null @@ -1,47 +0,0 @@ -import actions from 'content/actions'; -import followControllerReducer from 'content/reducers/follow-controller'; - -describe('follow-controller reducer', () => { - it ('returns the initial state', () => { - let state = followControllerReducer(undefined, {}); - expect(state).to.have.property('enabled', false); - expect(state).to.have.property('newTab'); - expect(state).to.have.deep.property('keys', ''); - }); - - it ('returns next state for FOLLOW_CONTROLLER_ENABLE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab: true }; - let state = followControllerReducer({ enabled: false, newTab: false }, action); - expect(state).to.have.property('enabled', true); - expect(state).to.have.property('newTab', true); - expect(state).to.have.property('keys', ''); - }); - - it ('returns next state for FOLLOW_CONTROLLER_DISABLE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_DISABLE }; - let state = followControllerReducer({ enabled: true }, action); - expect(state).to.have.property('enabled', false); - }); - - it ('returns next state for FOLLOW_CONTROLLER_KEY_PRESS', () => { - let action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'a'}; - let state = followControllerReducer({ keys: '' }, action); - expect(state).to.have.deep.property('keys', 'a'); - - action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'b'}; - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', 'ab'); - }); - - it ('returns next state for FOLLOW_CONTROLLER_BACKSPACE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_BACKSPACE }; - let state = followControllerReducer({ keys: 'ab' }, action); - expect(state).to.have.deep.property('keys', 'a'); - - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', ''); - - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', ''); - }); -}); diff --git a/test/content/reducers/follow-controller.test.ts b/test/content/reducers/follow-controller.test.ts new file mode 100644 index 0000000..8a4c2d4 --- /dev/null +++ b/test/content/reducers/follow-controller.test.ts @@ -0,0 +1,47 @@ +import actions from 'content/actions'; +import followControllerReducer from 'content/reducers/follow-controller'; + +describe('follow-controller reducer', () => { + it ('returns the initial state', () => { + let state = followControllerReducer(undefined, {}); + expect(state).to.have.property('enabled', false); + expect(state).to.have.property('newTab'); + expect(state).to.have.deep.property('keys', ''); + }); + + it ('returns next state for FOLLOW_CONTROLLER_ENABLE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab: true }; + let state = followControllerReducer({ enabled: false, newTab: false }, action); + expect(state).to.have.property('enabled', true); + expect(state).to.have.property('newTab', true); + expect(state).to.have.property('keys', ''); + }); + + it ('returns next state for FOLLOW_CONTROLLER_DISABLE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_DISABLE }; + let state = followControllerReducer({ enabled: true }, action); + expect(state).to.have.property('enabled', false); + }); + + it ('returns next state for FOLLOW_CONTROLLER_KEY_PRESS', () => { + let action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'a'}; + let state = followControllerReducer({ keys: '' }, action); + expect(state).to.have.deep.property('keys', 'a'); + + action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'b'}; + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', 'ab'); + }); + + it ('returns next state for FOLLOW_CONTROLLER_BACKSPACE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_BACKSPACE }; + let state = followControllerReducer({ keys: 'ab' }, action); + expect(state).to.have.deep.property('keys', 'a'); + + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', ''); + + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', ''); + }); +}); diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.js deleted file mode 100644 index 0011943..0000000 --- a/test/content/reducers/input.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import actions from 'content/actions'; -import inputReducer from 'content/reducers/input'; - -describe("input reducer", () => { - it('return the initial state', () => { - let state = inputReducer(undefined, {}); - expect(state).to.have.deep.property('keys', []); - }); - - it('return next state for INPUT_KEY_PRESS', () => { - let action = { type: actions.INPUT_KEY_PRESS, key: 'a' }; - let state = inputReducer(undefined, action); - expect(state).to.have.deep.property('keys', ['a']); - - action = { type: actions.INPUT_KEY_PRESS, key: 'b' }; - state = inputReducer(state, action); - expect(state).to.have.deep.property('keys', ['a', 'b']); - }); - - it('return next state for INPUT_CLEAR_KEYS', () => { - let action = { type: actions.INPUT_CLEAR_KEYS }; - let state = inputReducer({ keys: [1, 2, 3] }, action); - expect(state).to.have.deep.property('keys', []); - }); -}); diff --git a/test/content/reducers/input.test.ts b/test/content/reducers/input.test.ts new file mode 100644 index 0000000..0011943 --- /dev/null +++ b/test/content/reducers/input.test.ts @@ -0,0 +1,25 @@ +import actions from 'content/actions'; +import inputReducer from 'content/reducers/input'; + +describe("input reducer", () => { + it('return the initial state', () => { + let state = inputReducer(undefined, {}); + expect(state).to.have.deep.property('keys', []); + }); + + it('return next state for INPUT_KEY_PRESS', () => { + let action = { type: actions.INPUT_KEY_PRESS, key: 'a' }; + let state = inputReducer(undefined, action); + expect(state).to.have.deep.property('keys', ['a']); + + action = { type: actions.INPUT_KEY_PRESS, key: 'b' }; + state = inputReducer(state, action); + expect(state).to.have.deep.property('keys', ['a', 'b']); + }); + + it('return next state for INPUT_CLEAR_KEYS', () => { + let action = { type: actions.INPUT_CLEAR_KEYS }; + let state = inputReducer({ keys: [1, 2, 3] }, action); + expect(state).to.have.deep.property('keys', []); + }); +}); diff --git a/test/content/reducers/mark.test.js b/test/content/reducers/mark.test.js deleted file mode 100644 index 76efbf7..0000000 --- a/test/content/reducers/mark.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import actions from 'content/actions'; -import reducer from 'content/reducers/mark'; - -describe("mark reducer", () => { - it('return the initial state', () => { - let state = reducer(undefined, {}); - expect(state.setMode).to.be.false; - expect(state.jumpMode).to.be.false; - expect(state.marks).to.be.empty; - }); - - it('starts set mode', () => { - let action = { type: actions.MARK_START_SET }; - let state = reducer(undefined, action); - expect(state.setMode).to.be.true; - }); - - it('starts jump mode', () => { - let action = { type: actions.MARK_START_JUMP }; - let state = reducer(undefined, action); - expect(state.jumpMode).to.be.true; - }); - - it('cancels set and jump mode', () => { - let action = { type: actions.MARK_CANCEL }; - let state = reducer({ setMode: true }, action); - expect(state.setMode).to.be.false; - - state = reducer({ jumpMode: true }, action); - expect(state.jumpMode).to.be.false; - }); - - it('stores local mark', () => { - let action = { type: actions.MARK_SET_LOCAL, key: 'a', x: 20, y: 30}; - let state = reducer({ setMode: true }, action); - expect(state.setMode).to.be.false; - expect(state.marks['a']).to.be.an('object') - expect(state.marks['a'].x).to.equal(20) - expect(state.marks['a'].y).to.equal(30) - }); -}); diff --git a/test/content/reducers/mark.test.ts b/test/content/reducers/mark.test.ts new file mode 100644 index 0000000..76efbf7 --- /dev/null +++ b/test/content/reducers/mark.test.ts @@ -0,0 +1,41 @@ +import actions from 'content/actions'; +import reducer from 'content/reducers/mark'; + +describe("mark reducer", () => { + it('return the initial state', () => { + let state = reducer(undefined, {}); + expect(state.setMode).to.be.false; + expect(state.jumpMode).to.be.false; + expect(state.marks).to.be.empty; + }); + + it('starts set mode', () => { + let action = { type: actions.MARK_START_SET }; + let state = reducer(undefined, action); + expect(state.setMode).to.be.true; + }); + + it('starts jump mode', () => { + let action = { type: actions.MARK_START_JUMP }; + let state = reducer(undefined, action); + expect(state.jumpMode).to.be.true; + }); + + it('cancels set and jump mode', () => { + let action = { type: actions.MARK_CANCEL }; + let state = reducer({ setMode: true }, action); + expect(state.setMode).to.be.false; + + state = reducer({ jumpMode: true }, action); + expect(state.jumpMode).to.be.false; + }); + + it('stores local mark', () => { + let action = { type: actions.MARK_SET_LOCAL, key: 'a', x: 20, y: 30}; + let state = reducer({ setMode: true }, action); + expect(state.setMode).to.be.false; + expect(state.marks['a']).to.be.an('object') + expect(state.marks['a'].x).to.equal(20) + expect(state.marks['a'].y).to.equal(30) + }); +}); diff --git a/test/content/reducers/setting.test.js b/test/content/reducers/setting.test.js deleted file mode 100644 index 4e4c095..0000000 --- a/test/content/reducers/setting.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import actions from 'content/actions'; -import settingReducer from 'content/reducers/setting'; - -describe("content setting reducer", () => { - it('return the initial state', () => { - let state = settingReducer(undefined, {}); - expect(state.keymaps).to.be.empty; - }); - - it('return next state for SETTING_SET', () => { - let newSettings = { red: 'apple', yellow: 'banana' }; - let action = { type: actions.SETTING_SET, value: newSettings }; - let state = settingReducer(undefined, action); - expect(state).to.deep.equal(newSettings); - expect(state).not.to.equal(newSettings); // assert deep copy - }); -}); diff --git a/test/content/reducers/setting.test.ts b/test/content/reducers/setting.test.ts new file mode 100644 index 0000000..4e4c095 --- /dev/null +++ b/test/content/reducers/setting.test.ts @@ -0,0 +1,17 @@ +import actions from 'content/actions'; +import settingReducer from 'content/reducers/setting'; + +describe("content setting reducer", () => { + it('return the initial state', () => { + let state = settingReducer(undefined, {}); + expect(state.keymaps).to.be.empty; + }); + + it('return next state for SETTING_SET', () => { + let newSettings = { red: 'apple', yellow: 'banana' }; + let action = { type: actions.SETTING_SET, value: newSettings }; + let state = settingReducer(undefined, action); + expect(state).to.deep.equal(newSettings); + expect(state).not.to.equal(newSettings); // assert deep copy + }); +}); -- cgit v1.2.3