aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/background/mock/MockBrowserSettingRepository.ts10
-rw-r--r--test/background/mock/MockConsoleClient.ts23
-rw-r--r--test/background/mock/MockNavigateClient.ts19
-rw-r--r--test/background/mock/MockRepeatRepository.ts14
-rw-r--r--test/background/mock/MockTabPresenter.ts179
-rw-r--r--test/background/mock/MockWindowPresenter.ts7
-rw-r--r--test/background/mock/MockZoomPresenter.ts15
-rw-r--r--test/background/operators/impls/CancelOperator.test.ts24
-rw-r--r--test/background/operators/impls/CloseTabOperator.test.ts61
-rw-r--r--test/background/operators/impls/CloseTabRightOperator.test.ts24
-rw-r--r--test/background/operators/impls/CommandOperatorFactoryChain.test.ts42
-rw-r--r--test/background/operators/impls/DuplicateTabOperator.test.ts25
-rw-r--r--test/background/operators/impls/InternalOpenURLOperator.test.ts0
-rw-r--r--test/background/operators/impls/InternalOperatorFactoryChain.test.ts37
-rw-r--r--test/background/operators/impls/NavigateHistoryNextOperator.test.ts25
-rw-r--r--test/background/operators/impls/NavigateHistoryPrevOperator.test.ts25
-rw-r--r--test/background/operators/impls/NavigateLinkNextOperator.test.ts22
-rw-r--r--test/background/operators/impls/NavigateLinkPrevOperator.test.ts22
-rw-r--r--test/background/operators/impls/NavigateOperatorFactoryChain.test.ts56
-rw-r--r--test/background/operators/impls/NavigateParentOperator.test.ts53
-rw-r--r--test/background/operators/impls/NavigateRootOperator.test.ts18
-rw-r--r--test/background/operators/impls/OpenHomeOperator.test.ts70
-rw-r--r--test/background/operators/impls/OpenSourceOperator.test.ts21
-rw-r--r--test/background/operators/impls/PinTabOperator.test.ts25
-rw-r--r--test/background/operators/impls/ReloadTabOperator.test.ts34
-rw-r--r--test/background/operators/impls/ReopenTabOperator.test.ts17
-rw-r--r--test/background/operators/impls/RepeatLastOperator.test.ts56
-rw-r--r--test/background/operators/impls/RepeatOperatorFactoryChain.test.ts32
-rw-r--r--test/background/operators/impls/ResetZoomOperator.test.ts17
-rw-r--r--test/background/operators/impls/SelectFirstTabOperator.test.ts20
-rw-r--r--test/background/operators/impls/SelectLastTabOperator.test.ts20
-rw-r--r--test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts38
-rw-r--r--test/background/operators/impls/SelectTabNextOperator.test.ts35
-rw-r--r--test/background/operators/impls/SelectTabPrevOperator.test.ts35
-rw-r--r--test/background/operators/impls/ShowAddBookmarkOperator.test.ts50
-rw-r--r--test/background/operators/impls/ShowBufferCommandOperator.test.ts25
-rw-r--r--test/background/operators/impls/ShowCommandOperator.test.ts25
-rw-r--r--test/background/operators/impls/ShowOpenCommandOperator.test.ts50
-rw-r--r--test/background/operators/impls/ShowTabOpenCommandOperator.test.ts50
-rw-r--r--test/background/operators/impls/ShowWinOpenCommandOperator.test.ts50
-rw-r--r--test/background/operators/impls/StartFindOperator.test.ts22
-rw-r--r--test/background/operators/impls/TabOperatorFactoryChain.test.ts71
-rw-r--r--test/background/operators/impls/TogglePinnedTabOperator.test.ts32
-rw-r--r--test/background/operators/impls/UnpinTabOperator.test.ts25
-rw-r--r--test/background/operators/impls/ZoomInOperator.test.ts17
-rw-r--r--test/background/operators/impls/ZoomOperatorFactoryChain.test.ts28
-rw-r--r--test/background/operators/impls/ZoomOutOperator.test.ts17
-rw-r--r--test/background/usecases/NavigateUseCase.test.ts183
-rw-r--r--test/content/mock/MockAddonEnabledRepository.ts18
-rw-r--r--test/content/mock/MockAddonIndicatorClient.ts13
-rw-r--r--test/content/mock/MockClipboardRepository.ts16
-rw-r--r--test/content/mock/MockFindMasterClient.ts11
-rw-r--r--test/content/mock/MockFocusPresenter.ts7
-rw-r--r--test/content/mock/MockFollowMasterClient.ts16
-rw-r--r--test/content/mock/MockMarkKeyRepository.ts43
-rw-r--r--test/content/mock/MockOperationClient.ts16
-rw-r--r--test/content/mock/MockScrollPresenter.ts6
-rw-r--r--test/content/mock/MockSettingRepository.ts20
-rw-r--r--test/content/mock/MockURLRepository.ts9
-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
-rw-r--r--test/content/usecases/ClipboardUseCase.test.ts95
-rw-r--r--test/content/usecases/HintKeyProducer.test.ts33
87 files changed, 2405 insertions, 291 deletions
diff --git a/test/background/mock/MockBrowserSettingRepository.ts b/test/background/mock/MockBrowserSettingRepository.ts
new file mode 100644
index 0000000..22e7084
--- /dev/null
+++ b/test/background/mock/MockBrowserSettingRepository.ts
@@ -0,0 +1,10 @@
+import BrowserSettingRepository from "../../../src/background/repositories/BrowserSettingRepository";
+
+export default class MockBrowserSettingRepository
+ implements BrowserSettingRepository {
+ constructor(private readonly homepageUrls: string[]) {}
+
+ getHomepageUrls(): Promise<string[]> {
+ return Promise.resolve(this.homepageUrls);
+ }
+}
diff --git a/test/background/mock/MockConsoleClient.ts b/test/background/mock/MockConsoleClient.ts
new file mode 100644
index 0000000..d1f8fc3
--- /dev/null
+++ b/test/background/mock/MockConsoleClient.ts
@@ -0,0 +1,23 @@
+import ConsoleClient from "../../../src/background/infrastructures/ConsoleClient";
+
+export default class MockConsoleClient implements ConsoleClient {
+ hide(_tabId: number): Promise<any> {
+ throw new Error("not implemented");
+ }
+
+ showCommand(_tabId: number, _command: string): Promise<any> {
+ throw new Error("not implemented");
+ }
+
+ showError(_tabId: number, _message: string): Promise<any> {
+ throw new Error("not implemented");
+ }
+
+ showFind(_tabId: number): Promise<any> {
+ throw new Error("not implemented");
+ }
+
+ showInfo(_tabId: number, _message: string): Promise<any> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/mock/MockNavigateClient.ts b/test/background/mock/MockNavigateClient.ts
new file mode 100644
index 0000000..d9442a4
--- /dev/null
+++ b/test/background/mock/MockNavigateClient.ts
@@ -0,0 +1,19 @@
+import NavigateClient from "../../../src/background/clients/NavigateClient";
+
+export default class MockNavigateClient implements NavigateClient {
+ historyNext(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ historyPrev(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ linkNext(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ linkPrev(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/mock/MockRepeatRepository.ts b/test/background/mock/MockRepeatRepository.ts
new file mode 100644
index 0000000..1a686c8
--- /dev/null
+++ b/test/background/mock/MockRepeatRepository.ts
@@ -0,0 +1,14 @@
+import RepeatRepository from "../../../src/background/repositories/RepeatRepository";
+import { Operation } from "../../../src/shared/operations";
+
+export default class MockRepeatRepository implements RepeatRepository {
+ private op: Operation | undefined = undefined;
+
+ getLastOperation(): Operation | undefined {
+ return this.op;
+ }
+
+ setLastOperation(op: Operation): void {
+ this.op = op;
+ }
+}
diff --git a/test/background/mock/MockTabPresenter.ts b/test/background/mock/MockTabPresenter.ts
new file mode 100644
index 0000000..22fb947
--- /dev/null
+++ b/test/background/mock/MockTabPresenter.ts
@@ -0,0 +1,179 @@
+import TabPresenter from "../../../src/background/presenters/TabPresenter";
+
+export default class MockTabPresenter implements TabPresenter {
+ private readonly tabs: browser.tabs.Tab[] = [];
+ private readonly zooms: number[] = [];
+ private nextid = 0;
+
+ private readonly lastSelectedId: number | undefined;
+
+ private static defaultTabOptions = {
+ hidden: false,
+ highlighted: false,
+ incognito: false,
+ isArticle: false,
+ isInReaderMode: false,
+ lastAccessed: 0,
+ pinned: false,
+ selected: false,
+ windowId: 0,
+ };
+
+ create(
+ url: string,
+ opts?: {
+ active?: boolean;
+ cookieStoreId?: string;
+ index?: number;
+ openerTabId?: number;
+ pinned?: boolean;
+ windowId?: number;
+ }
+ ): Promise<browser.tabs.Tab> {
+ const tab = {
+ ...MockTabPresenter.defaultTabOptions,
+ ...opts,
+ id: this.nextid++,
+ active: false,
+ title: "welcome, world",
+ url,
+ index: this.tabs.length,
+ };
+ if (opts?.active || this.tabs.length === 0) {
+ this.tabs.forEach((t) => (t.active = false));
+ tab.active = true;
+ }
+ this.tabs.push(tab);
+ this.zooms.push(1);
+ return Promise.resolve(tab);
+ }
+
+ duplicate(id: number): Promise<browser.tabs.Tab> {
+ const src = this.tabs.find((t) => t.id === id);
+ if (!src) {
+ throw new Error(`tab ${id} not found`);
+ }
+ this.tabs.forEach((t) => (t.active = false));
+ const tab = { ...src, id: this.nextid++, active: true };
+ this.tabs.push(tab);
+ this.zooms.push(1);
+
+ return Promise.resolve(tab);
+ }
+
+ getAll(): Promise<browser.tabs.Tab[]> {
+ return Promise.resolve([...this.tabs]);
+ }
+
+ getByKeyword(
+ keyword: string,
+ excludePinned: boolean
+ ): Promise<browser.tabs.Tab[]> {
+ const tabs = this.tabs
+
+ .filter((t) => {
+ return (
+ (t.url && t.url.toLowerCase().includes(keyword.toLowerCase())) ||
+ (t.title && t.title.toLowerCase().includes(keyword.toLowerCase()))
+ );
+ })
+ .filter((t) => {
+ return !(excludePinned && t.pinned);
+ });
+ return Promise.resolve(tabs);
+ }
+
+ getCurrent(): Promise<browser.tabs.Tab> {
+ const tab = this.tabs.find((t) => t.active);
+ if (!tab) {
+ throw new Error("active tab not found");
+ }
+ return Promise.resolve(tab);
+ }
+
+ getLastSelectedId(): Promise<number | undefined> {
+ return Promise.resolve(this.lastSelectedId);
+ }
+
+ getZoom(tabId: number): Promise<number> {
+ const index = this.tabs.findIndex((t) => t.id === tabId);
+ if (index === -1) {
+ throw new Error(`tab ${tabId} not found`);
+ }
+ return Promise.resolve(this.zooms[index]);
+ }
+
+ onSelected(
+ _listener: (arg: { tabId: number; windowId: number }) => void
+ ): void {
+ throw new Error("not implemented");
+ }
+
+ open(url: string, tabId?: number): Promise<browser.tabs.Tab> {
+ let tab = this.tabs.find((t) => t.active);
+ if (!tab) {
+ throw new Error(`active tab not found`);
+ }
+ if (tabId !== undefined) {
+ tab = this.tabs.find((t) => t.id === tabId);
+ }
+ if (!tab) {
+ throw new Error(`tab ${tabId} not found`);
+ }
+ tab.url = url;
+ return Promise.resolve(tab);
+ }
+
+ reload(_tabId: number, _cache: boolean): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ remove(ids: number[]): Promise<void> {
+ for (const id of ids) {
+ const index = this.tabs.findIndex((t) => t.id === id);
+ if (index === -1) {
+ throw new Error(`tab ${id} not found`);
+ }
+ const tab = this.tabs[index];
+ this.tabs.splice(index, 1);
+ this.zooms.splice(index, 1);
+ if (tab.active) {
+ this.tabs[Math.min(index, this.tabs.length - 1)].active = true;
+ }
+ }
+
+ return Promise.resolve(undefined);
+ }
+
+ reopen(): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ select(tabId: number): Promise<void> {
+ const tab = this.tabs.find((t) => t.id === tabId);
+ if (!tab) {
+ throw new Error(`tab ${tabId} not found`);
+ }
+ this.tabs.forEach((t) => (t.active = false));
+ tab.active = true;
+ return Promise.resolve(undefined);
+ }
+
+ setPinned(tabId: number, pinned: boolean): Promise<void> {
+ const tab = this.tabs.find((t) => t.id === tabId);
+ if (!tab) {
+ throw new Error(`tab ${tabId} not found`);
+ }
+ tab.pinned = pinned;
+ return Promise.resolve();
+ }
+
+ setZoom(tabId: number, factor: number): Promise<void> {
+ const index = this.tabs.findIndex((t) => t.id === tabId);
+ if (index === -1) {
+ throw new Error(`tab ${tabId} not found`);
+ }
+ this.zooms[index] = factor;
+ return Promise.resolve();
+ }
+}
diff --git a/test/background/mock/MockWindowPresenter.ts b/test/background/mock/MockWindowPresenter.ts
new file mode 100644
index 0000000..420ae8b
--- /dev/null
+++ b/test/background/mock/MockWindowPresenter.ts
@@ -0,0 +1,7 @@
+import WindowPresenter from "../../../src/background/presenters/WindowPresenter";
+
+export default class MockWindowPresenter implements WindowPresenter {
+ create(_url: string): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/mock/MockZoomPresenter.ts b/test/background/mock/MockZoomPresenter.ts
new file mode 100644
index 0000000..53d1980
--- /dev/null
+++ b/test/background/mock/MockZoomPresenter.ts
@@ -0,0 +1,15 @@
+import ZoomPresenter from "../../../src/background/presenters/ZoomPresenter";
+
+export default class MockZoomPresenter implements ZoomPresenter {
+ resetZoom(): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ zoomIn(): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ zoomOut(): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/background/operators/impls/CancelOperator.test.ts b/test/background/operators/impls/CancelOperator.test.ts
new file mode 100644
index 0000000..915becf
--- /dev/null
+++ b/test/background/operators/impls/CancelOperator.test.ts
@@ -0,0 +1,24 @@
+import sinon from "sinon";
+import CancelOperator from "../../../../src/background/operators/impls/CancelOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("CancelOperator", () => {
+ describe("#run", () => {
+ it("hides console", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const currenTab = await tabPresenter.create("https://example.com/");
+
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("hide")
+ .withArgs(currenTab?.id);
+ const sut = new CancelOperator(tabPresenter, consoleClient);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/CloseTabOperator.test.ts b/test/background/operators/impls/CloseTabOperator.test.ts
new file mode 100644
index 0000000..ba9cbfe
--- /dev/null
+++ b/test/background/operators/impls/CloseTabOperator.test.ts
@@ -0,0 +1,61 @@
+import { expect } from "chai";
+import CloseTabOperator from "../../../../src/background/operators/impls/CloseTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("CloseTabOperator", () => {
+ describe("#run", () => {
+ it("close a current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new CloseTabOperator(tabPresenter);
+
+ await sut.run();
+
+ const tabs = await tabPresenter.getAll();
+ expect(tabs.map((t) => t.url)).to.deep.equal([
+ "https://example.com/1",
+ "https://example.com/3",
+ ]);
+ });
+
+ it("close a current tab forcely", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", {
+ pinned: true,
+ active: false,
+ });
+ await tabPresenter.create("https://example.com/2", {
+ pinned: true,
+ active: true,
+ });
+ await tabPresenter.create("https://example.com/3", {
+ pinned: true,
+ active: false,
+ });
+ const sut = new CloseTabOperator(tabPresenter, true);
+
+ await sut.run();
+
+ const tabs = await tabPresenter.getAll();
+ expect(tabs.map((t) => t.url)).to.deep.equal([
+ "https://example.com/1",
+ "https://example.com/3",
+ ]);
+ });
+
+ it("close a current tab and select left of the closed tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new CloseTabOperator(tabPresenter, false, true);
+
+ await sut.run();
+
+ const tab = await tabPresenter.getCurrent();
+ expect(tab.url).to.equal("https://example.com/1");
+ });
+ });
+});
diff --git a/test/background/operators/impls/CloseTabRightOperator.test.ts b/test/background/operators/impls/CloseTabRightOperator.test.ts
new file mode 100644
index 0000000..c2a106c
--- /dev/null
+++ b/test/background/operators/impls/CloseTabRightOperator.test.ts
@@ -0,0 +1,24 @@
+import { expect } from "chai";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import CloseTabRightOperator from "../../../../src/background/operators/impls/CloseTabRightOperator";
+
+describe("CloseTabRightOperator", () => {
+ describe("#run", () => {
+ it("close the right of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ await tabPresenter.create("https://example.com/4", { active: false });
+ const sut = new CloseTabRightOperator(tabPresenter);
+
+ await sut.run();
+
+ const tabs = await tabPresenter.getAll();
+ expect(tabs.map((t) => t.url)).to.deep.equal([
+ "https://example.com/1",
+ "https://example.com/2",
+ ]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/CommandOperatorFactoryChain.test.ts b/test/background/operators/impls/CommandOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..e481c5a
--- /dev/null
+++ b/test/background/operators/impls/CommandOperatorFactoryChain.test.ts
@@ -0,0 +1,42 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import CommandOperatorFactoryChain from "../../../../src/background/operators/impls/CommandOperatorFactoryChain";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+import * as operations from "../../../../src/shared/operations";
+import ShowCommandOperator from "../../../../src/background/operators/impls/ShowCommandOperator";
+import ShowTabOpenCommandOperator from "../../../../src/background/operators/impls/ShowTabOpenCommandOperator";
+import ShowWinOpenCommandOperator from "../../../../src/background/operators/impls/ShowWinOpenCommandOperator";
+import ShowBufferCommandOperator from "../../../../src/background/operators/impls/ShowBufferCommandOperator";
+import ShowAddBookmarkOperator from "../../../../src/background/operators/impls/ShowAddBookmarkOperator";
+import StartFindOperator from "../../../../src/background/operators/impls/StartFindOperator";
+
+describe("CommandOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const consoleClient = new MockConsoleClient();
+ const sut = new CommandOperatorFactoryChain(tabPresenter, consoleClient);
+
+ expect(sut.create({ type: operations.COMMAND_SHOW })).to.be.instanceOf(
+ ShowCommandOperator
+ );
+ expect(
+ sut.create({ type: operations.COMMAND_SHOW_TABOPEN, alter: true })
+ ).to.be.instanceOf(ShowTabOpenCommandOperator);
+ expect(
+ sut.create({ type: operations.COMMAND_SHOW_WINOPEN, alter: true })
+ ).to.be.instanceOf(ShowWinOpenCommandOperator);
+ expect(
+ sut.create({ type: operations.COMMAND_SHOW_BUFFER })
+ ).to.be.instanceOf(ShowBufferCommandOperator);
+ expect(
+ sut.create({ type: operations.COMMAND_SHOW_ADDBOOKMARK, alter: true })
+ ).to.be.instanceOf(ShowAddBookmarkOperator);
+ expect(sut.create({ type: operations.FIND_START })).to.be.instanceOf(
+ StartFindOperator
+ );
+ expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/DuplicateTabOperator.test.ts b/test/background/operators/impls/DuplicateTabOperator.test.ts
new file mode 100644
index 0000000..ce2c19d
--- /dev/null
+++ b/test/background/operators/impls/DuplicateTabOperator.test.ts
@@ -0,0 +1,25 @@
+import { expect } from "chai";
+import DuplicateTabOperator from "../../../../src/background/operators/impls/DuplicateTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("DuplicateTabOperator", () => {
+ describe("#run", () => {
+ it("duplicate a tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new DuplicateTabOperator(tabPresenter);
+
+ await sut.run();
+
+ const tabs = await tabPresenter.getAll();
+ expect(tabs.map((t) => t.url)).to.deep.equal([
+ "https://example.com/1",
+ "https://example.com/2",
+ "https://example.com/3",
+ "https://example.com/2",
+ ]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/InternalOpenURLOperator.test.ts b/test/background/operators/impls/InternalOpenURLOperator.test.ts
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/background/operators/impls/InternalOpenURLOperator.test.ts
diff --git a/test/background/operators/impls/InternalOperatorFactoryChain.test.ts b/test/background/operators/impls/InternalOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..09029db
--- /dev/null
+++ b/test/background/operators/impls/InternalOperatorFactoryChain.test.ts
@@ -0,0 +1,37 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import InternalOperatorFactoryChain from "../../../../src/background/operators/impls/InternalOperatorFactoryChain";
+import MockWindowPresenter from "../../mock/MockWindowPresenter";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+import CancelOperator from "../../../../src/background/operators/impls/CancelOperator";
+import InternalOpenURLOperator from "../../../../src/background/operators/impls/InternalOpenURLOperator";
+import * as operations from "../../../../src/shared/operations";
+
+describe("InternalOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const windowPresenter = new MockWindowPresenter();
+ const tabPresenter = new MockTabPresenter();
+ const consoleClient = new MockConsoleClient();
+ const sut = new InternalOperatorFactoryChain(
+ windowPresenter,
+ tabPresenter,
+ consoleClient
+ );
+
+ expect(sut.create({ type: operations.CANCEL })).to.be.instanceOf(
+ CancelOperator
+ );
+ expect(
+ sut.create({
+ type: operations.INTERNAL_OPEN_URL,
+ url: "https://example.com",
+ newTab: false,
+ newWindow: false,
+ })
+ ).to.be.instanceOf(InternalOpenURLOperator);
+ expect(sut.create({ type: operations.COMMAND_SHOW })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateHistoryNextOperator.test.ts b/test/background/operators/impls/NavigateHistoryNextOperator.test.ts
new file mode 100644
index 0000000..de8f597
--- /dev/null
+++ b/test/background/operators/impls/NavigateHistoryNextOperator.test.ts
@@ -0,0 +1,25 @@
+import sinon from "sinon";
+import NavigateHistoryNextOperator from "../../../../src/background/operators/impls/NavigateHistoryNextOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockNavigateClient from "../../mock/MockNavigateClient";
+
+describe("NavigateHistoryNextOperator", () => {
+ describe("#run", () => {
+ it("send a message to navigate next in the history", async () => {
+ const navigateClient = new MockNavigateClient();
+ const mock = sinon
+ .mock(navigateClient)
+ .expects("historyNext")
+ .withArgs(1);
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new NavigateHistoryNextOperator(tabPresenter, navigateClient);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts b/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts
new file mode 100644
index 0000000..6ebe71e
--- /dev/null
+++ b/test/background/operators/impls/NavigateHistoryPrevOperator.test.ts
@@ -0,0 +1,25 @@
+import sinon from "sinon";
+import NavigateHistoryPrevOperator from "../../../../src/background/operators/impls/NavigateHistoryPrevOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockNavigateClient from "../../mock/MockNavigateClient";
+
+describe("NavigateHistoryPrevOperator", () => {
+ describe("#run", () => {
+ it("send a message to navigate previous in the history", async () => {
+ const navigateClient = new MockNavigateClient();
+ const mock = sinon
+ .mock(navigateClient)
+ .expects("historyPrev")
+ .withArgs(1);
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new NavigateHistoryPrevOperator(tabPresenter, navigateClient);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateLinkNextOperator.test.ts b/test/background/operators/impls/NavigateLinkNextOperator.test.ts
new file mode 100644
index 0000000..09c4907
--- /dev/null
+++ b/test/background/operators/impls/NavigateLinkNextOperator.test.ts
@@ -0,0 +1,22 @@
+import sinon from "sinon";
+import NavigateLinkNextOperator from "../../../../src/background/operators/impls/NavigateLinkNextOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockNavigateClient from "../../mock/MockNavigateClient";
+
+describe("NavigateLinkNextOperator", () => {
+ describe("#run", () => {
+ it("send a message to navigate next page", async () => {
+ const navigateClient = new MockNavigateClient();
+ const mock = sinon.mock(navigateClient).expects("linkNext").withArgs(1);
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new NavigateLinkNextOperator(tabPresenter, navigateClient);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateLinkPrevOperator.test.ts b/test/background/operators/impls/NavigateLinkPrevOperator.test.ts
new file mode 100644
index 0000000..6b7f791
--- /dev/null
+++ b/test/background/operators/impls/NavigateLinkPrevOperator.test.ts
@@ -0,0 +1,22 @@
+import sinon from "sinon";
+import NavigateLinkPrevOperator from "../../../../src/background/operators/impls/NavigateLinkPrevOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockNavigateClient from "../../mock/MockNavigateClient";
+
+describe("NavigateLinkPrevOperator", () => {
+ describe("#run", () => {
+ it("send a message to navigate next page", async () => {
+ const navigateClient = new MockNavigateClient();
+ const mock = sinon.mock(navigateClient).expects("linkPrev").withArgs(1);
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const sut = new NavigateLinkPrevOperator(tabPresenter, navigateClient);
+
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts b/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..dfb5654
--- /dev/null
+++ b/test/background/operators/impls/NavigateOperatorFactoryChain.test.ts
@@ -0,0 +1,56 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import NavigateOperatorFactoryChain from "../../../../src/background/operators/impls/NavigateOperatorFactoryChain";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockNavigateClient from "../../mock/MockNavigateClient";
+import MockBrowserSettingRepository from "../../mock/MockBrowserSettingRepository";
+import NavigateHistoryPrevOperator from "../../../../src/background/operators/impls/NavigateHistoryPrevOperator";
+import NavigateHistoryNextOperator from "../../../../src/background/operators/impls/NavigateHistoryNextOperator";
+import NavigateLinkPrevOperator from "../../../../src/background/operators/impls/NavigateLinkPrevOperator";
+import NavigateLinkNextOperator from "../../../../src/background/operators/impls/NavigateLinkNextOperator";
+import NavigateParentOperator from "../../../../src/background/operators/impls/NavigateParentOperator";
+import NavigateRootOperator from "../../../../src/background/operators/impls/NavigateRootOperator";
+import OpenHomeOperator from "../../../../src/background/operators/impls/OpenHomeOperator";
+import OpenSourceOperator from "../../../../src/background/operators/impls/OpenSourceOperator";
+import * as operations from "../../../../src/shared/operations";
+
+describe("NavigateOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const navigateClient = new MockNavigateClient();
+ const browserSettingRepository = new MockBrowserSettingRepository([]);
+ const sut = new NavigateOperatorFactoryChain(
+ tabPresenter,
+ navigateClient,
+ browserSettingRepository
+ );
+
+ expect(
+ sut.create({ type: operations.NAVIGATE_HISTORY_PREV })
+ ).to.be.instanceOf(NavigateHistoryPrevOperator);
+ expect(
+ sut.create({ type: operations.NAVIGATE_HISTORY_NEXT })
+ ).to.be.instanceOf(NavigateHistoryNextOperator);
+ expect(
+ sut.create({ type: operations.NAVIGATE_LINK_PREV })
+ ).to.be.instanceOf(NavigateLinkPrevOperator);
+ expect(
+ sut.create({ type: operations.NAVIGATE_LINK_NEXT })
+ ).to.be.instanceOf(NavigateLinkNextOperator);
+ expect(sut.create({ type: operations.NAVIGATE_PARENT })).to.be.instanceOf(
+ NavigateParentOperator
+ );
+ expect(sut.create({ type: operations.NAVIGATE_ROOT })).to.be.instanceOf(
+ NavigateRootOperator
+ );
+ expect(sut.create({ type: operations.PAGE_SOURCE })).to.be.instanceOf(
+ OpenSourceOperator
+ );
+ expect(
+ sut.create({ type: operations.PAGE_HOME, newTab: false })
+ ).to.be.instanceOf(OpenHomeOperator);
+ expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateParentOperator.test.ts b/test/background/operators/impls/NavigateParentOperator.test.ts
new file mode 100644
index 0000000..cc57f17
--- /dev/null
+++ b/test/background/operators/impls/NavigateParentOperator.test.ts
@@ -0,0 +1,53 @@
+import { expect } from "chai";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import NavigateParentOperator from "../../../../src/background/operators/impls/NavigateParentOperator";
+
+describe("NavigateParentOperator", () => {
+ describe("#run", () => {
+ it("opens a parent directory of the file in the URL", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/fruits/yellow/banana", {
+ active: true,
+ });
+ const sut = new NavigateParentOperator(tabPresenter);
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.com/fruits/yellow/");
+ });
+
+ it("opens a parent directory of the directoryin the URL", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/fruits/yellow/");
+ const sut = new NavigateParentOperator(tabPresenter);
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.com/fruits/");
+ });
+
+ it("removes a hash in the URL", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/fruits/yellow/#top");
+ const sut = new NavigateParentOperator(tabPresenter);
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.com/fruits/yellow/");
+ });
+
+ it("removes query parameters in the URL", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/search?q=apple");
+ const sut = new NavigateParentOperator(tabPresenter);
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.com/search");
+ });
+ });
+});
diff --git a/test/background/operators/impls/NavigateRootOperator.test.ts b/test/background/operators/impls/NavigateRootOperator.test.ts
new file mode 100644
index 0000000..bbe574c
--- /dev/null
+++ b/test/background/operators/impls/NavigateRootOperator.test.ts
@@ -0,0 +1,18 @@
+import { expect } from "chai";
+import NavigateRootOperator from "../../../../src/background/operators/impls/NavigateRootOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("NavigateRootOperator", () => {
+ describe("#run", () => {
+ it("opens root directory in the URL", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/search?q=apple#top");
+ const sut = new NavigateRootOperator(tabPresenter);
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.com");
+ });
+ });
+});
diff --git a/test/background/operators/impls/OpenHomeOperator.test.ts b/test/background/operators/impls/OpenHomeOperator.test.ts
new file mode 100644
index 0000000..3c9288f
--- /dev/null
+++ b/test/background/operators/impls/OpenHomeOperator.test.ts
@@ -0,0 +1,70 @@
+import { expect } from "chai";
+import OpenHomeOperator from "../../../../src/background/operators/impls/OpenHomeOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockBrowserSettingRepository from "../../mock/MockBrowserSettingRepository";
+
+describe("OpenHomeOperator", () => {
+ describe("#run", () => {
+ it("opens a home page of the browser into the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/");
+ const browserSettingRepository = new MockBrowserSettingRepository([
+ "https://example.net/",
+ ]);
+ const sut = new OpenHomeOperator(
+ tabPresenter,
+ browserSettingRepository,
+ false
+ );
+
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.be.equal("https://example.net/");
+ });
+
+ it("opens a home page of the browser into a new tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/");
+ const browserSettingRepository = new MockBrowserSettingRepository([
+ "https://example.net/",
+ ]);
+ const sut = new OpenHomeOperator(
+ tabPresenter,
+ browserSettingRepository,
+ true
+ );
+
+ await sut.run();
+
+ const urls = (await tabPresenter.getAll()).map((t) => t.url);
+ expect(urls).to.be.deep.equal([
+ "https://example.com/",
+ "https://example.net/",
+ ]);
+ });
+
+ it("opens home pages of the browser", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/");
+ const browserSettingRepository = new MockBrowserSettingRepository([
+ "https://example.net/",
+ "https://example.org/",
+ ]);
+ const sut = new OpenHomeOperator(
+ tabPresenter,
+ browserSettingRepository,
+ false
+ );
+
+ await sut.run();
+
+ const urls = (await tabPresenter.getAll()).map((t) => t.url);
+ expect(urls).to.be.deep.equal([
+ "https://example.com/",
+ "https://example.net/",
+ "https://example.org/",
+ ]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/OpenSourceOperator.test.ts b/test/background/operators/impls/OpenSourceOperator.test.ts
new file mode 100644
index 0000000..541032b
--- /dev/null
+++ b/test/background/operators/impls/OpenSourceOperator.test.ts
@@ -0,0 +1,21 @@
+import { expect } from "chai";
+import OpenSourceOperator from "../../../../src/background/operators/impls/OpenSourceOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("OpenSourceOperator", () => {
+ describe("#run", () => {
+ it("opens view-source URL of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/");
+ const sut = new OpenSourceOperator(tabPresenter);
+
+ await sut.run();
+
+ const urls = (await tabPresenter.getAll()).map((t) => t.url);
+ expect(urls).to.be.deep.equal([
+ "https://example.com/",
+ "view-source:https://example.com/",
+ ]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/PinTabOperator.test.ts b/test/background/operators/impls/PinTabOperator.test.ts
new file mode 100644
index 0000000..0c940b6
--- /dev/null
+++ b/test/background/operators/impls/PinTabOperator.test.ts
@@ -0,0 +1,25 @@
+import { expect } from "chai";
+import PinTabOperator from "../../../../src/background/operators/impls/PinTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("PinTabOperator", () => {
+ describe("#run", () => {
+ it("make pinned to the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/", {
+ active: true,
+ pinned: false,
+ });
+ await tabPresenter.create("https://example.com/", {
+ active: false,
+ pinned: false,
+ });
+ const sut = new PinTabOperator(tabPresenter);
+
+ await sut.run();
+
+ const pins = (await tabPresenter.getAll()).map((t) => t.pinned);
+ expect(pins).to.deep.equal([true, false]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/ReloadTabOperator.test.ts b/test/background/operators/impls/ReloadTabOperator.test.ts
new file mode 100644
index 0000000..e87782b
--- /dev/null
+++ b/test/background/operators/impls/ReloadTabOperator.test.ts
@@ -0,0 +1,34 @@
+import sinon from "sinon";
+import ReloadTabOperator from "../../../../src/background/operators/impls/ReloadTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("ReloadTabOperator", () => {
+ describe("#run", () => {
+ it("reloads the current tab with cache", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/", { active: true });
+ await tabPresenter.create("https://example.com/", { active: false });
+ const mock = sinon.mock(tabPresenter).expects("reload").withArgs(0, true);
+
+ const sut = new ReloadTabOperator(tabPresenter, true);
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("reloads the current tab without cache", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/", { active: true });
+ await tabPresenter.create("https://example.com/", { active: false });
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("reload")
+ .withArgs(0, false);
+
+ const sut = new ReloadTabOperator(tabPresenter, false);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ReopenTabOperator.test.ts b/test/background/operators/impls/ReopenTabOperator.test.ts
new file mode 100644
index 0000000..43b1575
--- /dev/null
+++ b/test/background/operators/impls/ReopenTabOperator.test.ts
@@ -0,0 +1,17 @@
+import sinon from "sinon";
+import ReopenTabOperator from "../../../../src/background/operators/impls/ReopenTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("ReopenTabOperator", () => {
+ describe("#run", () => {
+ it("reopens closed tabs", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const mock = sinon.mock(tabPresenter).expects("reopen");
+
+ const sut = new ReopenTabOperator(tabPresenter);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/RepeatLastOperator.test.ts b/test/background/operators/impls/RepeatLastOperator.test.ts
new file mode 100644
index 0000000..57f1227
--- /dev/null
+++ b/test/background/operators/impls/RepeatLastOperator.test.ts
@@ -0,0 +1,56 @@
+import RepeatLastOperator from "../../../../src/background/operators/impls/RepeatLastOperator";
+import MockRepeatRepository from "../../mock/MockRepeatRepository";
+import OperatorFactory from "../../../../src/background/operators/OperatorFactory";
+import * as operations from "../../../../src/shared/operations";
+import Operator from "../../../../src/background/operators/Operator";
+import sinon from "sinon";
+
+class MockOperatorFactory implements OperatorFactory {
+ create(_op: operations.Operation): Operator {
+ throw new Error("not implemented");
+ }
+}
+
+class MockOperator implements Operator {
+ run(): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
+
+describe("RepeatLastOperator", () => {
+ describe("#run", () => {
+ it("repeat last operation", async () => {
+ const operator = new MockOperator();
+ const operatorMock = sinon.mock(operator).expects("run").once();
+ const repeatRepository = new MockRepeatRepository();
+ repeatRepository.setLastOperation({ type: operations.CANCEL });
+
+ const operatorFactory = new MockOperatorFactory();
+ const operatorFactoryMock = sinon
+ .mock(operatorFactory)
+ .expects("create")
+ .withArgs({ type: operations.CANCEL });
+ operatorFactoryMock.returns(operator);
+
+ const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
+ await sut.run();
+
+ operatorFactoryMock.verify();
+ operatorMock.verify();
+ });
+
+ it("does nothing if no last operations", async () => {
+ const repeatRepository = new MockRepeatRepository();
+ const operatorFactory = new MockOperatorFactory();
+ const operatorFactoryMock = sinon
+ .mock(operatorFactory)
+ .expects("create")
+ .never();
+
+ const sut = new RepeatLastOperator(repeatRepository, operatorFactory);
+ await sut.run();
+
+ operatorFactoryMock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts b/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..e12d788
--- /dev/null
+++ b/test/background/operators/impls/RepeatOperatorFactoryChain.test.ts
@@ -0,0 +1,32 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import RepeatOperatorFactoryChain from "../../../../src/background/operators/impls/RepeatOperatorFactoryChain";
+import RepeatLastOperator from "../../../../src/background/operators/impls/RepeatLastOperator";
+import OperatorFactory from "../../../../src/background/operators/OperatorFactory";
+import MockRepeatRepository from "../../mock/MockRepeatRepository";
+import Operator from "../../../../src/content/operators/Operator";
+import * as operations from "../../../../src/shared/operations";
+
+class MockOperatorFactory implements OperatorFactory {
+ create(_op: operations.Operation): Operator {
+ throw new Error("not implemented");
+ }
+}
+
+describe("RepeatOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const repeatRepository = new MockRepeatRepository();
+ const operatorFactory = new MockOperatorFactory();
+ const sut = new RepeatOperatorFactoryChain(
+ repeatRepository,
+ operatorFactory
+ );
+
+ expect(sut.create({ type: operations.REPEAT_LAST })).to.be.instanceOf(
+ RepeatLastOperator
+ );
+ expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/ResetZoomOperator.test.ts b/test/background/operators/impls/ResetZoomOperator.test.ts
new file mode 100644
index 0000000..68cda05
--- /dev/null
+++ b/test/background/operators/impls/ResetZoomOperator.test.ts
@@ -0,0 +1,17 @@
+import sinon from "sinon";
+import ResetZoomOperator from "../../../../src/background/operators/impls/ResetZoomOperator";
+import MockZoomPresenter from "../../mock/MockZoomPresenter";
+
+describe("ResetZoomOperator", () => {
+ describe("#run", () => {
+ it("resets zoom on the tab", async () => {
+ const zoomPresenter = new MockZoomPresenter();
+ const mock = sinon.mock(zoomPresenter).expects("resetZoom").once();
+
+ const sut = new ResetZoomOperator(zoomPresenter);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/SelectFirstTabOperator.test.ts b/test/background/operators/impls/SelectFirstTabOperator.test.ts
new file mode 100644
index 0000000..a3f1d7e
--- /dev/null
+++ b/test/background/operators/impls/SelectFirstTabOperator.test.ts
@@ -0,0 +1,20 @@
+import { expect } from "chai";
+import SelectFirstTabOperator from "../../../../src/background/operators/impls/SelectFirstTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("SelectFirstTabOperator", () => {
+ describe("#run", () => {
+ it("select the leftmost tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+
+ const sut = new SelectFirstTabOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/1");
+ });
+ });
+});
diff --git a/test/background/operators/impls/SelectLastTabOperator.test.ts b/test/background/operators/impls/SelectLastTabOperator.test.ts
new file mode 100644
index 0000000..b8cf5c4
--- /dev/null
+++ b/test/background/operators/impls/SelectLastTabOperator.test.ts
@@ -0,0 +1,20 @@
+import { expect } from "chai";
+import SelectLastTabOperator from "../../../../src/background/operators/impls/SelectLastTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("SelectLastTabOperator", () => {
+ describe("#run", () => {
+ it("select the rightmost tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+
+ const sut = new SelectLastTabOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/3");
+ });
+ });
+});
diff --git a/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts b/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts
new file mode 100644
index 0000000..5e6cc73
--- /dev/null
+++ b/test/background/operators/impls/SelectPreviousSelectedTabOperator.test.ts
@@ -0,0 +1,38 @@
+import { expect } from "chai";
+import sinon from "sinon";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import SelectPreviousSelectedTabOperator from "../../../../src/background/operators/impls/SelectPreviousSelectedTabOperator";
+
+describe("SelectPreviousSelectedTabOperator", () => {
+ describe("#run", () => {
+ it("select the last-selected tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ sinon.stub(tabPresenter, "getLastSelectedId").returns(Promise.resolve(0));
+
+ const sut = new SelectPreviousSelectedTabOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/1");
+ });
+
+ it("do nothing if no last-selected tabs", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ sinon
+ .stub(tabPresenter, "getLastSelectedId")
+ .returns(Promise.resolve(undefined));
+ const mock = sinon.mock(tabPresenter).expects("select").never();
+
+ const sut = new SelectPreviousSelectedTabOperator(tabPresenter);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/SelectTabNextOperator.test.ts b/test/background/operators/impls/SelectTabNextOperator.test.ts
new file mode 100644
index 0000000..5952d92
--- /dev/null
+++ b/test/background/operators/impls/SelectTabNextOperator.test.ts
@@ -0,0 +1,35 @@
+import { expect } from "chai";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import SelectTabNextOperator from "../../../../src/background/operators/impls/SelectTabNextOperator";
+
+describe("SelectTabNextOperator", () => {
+ describe("#run", () => {
+ it("select a right tab of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+
+ const sut = new SelectTabNextOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/3");
+ });
+ });
+
+ describe("#run", () => {
+ it("select a right tab of the current tab in rotation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: false });
+ await tabPresenter.create("https://example.com/3", { active: true });
+
+ const sut = new SelectTabNextOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/1");
+ });
+ });
+});
diff --git a/test/background/operators/impls/SelectTabPrevOperator.test.ts b/test/background/operators/impls/SelectTabPrevOperator.test.ts
new file mode 100644
index 0000000..c9092fa
--- /dev/null
+++ b/test/background/operators/impls/SelectTabPrevOperator.test.ts
@@ -0,0 +1,35 @@
+import { expect } from "chai";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import SelectTabPrevOperator from "../../../../src/background/operators/impls/SelectTabPrevOperator";
+
+describe("SelectTabPrevOperator", () => {
+ describe("#run", () => {
+ it("select a left tab of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+
+ const sut = new SelectTabPrevOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/1");
+ });
+ });
+
+ describe("#run", () => {
+ it("select a left tab of the current tab in rotation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: true });
+ await tabPresenter.create("https://example.com/2", { active: false });
+ await tabPresenter.create("https://example.com/3", { active: false });
+
+ const sut = new SelectTabPrevOperator(tabPresenter);
+ await sut.run();
+
+ const url = (await tabPresenter.getCurrent()).url;
+ expect(url).to.equal("https://example.com/3");
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowAddBookmarkOperator.test.ts b/test/background/operators/impls/ShowAddBookmarkOperator.test.ts
new file mode 100644
index 0000000..1e083c2
--- /dev/null
+++ b/test/background/operators/impls/ShowAddBookmarkOperator.test.ts
@@ -0,0 +1,50 @@
+import sinon from "sinon";
+import ShowAddBookmarkOperator from "../../../../src/background/operators/impls/ShowAddBookmarkOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowAddBookmarkOperator", () => {
+ describe("#run", () => {
+ it("show command with addbookmark command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "addbookmark ");
+
+ const sut = new ShowAddBookmarkOperator(
+ tabPresenter,
+ consoleClient,
+ false
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("show command with addbookmark command and an URL of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "addbookmark welcome, world");
+
+ const sut = new ShowAddBookmarkOperator(
+ tabPresenter,
+ consoleClient,
+ true
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowBufferCommandOperator.test.ts b/test/background/operators/impls/ShowBufferCommandOperator.test.ts
new file mode 100644
index 0000000..91455b3
--- /dev/null
+++ b/test/background/operators/impls/ShowBufferCommandOperator.test.ts
@@ -0,0 +1,25 @@
+import sinon from "sinon";
+import ShowBufferCommandOperator from "../../../../src/background/operators/impls/ShowBufferCommandOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowBufferCommandOperator", () => {
+ describe("#run", () => {
+ it("show command with buffer command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "buffer ");
+
+ const sut = new ShowBufferCommandOperator(tabPresenter, consoleClient);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowCommandOperator.test.ts b/test/background/operators/impls/ShowCommandOperator.test.ts
new file mode 100644
index 0000000..83b028c
--- /dev/null
+++ b/test/background/operators/impls/ShowCommandOperator.test.ts
@@ -0,0 +1,25 @@
+import sinon from "sinon";
+import ShowCommandOperator from "../../../../src/background/operators/impls/ShowCommandOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowCommandOperator", () => {
+ describe("#run", () => {
+ it("show command with addbookmark command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "");
+
+ const sut = new ShowCommandOperator(tabPresenter, consoleClient);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowOpenCommandOperator.test.ts b/test/background/operators/impls/ShowOpenCommandOperator.test.ts
new file mode 100644
index 0000000..2c2105a
--- /dev/null
+++ b/test/background/operators/impls/ShowOpenCommandOperator.test.ts
@@ -0,0 +1,50 @@
+import sinon from "sinon";
+import ShowOpenCommandOperator from "../../../../src/background/operators/impls/ShowOpenCommandOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowOpenCommandOperator", () => {
+ describe("#run", () => {
+ it("show command with open command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "open ");
+
+ const sut = new ShowOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ false
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("show command with open command and an URL of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "open https://example.com/2");
+
+ const sut = new ShowOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ true
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts b/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts
new file mode 100644
index 0000000..e291d05
--- /dev/null
+++ b/test/background/operators/impls/ShowTabOpenCommandOperator.test.ts
@@ -0,0 +1,50 @@
+import sinon from "sinon";
+import ShowTabOpenCommandOperator from "../../../../src/background/operators/impls/ShowTabOpenCommandOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowTabOpenCommandOperator", () => {
+ describe("#run", () => {
+ it("show command with tabopen command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "tabopen ");
+
+ const sut = new ShowTabOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ false
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("show command with tabopen command and an URL of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "tabopen https://example.com/2");
+
+ const sut = new ShowTabOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ true
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts b/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts
new file mode 100644
index 0000000..c81a2d4
--- /dev/null
+++ b/test/background/operators/impls/ShowWinOpenCommandOperator.test.ts
@@ -0,0 +1,50 @@
+import sinon from "sinon";
+import ShowWinOpenCommandOperator from "../../../../src/background/operators/impls/ShowWinOpenCommandOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("ShowWinOpenCommandOperator", () => {
+ describe("#run", () => {
+ it("show command with winopen command", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "winopen ");
+
+ const sut = new ShowWinOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ false
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+
+ it("show command with winopen command and an URL of the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon
+ .mock(consoleClient)
+ .expects("showCommand")
+ .withArgs(1, "winopen https://example.com/2");
+
+ const sut = new ShowWinOpenCommandOperator(
+ tabPresenter,
+ consoleClient,
+ true
+ );
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/StartFindOperator.test.ts b/test/background/operators/impls/StartFindOperator.test.ts
new file mode 100644
index 0000000..7764520
--- /dev/null
+++ b/test/background/operators/impls/StartFindOperator.test.ts
@@ -0,0 +1,22 @@
+import sinon from "sinon";
+import StartFindOperator from "../../../../src/background/operators/impls/StartFindOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import MockConsoleClient from "../../mock/MockConsoleClient";
+
+describe("StartFindOperator", () => {
+ describe("#run", () => {
+ it("show find console", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/1", { active: false });
+ await tabPresenter.create("https://example.com/2", { active: true });
+ await tabPresenter.create("https://example.com/3", { active: false });
+ const consoleClient = new MockConsoleClient();
+ const mock = sinon.mock(consoleClient).expects("showFind").withArgs(1);
+
+ const sut = new StartFindOperator(tabPresenter, consoleClient);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/TabOperatorFactoryChain.test.ts b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..7ab5de0
--- /dev/null
+++ b/test/background/operators/impls/TabOperatorFactoryChain.test.ts
@@ -0,0 +1,71 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import TabOperatorFactoryChain from "../../../../src/background/operators/impls/TabOperatorFactoryChain";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+import DuplicateTabOperator from "../../../../src/background/operators/impls/DuplicateTabOperator";
+import TogglePinnedTabOperator from "../../../../src/background/operators/impls/TogglePinnedTabOperator";
+import UnpinTabOperator from "../../../../src/background/operators/impls/UnpinTabOperator";
+import PinTabOperator from "../../../../src/background/operators/impls/PinTabOperator";
+import ReloadTabOperator from "../../../../src/background/operators/impls/ReloadTabOperator";
+import SelectPreviousSelectedTabOperator from "../../../../src/background/operators/impls/SelectPreviousSelectedTabOperator";
+import SelectLastTabOperator from "../../../../src/background/operators/impls/SelectLastTabOperator";
+import SelectFirstTabOperator from "../../../../src/background/operators/impls/SelectFirstTabOperator";
+import SelectTabNextOperator from "../../../../src/background/operators/impls/SelectTabNextOperator";
+import SelectTabPrevOperator from "../../../../src/background/operators/impls/SelectTabPrevOperator";
+import ReopenTabOperator from "../../../../src/background/operators/impls/ReopenTabOperator";
+import CloseTabOperator from "../../../../src/background/operators/impls/CloseTabOperator";
+import CloseTabRightOperator from "../../../../src/background/operators/impls/CloseTabRightOperator";
+import * as operations from "../../../../src/shared/operations";
+
+describe("TabOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const tabPresenter = new MockTabPresenter();
+ const sut = new TabOperatorFactoryChain(tabPresenter);
+
+ expect(sut.create({ type: operations.TAB_CLOSE })).to.be.instanceOf(
+ CloseTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_CLOSE_RIGHT })).to.be.instanceOf(
+ CloseTabRightOperator
+ );
+ expect(sut.create({ type: operations.TAB_CLOSE_FORCE })).to.be.instanceOf(
+ CloseTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_REOPEN })).to.be.instanceOf(
+ ReopenTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_PREV })).to.be.instanceOf(
+ SelectTabPrevOperator
+ );
+ expect(sut.create({ type: operations.TAB_NEXT })).to.be.instanceOf(
+ SelectTabNextOperator
+ );
+ 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_RELOAD, cache: false })
+ ).to.be.instanceOf(ReloadTabOperator);
+ expect(sut.create({ type: operations.TAB_PIN })).to.be.instanceOf(
+ PinTabOperator
+ );
+ expect(sut.create({ type: operations.TAB_UNPIN })).to.be.instanceOf(
+ UnpinTabOperator
+ );
+ expect(
+ sut.create({ type: operations.TAB_TOGGLE_PINNED })
+ ).to.be.instanceOf(TogglePinnedTabOperator);
+ expect(sut.create({ type: operations.TAB_DUPLICATE })).to.be.instanceOf(
+ DuplicateTabOperator
+ );
+ expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/TogglePinnedTabOperator.test.ts b/test/background/operators/impls/TogglePinnedTabOperator.test.ts
new file mode 100644
index 0000000..f155f83
--- /dev/null
+++ b/test/background/operators/impls/TogglePinnedTabOperator.test.ts
@@ -0,0 +1,32 @@
+import { expect } from "chai";
+import TogglePinnedTabOperator from "../../../../src/background/operators/impls/TogglePinnedTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("TogglePinnedTabOperator", () => {
+ describe("#run", () => {
+ it("toggle pinned to the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/", {
+ active: true,
+ pinned: false,
+ });
+ await tabPresenter.create("https://example.com/", {
+ active: false,
+ pinned: false,
+ });
+ const sut = new TogglePinnedTabOperator(tabPresenter);
+
+ await sut.run();
+ expect((await tabPresenter.getAll()).map((t) => t.pinned)).to.deep.equal([
+ true,
+ false,
+ ]);
+
+ await sut.run();
+ expect((await tabPresenter.getAll()).map((t) => t.pinned)).to.deep.equal([
+ false,
+ false,
+ ]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/UnpinTabOperator.test.ts b/test/background/operators/impls/UnpinTabOperator.test.ts
new file mode 100644
index 0000000..745f48c
--- /dev/null
+++ b/test/background/operators/impls/UnpinTabOperator.test.ts
@@ -0,0 +1,25 @@
+import { expect } from "chai";
+import UnpinTabOperator from "../../../../src/background/operators/impls/UnpinTabOperator";
+import MockTabPresenter from "../../mock/MockTabPresenter";
+
+describe("UnpinTabOperator", () => {
+ describe("#run", () => {
+ it("make unpinned to the current tab", async () => {
+ const tabPresenter = new MockTabPresenter();
+ await tabPresenter.create("https://example.com/", {
+ active: true,
+ pinned: true,
+ });
+ await tabPresenter.create("https://example.com/", {
+ active: false,
+ pinned: true,
+ });
+ const sut = new UnpinTabOperator(tabPresenter);
+
+ await sut.run();
+
+ const pins = (await tabPresenter.getAll()).map((t) => t.pinned);
+ expect(pins).to.deep.equal([false, true]);
+ });
+ });
+});
diff --git a/test/background/operators/impls/ZoomInOperator.test.ts b/test/background/operators/impls/ZoomInOperator.test.ts
new file mode 100644
index 0000000..097e760
--- /dev/null
+++ b/test/background/operators/impls/ZoomInOperator.test.ts
@@ -0,0 +1,17 @@
+import sinon from "sinon";
+import ZoomInOperator from "../../../../src/background/operators/impls/ZoomInOperator";
+import MockZoomPresenter from "../../mock/MockZoomPresenter";
+
+describe("ZoomInOperator", () => {
+ describe("#run", () => {
+ it("zoom-out the current tab", async () => {
+ const zoomPresenter = new MockZoomPresenter();
+ const mock = sinon.mock(zoomPresenter).expects("zoomIn").once();
+
+ const sut = new ZoomInOperator(zoomPresenter);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts b/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts
new file mode 100644
index 0000000..10c1cee
--- /dev/null
+++ b/test/background/operators/impls/ZoomOperatorFactoryChain.test.ts
@@ -0,0 +1,28 @@
+import "reflect-metadata";
+import { expect } from "chai";
+import ZoomOperatorFactoryChain from "../../../../src/background/operators/impls/ZoomOperatorFactoryChain";
+import MockZoomPresenter from "../../mock/MockZoomPresenter";
+import ZoomInOperator from "../../../../src/background/operators/impls/ZoomInOperator";
+import ZoomOutOperator from "../../../../src/background/operators/impls/ZoomOutOperator";
+import ResetZoomOperator from "../../../../src/background/operators/impls/ResetZoomOperator";
+import * as operations from "../../../../src/shared/operations";
+
+describe("ZoomOperatorFactoryChain", () => {
+ describe("#create", () => {
+ it("returns a operator for the operation", async () => {
+ const zoomPresenter = new MockZoomPresenter();
+ const sut = new ZoomOperatorFactoryChain(zoomPresenter);
+
+ expect(sut.create({ type: operations.ZOOM_IN })).to.be.instanceOf(
+ ZoomInOperator
+ );
+ expect(sut.create({ type: operations.ZOOM_OUT })).to.be.instanceOf(
+ ZoomOutOperator
+ );
+ expect(sut.create({ type: operations.ZOOM_NEUTRAL })).to.be.instanceOf(
+ ResetZoomOperator
+ );
+ expect(sut.create({ type: operations.CANCEL })).to.be.null;
+ });
+ });
+});
diff --git a/test/background/operators/impls/ZoomOutOperator.test.ts b/test/background/operators/impls/ZoomOutOperator.test.ts
new file mode 100644
index 0000000..e0bbcd9
--- /dev/null
+++ b/test/background/operators/impls/ZoomOutOperator.test.ts
@@ -0,0 +1,17 @@
+import sinon from "sinon";
+import ZoomOutOperator from "../../../../src/background/operators/impls/ZoomOutOperator";
+import MockZoomPresenter from "../../mock/MockZoomPresenter";
+
+describe("ZoomOutOperator", () => {
+ describe("#run", () => {
+ it("zoom-in the current tab", async () => {
+ const zoomPresenter = new MockZoomPresenter();
+ const mock = sinon.mock(zoomPresenter).expects("zoomOut").once();
+
+ const sut = new ZoomOutOperator(zoomPresenter);
+ await sut.run();
+
+ mock.verify();
+ });
+ });
+});
diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts
deleted file mode 100644
index 086d6cd..0000000
--- a/test/background/usecases/NavigateUseCase.test.ts
+++ /dev/null
@@ -1,183 +0,0 @@
-import "reflect-metadata";
-import TabPresenter from "../../../src/background/presenters/TabPresenter";
-import NavigateUseCase from "../../../src/background/usecases/NavigateUseCase";
-import NavigateClient from "../../../src/background/clients/NavigateClient";
-import * as sinon from "sinon";
-
-class MockTabPresenter implements TabPresenter {
- create(_url: string, _opts?: unknown): Promise<browser.tabs.Tab> {
- throw new Error("not implemented");
- }
-
- duplicate(_id: number): Promise<browser.tabs.Tab> {
- throw new Error("not implemented");
- }
-
- getAll(): Promise<browser.tabs.Tab[]> {
- throw new Error("not implemented");
- }
-
- getByKeyword(
- _keyword: string,
- _excludePinned: boolean
- ): Promise<browser.tabs.Tab[]> {
- throw new Error("not implemented");
- }
-
- getCurrent(): Promise<browser.tabs.Tab> {
- throw new Error("not implemented");
- }
-
- getLastSelectedId(): Promise<number | undefined> {
- throw new Error("not implemented");
- }
-
- getZoom(_tabId: number): Promise<number> {
- throw new Error("not implemented");
- }
-
- onSelected(
- _listener: (arg: { tabId: number; windowId: number }) => void
- ): void {
- throw new Error("not implemented");
- }
-
- open(_url: string, _tabId?: number): Promise<browser.tabs.Tab> {
- throw new Error("not implemented");
- }
-
- reload(_tabId: number, _cache: boolean): Promise<void> {
- throw new Error("not implemented");
- }
-
- remove(_ids: number[]): Promise<void> {
- throw new Error("not implemented");
- }
-
- reopen(): Promise<void> {
- throw new Error("not implemented");
- }
-
- select(_tabId: number): Promise<void> {
- throw new Error("not implemented");
- }
-
- setPinned(_tabId: number, _pinned: boolean): Promise<void> {
- throw new Error("not implemented");
- }
-
- setZoom(_tabId: number, _factor: number): Promise<void> {
- throw new Error("not implemented");
- }
-}
-
-describe("NavigateUseCase", () => {
- let sut: NavigateUseCase;
- let tabPresenter: TabPresenter;
- let navigateClient: NavigateClient;
-
- beforeEach(() => {
- tabPresenter = new MockTabPresenter();
- navigateClient = new NavigateClient();
- sut = new NavigateUseCase(tabPresenter, navigateClient);
- });
-
- const newTab = (url: string): browser.tabs.Tab => {
- return {
- index: 0,
- title: "dummy title",
- url: url,
- active: true,
- hidden: false,
- highlighted: false,
- incognito: false,
- isArticle: false,
- isInReaderMode: false,
- lastAccessed: 1585446733000,
- pinned: false,
- selected: false,
- windowId: 0,
- };
- };
-
- describe("#openParent()", async () => {
- it("opens parent directory of file", async () => {
- sinon
- .stub(tabPresenter, "getCurrent")
- .returns(
- Promise.resolve(newTab("https://google.com/fruits/yellow/banana"))
- );
-
- const mock = sinon
- .mock(tabPresenter)
- .expects("open")
- .withArgs("https://google.com/fruits/yellow/");
-
- await sut.openParent();
-
- mock.verify();
- });
-
- it("opens parent directory of directory", async () => {
- sinon
- .stub(tabPresenter, "getCurrent")
- .returns(Promise.resolve(newTab("https://google.com/fruits/yellow/")));
-
- const mock = sinon
- .mock(tabPresenter)
- .expects("open")
- .withArgs("https://google.com/fruits/");
-
- await sut.openParent();
-
- mock.verify();
- });
-
- it("removes hash", async () => {
- sinon
- .stub(tabPresenter, "getCurrent")
- .returns(Promise.resolve(newTab("https://google.com/#top")));
-
- const mock = sinon
- .mock(tabPresenter)
- .expects("open")
- .withArgs("https://google.com/");
-
- await sut.openParent();
-
- mock.verify();
- });
-
- it("removes search query", async () => {
- sinon
- .stub(tabPresenter, "getCurrent")
- .returns(Promise.resolve(newTab("https://google.com/search?q=apple")));
-
- const mock = sinon
- .mock(tabPresenter)
- .expects("open")
- .withArgs("https://google.com/search");
-
- await sut.openParent();
-
- mock.verify();
- });
- });
-
- describe("#openRoot()", () => {
- it("opens root direectory", async () => {
- sinon
- .stub(tabPresenter, "getCurrent")
- .returns(Promise.resolve(newTab("https://google.com/seach?q=apple")));
-
- const mock = sinon
- .mock(tabPresenter)
- .expects("open")
- .withArgs("https://google.com");
-
- await sut.openRoot();
-
- mock.verify();
- });
- });
-});
diff --git a/test/content/mock/MockAddonEnabledRepository.ts b/test/content/mock/MockAddonEnabledRepository.ts
new file mode 100644
index 0000000..cbe248b
--- /dev/null
+++ b/test/content/mock/MockAddonEnabledRepository.ts
@@ -0,0 +1,18 @@
+import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
+
+export default class MockAddonEnabledRepository
+ implements AddonEnabledRepository {
+ public enabled: boolean;
+
+ constructor(initialValue = false) {
+ this.enabled = initialValue;
+ }
+
+ get(): boolean {
+ return this.enabled;
+ }
+
+ set(on: boolean): void {
+ this.enabled = on;
+ }
+}
diff --git a/test/content/mock/MockAddonIndicatorClient.ts b/test/content/mock/MockAddonIndicatorClient.ts
new file mode 100644
index 0000000..6ea9798
--- /dev/null
+++ b/test/content/mock/MockAddonIndicatorClient.ts
@@ -0,0 +1,13 @@
+import AddonIndicatorClient from "../../../src/content/client/AddonIndicatorClient";
+
+export default class MockAddonIndicatorClient implements AddonIndicatorClient {
+ public enabled: boolean;
+
+ constructor(initialValue = false) {
+ this.enabled = initialValue;
+ }
+
+ async setEnabled(enabled: boolean): Promise<void> {
+ this.enabled = enabled;
+ }
+}
diff --git a/test/content/mock/MockClipboardRepository.ts b/test/content/mock/MockClipboardRepository.ts
new file mode 100644
index 0000000..c6e53bd
--- /dev/null
+++ b/test/content/mock/MockClipboardRepository.ts
@@ -0,0 +1,16 @@
+import ClipboardRepository from "../../../src/content/repositories/ClipboardRepository";
+
+export default class MockClipboardRepository implements ClipboardRepository {
+ private value: string;
+
+ constructor(initValue = "") {
+ this.value = initValue;
+ }
+ read(): string {
+ return this.value;
+ }
+
+ write(text: string): void {
+ this.value = text;
+ }
+}
diff --git a/test/content/mock/MockFindMasterClient.ts b/test/content/mock/MockFindMasterClient.ts
new file mode 100644
index 0000000..a035cc5
--- /dev/null
+++ b/test/content/mock/MockFindMasterClient.ts
@@ -0,0 +1,11 @@
+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/mock/MockFocusPresenter.ts b/test/content/mock/MockFocusPresenter.ts
new file mode 100644
index 0000000..43454d0
--- /dev/null
+++ b/test/content/mock/MockFocusPresenter.ts
@@ -0,0 +1,7 @@
+import FocusPresenter from "../../../src/content/presenters/FocusPresenter";
+
+export default class MockFocusPresenter implements FocusPresenter {
+ focusFirstElement(): boolean {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/content/mock/MockFollowMasterClient.ts b/test/content/mock/MockFollowMasterClient.ts
new file mode 100644
index 0000000..fc660d5
--- /dev/null
+++ b/test/content/mock/MockFollowMasterClient.ts
@@ -0,0 +1,16 @@
+import FollowMasterClient from "../../../src/content/client/FollowMasterClient";
+import Key from "../../../src/shared/settings/Key";
+
+export default class MockFollowMasterClient implements FollowMasterClient {
+ responseHintCount(_count: number): void {
+ throw new Error("not implemented");
+ }
+
+ sendKey(_key: Key): void {
+ throw new Error("not implemented");
+ }
+
+ startFollow(_newTab: boolean, _background: boolean): void {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/content/mock/MockMarkKeyRepository.ts b/test/content/mock/MockMarkKeyRepository.ts
new file mode 100644
index 0000000..12bc75c
--- /dev/null
+++ b/test/content/mock/MockMarkKeyRepository.ts
@@ -0,0 +1,43 @@
+import MarkKeyRepository from "../../../src/content/repositories/MarkKeyRepository";
+
+export default class MockMarkKeyRepository implements MarkKeyRepository {
+ public jumpMode: boolean;
+ public setMode: boolean;
+
+ constructor(
+ initialValue: {
+ jumpMode: boolean;
+ setMode: boolean;
+ } = {
+ jumpMode: false,
+ setMode: false,
+ }
+ ) {
+ this.jumpMode = initialValue.jumpMode;
+ this.setMode = initialValue.setMode;
+ }
+
+ disabeJumpMode(): void {
+ this.jumpMode = false;
+ }
+
+ disabeSetMode(): void {
+ this.setMode = false;
+ }
+
+ enableJumpMode(): void {
+ this.jumpMode = true;
+ }
+
+ enableSetMode(): void {
+ this.setMode = true;
+ }
+
+ isJumpMode(): boolean {
+ return this.jumpMode;
+ }
+
+ isSetMode(): boolean {
+ return this.setMode;
+ }
+}
diff --git a/test/content/mock/MockOperationClient.ts b/test/content/mock/MockOperationClient.ts
new file mode 100644
index 0000000..2f50f77
--- /dev/null
+++ b/test/content/mock/MockOperationClient.ts
@@ -0,0 +1,16 @@
+import OperationClient from "../../../src/content/client/OperationClient";
+import * as operations from "../../../src/shared/operations";
+
+export default class MockOperationClient implements OperationClient {
+ execBackgroundOp(_repeat: number, _op: operations.Operation): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ internalOpenUrl(
+ _url: string,
+ _newTab?: boolean,
+ _background?: boolean
+ ): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
diff --git a/test/content/mock/MockScrollPresenter.ts b/test/content/mock/MockScrollPresenter.ts
index c802227..8b4cf2a 100644
--- a/test/content/mock/MockScrollPresenter.ts
+++ b/test/content/mock/MockScrollPresenter.ts
@@ -3,10 +3,10 @@ import ScrollPresenter, {
} from "../../../src/content/presenters/ScrollPresenter";
export default class MockScrollPresenter implements ScrollPresenter {
- private pos: Point;
+ private readonly pos: Point;
- constructor() {
- this.pos = { x: 0, y: 0 };
+ constructor(initX = 0, initY = 0) {
+ this.pos = { x: initX, y: initY };
}
getScroll(): Point {
diff --git a/test/content/mock/MockSettingRepository.ts b/test/content/mock/MockSettingRepository.ts
new file mode 100644
index 0000000..5242713
--- /dev/null
+++ b/test/content/mock/MockSettingRepository.ts
@@ -0,0 +1,20 @@
+import SettingRepository from "../../../src/content/repositories/SettingRepository";
+import Settings, {
+ DefaultSetting,
+} from "../../../src/shared/settings/Settings";
+
+export default class MockSettingRepository implements SettingRepository {
+ private value: Settings;
+
+ constructor(initValue: Settings = DefaultSetting) {
+ this.value = initValue;
+ }
+
+ get(): Settings {
+ return this.value;
+ }
+
+ set(setting: Settings): void {
+ this.value = setting;
+ }
+}
diff --git a/test/content/mock/MockURLRepository.ts b/test/content/mock/MockURLRepository.ts
new file mode 100644
index 0000000..731a7fb
--- /dev/null
+++ b/test/content/mock/MockURLRepository.ts
@@ -0,0 +1,9 @@
+import URLRepository from "../../../src/content/operators/impls/URLRepository";
+
+export default class MockURLRepository implements URLRepository {
+ constructor(private url: string = "https://example.com/") {}
+
+ getCurrentURL(): string {
+ return this.url;
+ }
+}
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;
+ });
+ });
+});
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);
+ });
+ });
});