aboutsummaryrefslogtreecommitdiff
path: root/test/content/operators
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-12-10 12:52:17 +0000
committerGitHub <noreply@github.com>2020-12-10 12:52:17 +0000
commit5a0444d7bb7eae27fdca5c2be8fc3ec6c36d53bd (patch)
tree46d70e19f9720d237f4423c1debfcacdd088ce0b /test/content/operators
parenta3c34a309c4b1421eb4914c3fbeba327a5400021 (diff)
parentd2fb674566393d9a8b88d71dba9f5081786b118c (diff)
Merge pull request #917 from ueokande/operation-as-a-operator
refactor: Make each operation as an operator
Diffstat (limited to 'test/content/operators')
-rw-r--r--test/content/operators/impls/AddonOperatorFactoryChain.test.ts29
-rw-r--r--test/content/operators/impls/BackgroundOperationOperator.test.ts38
-rw-r--r--test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts31
-rw-r--r--test/content/operators/impls/DisableAddonOperator.test.ts19
-rw-r--r--test/content/operators/impls/EnableAddonOperator.test.ts19
-rw-r--r--test/content/operators/impls/EnableJumpMarkOperator.test.ts19
-rw-r--r--test/content/operators/impls/EnableSetMarkOperator.test.ts19
-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/operators/impls/FocusOperator.test.ts17
-rw-r--r--test/content/operators/impls/FocusOperatorFactoryChain.test.ts17
-rw-r--r--test/content/operators/impls/FollowOperatorFactoryChain.test.ts20
-rw-r--r--test/content/operators/impls/HorizontalScrollOperator.test.ts28
-rw-r--r--test/content/operators/impls/MarkOperatorFactoryChain.test.ts21
-rw-r--r--test/content/operators/impls/PageScrollOperator.test.ts28
-rw-r--r--test/content/operators/impls/PasteOperator.test.ts51
-rw-r--r--test/content/operators/impls/ScrollOperatorFactoryChain.test.ts46
-rw-r--r--test/content/operators/impls/ScrollToBottomOperator.test.ts18
-rw-r--r--test/content/operators/impls/ScrollToEndOperator.test.ts18
-rw-r--r--test/content/operators/impls/ScrollToHomeOperator.test.ts18
-rw-r--r--test/content/operators/impls/ScrollToTopOperator.test.ts18
-rw-r--r--test/content/operators/impls/StartFollowOperator.test.ts20
-rw-r--r--test/content/operators/impls/ToggleAddonOperator.test.ts24
-rw-r--r--test/content/operators/impls/VerticalScrollOperator.test.ts28
-rw-r--r--test/content/operators/impls/YankURLOperator.test.ts26
26 files changed, 627 insertions, 0 deletions
diff --git a/test/content/operators/impls/AddonOperatorFactoryChain.test.ts b/test/content/operators/impls/AddonOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..c064bb9
--- /dev/null
+++ b/test/content/operators/impls/AddonOperatorFactoryChain.test.ts
@@ -0,0 +1,29 @@
+import AddonOperatorFactoryChain from "../../../../src/content/operators/impls/AddonOperatorFactoryChain";
+import EnableAddonOperator from "../../../../src/content/operators/impls/EnableAddonOperator";
+import DisableAddonOperator from "../../../../src/content/operators/impls/DisableAddonOperator";
+import ToggleAddonOperator from "../../../../src/content/operators/impls/ToggleAddonOperator";
+import * as operations from "../../../../src/shared/operations";
+import { expect } from "chai";
+import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient";
+import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository";
+
+describe("AddonOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new AddonOperatorFactoryChain(
+ new MockAddonIndicatorClient(),
+ new MockAddonEnabledRepository()
+ );
+ expect(sut.create({ type: operations.ADDON_ENABLE }, 0)).to.be.instanceOf(
+ EnableAddonOperator
+ );
+ expect(
+ sut.create({ type: operations.ADDON_DISABLE }, 0)
+ ).to.be.instanceOf(DisableAddonOperator);
+ expect(
+ sut.create({ type: operations.ADDON_TOGGLE_ENABLED }, 0)
+ ).to.be.instanceOf(ToggleAddonOperator);
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/BackgroundOperationOperator.test.ts b/test/content/operators/impls/BackgroundOperationOperator.test.ts
new file mode 100644
index 0000000..b8b1fbd
--- /dev/null
+++ b/test/content/operators/impls/BackgroundOperationOperator.test.ts
@@ -0,0 +1,38 @@
+import * as operations from "../../../../src/shared/operations";
+import BackgroundOperationOperator from "../../../../src/content/operators/impls/BackgroundOperationOperator";
+import OperationClient from "../../../../src/content/client/OperationClient";
+import { expect } from "chai";
+
+class MockOperationClient implements OperationClient {
+ public readonly executedOps: {
+ op: operations.Operation;
+ repeat: number;
+ }[] = [];
+ async execBackgroundOp(
+ repeat: number,
+ op: operations.Operation
+ ): Promise<void> {
+ this.executedOps.push({ repeat, op });
+ }
+
+ internalOpenUrl(): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
+
+describe("BackgroundOperationOperator", () => {
+ describe("#run", () => {
+ it("returns an operator", async () => {
+ const client = new MockOperationClient();
+ const sut = new BackgroundOperationOperator(client, 2, {
+ type: operations.TAB_CLOSE,
+ });
+
+ await sut.run();
+
+ expect(client.executedOps).to.deep.equal([
+ { op: { type: operations.TAB_CLOSE }, repeat: 2 },
+ ]);
+ });
+ });
+});
diff --git a/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts b/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..9ddc229
--- /dev/null
+++ b/test/content/operators/impls/ClipboardOperatorFactoryChain.test.ts
@@ -0,0 +1,31 @@
+import * as operations from "../../../../src/shared/operations";
+import { expect } from "chai";
+import ClipboardOperatorFactoryChain from "../../../../src/content/operators/impls/ClipboardOperatorFactoryChain";
+import YankURLOperator from "../../../../src/content/operators/impls/YankURLOperator";
+import PasteOperator from "../../../../src/content/operators/impls/PasteOperator";
+import MockClipboardRepository from "../../mock/MockClipboardRepository";
+import MockOperationClient from "../../mock/MockOperationClient";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+import MockURLRepository from "../../mock/MockURLRepository";
+
+describe("ClipboardOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new ClipboardOperatorFactoryChain(
+ new MockClipboardRepository(),
+ new MockConsoleClient(),
+ new MockOperationClient(),
+ new MockSettingRepository(),
+ new MockURLRepository()
+ );
+ expect(sut.create({ type: operations.URLS_YANK }, 0)).to.be.instanceOf(
+ YankURLOperator
+ );
+ expect(
+ sut.create({ type: operations.URLS_PASTE, newTab: false }, 0)
+ ).to.be.instanceOf(PasteOperator);
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/DisableAddonOperator.test.ts b/test/content/operators/impls/DisableAddonOperator.test.ts
new file mode 100644
index 0000000..358ae44
--- /dev/null
+++ b/test/content/operators/impls/DisableAddonOperator.test.ts
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import DisableAddonOperator from "../../../../src/content/operators/impls/DisableAddonOperator";
+import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient";
+import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository";
+
+describe("DisableAddonOperator", () => {
+ describe("#run", () => {
+ it("disables addon", async () => {
+ const client = new MockAddonIndicatorClient(true);
+ const repository = new MockAddonEnabledRepository(true);
+ const sut = new DisableAddonOperator(client, repository);
+
+ await sut.run();
+
+ expect(client.enabled).to.be.false;
+ expect(repository.enabled).to.be.false;
+ });
+ });
+});
diff --git a/test/content/operators/impls/EnableAddonOperator.test.ts b/test/content/operators/impls/EnableAddonOperator.test.ts
new file mode 100644
index 0000000..a6ca31b
--- /dev/null
+++ b/test/content/operators/impls/EnableAddonOperator.test.ts
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import EnableAddonOperator from "../../../../src/content/operators/impls/EnableAddonOperator";
+import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient";
+import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository";
+
+describe("EnableAddonOperator", () => {
+ describe("#run", () => {
+ it("enabled addon", async () => {
+ const client = new MockAddonIndicatorClient(false);
+ const repository = new MockAddonEnabledRepository(false);
+ const sut = new EnableAddonOperator(client, repository);
+
+ await sut.run();
+
+ expect(client.enabled).to.be.true;
+ expect(repository.enabled).to.be.true;
+ });
+ });
+});
diff --git a/test/content/operators/impls/EnableJumpMarkOperator.test.ts b/test/content/operators/impls/EnableJumpMarkOperator.test.ts
new file mode 100644
index 0000000..66b4ecd
--- /dev/null
+++ b/test/content/operators/impls/EnableJumpMarkOperator.test.ts
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import EnableJumpMarkOperator from "../../../../src/content/operators/impls/EnableJumpMarkOperator";
+import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository";
+
+describe("EnableJumpMarkOperator", () => {
+ describe("#run", () => {
+ it("starts mark jump mode", async () => {
+ const repository = new MockMarkKeyRepository({
+ jumpMode: false,
+ setMode: false,
+ });
+ const sut = new EnableJumpMarkOperator(repository);
+
+ await sut.run();
+
+ expect(repository.jumpMode).to.be.true;
+ });
+ });
+});
diff --git a/test/content/operators/impls/EnableSetMarkOperator.test.ts b/test/content/operators/impls/EnableSetMarkOperator.test.ts
new file mode 100644
index 0000000..b28874d
--- /dev/null
+++ b/test/content/operators/impls/EnableSetMarkOperator.test.ts
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import EnableSetMarkOperator from "../../../../src/content/operators/impls/EnableSetMarkOperator";
+import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository";
+
+describe("EnableSetMarkOperator", () => {
+ describe("#run", () => {
+ it("starts mark set mode", async () => {
+ const repository = new MockMarkKeyRepository({
+ jumpMode: false,
+ setMode: false,
+ });
+ const sut = new EnableSetMarkOperator(repository);
+
+ await sut.run();
+
+ expect(repository.setMode).to.be.true;
+ });
+ });
+});
diff --git a/test/content/operators/impls/FindNextOperator.test.ts b/test/content/operators/impls/FindNextOperator.test.ts
new file mode 100644
index 0000000..d93d45e
--- /dev/null
+++ b/test/content/operators/impls/FindNextOperator.test.ts
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 0000000..6c599ae
--- /dev/null
+++ b/test/content/operators/impls/FindOperatorFactoryChain.test.ts
@@ -0,0 +1,21 @@
+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
new file mode 100644
index 0000000..1ebde8d
--- /dev/null
+++ b/test/content/operators/impls/FindPrevOperator.test.ts
@@ -0,0 +1,17 @@
+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/operators/impls/FocusOperator.test.ts b/test/content/operators/impls/FocusOperator.test.ts
new file mode 100644
index 0000000..a0eb53b
--- /dev/null
+++ b/test/content/operators/impls/FocusOperator.test.ts
@@ -0,0 +1,17 @@
+import sinon from "sinon";
+import FocusOperator from "../../../../src/content/operators/impls/FocusOperator";
+import MockFocusPresenter from "../../mock/MockFocusPresenter";
+
+describe("FocusOperator", () => {
+ describe("#run", () => {
+ it("focus a first input", async () => {
+ const presenter = new MockFocusPresenter();
+ const mock = sinon.mock(presenter).expects("focusFirstElement");
+ const sut = new FocusOperator(presenter);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/content/operators/impls/FocusOperatorFactoryChain.test.ts b/test/content/operators/impls/FocusOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..91f734b
--- /dev/null
+++ b/test/content/operators/impls/FocusOperatorFactoryChain.test.ts
@@ -0,0 +1,17 @@
+import * as operations from "../../../../src/shared/operations";
+import { expect } from "chai";
+import FocusOperatorFactoryChain from "../../../../src/content/operators/impls/FocusOperatorFactoryChain";
+import FocusOperator from "../../../../src/content/operators/impls/FocusOperator";
+import MockFocusPresenter from "../../mock/MockFocusPresenter";
+
+describe("FocusOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new FocusOperatorFactoryChain(new MockFocusPresenter());
+ expect(sut.create({ type: operations.FOCUS_INPUT }, 0)).to.be.instanceOf(
+ FocusOperator
+ );
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/FollowOperatorFactoryChain.test.ts b/test/content/operators/impls/FollowOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..526a93c
--- /dev/null
+++ b/test/content/operators/impls/FollowOperatorFactoryChain.test.ts
@@ -0,0 +1,20 @@
+import * as operations from "../../../../src/shared/operations";
+import { expect } from "chai";
+import FocusOperatorFactoryChain from "../../../../src/content/operators/impls/FocusOperatorFactoryChain";
+import FocusOperator from "../../../../src/content/operators/impls/FocusOperator";
+import MockFocusPresenter from "../../mock/MockFocusPresenter";
+
+describe("FocusOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new FocusOperatorFactoryChain(new MockFocusPresenter());
+ expect(
+ sut.create(
+ { type: operations.FOCUS_INPUT, newTab: false, background: false },
+ 0
+ )
+ ).to.be.instanceOf(FocusOperator);
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/HorizontalScrollOperator.test.ts b/test/content/operators/impls/HorizontalScrollOperator.test.ts
new file mode 100644
index 0000000..f77a34e
--- /dev/null
+++ b/test/content/operators/impls/HorizontalScrollOperator.test.ts
@@ -0,0 +1,28 @@
+import { expect } from "chai";
+import HorizontalScrollOperator from "../../../../src/content/operators/impls/HorizontalScrollOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("HorizontalScrollOperator", () => {
+ describe("#run", () => {
+ it("scroll horizontally", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new HorizontalScrollOperator(presenter, settingRepository, 1);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 1, y: 0 });
+ });
+
+ it("scroll horizontally with repeats", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new HorizontalScrollOperator(presenter, settingRepository, 5);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 5, y: 0 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/MarkOperatorFactoryChain.test.ts b/test/content/operators/impls/MarkOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..1f094dd
--- /dev/null
+++ b/test/content/operators/impls/MarkOperatorFactoryChain.test.ts
@@ -0,0 +1,21 @@
+import * as operations from "../../../../src/shared/operations";
+import { expect } from "chai";
+import MarkOperatorFactoryChain from "../../../../src/content/operators/impls/MarkOperatorFactoryChain";
+import MockMarkKeyRepository from "../../mock/MockMarkKeyRepository";
+import EnableSetMarkOperator from "../../../../src/content/operators/impls/EnableSetMarkOperator";
+import EnableJumpMarkOperator from "../../../../src/content/operators/impls/EnableJumpMarkOperator";
+
+describe("MarkOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new MarkOperatorFactoryChain(new MockMarkKeyRepository());
+ expect(
+ sut.create({ type: operations.MARK_SET_PREFIX }, 0)
+ ).to.be.instanceOf(EnableSetMarkOperator);
+ expect(
+ sut.create({ type: operations.MARK_JUMP_PREFIX }, 0)
+ ).to.be.instanceOf(EnableJumpMarkOperator);
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/PageScrollOperator.test.ts b/test/content/operators/impls/PageScrollOperator.test.ts
new file mode 100644
index 0000000..80c9185
--- /dev/null
+++ b/test/content/operators/impls/PageScrollOperator.test.ts
@@ -0,0 +1,28 @@
+import { expect } from "chai";
+import PageScrollOperator from "../../../../src/content/operators/impls/PageScrollOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("PageScrollOperator", () => {
+ describe("#run", () => {
+ it("scroll by a page", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new PageScrollOperator(presenter, settingRepository, 1);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 1, y: 0 });
+ });
+
+ it("scroll by a page with repeats", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new PageScrollOperator(presenter, settingRepository, 5);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 5, y: 0 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/PasteOperator.test.ts b/test/content/operators/impls/PasteOperator.test.ts
new file mode 100644
index 0000000..8a3a374
--- /dev/null
+++ b/test/content/operators/impls/PasteOperator.test.ts
@@ -0,0 +1,51 @@
+import sinon from "sinon";
+import PasteOperator from "../../../../src/content/operators/impls/PasteOperator";
+import MockClipboardRepository from "../../mock/MockClipboardRepository";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+import MockOperationClient from "../../mock/MockOperationClient";
+
+describe("PasteOperator", () => {
+ describe("#run", () => {
+ it("open a search url", async () => {
+ const clipboardRepository = new MockClipboardRepository("apple");
+ const settingRepository = new MockSettingRepository();
+ const operationClient = new MockOperationClient();
+ const mockOperationClient = sinon
+ .mock(operationClient)
+ .expects("internalOpenUrl")
+ .withArgs("https://google.com/search?q=apple");
+ const sut = new PasteOperator(
+ clipboardRepository,
+ settingRepository,
+ operationClient,
+ false
+ );
+
+ await sut.run();
+
+ mockOperationClient.verify();
+ });
+
+ it("open a url", async () => {
+ const clipboardRepository = new MockClipboardRepository(
+ "https://example.com/"
+ );
+ const settingRepository = new MockSettingRepository();
+ const operationClient = new MockOperationClient();
+ const mockOperationClient = sinon
+ .mock(operationClient)
+ .expects("internalOpenUrl")
+ .withArgs("https://example.com/");
+ const sut = new PasteOperator(
+ clipboardRepository,
+ settingRepository,
+ operationClient,
+ false
+ );
+
+ await sut.run();
+
+ mockOperationClient.verify();
+ });
+ });
+});
diff --git a/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts b/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..08034cb
--- /dev/null
+++ b/test/content/operators/impls/ScrollOperatorFactoryChain.test.ts
@@ -0,0 +1,46 @@
+import { expect } from "chai";
+import ScrollOperatorFactoryChain from "../../../../src/content/operators/impls/ScrollOperatorFactoryChain";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+import HorizontalScrollOperator from "../../../../src/content/operators/impls/HorizontalScrollOperator";
+import VerticalScrollOperator from "../../../../src/content/operators/impls/VerticalScrollOperator";
+import PageScrollOperator from "../../../../src/content/operators/impls/PageScrollOperator";
+import ScrollToTopOperator from "../../../../src/content/operators/impls/ScrollToTopOperator";
+import ScrollToBottomOperator from "../../../../src/content/operators/impls/ScrollToBottomOperator";
+import ScrollToHomeOperator from "../../../../src/content/operators/impls/ScrollToHomeOperator";
+import ScrollToEndOperator from "../../../../src/content/operators/impls/ScrollToEndOperator";
+import * as operations from "../../../../src/shared/operations";
+
+describe("ScrollOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns an operator", () => {
+ const sut = new ScrollOperatorFactoryChain(
+ new MockScrollPresenter(),
+ new MockSettingRepository()
+ );
+ expect(
+ sut.create({ type: operations.SCROLL_HORIZONALLY, count: 10 }, 0)
+ ).to.be.instanceOf(HorizontalScrollOperator);
+ expect(
+ sut.create({ type: operations.SCROLL_VERTICALLY, count: 10 }, 0)
+ ).to.be.instanceOf(VerticalScrollOperator);
+ expect(
+ sut.create({ type: operations.SCROLL_PAGES, count: 10 }, 0)
+ ).to.be.instanceOf(PageScrollOperator);
+ expect(sut.create({ type: operations.SCROLL_TOP }, 0)).to.be.instanceOf(
+ ScrollToTopOperator
+ );
+ expect(
+ sut.create({ type: operations.SCROLL_BOTTOM }, 0)
+ ).to.be.instanceOf(ScrollToBottomOperator);
+ expect(sut.create({ type: operations.SCROLL_HOME }, 0)).to.be.instanceOf(
+ ScrollToHomeOperator
+ );
+ expect(sut.create({ type: operations.SCROLL_END }, 0)).to.be.instanceOf(
+ ScrollToEndOperator
+ );
+ expect(sut.create({ type: operations.PAGE_HOME, newTab: false }, 0)).to.be
+ .null;
+ });
+ });
+});
diff --git a/test/content/operators/impls/ScrollToBottomOperator.test.ts b/test/content/operators/impls/ScrollToBottomOperator.test.ts
new file mode 100644
index 0000000..500c8f2
--- /dev/null
+++ b/test/content/operators/impls/ScrollToBottomOperator.test.ts
@@ -0,0 +1,18 @@
+import { expect } from "chai";
+import ScrollToBottomOperator from "../../../../src/content/operators/impls/ScrollToBottomOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("ScrollToBottomOperator", () => {
+ describe("#run", () => {
+ it("scroll to bottom", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new ScrollToBottomOperator(presenter, settingRepository);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 0, y: Infinity });
+ });
+ });
+});
diff --git a/test/content/operators/impls/ScrollToEndOperator.test.ts b/test/content/operators/impls/ScrollToEndOperator.test.ts
new file mode 100644
index 0000000..0c98c8d
--- /dev/null
+++ b/test/content/operators/impls/ScrollToEndOperator.test.ts
@@ -0,0 +1,18 @@
+import { expect } from "chai";
+import ScrollToEndOperator from "../../../../src/content/operators/impls/ScrollToEndOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("ScrollToEndOperator", () => {
+ describe("#run", () => {
+ it("scroll to rightmost", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new ScrollToEndOperator(presenter, settingRepository);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: Infinity, y: 0 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/ScrollToHomeOperator.test.ts b/test/content/operators/impls/ScrollToHomeOperator.test.ts
new file mode 100644
index 0000000..f8614d2
--- /dev/null
+++ b/test/content/operators/impls/ScrollToHomeOperator.test.ts
@@ -0,0 +1,18 @@
+import { expect } from "chai";
+import ScrollToHomeOperator from "../../../../src/content/operators/impls/ScrollToHomeOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("ScrollToHomeOperator", () => {
+ describe("#run", () => {
+ it("scroll to leftmost", async () => {
+ const presenter = new MockScrollPresenter(10, 10);
+ const settingRepository = new MockSettingRepository();
+ const sut = new ScrollToHomeOperator(presenter, settingRepository);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 10 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/ScrollToTopOperator.test.ts b/test/content/operators/impls/ScrollToTopOperator.test.ts
new file mode 100644
index 0000000..25a84ba
--- /dev/null
+++ b/test/content/operators/impls/ScrollToTopOperator.test.ts
@@ -0,0 +1,18 @@
+import { expect } from "chai";
+import ScrollToTopOperator from "../../../../src/content/operators/impls/ScrollToTopOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("ScrollToTopOperator", () => {
+ describe("#run", () => {
+ it("scroll to top", async () => {
+ const presenter = new MockScrollPresenter(10, 10);
+ const settingRepository = new MockSettingRepository();
+ const sut = new ScrollToTopOperator(presenter, settingRepository);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 10, y: 0 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/StartFollowOperator.test.ts b/test/content/operators/impls/StartFollowOperator.test.ts
new file mode 100644
index 0000000..8f9bd2d
--- /dev/null
+++ b/test/content/operators/impls/StartFollowOperator.test.ts
@@ -0,0 +1,20 @@
+import sinon from "sinon";
+import StartFollowOperator from "../../../../src/content/operators/impls/StartFollowOperator";
+import MockFollowMasterClient from "../../mock/MockFollowMasterClient";
+
+describe("StartFollowOperator", () => {
+ describe("#run", () => {
+ it("starts following links", async () => {
+ const client = new MockFollowMasterClient();
+ const mock = sinon
+ .mock(client)
+ .expects("startFollow")
+ .withArgs(true, false);
+ const sut = new StartFollowOperator(client, true, false);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/content/operators/impls/ToggleAddonOperator.test.ts b/test/content/operators/impls/ToggleAddonOperator.test.ts
new file mode 100644
index 0000000..6026eb1
--- /dev/null
+++ b/test/content/operators/impls/ToggleAddonOperator.test.ts
@@ -0,0 +1,24 @@
+import { expect } from "chai";
+import ToggleAddonOperator from "../../../../src/content/operators/impls/ToggleAddonOperator";
+import MockAddonIndicatorClient from "../../mock/MockAddonIndicatorClient";
+import MockAddonEnabledRepository from "../../mock/MockAddonEnabledRepository";
+
+describe("ToggleAddonOperator", () => {
+ describe("#run", () => {
+ it("toggles addon-enabled state", async () => {
+ const client = new MockAddonIndicatorClient(true);
+ const repository = new MockAddonEnabledRepository(true);
+ const sut = new ToggleAddonOperator(client, repository);
+
+ await sut.run();
+
+ expect(client.enabled).to.be.false;
+ expect(repository.enabled).to.be.false;
+
+ await sut.run();
+
+ expect(client.enabled).to.be.true;
+ expect(repository.enabled).to.be.true;
+ });
+ });
+});
diff --git a/test/content/operators/impls/VerticalScrollOperator.test.ts b/test/content/operators/impls/VerticalScrollOperator.test.ts
new file mode 100644
index 0000000..05b15d2
--- /dev/null
+++ b/test/content/operators/impls/VerticalScrollOperator.test.ts
@@ -0,0 +1,28 @@
+import { expect } from "chai";
+import VerticalScrollOperator from "../../../../src/content/operators/impls/VerticalScrollOperator";
+import MockScrollPresenter from "../../mock/MockScrollPresenter";
+import MockSettingRepository from "../../mock/MockSettingRepository";
+
+describe("VerticalScrollOperator", () => {
+ describe("#run", () => {
+ it("scroll vertically", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new VerticalScrollOperator(presenter, settingRepository, 1);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 1 });
+ });
+
+ it("scroll vertically with repeats", async () => {
+ const presenter = new MockScrollPresenter();
+ const settingRepository = new MockSettingRepository();
+ const sut = new VerticalScrollOperator(presenter, settingRepository, 5);
+
+ await sut.run();
+
+ expect(presenter.getScroll()).to.deep.equal({ x: 0, y: 5 });
+ });
+ });
+});
diff --git a/test/content/operators/impls/YankURLOperator.test.ts b/test/content/operators/impls/YankURLOperator.test.ts
new file mode 100644
index 0000000..46e3d06
--- /dev/null
+++ b/test/content/operators/impls/YankURLOperator.test.ts
@@ -0,0 +1,26 @@
+import { expect } from "chai";
+import MockClipboardRepository from "../../mock/MockClipboardRepository";
+import YankURLOperator from "../../../../src/content/operators/impls/YankURLOperator";
+import MockURLRepository from "../../mock/MockURLRepository";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("YankOperation", () => {
+ describe("#run", () => {
+ it("copy current URL", async () => {
+ const clipboardRepository = new MockClipboardRepository();
+ const consoleClient = new MockConsoleClient();
+ const urlRepository = new MockURLRepository("https://example.com/");
+ const sut = new YankURLOperator(
+ clipboardRepository,
+ consoleClient,
+ urlRepository
+ );
+
+ await sut.run();
+
+ expect(clipboardRepository.read()).to.equal("https://example.com/");
+ expect(consoleClient.text).to.equal("Yanked https://example.com/");
+ expect(consoleClient.isError).to.be.false;
+ });
+ });
+});