diff options
Diffstat (limited to 'test/background')
5 files changed, 52 insertions, 12 deletions
diff --git a/test/background/mock/MockReadyFrameRepository.ts b/test/background/mock/MockReadyFrameRepository.ts new file mode 100644 index 0000000..63b7cf4 --- /dev/null +++ b/test/background/mock/MockReadyFrameRepository.ts @@ -0,0 +1,15 @@ +import ReadyFrameRepository from "../../../src/background/repositories/ReadyFrameRepository"; + +export default class MockReadyFrameRepository implements ReadyFrameRepository { + clearFrameIds(_tabId: number): Promise<void> { + throw new Error("not implemented"); + } + + addFrameId(_tabId: number, _fraemId: number): Promise<void> { + throw new Error("not implemented"); + } + + getFrameIds(_tabId: number): Promise<number[] | undefined> { + throw new Error("not implemented"); + } +} diff --git a/test/background/operators/impls/FindNextOperator.test.ts b/test/background/operators/impls/FindNextOperator.test.ts index 0bee3f5..b5088df 100644 --- a/test/background/operators/impls/FindNextOperator.test.ts +++ b/test/background/operators/impls/FindNextOperator.test.ts @@ -4,7 +4,7 @@ import FindNextOperator from "../../../../src/background/operators/impls/FindNex import MockFindRepository from "../../mock/MockFindRepository"; import MockFindClient from "../../mock/MockFindClient"; import MockConsoleClient from "../../mock/MockConsoleClient"; -import MockFramePresenter from "../../mock/MockFramePresenter"; +import MockReadyFrameRepository from "../../mock/MockReadyFrameRepository"; describe("FindNextOperator", () => { const keyword = "hello"; @@ -14,13 +14,13 @@ describe("FindNextOperator", () => { const findRepository = new MockFindRepository(); const findClient = new MockFindClient(); const consoleClient = new MockConsoleClient(); - const framePresenter = new MockFramePresenter(); + const frameRepository = new MockReadyFrameRepository(); const sut = new FindNextOperator( tabPresenter, findRepository, findClient, consoleClient, - framePresenter + frameRepository ); let currentTabId: number; @@ -152,7 +152,7 @@ describe("FindNextOperator", () => { .stub(findRepository, "getGlobalKeyword") .returns(Promise.resolve(keyword)); sinon - .stub(framePresenter, "getAllFrameIds") + .stub(frameRepository, "getFrameIds") .returns(Promise.resolve(frameIds)); sinon.stub(consoleClient, "showInfo").returns(Promise.resolve()); diff --git a/test/background/operators/impls/FindPrevOperator.test.ts b/test/background/operators/impls/FindPrevOperator.test.ts index ebac0dc..296f0dd 100644 --- a/test/background/operators/impls/FindPrevOperator.test.ts +++ b/test/background/operators/impls/FindPrevOperator.test.ts @@ -4,7 +4,7 @@ import FindPrevOperator from "../../../../src/background/operators/impls/FindPre import MockFindRepository from "../../mock/MockFindRepository"; import MockFindClient from "../../mock/MockFindClient"; import MockConsoleClient from "../../mock/MockConsoleClient"; -import MockFramePresenter from "../../mock/MockFramePresenter"; +import MockReadyFrameRepository from "../../mock/MockReadyFrameRepository"; describe("FindPrevOperator", () => { const keyword = "hello"; @@ -14,13 +14,13 @@ describe("FindPrevOperator", () => { const findRepository = new MockFindRepository(); const findClient = new MockFindClient(); const consoleClient = new MockConsoleClient(); - const framePresenter = new MockFramePresenter(); + const frameRepository = new MockReadyFrameRepository(); const sut = new FindPrevOperator( tabPresenter, findRepository, findClient, consoleClient, - framePresenter + frameRepository ); let currentTabId: number; @@ -152,7 +152,7 @@ describe("FindPrevOperator", () => { .stub(findRepository, "getGlobalKeyword") .returns(Promise.resolve(keyword)); sinon - .stub(framePresenter, "getAllFrameIds") + .stub(frameRepository, "getFrameIds") .returns(Promise.resolve(frameIds)); sinon.stub(consoleClient, "showInfo").returns(Promise.resolve()); diff --git a/test/background/repositories/ReadyFrameRepository.test.ts b/test/background/repositories/ReadyFrameRepository.test.ts new file mode 100644 index 0000000..d952a9b --- /dev/null +++ b/test/background/repositories/ReadyFrameRepository.test.ts @@ -0,0 +1,25 @@ +import { expect } from "chai"; +import { ReadyFrameRepositoryImpl } from "../../../src/background/repositories/ReadyFrameRepository"; + +describe("background/repositories/ReadyFrameRepositoryImpl", () => { + let sut: ReadyFrameRepositoryImpl; + + beforeEach(() => { + sut = new ReadyFrameRepositoryImpl(); + }); + + it("get and set a keyword", async () => { + expect(await sut.getFrameIds(1)).to.be.undefined; + + await sut.addFrameId(1, 10); + await sut.addFrameId(1, 11); + await sut.addFrameId(2, 20); + + expect(await sut.getFrameIds(1)).to.deep.equal([10, 11]); + expect(await sut.getFrameIds(2)).to.deep.equal([20]); + + await sut.clearFrameIds(1); + + expect(await sut.getFrameIds(1)).to.be.undefined; + }); +}); diff --git a/test/background/usecases/StartFindUseCase.test.ts b/test/background/usecases/StartFindUseCase.test.ts index 22ff9a5..99ab508 100644 --- a/test/background/usecases/StartFindUseCase.test.ts +++ b/test/background/usecases/StartFindUseCase.test.ts @@ -2,7 +2,7 @@ import * as sinon from "sinon"; import MockFindClient from "../mock/MockFindClient"; import MockFindRepository from "../mock/MockFindRepository"; import MockConsoleClient from "../mock/MockConsoleClient"; -import MockFramePresenter from "../mock/MockFramePresenter"; +import MockReadyFrameRepository from "../mock/MockReadyFrameRepository"; import StartFindUseCase from "../../../src/background/usecases/StartFindUseCase"; describe("StartFindUseCase", () => { @@ -13,19 +13,19 @@ describe("StartFindUseCase", () => { const findClient = new MockFindClient(); const findRepository = new MockFindRepository(); const consoleClient = new MockConsoleClient(); - const framePresenter = new MockFramePresenter(); + const frameRepository = new MockReadyFrameRepository(); const sut = new StartFindUseCase( findClient, findRepository, consoleClient, - framePresenter + frameRepository ); beforeEach(async () => { sinon.restore(); sinon - .stub(framePresenter, "getAllFrameIds") + .stub(frameRepository, "getFrameIds") .returns(Promise.resolve(frameIds)); }); |