From 8bbc3d9d159237f280c3e952cd1cb124601ed6d6 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 3 Dec 2020 23:15:24 +0900 Subject: Add operator tests --- test/background/mock/MockZoomPresenter.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/background/mock/MockZoomPresenter.ts (limited to 'test/background/mock/MockZoomPresenter.ts') diff --git a/test/background/mock/MockZoomPresenter.ts b/test/background/mock/MockZoomPresenter.ts new file mode 100644 index 0000000..a1ca100 --- /dev/null +++ b/test/background/mock/MockZoomPresenter.ts @@ -0,0 +1,15 @@ +import ZoomPresenter from "../../../src/background/usecases/ZoomPresenter"; + +export default class MockZoomPresenter implements ZoomPresenter { + resetZoom(): Promise { + throw new Error("not implemented"); + } + + zoomIn(): Promise { + throw new Error("not implemented"); + } + + zoomOut(): Promise { + throw new Error("not implemented"); + } +} -- cgit v1.2.3 From 18d3a6411753e97cd49b71b41db7bda8055a2762 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 5 Dec 2020 09:56:40 +0900 Subject: Remove unused classes --- src/background/di.ts | 2 +- .../operators/impls/ResetZoomOperator.ts | 2 +- src/background/operators/impls/ZoomInOperator.ts | 2 +- .../operators/impls/ZoomOperatorFactoryChain.ts | 2 +- src/background/operators/impls/ZoomOutOperator.ts | 2 +- src/background/presenters/ZoomPresenter.ts | 60 +++++++ src/background/usecases/AddonEnabledUseCase.ts | 2 +- src/background/usecases/CommandUseCase.ts | 2 +- src/background/usecases/ConsoleUseCase.ts | 65 -------- src/background/usecases/FindUseCase.ts | 17 +- src/background/usecases/NavigateUseCase.ts | 58 ------- src/background/usecases/TabSelectUseCase.ts | 51 ------ src/background/usecases/TabUseCase.ts | 105 ------------ src/background/usecases/ZoomPresenter.ts | 60 ------- src/background/usecases/ZoomUseCase.ts | 51 ------ test/background/mock/MockZoomPresenter.ts | 2 +- test/background/usecases/NavigateUseCase.test.ts | 185 --------------------- 17 files changed, 70 insertions(+), 598 deletions(-) create mode 100644 src/background/presenters/ZoomPresenter.ts delete mode 100644 src/background/usecases/ConsoleUseCase.ts delete mode 100644 src/background/usecases/NavigateUseCase.ts delete mode 100644 src/background/usecases/TabSelectUseCase.ts delete mode 100644 src/background/usecases/TabUseCase.ts delete mode 100644 src/background/usecases/ZoomPresenter.ts delete mode 100644 src/background/usecases/ZoomUseCase.ts delete mode 100644 test/background/usecases/NavigateUseCase.test.ts (limited to 'test/background/mock/MockZoomPresenter.ts') diff --git a/src/background/di.ts b/src/background/di.ts index 9ec3c74..efdf363 100644 --- a/src/background/di.ts +++ b/src/background/di.ts @@ -16,7 +16,7 @@ import { NavigateClientImpl } from "./clients/NavigateClient"; import { ConsoleClientImpl } from "./infrastructures/ConsoleClient"; import { BrowserSettingRepositoryImpl } from "./repositories/BrowserSettingRepository"; import { RepeatRepositoryImpl } from "./repositories/RepeatRepository"; -import { ZoomPresenterImpl } from "./usecases/ZoomPresenter"; +import { ZoomPresenterImpl } from "./presenters/ZoomPresenter"; import { WindowPresenterImpl } from "./presenters/WindowPresenter"; container.register("LocalSettingRepository", { diff --git a/src/background/operators/impls/ResetZoomOperator.ts b/src/background/operators/impls/ResetZoomOperator.ts index 48db1d5..96af733 100644 --- a/src/background/operators/impls/ResetZoomOperator.ts +++ b/src/background/operators/impls/ResetZoomOperator.ts @@ -1,5 +1,5 @@ import Operator from "../Operator"; -import ZoomPresenter from "../../usecases/ZoomPresenter"; +import ZoomPresenter from "../../presenters/ZoomPresenter"; export default class ResetZoomOperator implements Operator { constructor(private readonly zoomPresenter: ZoomPresenter) {} diff --git a/src/background/operators/impls/ZoomInOperator.ts b/src/background/operators/impls/ZoomInOperator.ts index 9ed1861..e900f0d 100644 --- a/src/background/operators/impls/ZoomInOperator.ts +++ b/src/background/operators/impls/ZoomInOperator.ts @@ -1,5 +1,5 @@ import Operator from "../Operator"; -import ZoomPresenter from "../../usecases/ZoomPresenter"; +import ZoomPresenter from "../../presenters/ZoomPresenter"; export default class ZoomInOperator implements Operator { constructor(private readonly zoomPresenter: ZoomPresenter) {} diff --git a/src/background/operators/impls/ZoomOperatorFactoryChain.ts b/src/background/operators/impls/ZoomOperatorFactoryChain.ts index ebcf2a5..bf930a7 100644 --- a/src/background/operators/impls/ZoomOperatorFactoryChain.ts +++ b/src/background/operators/impls/ZoomOperatorFactoryChain.ts @@ -4,7 +4,7 @@ import OperatorFactoryChain from "../OperatorFactoryChain"; import ZoomInOperator from "./ZoomInOperator"; import ZoomOutOperator from "./ZoomOutOperator"; import ResetZoomOperator from "./ResetZoomOperator"; -import ZoomPresenter from "../../usecases/ZoomPresenter"; +import ZoomPresenter from "../../presenters/ZoomPresenter"; import * as operations from "../../../shared/operations"; @injectable() diff --git a/src/background/operators/impls/ZoomOutOperator.ts b/src/background/operators/impls/ZoomOutOperator.ts index 35f5d3d..0c0389e 100644 --- a/src/background/operators/impls/ZoomOutOperator.ts +++ b/src/background/operators/impls/ZoomOutOperator.ts @@ -1,5 +1,5 @@ import Operator from "../Operator"; -import ZoomPresenter from "../../usecases/ZoomPresenter"; +import ZoomPresenter from "../../presenters/ZoomPresenter"; export default class ZoomOutOperator implements Operator { constructor(private readonly zoomPresenter: ZoomPresenter) {} diff --git a/src/background/presenters/ZoomPresenter.ts b/src/background/presenters/ZoomPresenter.ts new file mode 100644 index 0000000..5a3c64d --- /dev/null +++ b/src/background/presenters/ZoomPresenter.ts @@ -0,0 +1,60 @@ +const ZOOM_SETTINGS = [ + 0.33, + 0.5, + 0.66, + 0.75, + 0.8, + 0.9, + 1.0, + 1.1, + 1.25, + 1.5, + 1.75, + 2.0, + 2.5, + 3.0, +] as const; + +export default interface ZoomPresenter { + zoomIn(): Promise; + zoomOut(): Promise; + resetZoom(): Promise; +} + +export class ZoomPresenterImpl implements ZoomPresenter { + async zoomIn(): Promise { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + const tabId = tab[0].id as number; + const current = await browser.tabs.getZoom(tabId); + const factor = ZOOM_SETTINGS.find((f) => f > current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } + } + + async zoomOut(): Promise { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + const tabId = tab[0].id as number; + const current = await browser.tabs.getZoom(tabId); + const factor = ZOOM_SETTINGS.slice(0) + .reverse() + .find((f) => f < current); + if (factor) { + return browser.tabs.setZoom(tabId, factor); + } + } + + async resetZoom(): Promise { + const tab = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + return browser.tabs.setZoom(tab[0].id, 1); + } +} diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts index f563ab0..f9bafde 100644 --- a/src/background/usecases/AddonEnabledUseCase.ts +++ b/src/background/usecases/AddonEnabledUseCase.ts @@ -22,7 +22,7 @@ export default class AddonEnabledUseCase { return this.indicatorPresentor.indicate(enabled); } - onIndicatorClick(tabId: number): Promise { + private onIndicatorClick(tabId: number): Promise { return this.contentMessageClient.toggleAddonEnabled(tabId); } diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index cadcad1..18ddd4d 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -12,7 +12,7 @@ import ContentMessageClient from "../infrastructures/ContentMessageClient"; import RepeatUseCase from "../usecases/RepeatUseCase"; @injectable() -export default class CommandIndicator { +export default class CommandUseCase { constructor( @inject("TabPresenter") private readonly tabPresenter: TabPresenter, diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts deleted file mode 100644 index 4adba65..0000000 --- a/src/background/usecases/ConsoleUseCase.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import TabPresenter from "../presenters/TabPresenter"; -import ConsoleClient from "../infrastructures/ConsoleClient"; - -@injectable() -export default class ConsoleUseCase { - constructor( - @inject("TabPresenter") - private readonly tabPresenter: TabPresenter, - @inject("ConsoleClient") - private readonly consoleClient: ConsoleClient - ) {} - - async showCommand(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showCommand(tab.id as number, ""); - } - - async showOpenCommand(alter: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - let command = "open "; - if (alter) { - command += tab.url || ""; - } - return this.consoleClient.showCommand(tab.id as number, command); - } - - async showTabopenCommand(alter: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - let command = "tabopen "; - if (alter) { - command += tab.url || ""; - } - return this.consoleClient.showCommand(tab.id as number, command); - } - - async showWinopenCommand(alter: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - let command = "winopen "; - if (alter) { - command += tab.url || ""; - } - return this.consoleClient.showCommand(tab.id as number, command); - } - - async showBufferCommand(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const command = "buffer "; - return this.consoleClient.showCommand(tab.id as number, command); - } - - async showAddbookmarkCommand(alter: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - let command = "addbookmark "; - if (alter) { - command += tab.title || ""; - } - return this.consoleClient.showCommand(tab.id as number, command); - } - - async hideConsole(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.hide(tab.id as number); - } -} diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index 404fb48..ce96e03 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -1,17 +1,9 @@ -import { inject, injectable } from "tsyringe"; +import { injectable } from "tsyringe"; import FindRepository from "../repositories/FindRepository"; -import TabPresenter from "../presenters/TabPresenter"; -import ConsoleClient from "../infrastructures/ConsoleClient"; @injectable() export default class FindUseCase { - constructor( - @inject("TabPresenter") - private readonly tabPresenter: TabPresenter, - private readonly findRepository: FindRepository, - @inject("ConsoleClient") - private readonly consoleClient: ConsoleClient - ) {} + constructor(private readonly findRepository: FindRepository) {} getKeyword(): Promise { return this.findRepository.getKeyword(); @@ -20,9 +12,4 @@ export default class FindUseCase { setKeyword(keyword: string): Promise { return this.findRepository.setKeyword(keyword); } - - async findStart(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showFind(tab.id as number); - } } diff --git a/src/background/usecases/NavigateUseCase.ts b/src/background/usecases/NavigateUseCase.ts deleted file mode 100644 index 29e629a..0000000 --- a/src/background/usecases/NavigateUseCase.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import NavigateClient from "../clients/NavigateClient"; -import TabPresenter from "../presenters/TabPresenter"; - -@injectable() -export default class NavigateUseCase { - constructor( - @inject("TabPresenter") - private readonly tabPresenter: TabPresenter, - @inject("NavigateClient") - private readonly navigateClient: NavigateClient - ) {} - - async openHistoryNext(): Promise { - const tab = await this.tabPresenter.getCurrent(); - await this.navigateClient.historyNext(tab.id!); - } - - async openHistoryPrev(): Promise { - const tab = await this.tabPresenter.getCurrent(); - await this.navigateClient.historyPrev(tab.id!); - } - - async openLinkNext(): Promise { - const tab = await this.tabPresenter.getCurrent(); - await this.navigateClient.linkNext(tab.id!); - } - - async openLinkPrev(): Promise { - const tab = await this.tabPresenter.getCurrent(); - await this.navigateClient.linkPrev(tab.id!); - } - - async openParent(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const url = new URL(tab.url!); - if (url.hash.length > 0) { - url.hash = ""; - } else if (url.search.length > 0) { - url.search = ""; - } else { - const basenamePattern = /\/[^/]+$/; - const lastDirPattern = /\/[^/]+\/$/; - if (basenamePattern.test(url.pathname)) { - url.pathname = url.pathname.replace(basenamePattern, "/"); - } else if (lastDirPattern.test(url.pathname)) { - url.pathname = url.pathname.replace(lastDirPattern, "/"); - } - } - await this.tabPresenter.open(url.href); - } - - async openRoot(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const url = new URL(tab.url!); - await this.tabPresenter.open(url.origin); - } -} diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts deleted file mode 100644 index 663ceb8..0000000 --- a/src/background/usecases/TabSelectUseCase.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import TabPresenter from "../presenters/TabPresenter"; - -@injectable() -export default class TabSelectUseCase { - constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {} - - async selectPrev(count: number): Promise { - const tabs = await this.tabPresenter.getAll(); - if (tabs.length < 2) { - return; - } - const tab = tabs.find((t) => t.active); - if (!tab) { - return; - } - const select = (tab.index - count + tabs.length) % tabs.length; - return this.tabPresenter.select(tabs[select].id as number); - } - - async selectNext(count: number): Promise { - const tabs = await this.tabPresenter.getAll(); - if (tabs.length < 2) { - return; - } - const tab = tabs.find((t) => t.active); - if (!tab) { - return; - } - const select = (tab.index + count) % tabs.length; - return this.tabPresenter.select(tabs[select].id as number); - } - - async selectFirst(): Promise { - const tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[0].id as number); - } - - async selectLast(): Promise { - const tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[tabs.length - 1].id as number); - } - - async selectPrevSelected(): Promise { - const tabId = await this.tabPresenter.getLastSelectedId(); - if (tabId === null || typeof tabId === "undefined") { - return Promise.resolve(); - } - return this.tabPresenter.select(tabId); - } -} diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts deleted file mode 100644 index be01032..0000000 --- a/src/background/usecases/TabUseCase.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import TabPresenter from "../presenters/TabPresenter"; -import WindowPresenter from "../presenters/WindowPresenter"; -import BrowserSettingRepository from "../repositories/BrowserSettingRepository"; - -@injectable() -export default class TabUseCase { - constructor( - @inject("TabPresenter") - private readonly tabPresenter: TabPresenter, - @inject("WindowPresenter") - private readonly windowPresenter: WindowPresenter, - @inject("BrowserSettingRepository") - private readonly browserSettingRepository: BrowserSettingRepository - ) {} - - async close(force: boolean, selectLeft = false): Promise { - const tab = await this.tabPresenter.getCurrent(); - if (!force && tab.pinned) { - return Promise.resolve(); - } - if (selectLeft && tab.index > 0) { - const tabs = await this.tabPresenter.getAll(); - await this.tabPresenter.select(tabs[tab.index - 1].id as number); - } - return this.tabPresenter.remove([tab.id as number]); - } - - async closeRight(): Promise { - const tabs = await this.tabPresenter.getAll(); - tabs.sort((t1, t2) => t1.index - t2.index); - const index = tabs.findIndex((t) => t.active); - if (index < 0) { - return; - } - for (let i = index + 1; i < tabs.length; ++i) { - const tab = tabs[i]; - if (!tab.pinned) { - this.tabPresenter.remove([tab.id as number]); - } - } - } - - reopen(): Promise { - return this.tabPresenter.reopen(); - } - - async reload(cache: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.reload(tab.id as number, cache); - } - - async setPinned(pinned: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id as number, pinned); - } - - async togglePinned(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id as number, !tab.pinned); - } - - async duplicate(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.duplicate(tab.id as number); - } - - async openPageSource(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const url = "view-source:" + tab.url; - return this.tabPresenter.create(url); - } - - async openHome(newTab: boolean): Promise { - const tab = await this.tabPresenter.getCurrent(); - const urls = await this.browserSettingRepository.getHomepageUrls(); - if (urls.length === 1 && urls[0] === "about:home") { - // eslint-disable-next-line max-len - throw new Error( - "Cannot open Firefox Home (about:home) by WebExtensions, set your custom URLs" - ); - } - if (urls.length === 1 && !newTab) { - return this.tabPresenter.open(urls[0], tab.id); - } - for (const url of urls) { - this.tabPresenter.create(url); - } - } - - async openURL( - url: string, - newTab?: boolean, - newWindow?: boolean - ): Promise { - if (newWindow) { - await this.windowPresenter.create(url); - } else if (newTab) { - await this.tabPresenter.create(url); - } else { - const tab = await this.tabPresenter.getCurrent(); - await this.tabPresenter.open(url, tab.id); - } - } -} diff --git a/src/background/usecases/ZoomPresenter.ts b/src/background/usecases/ZoomPresenter.ts deleted file mode 100644 index 5a3c64d..0000000 --- a/src/background/usecases/ZoomPresenter.ts +++ /dev/null @@ -1,60 +0,0 @@ -const ZOOM_SETTINGS = [ - 0.33, - 0.5, - 0.66, - 0.75, - 0.8, - 0.9, - 1.0, - 1.1, - 1.25, - 1.5, - 1.75, - 2.0, - 2.5, - 3.0, -] as const; - -export default interface ZoomPresenter { - zoomIn(): Promise; - zoomOut(): Promise; - resetZoom(): Promise; -} - -export class ZoomPresenterImpl implements ZoomPresenter { - async zoomIn(): Promise { - const tab = await browser.tabs.query({ - active: true, - currentWindow: true, - }); - const tabId = tab[0].id as number; - const current = await browser.tabs.getZoom(tabId); - const factor = ZOOM_SETTINGS.find((f) => f > current); - if (factor) { - return browser.tabs.setZoom(tabId, factor); - } - } - - async zoomOut(): Promise { - const tab = await browser.tabs.query({ - active: true, - currentWindow: true, - }); - const tabId = tab[0].id as number; - const current = await browser.tabs.getZoom(tabId); - const factor = ZOOM_SETTINGS.slice(0) - .reverse() - .find((f) => f < current); - if (factor) { - return browser.tabs.setZoom(tabId, factor); - } - } - - async resetZoom(): Promise { - const tab = await browser.tabs.query({ - active: true, - currentWindow: true, - }); - return browser.tabs.setZoom(tab[0].id, 1); - } -} diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts deleted file mode 100644 index 173e4d7..0000000 --- a/src/background/usecases/ZoomUseCase.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import TabPresenter from "../presenters/TabPresenter"; - -const ZOOM_SETTINGS: number[] = [ - 0.33, - 0.5, - 0.66, - 0.75, - 0.8, - 0.9, - 1.0, - 1.1, - 1.25, - 1.5, - 1.75, - 2.0, - 2.5, - 3.0, -]; - -@injectable() -export default class ZoomUseCase { - constructor(@inject("TabPresenter") private tabPresenter: TabPresenter) {} - - async zoomIn(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const tabId = tab.id as number; - const current = await this.tabPresenter.getZoom(tabId); - const factor = ZOOM_SETTINGS.find((f) => f > current); - if (factor) { - return this.tabPresenter.setZoom(tabId as number, factor); - } - } - - async zoomOut(): Promise { - const tab = await this.tabPresenter.getCurrent(); - const tabId = tab.id as number; - const current = await this.tabPresenter.getZoom(tabId); - const factor = ZOOM_SETTINGS.slice(0) - .reverse() - .find((f) => f < current); - if (factor) { - return this.tabPresenter.setZoom(tabId as number, factor); - } - } - - async zoomNutoral(): Promise { - const tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setZoom(tab.id as number, 1); - } -} diff --git a/test/background/mock/MockZoomPresenter.ts b/test/background/mock/MockZoomPresenter.ts index a1ca100..53d1980 100644 --- a/test/background/mock/MockZoomPresenter.ts +++ b/test/background/mock/MockZoomPresenter.ts @@ -1,4 +1,4 @@ -import ZoomPresenter from "../../../src/background/usecases/ZoomPresenter"; +import ZoomPresenter from "../../../src/background/presenters/ZoomPresenter"; export default class MockZoomPresenter implements ZoomPresenter { resetZoom(): Promise { diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts deleted file mode 100644 index f1b94a7..0000000 --- a/test/background/usecases/NavigateUseCase.test.ts +++ /dev/null @@ -1,185 +0,0 @@ -import "reflect-metadata"; -import TabPresenter from "../../../src/background/presenters/TabPresenter"; -import NavigateUseCase from "../../../src/background/usecases/NavigateUseCase"; -import NavigateClient, { - NavigateClientImpl, -} from "../../../src/background/clients/NavigateClient"; -import * as sinon from "sinon"; - -class MockTabPresenter implements TabPresenter { - create(_url: string, _opts?: unknown): Promise { - throw new Error("not implemented"); - } - - duplicate(_id: number): Promise { - throw new Error("not implemented"); - } - - getAll(): Promise { - throw new Error("not implemented"); - } - - getByKeyword( - _keyword: string, - _excludePinned: boolean - ): Promise { - throw new Error("not implemented"); - } - - getCurrent(): Promise { - throw new Error("not implemented"); - } - - getLastSelectedId(): Promise { - throw new Error("not implemented"); - } - - getZoom(_tabId: number): Promise { - 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 { - throw new Error("not implemented"); - } - - reload(_tabId: number, _cache: boolean): Promise { - throw new Error("not implemented"); - } - - remove(_ids: number[]): Promise { - throw new Error("not implemented"); - } - - reopen(): Promise { - throw new Error("not implemented"); - } - - select(_tabId: number): Promise { - throw new Error("not implemented"); - } - - setPinned(_tabId: number, _pinned: boolean): Promise { - throw new Error("not implemented"); - } - - setZoom(_tabId: number, _factor: number): Promise { - throw new Error("not implemented"); - } -} - -describe("NavigateUseCase", () => { - let sut: NavigateUseCase; - let tabPresenter: TabPresenter; - let navigateClient: NavigateClient; - - beforeEach(() => { - tabPresenter = new MockTabPresenter(); - navigateClient = new NavigateClientImpl(); - 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(); - }); - }); -}); -- cgit v1.2.3