aboutsummaryrefslogtreecommitdiff
path: root/test/background/operators/impls/FindNextOperator.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/operators/impls/FindNextOperator.test.ts')
-rw-r--r--test/background/operators/impls/FindNextOperator.test.ts90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/background/operators/impls/FindNextOperator.test.ts b/test/background/operators/impls/FindNextOperator.test.ts
new file mode 100644
index 0000000..20208ae
--- /dev/null
+++ b/test/background/operators/impls/FindNextOperator.test.ts
@@ -0,0 +1,90 @@
+import sinon from "sinon";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import FindNextOperator from "../../../../src/background/operators/impls/FindNextOperator";
+import { FindState } from "../../../../src/background/repositories/FindRepository";
+import MockFindRepository from "../../mock/MockFindRepository";
+import MockFindClient from "../../mock/MockFindClient";
+
+describe("FindNextOperator", () => {
+ describe("#run", () => {
+ it("throws an error on no previous keywords", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const findRepository = new MockFindRepository();
+ const findClient = new MockFindClient();
+ await tabPresenter.create("https://example.com/");
+
+ const sut = new FindNextOperator(
+ tabPresenter,
+ findRepository,
+ findClient
+ );
+ try {
+ await sut.run();
+ } catch (e) {
+ return;
+ }
+ throw new Error("unexpected reach");
+ });
+
+ it("select a next next", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const findRepository = new MockFindRepository();
+ const findClient = new MockFindClient();
+ const currentTab = await tabPresenter.create("https://example.com/");
+
+ const state: FindState = {
+ keyword: "Hello, world",
+ rangeData: [
+ {
+ framePos: 0,
+ startOffset: 0,
+ endOffset: 10,
+ startTextNodePos: 0,
+ endTextNodePos: 0,
+ text: "Hello, world",
+ },
+ {
+ framePos: 1,
+ startOffset: 0,
+ endOffset: 10,
+ startTextNodePos: 1,
+ endTextNodePos: 1,
+ text: "Hello, world",
+ },
+ {
+ framePos: 2,
+ startOffset: 2,
+ endOffset: 10,
+ startTextNodePos: 1,
+ endTextNodePos: 1,
+ text: "Hello, world",
+ },
+ ],
+ highlightPosition: 0,
+ };
+
+ await findRepository.setLocalState(currentTab.id!, state);
+ const mock = sinon.mock(findClient);
+ mock
+ .expects("selectKeyword")
+ .withArgs(currentTab?.id, state.rangeData[1]);
+ mock
+ .expects("selectKeyword")
+ .withArgs(currentTab?.id, state.rangeData[2]);
+ mock
+ .expects("selectKeyword")
+ .withArgs(currentTab?.id, state.rangeData[0]);
+ const sut = new FindNextOperator(
+ tabPresenter,
+ findRepository,
+ findClient
+ );
+
+ await sut.run();
+ await sut.run();
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});