diff options
Diffstat (limited to 'test/console')
-rw-r--r-- | test/console/actions/console.test.ts | 44 | ||||
-rw-r--r-- | test/console/commandline/CommandLineParser.test.ts | 10 | ||||
-rw-r--r-- | test/console/commandline/CommandParser.test.ts | 10 | ||||
-rw-r--r-- | test/console/components/console/Completion.test.tsx | 195 | ||||
-rw-r--r-- | test/console/reducers/console.test.ts | 149 |
5 files changed, 205 insertions, 203 deletions
diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts index e6567b2..5a531a6 100644 --- a/test/console/actions/console.test.ts +++ b/test/console/actions/console.test.ts @@ -1,69 +1,69 @@ -import * as actions from '../../../src/console/actions'; -import * as consoleActions from '../../../src/console/actions/console'; -import { expect } from 'chai'; +import * as actions from "../../../src/console/actions"; +import * as consoleActions from "../../../src/console/actions/console"; +import { expect } from "chai"; describe("console actions", () => { - describe('hide', () => { - it('create CONSOLE_HIDE action', () => { + describe("hide", () => { + it("create CONSOLE_HIDE action", () => { const action = consoleActions.hide(); expect(action.type).to.equal(actions.CONSOLE_HIDE); }); }); describe("showCommand", () => { - it('create CONSOLE_SHOW_COMMAND action', async () => { - const action = await consoleActions.showCommand('hello'); + it("create CONSOLE_SHOW_COMMAND action", async () => { + const action = await consoleActions.showCommand("hello"); expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND); - expect(action.text).to.equal('hello'); + expect(action.text).to.equal("hello"); }); }); describe("showFind", () => { - it('create CONSOLE_SHOW_FIND action', () => { + it("create CONSOLE_SHOW_FIND action", () => { const action = consoleActions.showFind(); expect(action.type).to.equal(actions.CONSOLE_SHOW_FIND); }); }); describe("showError", () => { - it('create CONSOLE_SHOW_ERROR action', () => { - const action = consoleActions.showError('an error'); + it("create CONSOLE_SHOW_ERROR action", () => { + const action = consoleActions.showError("an error"); expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR); - expect(action.text).to.equal('an error'); + expect(action.text).to.equal("an error"); }); }); describe("showInfo", () => { - it('create CONSOLE_SHOW_INFO action', () => { - const action = consoleActions.showInfo('an info'); + it("create CONSOLE_SHOW_INFO action", () => { + const action = consoleActions.showInfo("an info"); expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO); - expect(action.text).to.equal('an info'); + expect(action.text).to.equal("an info"); }); }); describe("hideCommand", () => { - it('create CONSOLE_HIDE_COMMAND action', () => { + it("create CONSOLE_HIDE_COMMAND action", () => { const action = consoleActions.hideCommand(); expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND); }); }); - describe('setConsoleText', () => { - it('create CONSOLE_SET_CONSOLE_TEXT action', () => { - const action = consoleActions.setConsoleText('hello world'); + describe("setConsoleText", () => { + it("create CONSOLE_SET_CONSOLE_TEXT action", () => { + const action = consoleActions.setConsoleText("hello world"); expect(action.type).to.equal(actions.CONSOLE_SET_CONSOLE_TEXT); - expect(action.consoleText).to.equal('hello world'); + expect(action.consoleText).to.equal("hello world"); }); }); describe("completionPrev", () => { - it('create CONSOLE_COMPLETION_PREV action', () => { + it("create CONSOLE_COMPLETION_PREV action", () => { const action = consoleActions.completionPrev(); expect(action.type).to.equal(actions.CONSOLE_COMPLETION_PREV); }); }); describe("completionNext", () => { - it('create CONSOLE_COMPLETION_NEXT action', () => { + it("create CONSOLE_COMPLETION_NEXT action", () => { const action = consoleActions.completionNext(); expect(action.type).to.equal(actions.CONSOLE_COMPLETION_NEXT); }); diff --git a/test/console/commandline/CommandLineParser.test.ts b/test/console/commandline/CommandLineParser.test.ts index 6aec682..7cba04c 100644 --- a/test/console/commandline/CommandLineParser.test.ts +++ b/test/console/commandline/CommandLineParser.test.ts @@ -1,4 +1,6 @@ -import CommandLineParser, {InputPhase} from "../../../src/console/commandline/CommandLineParser"; +import CommandLineParser, { + InputPhase, +} from "../../../src/console/commandline/CommandLineParser"; import { Command } from "../../../src/shared/Command"; import { expect } from "chai"; @@ -9,7 +11,7 @@ describe("CommandLineParser", () => { expect(sut.inputPhase("")).to.equal(InputPhase.OnCommand); expect(sut.inputPhase("op")).to.equal(InputPhase.OnCommand); expect(sut.inputPhase("open ")).to.equal(InputPhase.OnArgs); - expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs) + expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs); }); }); describe("#parse", () => { @@ -24,6 +26,6 @@ describe("CommandLineParser", () => { command: Command.QuitAll, args: "", }); - }) - }) + }); + }); }); diff --git a/test/console/commandline/CommandParser.test.ts b/test/console/commandline/CommandParser.test.ts index 4ad78fd..f72afd6 100644 --- a/test/console/commandline/CommandParser.test.ts +++ b/test/console/commandline/CommandParser.test.ts @@ -1,6 +1,8 @@ -import CommandParser, { UnknownCommandError } from "../../../src/console/commandline/CommandParser"; +import CommandParser, { + UnknownCommandError, +} from "../../../src/console/commandline/CommandParser"; import { Command } from "../../../src/shared/Command"; -import { expect } from "chai" +import { expect } from "chai"; describe("CommandParser", () => { describe("#parse", () => { @@ -10,6 +12,6 @@ describe("CommandParser", () => { expect(sut.parse("w")).to.equal(Command.WindowOpen); expect(sut.parse("bdelete!")).to.equal(Command.BufferDeleteForce); expect(() => sut.parse("harakiri")).to.throw(UnknownCommandError); - }) - }) + }); + }); }); diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx index e411c4a..200bb1a 100644 --- a/test/console/components/console/Completion.test.tsx +++ b/test/console/components/console/Completion.test.tsx @@ -1,53 +1,59 @@ -import React from 'react'; -import Completion from 'console/components/console/Completion' -import ReactTestRenderer from 'react-test-renderer'; +import React from "react"; +import Completion from "console/components/console/Completion"; +import ReactTestRenderer from "react-test-renderer"; describe("console/components/console/completion", () => { - const completions = [{ - name: "Fruit", - items: [{ caption: "apple" }, { caption: "banana" }, { caption: "cherry" }], - }, { - name: "Element", - items: [{ caption: "argon" }, { caption: "boron" }, { caption: "carbon" }], - }]; - - it('renders Completion component', () => { - const root = ReactTestRenderer.create(<Completion - completions={completions} - size={30} - />).root; + const completions = [ + { + name: "Fruit", + items: [ + { caption: "apple" }, + { caption: "banana" }, + { caption: "cherry" }, + ], + }, + { + name: "Element", + items: [ + { caption: "argon" }, + { caption: "boron" }, + { caption: "carbon" }, + ], + }, + ]; + + it("renders Completion component", () => { + const root = ReactTestRenderer.create( + <Completion completions={completions} size={30} /> + ).root; expect(root.children).to.have.lengthOf(1); const children = root.children[0].children; expect(children).to.have.lengthOf(8); - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); - expect(children[3].props.caption).to.equal('cherry'); - expect(children[4].props.title).to.equal('Element'); - expect(children[5].props.caption).to.equal('argon'); - expect(children[6].props.caption).to.equal('boron'); - expect(children[7].props.caption).to.equal('carbon'); + expect(children[0].props.title).to.equal("Fruit"); + expect(children[1].props.caption).to.equal("apple"); + expect(children[2].props.caption).to.equal("banana"); + expect(children[3].props.caption).to.equal("cherry"); + expect(children[4].props.title).to.equal("Element"); + expect(children[5].props.caption).to.equal("argon"); + expect(children[6].props.caption).to.equal("boron"); + expect(children[7].props.caption).to.equal("carbon"); }); - it('highlight current item', () => { - const root = ReactTestRenderer.create(<Completion - completions={completions} - size={30} - select={3} - />).root; + it("highlight current item", () => { + const root = ReactTestRenderer.create( + <Completion completions={completions} size={30} select={3} /> + ).root; const children = root.children[0].children; expect(children[5].props.highlight).to.be.true; }); - it('does not highlight any items', () => { - const root = ReactTestRenderer.create(<Completion - completions={completions} - size={30} - select={-1} - />).root; + it("does not highlight any items", () => { + const root = ReactTestRenderer.create( + <Completion completions={completions} size={30} select={-1} /> + ).root; const children = root.children[0].children; for (const li of children[0].children) { @@ -55,112 +61,95 @@ describe("console/components/console/completion", () => { } }); - it('limits completion items', () => { - let root = ReactTestRenderer.create(<Completion - completions={completions} - size={3} - select={-1} - />).root; + it("limits completion items", () => { + let root = ReactTestRenderer.create( + <Completion completions={completions} size={3} select={-1} /> + ).root; let children = root.children[0].children; expect(children).to.have.lengthOf(3); - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); + expect(children[0].props.title).to.equal("Fruit"); + expect(children[1].props.caption).to.equal("apple"); + expect(children[2].props.caption).to.equal("banana"); - root = ReactTestRenderer.create(<Completion - completions={completions} - size={3} select={0} - />).root; + root = ReactTestRenderer.create( + <Completion completions={completions} size={3} select={0} /> + ).root; children = root.children[0].children; expect(children[1].props.highlight).to.be.true; - }) - - it('scrolls up to down with select', () => { - const component = ReactTestRenderer.create(<Completion - completions={completions} - size={3} - select={1} - />); + }); + + it("scrolls up to down with select", () => { + const component = ReactTestRenderer.create( + <Completion completions={completions} size={3} select={1} /> + ); const root = component.root; let children = root.children[0].children; expect(children).to.have.lengthOf(3); - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); + expect(children[0].props.title).to.equal("Fruit"); + expect(children[1].props.caption).to.equal("apple"); + expect(children[2].props.caption).to.equal("banana"); - component.update(<Completion - completions={completions} - size={3} - select={2} - />); + component.update( + <Completion completions={completions} size={3} select={2} /> + ); children = root.children[0].children; expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('apple'); - expect(children[1].props.caption).to.equal('banana'); - expect(children[2].props.caption).to.equal('cherry'); + expect(children[0].props.caption).to.equal("apple"); + expect(children[1].props.caption).to.equal("banana"); + expect(children[2].props.caption).to.equal("cherry"); expect(children[2].props.highlight).to.be.true; - component.update(<Completion - completions={completions} - size={3} - select={3} - />); + component.update( + <Completion completions={completions} size={3} select={3} /> + ); children = root.children[0].children; expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('cherry'); - expect(children[1].props.title).to.equal('Element'); - expect(children[2].props.caption).to.equal('argon'); + expect(children[0].props.caption).to.equal("cherry"); + expect(children[1].props.title).to.equal("Element"); + expect(children[2].props.caption).to.equal("argon"); expect(children[2].props.highlight).to.be.true; }); - it('scrolls down to up with select', () => { - const component = ReactTestRenderer.create(<Completion - completions={completions} - size={3} - select={5} - />); + it("scrolls down to up with select", () => { + const component = ReactTestRenderer.create( + <Completion completions={completions} size={3} select={5} /> + ); const root = component.root; let children = root.children[0].children; expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('argon'); - expect(children[1].props.caption).to.equal('boron'); - expect(children[2].props.caption).to.equal('carbon'); + expect(children[0].props.caption).to.equal("argon"); + expect(children[1].props.caption).to.equal("boron"); + expect(children[2].props.caption).to.equal("carbon"); - component.update(<Completion - completions={completions} - size={3} - select={4} - />); + component.update( + <Completion completions={completions} size={3} select={4} /> + ); children = root.children[0].children; expect(children[1].props.highlight).to.be.true; - component.update(<Completion - completions={completions} - size={3} - select={3} - />); + component.update( + <Completion completions={completions} size={3} select={3} /> + ); children = root.children[0].children; expect(children[0].props.highlight).to.be.true; - component.update(<Completion - completions={completions} - size={3} - select={2} - />); + component.update( + <Completion completions={completions} size={3} select={2} /> + ); children = root.children[0].children; - expect(children[0].props.caption).to.equal('cherry'); - expect(children[1].props.title).to.equal('Element'); - expect(children[2].props.caption).to.equal('argon'); + expect(children[0].props.caption).to.equal("cherry"); + expect(children[1].props.title).to.equal("Element"); + expect(children[2].props.caption).to.equal("argon"); expect(children[0].props.highlight).to.be.true; }); }); diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts index 038e712..e8432c5 100644 --- a/test/console/reducers/console.test.ts +++ b/test/console/reducers/console.test.ts @@ -1,131 +1,140 @@ -import * as actions from 'console/actions'; -import reducer from 'console/reducers'; +import * as actions from "console/actions"; +import reducer from "console/reducers"; describe("console reducer", () => { - it('return the initial state', () => { + it("return the initial state", () => { const state = reducer(undefined, {}); - expect(state).to.have.property('mode', ''); - expect(state).to.have.property('messageText', ''); - expect(state).to.have.property('consoleText', ''); - expect(state).to.have.deep.property('completions', []); - expect(state).to.have.property('select', -1); + expect(state).to.have.property("mode", ""); + expect(state).to.have.property("messageText", ""); + expect(state).to.have.property("consoleText", ""); + expect(state).to.have.deep.property("completions", []); + expect(state).to.have.property("select", -1); }); - it('return next state for CONSOLE_HIDE', () => { + it("return next state for CONSOLE_HIDE", () => { const action = { type: actions.CONSOLE_HIDE }; - const state = reducer({ mode: 'error' }, action); - expect(state).to.have.property('mode', ''); - }) + const state = reducer({ mode: "error" }, action); + expect(state).to.have.property("mode", ""); + }); - it('return next state for CONSOLE_SHOW_COMMAND', () => { - const action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; + it("return next state for CONSOLE_SHOW_COMMAND", () => { + const action = { type: actions.CONSOLE_SHOW_COMMAND, text: "open " }; const state = reducer({}, action); - expect(state).to.have.property('mode', 'command'); - expect(state).to.have.property('consoleText', 'open '); + expect(state).to.have.property("mode", "command"); + expect(state).to.have.property("consoleText", "open "); }); - it('return next state for CONSOLE_SHOW_INFO', () => { - const action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' }; + it("return next state for CONSOLE_SHOW_INFO", () => { + const action = { type: actions.CONSOLE_SHOW_INFO, text: "an info" }; const state = reducer({}, action); - expect(state).to.have.property('mode', 'info'); - expect(state).to.have.property('messageText', 'an info'); + expect(state).to.have.property("mode", "info"); + expect(state).to.have.property("messageText", "an info"); }); - it('return next state for CONSOLE_SHOW_ERROR', () => { - const action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; + it("return next state for CONSOLE_SHOW_ERROR", () => { + const action = { type: actions.CONSOLE_SHOW_ERROR, text: "an error" }; const state = reducer({}, action); - expect(state).to.have.property('mode', 'error'); - expect(state).to.have.property('messageText', 'an error'); + expect(state).to.have.property("mode", "error"); + expect(state).to.have.property("messageText", "an error"); }); - it('return next state for CONSOLE_HIDE_COMMAND', () => { + it("return next state for CONSOLE_HIDE_COMMAND", () => { const action = { type: actions.CONSOLE_HIDE_COMMAND }; - let state = reducer({ mode: 'command' }, action); - expect(state).to.have.property('mode', ''); + let state = reducer({ mode: "command" }, action); + expect(state).to.have.property("mode", ""); - state = reducer({ mode: 'error' }, action); - expect(state).to.have.property('mode', 'error'); + state = reducer({ mode: "error" }, action); + expect(state).to.have.property("mode", "error"); }); - it('return next state for CONSOLE_SET_CONSOLE_TEXT', () => { + it("return next state for CONSOLE_SET_CONSOLE_TEXT", () => { const action = { type: actions.CONSOLE_SET_CONSOLE_TEXT, - consoleText: 'hello world' - } - const state = reducer({}, action) + consoleText: "hello world", + }; + const state = reducer({}, action); - expect(state).to.have.property('consoleText', 'hello world'); + expect(state).to.have.property("consoleText", "hello world"); }); - it ('return next state for CONSOLE_SET_COMPLETIONS', () => { + it("return next state for CONSOLE_SET_COMPLETIONS", () => { let state = { select: 0, completions: [], - } + }; const action = { type: actions.CONSOLE_SET_COMPLETIONS, - completions: [{ - name: 'Apple', - items: [1, 2, 3] - }, { - name: 'Banana', - items: [4, 5, 6] - }] - } + completions: [ + { + name: "Apple", + items: [1, 2, 3], + }, + { + name: "Banana", + items: [4, 5, 6], + }, + ], + }; state = reducer(state, action); - expect(state).to.have.property('completions', action.completions); - expect(state).to.have.property('select', -1); + expect(state).to.have.property("completions", action.completions); + expect(state).to.have.property("select", -1); }); - it ('return next state for CONSOLE_COMPLETION_NEXT', () => { + it("return next state for CONSOLE_COMPLETION_NEXT", () => { const action = { type: actions.CONSOLE_COMPLETION_NEXT }; let state = { select: -1, - completions: [{ - name: 'Apple', - items: [1, 2] - }, { - name: 'Banana', - items: [3] - }] + completions: [ + { + name: "Apple", + items: [1, 2], + }, + { + name: "Banana", + items: [3], + }, + ], }; state = reducer(state, action); - expect(state).to.have.property('select', 0); + expect(state).to.have.property("select", 0); state = reducer(state, action); - expect(state).to.have.property('select', 1); + expect(state).to.have.property("select", 1); state = reducer(state, action); - expect(state).to.have.property('select', 2); + expect(state).to.have.property("select", 2); state = reducer(state, action); - expect(state).to.have.property('select', -1); + expect(state).to.have.property("select", -1); }); - it ('return next state for CONSOLE_COMPLETION_PREV', () => { + it("return next state for CONSOLE_COMPLETION_PREV", () => { const action = { type: actions.CONSOLE_COMPLETION_PREV }; let state = { select: -1, - completions: [{ - name: 'Apple', - items: [1, 2] - }, { - name: 'Banana', - items: [3] - }] + completions: [ + { + name: "Apple", + items: [1, 2], + }, + { + name: "Banana", + items: [3], + }, + ], }; state = reducer(state, action); - expect(state).to.have.property('select', 2); + expect(state).to.have.property("select", 2); state = reducer(state, action); - expect(state).to.have.property('select', 1); + expect(state).to.have.property("select", 1); state = reducer(state, action); - expect(state).to.have.property('select', 0); + expect(state).to.have.property("select", 0); state = reducer(state, action); - expect(state).to.have.property('select', -1); + expect(state).to.have.property("select", -1); }); }); |