diff options
Diffstat (limited to 'test/content/usecases')
-rw-r--r-- | test/content/usecases/ClipboardUseCase.test.ts | 95 | ||||
-rw-r--r-- | test/content/usecases/HintKeyProducer.test.ts | 33 |
2 files changed, 23 insertions, 105 deletions
diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts deleted file mode 100644 index 5de3e69..0000000 --- a/test/content/usecases/ClipboardUseCase.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -import ClipboardRepository from "../../../src/content/repositories/ClipboardRepository"; -import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository"; -import ClipboardUseCase from "../../../src/content/usecases/ClipboardUseCase"; -import OperationClient from "../../../src/content/client/OperationClient"; -import ConsoleClient from "../../../src/content/client/ConsoleClient"; - -import * as sinon from "sinon"; -import { expect } from "chai"; -import { Operation } from "../../../src/shared/operations"; - -describe("ClipboardUseCase", () => { - let clipboardRepository: ClipboardRepository; - - let operationClient: OperationClient; - - let consoleClient: ConsoleClient; - - let sut: ClipboardUseCase; - - beforeEach(() => { - clipboardRepository = new (class implements ClipboardRepository { - read(): string { - return ""; - } - write(_text: string) {} - })(); - operationClient = new (class implements OperationClient { - execBackgroundOp(_repeat: number, _op: Operation): Promise<void> { - return Promise.resolve(); - } - internalOpenUrl( - _url: string, - _newTab?: boolean, - _background?: boolean - ): Promise<void> { - return Promise.resolve(); - } - })(); - consoleClient = new (class implements ConsoleClient { - error(_text: string): Promise<void> { - return Promise.resolve(); - } - info(_text: string): Promise<void> { - return Promise.resolve(); - } - })(); - - sut = new ClipboardUseCase( - clipboardRepository, - new SettingRepositoryImpl(), - consoleClient, - operationClient - ); - }); - - describe("#yankCurrentURL", () => { - it("yanks current url", async () => { - const href = window.location.href; - const mockRepository = sinon.mock(clipboardRepository); - mockRepository.expects("write").withArgs(href); - const mockConsoleClient = sinon.mock(consoleClient); - mockConsoleClient.expects("info").withArgs("Yanked " + href); - - const yanked = await sut.yankCurrentURL(); - - expect(yanked).to.equal(href); - mockRepository.verify(); - mockConsoleClient.verify(); - }); - }); - - describe("#openOrSearch", () => { - it("opens url from the clipboard", async () => { - const url = "https://github.com/ueokande/vim-vixen"; - sinon.stub(clipboardRepository, "read").returns(url); - const mockOperationClient = sinon.mock(operationClient); - mockOperationClient.expects("internalOpenUrl").withArgs(url, true); - - await sut.openOrSearch(true); - - mockOperationClient.verify(); - }); - - it("opens search results from the clipboard", async () => { - const url = "https://google.com/search?q=banana"; - sinon.stub(clipboardRepository, "read").returns("banana"); - const mockOperationClient = sinon.mock(operationClient); - mockOperationClient.expects("internalOpenUrl").withArgs(url, true); - - await sut.openOrSearch(true); - - mockOperationClient.verify(); - }); - }); -}); diff --git a/test/content/usecases/HintKeyProducer.test.ts b/test/content/usecases/HintKeyProducer.test.ts index f7e02ea..9d320b4 100644 --- a/test/content/usecases/HintKeyProducer.test.ts +++ b/test/content/usecases/HintKeyProducer.test.ts @@ -1,13 +1,7 @@ -import HintKeyProducer from "../../../src/content/usecases/HintKeyProducer"; +import { HintKeyRepositoryImpl } from "../../../src/content/repositories/HintKeyRepository"; import { expect } from "chai"; -describe("HintKeyProducer class", () => { - describe("#constructor", () => { - it("throws an exception on empty charset", () => { - expect(() => new HintKeyProducer("")).to.throw(TypeError); - }); - }); - +describe("HintKeyProducerImpl class", () => { describe("#produce", () => { it("produce incremented keys", () => { const charset = "abc"; @@ -30,10 +24,29 @@ describe("HintKeyProducer class", () => { "aba", ]; - const producer = new HintKeyProducer(charset); + const sut = new HintKeyRepositoryImpl(); + sut.reset(charset); for (let i = 0; i < sequences.length; ++i) { - expect(producer.produce()).to.equal(sequences[i]); + expect(sut.produce()).to.equal(sequences[i]); } }); }); + + describe("#reset", () => { + it("resets charset", () => { + const sut = new HintKeyRepositoryImpl(); + + sut.reset("ab"); + expect(sut.produce()).to.equal("a"); + expect(sut.produce()).to.equal("b"); + + sut.reset("xy"); + expect(sut.produce()).to.equal("x"); + expect(sut.produce()).to.equal("y"); + }); + it("throws an exception on empty charset", () => { + const sut = new HintKeyRepositoryImpl(); + expect(() => sut.reset("")).to.throw(TypeError); + }); + }); }); |