diff options
Diffstat (limited to 'test/console')
-rw-r--r-- | test/console/actions/completion.test.ts | 28 | ||||
-rw-r--r-- | test/console/actions/console.test.ts | 9 | ||||
-rw-r--r-- | test/console/completion/reducer.test.ts | 168 | ||||
-rw-r--r-- | test/console/reducers/completion.test.ts | 102 | ||||
-rw-r--r-- | test/console/reducers/console.test.ts | 11 |
5 files changed, 168 insertions, 150 deletions
diff --git a/test/console/actions/completion.test.ts b/test/console/actions/completion.test.ts deleted file mode 100644 index cd6899a..0000000 --- a/test/console/actions/completion.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import * as completionActions from "../../../src/console/actions/completion"; -import { - COMPLETION_COMPLETION_NEXT, - COMPLETION_COMPLETION_PREV, -} from "../../../src/console/actions/completion"; -import { expect } from "chai"; - -import browserFake from "webextensions-api-fake"; - -describe("completion actions", () => { - beforeEach(() => { - (global as any).browser = browserFake(); - }); - - describe("completionPrev", () => { - it("create COMPLETION_COMPLETION_PREV action", () => { - const action = completionActions.completionPrev(); - expect(action.type).to.equal(COMPLETION_COMPLETION_PREV); - }); - }); - - describe("completionNext", () => { - it("create COMPLETION_COMPLETION_NEXT action", () => { - const action = completionActions.completionNext(); - expect(action.type).to.equal(COMPLETION_COMPLETION_NEXT); - }); - }); -}); diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts index f5f102b..736dd54 100644 --- a/test/console/actions/console.test.ts +++ b/test/console/actions/console.test.ts @@ -2,7 +2,6 @@ import * as consoleActions from "../../../src/console/actions/console"; import { CONSOLE_HIDE, CONSOLE_HIDE_COMMAND, - CONSOLE_SET_CONSOLE_TEXT, CONSOLE_SHOW_COMMAND, CONSOLE_SHOW_ERROR, CONSOLE_SHOW_FIND, @@ -60,12 +59,4 @@ describe("console actions", () => { expect(action.type).to.equal(CONSOLE_HIDE_COMMAND); }); }); - - describe("setConsoleText", () => { - it("create CONSOLE_SET_CONSOLE_TEXT action", () => { - const action = consoleActions.setConsoleText("hello world"); - expect(action.type).to.equal(CONSOLE_SET_CONSOLE_TEXT); - expect(action.consoleText).to.equal("hello world"); - }); - }); }); diff --git a/test/console/completion/reducer.test.ts b/test/console/completion/reducer.test.ts new file mode 100644 index 0000000..b742872 --- /dev/null +++ b/test/console/completion/reducer.test.ts @@ -0,0 +1,168 @@ +import reducer, { + defaultState, + State, +} from "../../../src/console/completion/reducer"; +import { expect } from "chai"; +import { + initCompletion, + selectNext, + selectPrev, + setCompletions, + setCompletionSource, +} from "../../../src/console/completion/actions"; +import CompletionType from "../../../src/shared/CompletionType"; + +describe("completion reducer", () => { + describe("initCompletion", () => { + it("initializes completions", () => { + const nextState = reducer( + defaultState, + initCompletion([CompletionType.Bookmarks, CompletionType.History]) + ); + + expect(nextState.completionTypes).deep.equals([ + CompletionType.Bookmarks, + CompletionType.History, + ]); + }); + }); + + describe("setCompletionSource", () => { + it("sets a completion source", () => { + const nextState = reducer(defaultState, setCompletionSource("open ")); + + expect(nextState.completionSource).equals("open "); + }); + }); + + describe("setCompletions", () => { + it("sets completions", () => { + const nextState = reducer( + defaultState, + setCompletions([ + { + name: "Apple", + items: [{}, {}], + }, + { + name: "Banana", + items: [{}], + }, + ]) + ); + + expect(nextState.completions).deep.equals([ + { + name: "Apple", + items: [{}, {}], + }, + { + name: "Banana", + items: [{}], + }, + ]); + }); + }); + + describe("selectNext", () => { + context("when no completion groups", () => { + it("does nothing", () => { + const nextState = reducer(defaultState, selectNext()); + expect(nextState.select).equals(-1); + }); + }); + + context("when no completion items", () => { + it("does nothing", () => { + const state = { + ...defaultState, + completions: [{ name: "apple", items: [] }], + }; + const nextState = reducer(state, selectNext()); + expect(nextState.select).equals(-1); + }); + }); + + context("when completions exist", () => { + it("selects next selection", () => { + let state: State = { + ...defaultState, + select: -1, + completions: [ + { + name: "Apple", + items: [{}, {}], + }, + { + name: "Banana", + items: [{}], + }, + ], + }; + + state = reducer(state, selectNext()); + expect(state.select).equals(0); + + state = reducer(state, selectNext()); + expect(state.select).equals(1); + + state = reducer(state, selectNext()); + expect(state.select).equals(2); + + state = reducer(state, selectNext()); + expect(state.select).equals(-1); + }); + }); + }); + + describe("selectPrev", () => { + context("when no completion groups", () => { + it("does nothing", () => { + const nextState = reducer(defaultState, selectPrev()); + expect(nextState.select).equals(-1); + }); + + context("when no completion items", () => { + it("does nothing", () => { + const state = { + ...defaultState, + completions: [{ name: "apple", items: [] }], + }; + const nextState = reducer(state, selectPrev()); + expect(nextState.select).equals(-1); + }); + }); + }); + + context("when completions exist", () => { + it("selects a previous completion", () => { + let state: State = { + ...defaultState, + select: -1, + completions: [ + { + name: "Apple", + items: [{}, {}], + }, + { + name: "Banana", + items: [{}], + }, + ], + }; + + state = reducer(state, selectPrev()); + expect(state).to.have.property("select", 2); + + state = reducer(state, selectPrev()); + expect(state).to.have.property("select", 1); + + state = reducer(state, selectPrev()); + expect(state).to.have.property("select", 0); + + state = reducer(state, selectPrev()); + expect(state).to.have.property("select", -1); + }); + }); + }); +}); diff --git a/test/console/reducers/completion.test.ts b/test/console/reducers/completion.test.ts deleted file mode 100644 index 6c76369..0000000 --- a/test/console/reducers/completion.test.ts +++ /dev/null @@ -1,102 +0,0 @@ -import reducer, { State } from "../../../src/console/reducers/completion"; -import { expect } from "chai"; -import { - COMPLETION_COMPLETION_NEXT, - COMPLETION_COMPLETION_PREV, - COMPLETION_SET_COMPLETIONS, - CompletionAction, -} from "../../../src/console/actions/completion"; - -describe("completion reducer", () => { - it("return next state for CONSOLE_SET_COMPLETIONS", () => { - const initialState = reducer(undefined, {} as any); - let state: State = { - ...initialState, - select: 0, - completions: [], - }; - const action: CompletionAction = { - type: COMPLETION_SET_COMPLETIONS, - completions: [ - { - name: "Apple", - items: [{}, {}, {}], - }, - { - name: "Banana", - items: [{}, {}, {}], - }, - ], - completionSource: "", - }; - state = reducer(state, action); - expect(state).to.have.property("completions", action.completions); - expect(state).to.have.property("select", -1); - }); - - it("return next state for CONSOLE_COMPLETION_NEXT", () => { - const initialState = reducer(undefined, {} as any); - const action: CompletionAction = { - type: COMPLETION_COMPLETION_NEXT, - }; - let state = { - ...initialState, - select: -1, - completions: [ - { - name: "Apple", - items: [{}, {}], - }, - { - name: "Banana", - items: [{}], - }, - ], - }; - - state = reducer(state, action); - expect(state).to.have.property("select", 0); - - state = reducer(state, action); - expect(state).to.have.property("select", 1); - - state = reducer(state, action); - expect(state).to.have.property("select", 2); - - state = reducer(state, action); - expect(state).to.have.property("select", -1); - }); - - it("return next state for CONSOLE_COMPLETION_PREV", () => { - const initialState = reducer(undefined, {} as any); - const action: CompletionAction = { - type: COMPLETION_COMPLETION_PREV, - }; - let state = { - ...initialState, - select: -1, - completions: [ - { - name: "Apple", - items: [{}, {}], - }, - { - name: "Banana", - items: [{}], - }, - ], - }; - - state = reducer(state, action); - expect(state).to.have.property("select", 2); - - state = reducer(state, action); - expect(state).to.have.property("select", 1); - - state = reducer(state, action); - expect(state).to.have.property("select", 0); - - state = reducer(state, action); - expect(state).to.have.property("select", -1); - }); -}); diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts index 4d4859d..390dc66 100644 --- a/test/console/reducers/console.test.ts +++ b/test/console/reducers/console.test.ts @@ -3,7 +3,6 @@ import { expect } from "chai"; import { CONSOLE_HIDE, CONSOLE_HIDE_COMMAND, - CONSOLE_SET_CONSOLE_TEXT, CONSOLE_SHOW_COMMAND, CONSOLE_SHOW_ERROR, CONSOLE_SHOW_INFO, @@ -66,14 +65,4 @@ describe("console reducer", () => { state = reducer({ ...initialState, mode: "error" }, action); expect(state).to.have.property("mode", "error"); }); - - it("return next state for CONSOLE_SET_CONSOLE_TEXT", () => { - const action: ConsoleAction = { - type: CONSOLE_SET_CONSOLE_TEXT, - consoleText: "hello world", - }; - const state = reducer(undefined, action); - - expect(state).to.have.property("consoleText", "hello world"); - }); }); |