aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-07-29 22:29:40 +0900
committerGitHub <noreply@github.com>2021-07-29 22:29:40 +0900
commit5592b02a1500062628063862158116f382f3d8e2 (patch)
tree5c29d29a8fa1aa14f4f6407a66bcaf528c42555c /test
parent75236e9a41788f64df61b14a99e78aedc548e0ad (diff)
parent1160cf8aedf9810a76d84e3d99a72365e8aeae8a (diff)
Merge pull request #1213 from ueokande/cross-frame-search
Cross frame search
Diffstat (limited to 'test')
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts4
-rw-r--r--test/background/mock/MockFindClient.ts23
-rw-r--r--test/background/mock/MockFindRepository.ts31
-rw-r--r--test/background/mock/MockFramePresenter.ts7
-rw-r--r--test/background/mock/MockTabPresenter.ts4
-rw-r--r--test/background/operators/impls/FindNextOperator.test.ts179
-rw-r--r--test/background/operators/impls/FindOperatorFactoryChain.ts23
-rw-r--r--test/background/operators/impls/FindPrevOperator.test.ts179
-rw-r--r--test/background/operators/impls/TabOperatorFactoryChain.test.ts12
-rw-r--r--test/background/repositories/FindRepository.test.ts38
-rw-r--r--test/background/usecases/StartFindUseCase.test.ts180
-rw-r--r--test/content/mock/MockFindMasterClient.ts11
-rw-r--r--test/content/operators/impls/FindNextOperator.test.ts17
-rw-r--r--test/content/operators/impls/FindOperatorFactoryChain.test.ts21
-rw-r--r--test/content/operators/impls/FindPrevOperator.test.ts17
-rw-r--r--test/content/repositories/FindRepository.test.ts14
-rw-r--r--test/content/usecases/FindUseCase.test.ts160
17 files changed, 674 insertions, 246 deletions
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
index e1a88a2..319f217 100644
--- a/test/background/completion/TabCompletionUseCase.test.ts
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -82,6 +82,10 @@ class MockTabPresenter implements TabPresenter {
setZoom(_tabId: number, _factor: number): Promise<void> {
throw new Error("not implemented");
}
+
+ toggleReaderMode(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
}
describe("TabCompletionUseCase", () => {
diff --git a/test/background/mock/MockFindClient.ts b/test/background/mock/MockFindClient.ts
new file mode 100644
index 0000000..dd6d8f3
--- /dev/null
+++ b/test/background/mock/MockFindClient.ts
@@ -0,0 +1,23 @@
+import FindClient from "../../../src/background/clients/FindClient";
+
+export default class MockFindClient implements FindClient {
+ findNext(
+ _tabId: number,
+ _frameId: number,
+ _keyword: string
+ ): Promise<boolean> {
+ throw new Error("not implemented");
+ }
+
+ findPrev(
+ _tabId: number,
+ _frameId: number,
+ _keyword: string
+ ): Promise<boolean> {
+ throw new Error("not implemented");
+ }
+
+ clearSelection(_tabId: number, _frameId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/mock/MockFindRepository.ts b/test/background/mock/MockFindRepository.ts
new file mode 100644
index 0000000..d5151f8
--- /dev/null
+++ b/test/background/mock/MockFindRepository.ts
@@ -0,0 +1,31 @@
+import FindRepository, {
+ FindState,
+} from "../../../src/background/repositories/FindRepository";
+
+export default class MockFindRepository implements FindRepository {
+ private globalKeyword: string | undefined;
+ private localStates: { [tabId: number]: FindState } = {};
+
+ getGlobalKeyword(): Promise<string | undefined> {
+ return Promise.resolve(this.globalKeyword);
+ }
+
+ setGlobalKeyword(keyword: string): Promise<void> {
+ this.globalKeyword = keyword;
+ return Promise.resolve();
+ }
+
+ getLocalState(tabId: number): Promise<FindState | undefined> {
+ return Promise.resolve(this.localStates[tabId]);
+ }
+
+ setLocalState(tabId: number, state: FindState): Promise<void> {
+ this.localStates[tabId] = state;
+ return Promise.resolve();
+ }
+
+ deleteLocalState(tabId: number): Promise<void> {
+ delete this.localStates[tabId];
+ return Promise.resolve();
+ }
+}
diff --git a/test/background/mock/MockFramePresenter.ts b/test/background/mock/MockFramePresenter.ts
new file mode 100644
index 0000000..d688780
--- /dev/null
+++ b/test/background/mock/MockFramePresenter.ts
@@ -0,0 +1,7 @@
+import FramePresenter from "../../../src/background/presenters/FramePresenter";
+
+export default class MockFramePresenter implements FramePresenter {
+ getAllFrameIds(): Promise<number[]> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/mock/MockTabPresenter.ts b/test/background/mock/MockTabPresenter.ts
index 22fb947..0968e44 100644
--- a/test/background/mock/MockTabPresenter.ts
+++ b/test/background/mock/MockTabPresenter.ts
@@ -176,4 +176,8 @@ export default class MockTabPresenter implements TabPresenter {
this.zooms[index] = factor;
return Promise.resolve();
}
+
+ toggleReaderMode(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
}
diff --git a/test/background/operators/impls/FindNextOperator.test.ts b/test/background/operators/impls/FindNextOperator.test.ts
new file mode 100644
index 0000000..0bee3f5
--- /dev/null
+++ b/test/background/operators/impls/FindNextOperator.test.ts
@@ -0,0 +1,179 @@
+import * as sinon from "sinon";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import FindNextOperator from "../../../../src/background/operators/impls/FindNextOperator";
+import MockFindRepository from "../../mock/MockFindRepository";
+import MockFindClient from "../../mock/MockFindClient";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+import MockFramePresenter from "../../mock/MockFramePresenter";
+
+describe("FindNextOperator", () => {
+ const keyword = "hello";
+ const frameIds = [0, 100, 101];
+
+ const tabPresenter = new MockTabPresenter();
+ const findRepository = new MockFindRepository();
+ const findClient = new MockFindClient();
+ const consoleClient = new MockConsoleClient();
+ const framePresenter = new MockFramePresenter();
+ const sut = new FindNextOperator(
+ tabPresenter,
+ findRepository,
+ findClient,
+ consoleClient,
+ framePresenter
+ );
+
+ let currentTabId: number;
+
+ beforeEach(async () => {
+ sinon.restore();
+
+ const currentTab = await tabPresenter.create("https://example.com/", {
+ active: true,
+ });
+ currentTabId = currentTab.id!;
+ });
+
+ describe("#run", () => {
+ it("shows errors if no previous keywords", async () => {
+ sinon
+ .stub(findRepository, "getLocalState")
+ .returns(Promise.resolve(undefined));
+
+ const mock = sinon.mock(consoleClient);
+ mock
+ .expects("showError")
+ .withArgs(currentTabId, "No previous search keywords");
+
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("continues a search on the same frame", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 1,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 1 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("continues a search on next frame", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 1,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("clearSelection")
+ .withArgs(currentTabId, 100)
+ .returns(Promise.resolve());
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 101, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("exercise a wrap-search", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 2,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 101, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("clearSelection")
+ .withArgs(currentTabId, 101)
+ .returns(Promise.resolve());
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("starts a search with last keywords", async () => {
+ sinon
+ .stub(findRepository, "getLocalState")
+ .returns(Promise.resolve(undefined));
+ sinon
+ .stub(findRepository, "getGlobalKeyword")
+ .returns(Promise.resolve(keyword));
+ sinon
+ .stub(framePresenter, "getAllFrameIds")
+ .returns(Promise.resolve(frameIds));
+ sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/FindOperatorFactoryChain.ts b/test/background/operators/impls/FindOperatorFactoryChain.ts
new file mode 100644
index 0000000..0fd234f
--- /dev/null
+++ b/test/background/operators/impls/FindOperatorFactoryChain.ts
@@ -0,0 +1,23 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import TabOperatorFactoryChain from "../../../../src/background/operators/impls/TabOperatorFactoryChain";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import * as operations from "../../../../src/shared/operations";
+import FindNextOperator from "../../../../src/background/operators/impls/FindNextOperator";
+import FindPrevOperator from "../../../../src/background/operators/impls/FindPrevOperator";
+
+describe("FindOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const sut = new TabOperatorFactoryChain(tabPresenter);
+
+ expect(sut.create({ type: operations.FIND_NEXT })).to.be.instanceOf(
+ FindNextOperator
+ );
+ expect(sut.create({ type: operations.FIND_PREV })).to.be.instanceOf(
+ FindPrevOperator
+ );
+ });
+ });
+});
diff --git a/test/background/operators/impls/FindPrevOperator.test.ts b/test/background/operators/impls/FindPrevOperator.test.ts
new file mode 100644
index 0000000..ebac0dc
--- /dev/null
+++ b/test/background/operators/impls/FindPrevOperator.test.ts
@@ -0,0 +1,179 @@
+import * as sinon from "sinon";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import FindPrevOperator from "../../../../src/background/operators/impls/FindPrevOperator";
+import MockFindRepository from "../../mock/MockFindRepository";
+import MockFindClient from "../../mock/MockFindClient";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+import MockFramePresenter from "../../mock/MockFramePresenter";
+
+describe("FindPrevOperator", () => {
+ const keyword = "hello";
+ const frameIds = [0, 100, 101];
+
+ const tabPresenter = new MockTabPresenter();
+ const findRepository = new MockFindRepository();
+ const findClient = new MockFindClient();
+ const consoleClient = new MockConsoleClient();
+ const framePresenter = new MockFramePresenter();
+ const sut = new FindPrevOperator(
+ tabPresenter,
+ findRepository,
+ findClient,
+ consoleClient,
+ framePresenter
+ );
+
+ let currentTabId: number;
+
+ beforeEach(async () => {
+ sinon.restore();
+
+ const currentTab = await tabPresenter.create("https://example.com/", {
+ active: true,
+ });
+ currentTabId = currentTab.id!;
+ });
+
+ describe("#run", () => {
+ it("shows errors if no previous keywords", async () => {
+ sinon
+ .stub(findRepository, "getLocalState")
+ .returns(Promise.resolve(undefined));
+
+ const mock = sinon.mock(consoleClient);
+ mock
+ .expects("showError")
+ .withArgs(currentTabId, "No previous search keywords");
+
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("continues a search on the same frame", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 1,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 1 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("continues a search on next frame", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 1,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("clearSelection")
+ .withArgs(currentTabId, 100)
+ .returns(Promise.resolve());
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("exercise a wrap-search", async () => {
+ sinon.stub(findRepository, "getLocalState").returns(
+ Promise.resolve({
+ keyword,
+ frameIds,
+ framePos: 0,
+ })
+ );
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("clearSelection")
+ .withArgs(currentTabId, 0)
+ .returns(Promise.resolve());
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 101, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+
+ it("starts a search with last keywords", async () => {
+ sinon
+ .stub(findRepository, "getLocalState")
+ .returns(Promise.resolve(undefined));
+ sinon
+ .stub(findRepository, "getGlobalKeyword")
+ .returns(Promise.resolve(keyword));
+ sinon
+ .stub(framePresenter, "getAllFrameIds")
+ .returns(Promise.resolve(frameIds));
+ sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
+
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findPrev")
+ .withArgs(currentTabId, 101, keyword)
+ .returns(Promise.resolve(true));
+
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+
+ await sut.run();
+
+ mockFindRepository.verify();
+ mockFindClient.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/TabOperatorFactoryChain.test.ts b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
index 7ab5de0..a777973 100644
--- a/test/background/operators/impls/TabOperatorFactoryChain.test.ts
+++ b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
@@ -44,12 +44,12 @@ describe("TabOperatorFactoryChain", () => {
expect(sut.create({ type: operations.TAB_FIRST })).to.be.instanceOf(
SelectFirstTabOperator
);
- expect(
- sut.create({ type: operations.TAB_LAST, newTab: false })
- ).to.be.instanceOf(SelectLastTabOperator);
- expect(
- sut.create({ type: operations.TAB_PREV_SEL, newTab: false })
- ).to.be.instanceOf(SelectPreviousSelectedTabOperator);
+ expect(sut.create({ type: operations.TAB_LAST })).to.be.instanceOf(
+ SelectLastTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_PREV_SEL })).to.be.instanceOf(
+ SelectPreviousSelectedTabOperator
+ );
expect(
sut.create({ type: operations.TAB_RELOAD, cache: false })
).to.be.instanceOf(ReloadTabOperator);
diff --git a/test/background/repositories/FindRepository.test.ts b/test/background/repositories/FindRepository.test.ts
new file mode 100644
index 0000000..a08dc6d
--- /dev/null
+++ b/test/background/repositories/FindRepository.test.ts
@@ -0,0 +1,38 @@
+import { expect } from "chai";
+import { FindRepositoryImpl } from "../../../src/background/repositories/FindRepository";
+
+describe("background/repositories/FindRepositoryImpl", () => {
+ let sut: FindRepositoryImpl;
+
+ beforeEach(() => {
+ sut = new FindRepositoryImpl();
+ });
+
+ describe("global keyword", () => {
+ it("get and set a keyword", async () => {
+ expect(await sut.getGlobalKeyword()).to.be.undefined;
+
+ await sut.setGlobalKeyword("Hello, world");
+
+ const keyword = await sut.getGlobalKeyword();
+ expect(keyword).to.equal("Hello, world");
+ });
+ });
+
+ describe("local state", () => {
+ it("get and set a keyword", async () => {
+ expect(await sut.getLocalState(10)).to.be.undefined;
+
+ await sut.setLocalState(10, {
+ keyword: "Hello, world",
+ frameIds: [20, 21],
+ framePos: 0,
+ });
+
+ const state = await sut.getLocalState(10);
+ expect(state?.keyword).to.equal("Hello, world");
+
+ expect(await sut.getLocalState(20)).to.be.undefined;
+ });
+ });
+});
diff --git a/test/background/usecases/StartFindUseCase.test.ts b/test/background/usecases/StartFindUseCase.test.ts
new file mode 100644
index 0000000..22ff9a5
--- /dev/null
+++ b/test/background/usecases/StartFindUseCase.test.ts
@@ -0,0 +1,180 @@
+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 StartFindUseCase from "../../../src/background/usecases/StartFindUseCase";
+
+describe("StartFindUseCase", () => {
+ const currentTabId = 100;
+ const frameIds = [0, 100, 101];
+ const keyword = "hello";
+
+ const findClient = new MockFindClient();
+ const findRepository = new MockFindRepository();
+ const consoleClient = new MockConsoleClient();
+ const framePresenter = new MockFramePresenter();
+ const sut = new StartFindUseCase(
+ findClient,
+ findRepository,
+ consoleClient,
+ framePresenter
+ );
+
+ beforeEach(async () => {
+ sinon.restore();
+
+ sinon
+ .stub(framePresenter, "getAllFrameIds")
+ .returns(Promise.resolve(frameIds));
+ });
+
+ describe("startFind", () => {
+ it("starts a find with a keyword", async () => {
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(true));
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { frameIds, framePos: 1, keyword });
+ const mockConsoleClient = sinon.mock(consoleClient);
+ mockConsoleClient
+ .expects("showInfo")
+ .withArgs(currentTabId, "Pattern found: " + keyword);
+
+ await sut.startFind(currentTabId, keyword);
+
+ mockFindClient.verify();
+ mockFindRepository.verify();
+ mockConsoleClient.verify();
+ });
+
+ it("starts a find with last local state", async () => {
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(true));
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("getLocalState")
+ .withArgs(currentTabId)
+ .returns(Promise.resolve({ keyword, frameIds, framePos: 0 }));
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { frameIds, framePos: 1, keyword });
+ const mockConsoleClient = sinon.mock(consoleClient);
+ mockConsoleClient
+ .expects("showInfo")
+ .withArgs(currentTabId, "Pattern found: " + keyword);
+
+ await sut.startFind(currentTabId, undefined);
+
+ mockFindClient.verify();
+ mockFindRepository.verify();
+ mockConsoleClient.verify();
+ });
+
+ it("starts a find with last global state", async () => {
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(true));
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository
+ .expects("getLocalState")
+ .withArgs(currentTabId)
+ .returns(Promise.resolve(undefined));
+ mockFindRepository
+ .expects("getGlobalKeyword")
+ .returns(Promise.resolve(keyword));
+ mockFindRepository
+ .expects("setLocalState")
+ .withArgs(currentTabId, { frameIds, framePos: 1, keyword });
+ const mockConsoleClient = sinon.mock(consoleClient);
+ mockConsoleClient
+ .expects("showInfo")
+ .withArgs(currentTabId, "Pattern found: " + keyword);
+
+ await sut.startFind(currentTabId, undefined);
+
+ mockFindClient.verify();
+ mockFindRepository.verify();
+ mockConsoleClient.verify();
+ });
+
+ it("shows an error when pattern not found", async () => {
+ const mockFindClient = sinon.mock(findClient);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 0);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 100);
+ mockFindClient.expects("clearSelection").withArgs(currentTabId, 101);
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 0, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 100, keyword)
+ .returns(Promise.resolve(false));
+ mockFindClient
+ .expects("findNext")
+ .withArgs(currentTabId, 101, keyword)
+ .returns(Promise.resolve(false));
+ const mockFindRepository = sinon.mock(findRepository);
+ mockFindRepository.expects("setLocalState").never();
+ const mockConsoleClient = sinon.mock(consoleClient);
+ mockConsoleClient
+ .expects("showError")
+ .withArgs(currentTabId, "Pattern not found: " + keyword);
+
+ await sut.startFind(currentTabId, keyword);
+
+ mockFindClient.verify();
+ mockFindRepository.verify();
+ mockConsoleClient.verify();
+ });
+
+ it("shows an error when no last keywords", async () => {
+ sinon
+ .stub(findRepository, "getLocalState")
+ .returns(Promise.resolve(undefined));
+ sinon
+ .stub(findRepository, "getGlobalKeyword")
+ .returns(Promise.resolve(undefined));
+
+ const mockConsoleClient = sinon.mock(consoleClient);
+ mockConsoleClient
+ .expects("showError")
+ .withArgs(currentTabId, "No previous search keywords");
+
+ await sut.startFind(currentTabId, undefined);
+
+ mockConsoleClient.verify();
+ });
+ });
+});
diff --git a/test/content/mock/MockFindMasterClient.ts b/test/content/mock/MockFindMasterClient.ts
deleted file mode 100644
index a035cc5..0000000
--- a/test/content/mock/MockFindMasterClient.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import FindMasterClient from "../../../src/content/client/FindMasterClient";
-
-export default class MockFindMasterClient implements FindMasterClient {
- findNext(): void {
- throw new Error("not implemented");
- }
-
- findPrev(): void {
- throw new Error("not implemented");
- }
-}
diff --git a/test/content/operators/impls/FindNextOperator.test.ts b/test/content/operators/impls/FindNextOperator.test.ts
deleted file mode 100644
index d93d45e..0000000
--- a/test/content/operators/impls/FindNextOperator.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import sinon from "sinon";
-import FindNextOperator from "../../../../src/content/operators/impls/FindNextOperator";
-import MockFindMasterClient from "../../mock/MockFindMasterClient";
-
-describe("FindNextOperator", () => {
- describe("#run", () => {
- it("find next keyword", async () => {
- const client = new MockFindMasterClient();
- const mock = sinon.mock(client).expects("findNext").exactly(3);
- const sut = new FindNextOperator(client, 3);
-
- await sut.run();
-
- mock.verify();
- });
- });
-});
diff --git a/test/content/operators/impls/FindOperatorFactoryChain.test.ts b/test/content/operators/impls/FindOperatorFactoryChain.test.ts
deleted file mode 100644
index 6c599ae..0000000
--- a/test/content/operators/impls/FindOperatorFactoryChain.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import * as operations from "../../../../src/shared/operations";
-import { expect } from "chai";
-import FindOperatorFactoryChain from "../../../../src/content/operators/impls/FindOperatorFactoryChain";
-import MockFindMasterClient from "../../mock/MockFindMasterClient";
-import FindNextOperator from "../../../../src/content/operators/impls/FindNextOperator";
-import FindPrevOperator from "../../../../src/content/operators/impls/FindPrevOperator";
-
-describe("FindOperatorFactoryChain", () => {
- describe("#create", () => {
- it("returns an operator", () => {
- const sut = new FindOperatorFactoryChain(new MockFindMasterClient());
- expect(sut.create({ type: operations.FIND_NEXT }, 0)).to.be.instanceOf(
- FindNextOperator
- );
- expect(sut.create({ type: operations.FIND_PREV }, 0)).to.be.instanceOf(
- FindPrevOperator
- );
- expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
- });
- });
-});
diff --git a/test/content/operators/impls/FindPrevOperator.test.ts b/test/content/operators/impls/FindPrevOperator.test.ts
deleted file mode 100644
index 1ebde8d..0000000
--- a/test/content/operators/impls/FindPrevOperator.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import sinon from "sinon";
-import FindPrevOperator from "../../../../src/content/operators/impls/FindPrevOperator";
-import MockFindMasterClient from "../../mock/MockFindMasterClient";
-
-describe("FindPrevOperator", () => {
- describe("#run", () => {
- it("find previous keyword", async () => {
- const client = new MockFindMasterClient();
- const mock = sinon.mock(client).expects("findPrev").exactly(3);
- const sut = new FindPrevOperator(client, 3);
-
- await sut.run();
-
- mock.verify();
- });
- });
-});
diff --git a/test/content/repositories/FindRepository.test.ts b/test/content/repositories/FindRepository.test.ts
deleted file mode 100644
index e0abb9d..0000000
--- a/test/content/repositories/FindRepository.test.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { FindRepositoryImpl } from "../../../src/content/repositories/FindRepository";
-import { expect } from "chai";
-
-describe("FindRepositoryImpl", () => {
- it("updates and gets last keyword", () => {
- const sut = new FindRepositoryImpl();
-
- expect(sut.getLastKeyword()).to.be.null;
-
- sut.setLastKeyword("monkey");
-
- expect(sut.getLastKeyword()).to.equal("monkey");
- });
-});
diff --git a/test/content/usecases/FindUseCase.test.ts b/test/content/usecases/FindUseCase.test.ts
deleted file mode 100644
index b53ef74..0000000
--- a/test/content/usecases/FindUseCase.test.ts
+++ /dev/null
@@ -1,160 +0,0 @@
-import FindRepository from "../../../src/content/repositories/FindRepository";
-import FindPresenter from "../../../src/content/presenters/FindPresenter";
-import FindClient from "../../../src/content/client/FindClient";
-import FindUseCase from "../../../src/content/usecases/FindUseCase";
-import MockConsoleClient from "../mock/MockConsoleClient";
-import { expect } from "chai";
-
-class MockFindRepository implements FindRepository {
- public keyword: string | null;
-
- constructor() {
- this.keyword = null;
- }
-
- getLastKeyword(): string | null {
- return this.keyword;
- }
-
- setLastKeyword(keyword: string): void {
- this.keyword = keyword;
- }
-}
-
-class MockFindPresenter implements FindPresenter {
- public document: string;
-
- public highlighted: boolean;
-
- constructor() {
- this.document = "";
- this.highlighted = false;
- }
-
- find(keyword: string, _backward: boolean): boolean {
- const found = this.document.includes(keyword);
- this.highlighted = found;
- return found;
- }
-
- clearSelection(): void {
- this.highlighted = false;
- }
-}
-
-class MockFindClient implements FindClient {
- public keyword: string | null;
-
- constructor() {
- this.keyword = null;
- }
-
- getGlobalLastKeyword(): Promise<string | null> {
- return Promise.resolve(this.keyword);
- }
-
- setGlobalLastKeyword(keyword: string): Promise<void> {
- this.keyword = keyword;
- return Promise.resolve();
- }
-}
-
-describe("FindUseCase", () => {
- let repository: MockFindRepository;
- let presenter: MockFindPresenter;
- let client: MockFindClient;
- let consoleClient: MockConsoleClient;
- let sut: FindUseCase;
-
- beforeEach(() => {
- repository = new MockFindRepository();
- presenter = new MockFindPresenter();
- client = new MockFindClient();
- consoleClient = new MockConsoleClient();
- sut = new FindUseCase(presenter, repository, client, consoleClient);
- });
-
- describe("#startFind", () => {
- it("find next by ketword", async () => {
- presenter.document = "monkey punch";
-
- await sut.startFind("monkey");
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: monkey");
- expect(await repository.getLastKeyword()).to.equal("monkey");
- expect(await client.getGlobalLastKeyword()).to.equal("monkey");
- });
-
- it("find next by last keyword", async () => {
- presenter.document = "gorilla kick";
- repository.keyword = "gorilla";
-
- await sut.startFind(undefined);
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: gorilla");
- expect(await repository.getLastKeyword()).to.equal("gorilla");
- expect(await client.getGlobalLastKeyword()).to.equal("gorilla");
- });
-
- it("find next by global last keyword", async () => {
- presenter.document = "chimpanzee typing";
-
- repository.keyword = null;
- client.keyword = "chimpanzee";
-
- await sut.startFind(undefined);
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: chimpanzee");
- expect(await repository.getLastKeyword()).to.equal("chimpanzee");
- expect(await client.getGlobalLastKeyword()).to.equal("chimpanzee");
- });
-
- it("find not found error", async () => {
- presenter.document = "zoo";
-
- await sut.startFind("giraffe");
-
- expect(await presenter.highlighted).to.be.false;
- expect(await consoleClient.text).to.equal("Pattern not found: giraffe");
- expect(await repository.getLastKeyword()).to.equal("giraffe");
- expect(await client.getGlobalLastKeyword()).to.equal("giraffe");
- });
-
- it("show errors when no last keywords", async () => {
- repository.keyword = null;
- client.keyword = null;
-
- await sut.startFind(undefined);
-
- expect(await consoleClient.text).to.equal("No previous search keywords");
- expect(await consoleClient.isError).to.be.true;
- });
- });
-
- describe("#findNext", () => {
- it("finds by last keyword", async () => {
- presenter.document = "monkey punch";
- repository.keyword = "monkey";
-
- await sut.findNext();
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: monkey");
- });
-
- it("show errors when no last keywords", async () => {
- repository.keyword = null;
- client.keyword = null;
-
- await sut.findNext();
-
- expect(await consoleClient.text).to.equal("No previous search keywords");
- expect(await consoleClient.isError).to.be.true;
- });
- });
-
- describe("#findPrev", () => {});
-});