diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/actions/background.test.js | 14 | ||||
| -rw-r--r-- | test/actions/command.test.js | 51 | ||||
| -rw-r--r-- | test/actions/console.test.js | 37 | ||||
| -rw-r--r-- | test/actions/input.test.js | 21 | ||||
| -rw-r--r-- | test/background/key-queue.test.js | 50 | ||||
| -rw-r--r-- | test/background/keys.test.js | 70 | ||||
| -rw-r--r-- | test/reducers/console.test.js | 43 | ||||
| -rw-r--r-- | test/reducers/input.test.js | 34 | ||||
| -rw-r--r-- | test/shared/messages.test.js | 25 | 
9 files changed, 223 insertions, 122 deletions
| diff --git a/test/actions/background.test.js b/test/actions/background.test.js new file mode 100644 index 0000000..a3203ee --- /dev/null +++ b/test/actions/background.test.js @@ -0,0 +1,14 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import * as backgroundActions from '../../src/actions/background'; + +describe("background actions", () => { +  describe("requestCompletions", () => { +    it('create BACKGROUND_REQUEST_COMPLETIONS action', () => { +      let action = backgroundActions.requestCompletions('buffer hoge fuga'); +      expect(action.type).to.equal(actions.BACKGROUND_REQUEST_COMPLETIONS); +      expect(action.command).to.equal('buffer'); +      expect(action.keywords).to.equal('hoge fuga'); +    }); +  }); +}); diff --git a/test/actions/command.test.js b/test/actions/command.test.js new file mode 100644 index 0000000..01a67f2 --- /dev/null +++ b/test/actions/command.test.js @@ -0,0 +1,51 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import * as commandActions from '../../src/actions/command'; + +describe("command actions", () => { +  describe("exec", () => { +    context("open command", () => { +      it('create COMMAND_OPEN_URL acion with a full url', () => { +        let action = commandActions.exec("open https://github.com/") +        expect(action.type).to.equal(actions.COMMAND_OPEN_URL); +        expect(action.url).to.equal('https://github.com/'); +      }); + +      it('create COMMAND_OPEN_URL acion with a domain name', () => { +        let action = commandActions.exec("open github.com") +        expect(action.type).to.equal(actions.COMMAND_OPEN_URL); +        expect(action.url).to.equal('http://github.com'); +      }); +    }); + +    context("tabopen command", () => { +      it('create COMMAND_TABOPEN_URL acion with a full url', () => { +        let action = commandActions.exec("tabopen https://github.com/") +        expect(action.type).to.equal(actions.COMMAND_TABOPEN_URL); +        expect(action.url).to.equal('https://github.com/'); +      }); + +      it('create COMMAND_TABOPEN_URL acion with a domain name', () => { +        let action = commandActions.exec("tabopen github.com") +        expect(action.type).to.equal(actions.COMMAND_TABOPEN_URL); +        expect(action.url).to.equal('http://github.com'); +      }); +    }); + +    context("buffer command", () => { +      it('create COMMAND_BUFFER acion with a keywords', () => { +        let action = commandActions.exec("buffer foo bar") +        expect(action.type).to.equal(actions.COMMAND_BUFFER); +        expect(action.keywords).to.equal('foo bar'); +      }); +    }); + +    context("b command", () => { +      it('create COMMAND_BUFFER acion with a keywords', () => { +        let action = commandActions.exec("b foo bar") +        expect(action.type).to.equal(actions.COMMAND_BUFFER); +        expect(action.keywords).to.equal('foo bar'); +      }); +    }); +  }); +}); diff --git a/test/actions/console.test.js b/test/actions/console.test.js new file mode 100644 index 0000000..512ee40 --- /dev/null +++ b/test/actions/console.test.js @@ -0,0 +1,37 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import * as consoleActions from '../../src/actions/console'; + +describe("console actions", () => { +  describe("showCommand", () => { +    it('create CONSOLE_SHOW_COMMAND action', () => { +      let action = consoleActions.showCommand('hello'); +      expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND); +      expect(action.text).to.equal('hello'); +    }); +  }); + +  describe("setCompletions", () => { +    it('create CONSOLE_SET_COMPLETIONS action', () => { +      let action = consoleActions.setCompletions([1,2,3]); +      expect(action.type).to.equal(actions.CONSOLE_SET_COMPLETIONS); +      expect(action.completions).to.deep.equal([1, 2, 3]); +    }); +  }); + +  describe("showError", () => { +    it('create CONSOLE_SHOW_ERROR action', () => { +      let action = consoleActions.showError('an error'); +      expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR); +      expect(action.text).to.equal('an error'); +    }); +  }); + +  describe("hide", () => { +    it('create CONSOLE_HIDE action', () => { +      let action = consoleActions.hide(); +      expect(action.type).to.equal(actions.CONSOLE_HIDE); +    }); +  }); +}); + diff --git a/test/actions/input.test.js b/test/actions/input.test.js new file mode 100644 index 0000000..9ec6de4 --- /dev/null +++ b/test/actions/input.test.js @@ -0,0 +1,21 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import * as inputActions from '../../src/actions/input'; + +describe("input actions", () => { +  describe("keyPress", () => { +    it('create INPUT_KEY_PRESS action', () => { +      let action = inputActions.keyPress(123, true); +      expect(action.type).to.equal(actions.INPUT_KEY_PRESS); +      expect(action.code).to.equal(123); +      expect(action.ctrl).to.be.true; +    }); +  }); + +  describe("clearKeys", () => { +    it('create INPUT_CLEAR_KEYSaction', () => { +      let action = inputActions.clearKeys(); +      expect(action.type).to.equal(actions.INPUT_CLEAR_KEYS); +    }); +  }); +}); diff --git a/test/background/key-queue.test.js b/test/background/key-queue.test.js deleted file mode 100644 index ac43228..0000000 --- a/test/background/key-queue.test.js +++ /dev/null @@ -1,50 +0,0 @@ -import { expect } from "chai"; -import KeyQueue from '../../src/background/key-queue'; - -describe("keyQueue class", () => { -  const KEYMAP = { -    'g<C-X>GG': [], -    'gg': [ 'scroll.top' ], -  }; - -  const g = 'g'.charCodeAt(0); -  const G = 'G'.charCodeAt(0); -  const x = 'x'.charCodeAt(0); - -  describe("#push", () => { -    it("returns matched action", () => { -      let queue = new KeyQueue(KEYMAP); -      queue.push({ code: g }); -      let action = queue.push({ code: g }); - -      expect(action).to.deep.equal([ 'scroll.top' ]); -    }); - -    it("returns null on no actions matched", () => { -      let queue = new KeyQueue(KEYMAP); -      queue.push({ code: g }); -      let action = queue.push({ code: G }); - -      expect(action).to.be.null; -      expect(queue.asKeymapChars()).to.be.empty; -    }); -  }); - -  describe('#asKeymapChars', () => { -    let queue = new KeyQueue(KEYMAP); -    queue.push({ code: g }); -    queue.push({ code: x, ctrl: true }); -    queue.push({ code: G }); - -    expect(queue.asKeymapChars()).to.equal('g<C-X>G'); -  }); - -  describe('#asCaretChars', () => { -    let queue = new KeyQueue(KEYMAP); -    queue.push({ code: g }); -    queue.push({ code: x, ctrl: true }); -    queue.push({ code: G }); - -    expect(queue.asCaretChars()).to.equal('g^XG'); -  }); -}); diff --git a/test/background/keys.test.js b/test/background/keys.test.js index da9d430..2cb9a3a 100644 --- a/test/background/keys.test.js +++ b/test/background/keys.test.js @@ -1,55 +1,31 @@  import { expect } from "chai"; -import { identifyKey, identifyKeys, hasPrefix } from '../../src/background/keys'; +import * as keys from '../../src/background/keys'; -describe('keys', () => { -  describe('#identifyKey', () => { -    it('return true if key matched', () => { -      expect(identifyKey( -        { code: 100 }, -        { code: 100 })).to.be.true; -      expect(identifyKey( -        { code: 100, shift: true, ctrl: true }, -        { code: 100, shift: true, ctrl: true })).to.be.true; -      expect(identifyKey( -        { code: 100, shift: false, ctrl: false }, -        { code: 100 })).to.be.true; -    }); +describe("keys", () => { +  const KEYMAP = { +    'g<C-X>GG': [], +    'gg': { type: 'scroll.top' }, +  }; -    it('return false if key not matched', () => { -      expect(identifyKey( -        { code: 100 }, -        { code: 101 })).to.be.false; -      expect(identifyKey( -        { code: 100, shift: true, ctrl: true }, -        { code: 100, shift: true })).to.be.false; -    }); -  }); - -  describe('#identifyKeys', () => { -    it ('return true if keys matched', () => { -      let keys = [{ code: 100 }, { code: 101, ctrl: false}]; -      let prefix = [{ code: 100, ctrl: false }, { code: 101 }]; -      expect(hasPrefix(keys, prefix)).to.be.true; -    }); +  const g = 'g'.charCodeAt(0); +  const G = 'G'.charCodeAt(0); +  const x = 'x'.charCodeAt(0); -    it ('return false if keys matched', () => { -      let keys = [{ code: 100 }, { code: 101, ctrl: true }]; -      let prefix = [{ code: 100 }, { code: 101 }]; -      expect(hasPrefix(keys, prefix)).to.be.false; -    }); +  describe('#asKeymapChars', () => { +    let keySequence = [ +      { code: g }, +      { code: x, ctrl: true }, +      { code: G } +    ]; +    expect(keys.asKeymapChars(keySequence)).to.equal('g<C-X>G');    }); -  describe('#hasPrefix', () => { -    it ('return true if prefix matched', () => { -      let keys = [{ code: 100 }, { code: 101 }, { code: 102 }]; -      let prefix = [{ code: 100 }, { code: 101 }]; -      expect(hasPrefix(keys, prefix)).to.be.true; -    }); - -    it ('return false if prefix not matched', () => { -      let keys = [{ code: 100 }, { code: 101 }, { code: 102 }]; -      let prefix = [{ code: 102 }]; -      expect(hasPrefix(keys, prefix)).to.be.false; -    }); +  describe('#asCaretChars', () => { +    let keySequence = [ +      { code: g }, +      { code: x, ctrl: true }, +      { code: G } +    ]; +    expect(keys.asCaretChars(keySequence)).to.equal('g^XG');    });  }); diff --git a/test/reducers/console.test.js b/test/reducers/console.test.js new file mode 100644 index 0000000..9820a08 --- /dev/null +++ b/test/reducers/console.test.js @@ -0,0 +1,43 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import consoleReducer from '../../src/reducers/console'; + +describe("console reducer", () => { +  it('return the initial state', () => { +    let state = consoleReducer(undefined, {}); +    expect(state).to.have.property('errorShown', false); +    expect(state).to.have.property('errorText', ''); +    expect(state).to.have.property('commandShown', false); +    expect(state).to.have.property('commandText', ''); +    expect(state).to.have.deep.property('completions', []); +  }); + +  it('return next state for CONSOLE_SHOW_COMMAND', () => { +    let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; +    let state = consoleReducer({}, action); +    expect(state).to.have.property('commandShown', true); +    expect(state).to.have.property('commandText', 'open '); +    expect(state).to.have.property('errorShown', false); +  }); + +  it('return next state for CONSOLE_SET_COMPLETIONS', () => { +    let action = { type: actions.CONSOLE_SET_COMPLETIONS, completions: [1, 2, 3] }; +    let state = consoleReducer({}, action); +    expect(state).to.have.deep.property('completions', [1, 2, 3]); +  }); + +  it('return next state for CONSOLE_SHOW_ERROR', () => { +    let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; +    let state = consoleReducer({}, action); +    expect(state).to.have.property('errorShown', true); +    expect(state).to.have.property('errorText', 'an error'); +    expect(state).to.have.property('commandShown', false); +  }); + +  it('return next state for CONSOLE_HIDE', () => { +    let action = { type: actions.CONSOLE_HIDE }; +    let state = consoleReducer({}, action); +    expect(state).to.have.property('errorShown', false); +    expect(state).to.have.property('commandShown', false); +  }); +}); diff --git a/test/reducers/input.test.js b/test/reducers/input.test.js new file mode 100644 index 0000000..d7a0855 --- /dev/null +++ b/test/reducers/input.test.js @@ -0,0 +1,34 @@ +import { expect } from "chai"; +import actions from '../../src/actions'; +import inputReducer from '../../src/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, code: 123, ctrl: true }; +    let state = inputReducer(undefined, action); +    expect(state).to.have.deep.property('keys', [{ code: 123, ctrl: true }]); + +    action = { type: actions.INPUT_KEY_PRESS, code: 456, ctrl: false }; +    state = inputReducer(state, action); +    expect(state).to.have.deep.property('keys', [ +      { code: 123, ctrl: true }, +      { code: 456, ctrl: false } +    ]); +  }); + +  it('return next state for INPUT_CLEAR_KEYS', () => { +    let action = { type: actions.INPUT_CLEAR_KEYS }; +    let state = inputReducer({ +      keys: [ +        { code: 123, ctrl: true }, +        { code: 456, ctrl: false } +      ] +    }, action); +    expect(state).to.have.deep.property('keys', []); +  }); +}); diff --git a/test/shared/messages.test.js b/test/shared/messages.test.js deleted file mode 100644 index 0ebaf1a..0000000 --- a/test/shared/messages.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import { expect } from "chai"; -import * as messages from '../../src/shared/messages'; - -describe('messages', () => { -  describe('#receive', () => { -    it('received a message', (done) => { -      messages.receive(window, (message) => { -        expect(message).to.deep.equal({ type: 'vimvixen.test' }); -        done(); -      }); -      window.postMessage(JSON.stringify({ type: 'vimvixen.test' }), '*'); -    }); -  }); - -  describe('#send', () => { -    it('sends a message', (done) => { -      window.addEventListener('message', (e) => { -        let json = JSON.parse(e.data); -        expect(json).to.deep.equal({ type: 'vimvixen.test' }); -        done(); -      }); -      messages.send(window, { type: 'vimvixen.test' }); -    }); -  }); -}); | 
