diff options
Diffstat (limited to 'test')
37 files changed, 799 insertions, 3 deletions
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; + }); + }); +}); |