aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/background/controllers/FindController.ts15
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts14
-rw-r--r--src/background/repositories/FindRepository.ts22
-rw-r--r--src/background/usecases/FindUseCase.ts15
-rw-r--r--src/content/Application.ts8
-rw-r--r--src/content/client/FindClient.ts23
-rw-r--r--src/content/client/FindMasterClient.ts27
-rw-r--r--src/content/controllers/FindController.ts20
-rw-r--r--src/content/di.ts8
-rw-r--r--src/content/operators/impls/FindNextOperator.ts15
-rw-r--r--src/content/operators/impls/FindOperatorFactoryChain.ts25
-rw-r--r--src/content/operators/impls/FindPrevOperator.ts15
-rw-r--r--src/content/operators/impls/OperatorFactoryImpl.ts3
-rw-r--r--src/content/presenters/FindPresenter.ts29
-rw-r--r--src/content/repositories/FindRepository.ts17
-rw-r--r--src/content/usecases/FindUseCase.ts67
-rw-r--r--src/shared/messages.ts31
-rw-r--r--test/content/mock/MockFindMasterClient.ts11
-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/repositories/FindRepository.test.ts14
-rw-r--r--test/content/usecases/FindUseCase.test.ts160
23 files changed, 0 insertions, 594 deletions
diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts
deleted file mode 100644
index f3ea93f..0000000
--- a/src/background/controllers/FindController.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { injectable } from "tsyringe";
-import FindUseCase from "../usecases/FindUseCase";
-
-@injectable()
-export default class FindController {
- constructor(private findUseCase: FindUseCase) {}
-
- getKeyword(): Promise<string> {
- return this.findUseCase.getKeyword();
- }
-
- setKeyword(keyword: string): Promise<void> {
- return this.findUseCase.setKeyword(keyword);
- }
-}
diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 6023047..4a6a3b8 100644
--- a/src/background/infrastructures/ContentMessageListener.ts
+++ b/src/background/infrastructures/ContentMessageListener.ts
@@ -3,7 +3,6 @@ import * as messages from "../../shared/messages";
import * as operations from "../../shared/operations";
import CommandController from "../controllers/CommandController";
import SettingController from "../controllers/SettingController";
-import FindController from "../controllers/FindController";
import AddonEnabledController from "../controllers/AddonEnabledController";
import LinkController from "../controllers/LinkController";
import OperationController from "../controllers/OperationController";
@@ -19,7 +18,6 @@ export default class ContentMessageListener {
private readonly settingController: SettingController,
private readonly commandController: CommandController,
private readonly completionController: CompletionController,
- private readonly findController: FindController,
private readonly addonEnabledController: AddonEnabledController,
private readonly linkController: LinkController,
private readonly operationController: OperationController,
@@ -88,10 +86,6 @@ export default class ContentMessageListener {
);
case messages.SETTINGS_QUERY:
return this.onSettingsQuery();
- case messages.FIND_GET_KEYWORD:
- return this.onFindGetKeyword();
- case messages.FIND_SET_KEYWORD:
- return this.onFindSetKeyword(message.keyword);
case messages.ADDON_ENABLED_RESPONSE:
return this.onAddonEnabledResponse(message.enabled);
case messages.OPEN_URL:
@@ -132,14 +126,6 @@ export default class ContentMessageListener {
return (await this.settingController.getSetting()).toJSON();
}
- onFindGetKeyword(): Promise<string> {
- return this.findController.getKeyword();
- }
-
- onFindSetKeyword(keyword: string): Promise<void> {
- return this.findController.setKeyword(keyword);
- }
-
onAddonEnabledResponse(enabled: boolean): Promise<void> {
return this.addonEnabledController.indicate(enabled);
}
diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts
deleted file mode 100644
index 813e065..0000000
--- a/src/background/repositories/FindRepository.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { injectable } from "tsyringe";
-import MemoryStorage from "../infrastructures/MemoryStorage";
-
-const FIND_KEYWORD_KEY = "find-keyword";
-
-@injectable()
-export default class FindRepository {
- private cache: MemoryStorage;
-
- constructor() {
- this.cache = new MemoryStorage();
- }
-
- getKeyword(): Promise<string> {
- return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY));
- }
-
- setKeyword(keyword: string): Promise<void> {
- this.cache.set(FIND_KEYWORD_KEY, keyword);
- return Promise.resolve();
- }
-}
diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts
deleted file mode 100644
index cc111f2..0000000
--- a/src/background/usecases/FindUseCase.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { injectable } from "tsyringe";
-import FindRepository from "../repositories/FindRepository";
-
-@injectable()
-export default class FindUseCase {
- constructor(private readonly findRepository: FindRepository) {}
-
- getKeyword(): Promise<string> {
- return this.findRepository.getKeyword();
- }
-
- setKeyword(keyword: string): Promise<void> {
- return this.findRepository.setKeyword(keyword);
- }
-}
diff --git a/src/content/Application.ts b/src/content/Application.ts
index b09edfa..4c89fa0 100644
--- a/src/content/Application.ts
+++ b/src/content/Application.ts
@@ -1,6 +1,5 @@
import { injectable } from "tsyringe";
import MessageListener from "./MessageListener";
-import FindController from "./controllers/FindController";
import MarkController from "./controllers/MarkController";
import FollowMasterController from "./controllers/FollowMasterController";
import FollowSlaveController from "./controllers/FollowSlaveController";
@@ -22,7 +21,6 @@ export default class Application {
// eslint-disable-next-line max-params
constructor(
private messageListener: MessageListener,
- private findController: FindController,
private markController: MarkController,
private followMasterController: FollowMasterController,
private followSlaveController: FollowSlaveController,
@@ -47,12 +45,6 @@ export default class Application {
private routeMasterComponents() {
this.messageListener.onWebMessage((msg: Message, sender: Window) => {
switch (msg.type) {
- case messages.CONSOLE_ENTER_FIND:
- return this.findController.start(msg);
- case messages.FIND_NEXT:
- return this.findController.next(msg);
- case messages.FIND_PREV:
- return this.findController.prev(msg);
case messages.CONSOLE_UNFOCUS:
return this.consoleFrameController.unfocus(msg);
case messages.FOLLOW_START:
diff --git a/src/content/client/FindClient.ts b/src/content/client/FindClient.ts
deleted file mode 100644
index 7da5069..0000000
--- a/src/content/client/FindClient.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import * as messages from "../../shared/messages";
-
-export default interface FindClient {
- getGlobalLastKeyword(): Promise<string | null>;
-
- setGlobalLastKeyword(keyword: string): Promise<void>;
-}
-
-export class FindClientImpl implements FindClient {
- async getGlobalLastKeyword(): Promise<string | null> {
- const keyword = await browser.runtime.sendMessage({
- type: messages.FIND_GET_KEYWORD,
- });
- return keyword as string;
- }
-
- async setGlobalLastKeyword(keyword: string): Promise<void> {
- await browser.runtime.sendMessage({
- type: messages.FIND_SET_KEYWORD,
- keyword: keyword,
- });
- }
-}
diff --git a/src/content/client/FindMasterClient.ts b/src/content/client/FindMasterClient.ts
deleted file mode 100644
index 9c3f812..0000000
--- a/src/content/client/FindMasterClient.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import * as messages from "../../shared/messages";
-
-export default interface FindMasterClient {
- findNext(): void;
-
- findPrev(): void;
-}
-
-export class FindMasterClientImpl implements FindMasterClient {
- findNext(): void {
- window.top.postMessage(
- JSON.stringify({
- type: messages.FIND_NEXT,
- }),
- "*"
- );
- }
-
- findPrev(): void {
- window.top.postMessage(
- JSON.stringify({
- type: messages.FIND_PREV,
- }),
- "*"
- );
- }
-}
diff --git a/src/content/controllers/FindController.ts b/src/content/controllers/FindController.ts
deleted file mode 100644
index 3087d5d..0000000
--- a/src/content/controllers/FindController.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { injectable } from "tsyringe";
-import * as messages from "../../shared/messages";
-import FindUseCase from "../usecases/FindUseCase";
-
-@injectable()
-export default class FindController {
- constructor(private findUseCase: FindUseCase) {}
-
- async start(m: messages.ConsoleEnterFindMessage): Promise<void> {
- await this.findUseCase.startFind(m.text);
- }
-
- async next(_: messages.FindNextMessage): Promise<void> {
- await this.findUseCase.findNext();
- }
-
- async prev(_: messages.FindPrevMessage): Promise<void> {
- await this.findUseCase.findPrev();
- }
-}
diff --git a/src/content/di.ts b/src/content/di.ts
index e74d7ac..7a7fb08 100644
--- a/src/content/di.ts
+++ b/src/content/di.ts
@@ -6,10 +6,6 @@ import { AddressRepositoryImpl } from "./repositories/AddressRepository";
import { ClipboardRepositoryImpl } from "./repositories/ClipboardRepository";
import { ConsoleClientImpl } from "./client/ConsoleClient";
import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter";
-import { FindClientImpl } from "./client/FindClient";
-import { FindMasterClientImpl } from "./client/FindMasterClient";
-import { FindPresenterImpl } from "./presenters/FindPresenter";
-import { FindRepositoryImpl } from "./repositories/FindRepository";
import { FocusPresenterImpl } from "./presenters/FocusPresenter";
import { FollowKeyRepositoryImpl } from "./repositories/FollowKeyRepository";
import { FollowMasterClientImpl } from "./client/FollowMasterClient";
@@ -49,10 +45,6 @@ container.register("ConsoleClient", { useClass: ConsoleClientImpl });
container.register("ConsoleFramePresenter", {
useClass: ConsoleFramePresenterImpl,
});
-container.register("FindClient", { useClass: FindClientImpl });
-container.register("FindMasterClient", { useClass: FindMasterClientImpl });
-container.register("FindPresenter", { useClass: FindPresenterImpl });
-container.register("FindRepository", { useClass: FindRepositoryImpl });
container.register("FocusPresenter", { useClass: FocusPresenterImpl });
container.register("FollowKeyRepository", {
useClass: FollowKeyRepositoryImpl,
diff --git a/src/content/operators/impls/FindNextOperator.ts b/src/content/operators/impls/FindNextOperator.ts
deleted file mode 100644
index c67f6d9..0000000
--- a/src/content/operators/impls/FindNextOperator.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import Operator from "../Operator";
-import FindMasterClient from "../../client/FindMasterClient";
-
-export default class FindNextOperator implements Operator {
- constructor(
- private readonly findMasterClient: FindMasterClient,
- private readonly repeat: number
- ) {}
-
- async run(): Promise<void> {
- for (let i = 0; i < this.repeat; ++i) {
- this.findMasterClient.findNext();
- }
- }
-}
diff --git a/src/content/operators/impls/FindOperatorFactoryChain.ts b/src/content/operators/impls/FindOperatorFactoryChain.ts
deleted file mode 100644
index b3524c1..0000000
--- a/src/content/operators/impls/FindOperatorFactoryChain.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { inject, injectable } from "tsyringe";
-import Operator from "../Operator";
-import OperatorFactoryChain from "../OperatorFactoryChain";
-import FindNextOperator from "./FindNextOperator";
-import FindPrevOperator from "./FindPrevOperator";
-import FindMasterClient from "../../client/FindMasterClient";
-import * as operations from "../../../shared/operations";
-
-@injectable()
-export default class FindOperatorFactoryChain implements OperatorFactoryChain {
- constructor(
- @inject("FindMasterClient")
- private readonly findMasterClient: FindMasterClient
- ) {}
-
- create(op: operations.Operation, repeat: number): Operator | null {
- switch (op.type) {
- case operations.FIND_NEXT:
- return new FindNextOperator(this.findMasterClient, repeat);
- case operations.FIND_PREV:
- return new FindPrevOperator(this.findMasterClient, repeat);
- }
- return null;
- }
-}
diff --git a/src/content/operators/impls/FindPrevOperator.ts b/src/content/operators/impls/FindPrevOperator.ts
deleted file mode 100644
index f73e605..0000000
--- a/src/content/operators/impls/FindPrevOperator.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import Operator from "../Operator";
-import FindMasterClient from "../../client/FindMasterClient";
-
-export default class FindPrevOperator implements Operator {
- constructor(
- private readonly findMasterClient: FindMasterClient,
- private readonly repeat: number
- ) {}
-
- async run(): Promise<void> {
- for (let i = 0; i < this.repeat; ++i) {
- this.findMasterClient.findPrev();
- }
- }
-}
diff --git a/src/content/operators/impls/OperatorFactoryImpl.ts b/src/content/operators/impls/OperatorFactoryImpl.ts
index 22b35c8..bc9bbee 100644
--- a/src/content/operators/impls/OperatorFactoryImpl.ts
+++ b/src/content/operators/impls/OperatorFactoryImpl.ts
@@ -7,7 +7,6 @@ import { Operation } from "../../../shared/operations";
import OperationClient from "../../client/OperationClient";
import AddonOperatorFactoryChain from "./AddonOperatorFactoryChain";
import ClipboardOperatorFactoryChain from "./ClipboardOperatorFactoryChain";
-import FindOperatorFactoryChain from "./FindOperatorFactoryChain";
import FocusOperatorFactoryChain from "./FocusOperatorFactoryChain";
import FollowOperatorFactoryChain from "./FollowOperatorFactoryChain";
import MarkOperatorFactoryChain from "./MarkOperatorFactoryChain";
@@ -20,7 +19,6 @@ export default class OperatorFactoryImpl implements OperatorFactory {
constructor(
addonOperatorFactoryChain: AddonOperatorFactoryChain,
clipboardOperatorFactoryChain: ClipboardOperatorFactoryChain,
- findOperatorFactoryChain: FindOperatorFactoryChain,
focusOperatorFactoryChain: FocusOperatorFactoryChain,
followOperatorFactoryChain: FollowOperatorFactoryChain,
markOperatorFactoryChain: MarkOperatorFactoryChain,
@@ -31,7 +29,6 @@ export default class OperatorFactoryImpl implements OperatorFactory {
this.factoryChains = [
addonOperatorFactoryChain,
clipboardOperatorFactoryChain,
- findOperatorFactoryChain,
focusOperatorFactoryChain,
followOperatorFactoryChain,
markOperatorFactoryChain,
diff --git a/src/content/presenters/FindPresenter.ts b/src/content/presenters/FindPresenter.ts
deleted file mode 100644
index b25190c..0000000
--- a/src/content/presenters/FindPresenter.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-export default interface FindPresenter {
- find(keyword: string, backwards: boolean): boolean;
-
- clearSelection(): void;
-}
-
-export class FindPresenterImpl implements FindPresenter {
- find(keyword: string, backwards: boolean): boolean {
- const caseSensitive = false;
- const wrapScan = true;
-
- // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work
- // because of same origin policy
- const found = window.find(keyword, caseSensitive, backwards, wrapScan);
- if (found) {
- return found;
- }
- this.clearSelection();
-
- return window.find(keyword, caseSensitive, backwards, wrapScan);
- }
-
- clearSelection(): void {
- const sel = window.getSelection();
- if (sel) {
- sel.removeAllRanges();
- }
- }
-}
diff --git a/src/content/repositories/FindRepository.ts b/src/content/repositories/FindRepository.ts
deleted file mode 100644
index aeb200f..0000000
--- a/src/content/repositories/FindRepository.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-export default interface FindRepository {
- getLastKeyword(): string | null;
-
- setLastKeyword(keyword: string): void;
-}
-
-let current: string | null = null;
-
-export class FindRepositoryImpl implements FindRepository {
- getLastKeyword(): string | null {
- return current;
- }
-
- setLastKeyword(keyword: string): void {
- current = keyword;
- }
-}
diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts
deleted file mode 100644
index bff0eee..0000000
--- a/src/content/usecases/FindUseCase.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-import { injectable, inject } from "tsyringe";
-import FindPresenter from "../presenters/FindPresenter";
-import FindRepository from "../repositories/FindRepository";
-import FindClient from "../client/FindClient";
-import ConsoleClient from "../client/ConsoleClient";
-
-@injectable()
-export default class FindUseCase {
- constructor(
- @inject("FindPresenter") private presenter: FindPresenter,
- @inject("FindRepository") private repository: FindRepository,
- @inject("FindClient") private client: FindClient,
- @inject("ConsoleClient") private consoleClient: ConsoleClient
- ) {}
-
- async startFind(keyword?: string): Promise<void> {
- this.presenter.clearSelection();
- if (keyword) {
- this.saveKeyword(keyword);
- } else {
- const lastKeyword = await this.getKeyword();
- if (!lastKeyword) {
- return this.showNoLastKeywordError();
- }
- this.saveKeyword(lastKeyword);
- }
- return this.findNext();
- }
-
- findNext(): Promise<void> {
- return this.findNextPrev(false);
- }
-
- findPrev(): Promise<void> {
- return this.findNextPrev(true);
- }
-
- private async findNextPrev(backwards: boolean): Promise<void> {
- const keyword = await this.getKeyword();
- if (!keyword) {
- return this.showNoLastKeywordError();
- }
- const found = this.presenter.find(keyword, backwards);
- if (found) {
- this.consoleClient.info("Pattern found: " + keyword);
- } else {
- this.consoleClient.error("Pattern not found: " + keyword);
- }
- }
-
- private async getKeyword(): Promise<string | null> {
- let keyword = this.repository.getLastKeyword();
- if (!keyword) {
- keyword = await this.client.getGlobalLastKeyword();
- }
- return keyword;
- }
-
- private async saveKeyword(keyword: string): Promise<void> {
- this.repository.setLastKeyword(keyword);
- await this.client.setGlobalLastKeyword(keyword);
- }
-
- private async showNoLastKeywordError(): Promise<void> {
- await this.consoleClient.error("No previous search keywords");
- }
-}
diff --git a/src/shared/messages.ts b/src/shared/messages.ts
index 59329e7..2ad3b48 100644
--- a/src/shared/messages.ts
+++ b/src/shared/messages.ts
@@ -35,11 +35,6 @@ export const MARK_JUMP_GLOBAL = "mark.jump.global";
export const TAB_SCROLL_TO = "tab.scroll.to";
-export const FIND_NEXT = "find.next";
-export const FIND_PREV = "find.prev";
-export const FIND_GET_KEYWORD = "find.get.keyword";
-export const FIND_SET_KEYWORD = "find.set.keyword";
-
export const ADDON_ENABLED_QUERY = "addon.enabled.query";
export const ADDON_ENABLED_RESPONSE = "addon.enabled.response";
export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled";
@@ -227,24 +222,6 @@ export interface TabScrollToMessage {
y: number;
}
-export interface FindNextMessage {
- type: typeof FIND_NEXT;
-}
-
-export interface FindPrevMessage {
- type: typeof FIND_PREV;
-}
-
-export interface FindGetKeywordMessage {
- type: typeof FIND_GET_KEYWORD;
-}
-
-export interface FindSetKeywordMessage {
- type: typeof FIND_SET_KEYWORD;
- keyword: string;
- found: boolean;
-}
-
export interface AddonEnabledQueryMessage {
type: typeof ADDON_ENABLED_QUERY;
}
@@ -322,10 +299,6 @@ export type Message =
| MarkSetGlobalMessage
| MarkJumpGlobalMessage
| TabScrollToMessage
- | FindNextMessage
- | FindPrevMessage
- | FindGetKeywordMessage
- | FindSetKeywordMessage
| AddonEnabledQueryMessage
| AddonEnabledResponseMessage
| AddonToggleEnabledMessage
@@ -360,10 +333,6 @@ export const valueOf = (o: any): Message => {
case MARK_SET_GLOBAL:
case MARK_JUMP_GLOBAL:
case TAB_SCROLL_TO:
- case FIND_NEXT:
- case FIND_PREV:
- case FIND_GET_KEYWORD:
- case FIND_SET_KEYWORD:
case ADDON_ENABLED_QUERY:
case ADDON_ENABLED_RESPONSE:
case ADDON_TOGGLE_ENABLED:
diff --git a/test/content/mock/MockFindMasterClient.ts b/test/content/mock/MockFindMasterClient.ts
deleted file mode 100644
index a035cc5..0000000
--- a/test/content/mock/MockFindMasterClient.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-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/operators/impls/FindNextOperator.test.ts b/test/content/operators/impls/FindNextOperator.test.ts
deleted file mode 100644
index d93d45e..0000000
--- a/test/content/operators/impls/FindNextOperator.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-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
deleted file mode 100644
index 6c599ae..0000000
--- a/test/content/operators/impls/FindOperatorFactoryChain.test.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-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
deleted file mode 100644
index 1ebde8d..0000000
--- a/test/content/operators/impls/FindPrevOperator.test.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-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/repositories/FindRepository.test.ts b/test/content/repositories/FindRepository.test.ts
deleted file mode 100644
index e0abb9d..0000000
--- a/test/content/repositories/FindRepository.test.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { FindRepositoryImpl } from "../../../src/content/repositories/FindRepository";
-import { expect } from "chai";
-
-describe("FindRepositoryImpl", () => {
- it("updates and gets last keyword", () => {
- const sut = new FindRepositoryImpl();
-
- expect(sut.getLastKeyword()).to.be.null;
-
- sut.setLastKeyword("monkey");
-
- expect(sut.getLastKeyword()).to.equal("monkey");
- });
-});
diff --git a/test/content/usecases/FindUseCase.test.ts b/test/content/usecases/FindUseCase.test.ts
deleted file mode 100644
index b53ef74..0000000
--- a/test/content/usecases/FindUseCase.test.ts
+++ /dev/null
@@ -1,160 +0,0 @@
-import FindRepository from "../../../src/content/repositories/FindRepository";
-import FindPresenter from "../../../src/content/presenters/FindPresenter";
-import FindClient from "../../../src/content/client/FindClient";
-import FindUseCase from "../../../src/content/usecases/FindUseCase";
-import MockConsoleClient from "../mock/MockConsoleClient";
-import { expect } from "chai";
-
-class MockFindRepository implements FindRepository {
- public keyword: string | null;
-
- constructor() {
- this.keyword = null;
- }
-
- getLastKeyword(): string | null {
- return this.keyword;
- }
-
- setLastKeyword(keyword: string): void {
- this.keyword = keyword;
- }
-}
-
-class MockFindPresenter implements FindPresenter {
- public document: string;
-
- public highlighted: boolean;
-
- constructor() {
- this.document = "";
- this.highlighted = false;
- }
-
- find(keyword: string, _backward: boolean): boolean {
- const found = this.document.includes(keyword);
- this.highlighted = found;
- return found;
- }
-
- clearSelection(): void {
- this.highlighted = false;
- }
-}
-
-class MockFindClient implements FindClient {
- public keyword: string | null;
-
- constructor() {
- this.keyword = null;
- }
-
- getGlobalLastKeyword(): Promise<string | null> {
- return Promise.resolve(this.keyword);
- }
-
- setGlobalLastKeyword(keyword: string): Promise<void> {
- this.keyword = keyword;
- return Promise.resolve();
- }
-}
-
-describe("FindUseCase", () => {
- let repository: MockFindRepository;
- let presenter: MockFindPresenter;
- let client: MockFindClient;
- let consoleClient: MockConsoleClient;
- let sut: FindUseCase;
-
- beforeEach(() => {
- repository = new MockFindRepository();
- presenter = new MockFindPresenter();
- client = new MockFindClient();
- consoleClient = new MockConsoleClient();
- sut = new FindUseCase(presenter, repository, client, consoleClient);
- });
-
- describe("#startFind", () => {
- it("find next by ketword", async () => {
- presenter.document = "monkey punch";
-
- await sut.startFind("monkey");
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: monkey");
- expect(await repository.getLastKeyword()).to.equal("monkey");
- expect(await client.getGlobalLastKeyword()).to.equal("monkey");
- });
-
- it("find next by last keyword", async () => {
- presenter.document = "gorilla kick";
- repository.keyword = "gorilla";
-
- await sut.startFind(undefined);
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: gorilla");
- expect(await repository.getLastKeyword()).to.equal("gorilla");
- expect(await client.getGlobalLastKeyword()).to.equal("gorilla");
- });
-
- it("find next by global last keyword", async () => {
- presenter.document = "chimpanzee typing";
-
- repository.keyword = null;
- client.keyword = "chimpanzee";
-
- await sut.startFind(undefined);
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: chimpanzee");
- expect(await repository.getLastKeyword()).to.equal("chimpanzee");
- expect(await client.getGlobalLastKeyword()).to.equal("chimpanzee");
- });
-
- it("find not found error", async () => {
- presenter.document = "zoo";
-
- await sut.startFind("giraffe");
-
- expect(await presenter.highlighted).to.be.false;
- expect(await consoleClient.text).to.equal("Pattern not found: giraffe");
- expect(await repository.getLastKeyword()).to.equal("giraffe");
- expect(await client.getGlobalLastKeyword()).to.equal("giraffe");
- });
-
- it("show errors when no last keywords", async () => {
- repository.keyword = null;
- client.keyword = null;
-
- await sut.startFind(undefined);
-
- expect(await consoleClient.text).to.equal("No previous search keywords");
- expect(await consoleClient.isError).to.be.true;
- });
- });
-
- describe("#findNext", () => {
- it("finds by last keyword", async () => {
- presenter.document = "monkey punch";
- repository.keyword = "monkey";
-
- await sut.findNext();
-
- expect(await presenter.highlighted).to.be.true;
- expect(await consoleClient.text).to.equal("Pattern found: monkey");
- });
-
- it("show errors when no last keywords", async () => {
- repository.keyword = null;
- client.keyword = null;
-
- await sut.findNext();
-
- expect(await consoleClient.text).to.equal("No previous search keywords");
- expect(await consoleClient.isError).to.be.true;
- });
- });
-
- describe("#findPrev", () => {});
-});