aboutsummaryrefslogtreecommitdiff
path: root/test/background/operators
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-09-26 11:54:11 +0900
committerGitHub <noreply@github.com>2021-09-26 11:54:11 +0900
commit9154972485c24a5a90782cef17f75b3a79a13774 (patch)
tree4bc3d608f498176f50a74ca7fc03d2d501ac7920 /test/background/operators
parentcbf4b37bd0d5ba277d6400ed460d6a086ae1d7bb (diff)
parent91d4712e676782bb58fd7eb03fdc1f85111fca04 (diff)
Merge pull request #1264 from ueokande/fix-establish-connection-issue
Search a content from frames successfully loaded
Diffstat (limited to 'test/background/operators')
-rw-r--r--test/background/operators/impls/FindNextOperator.test.ts30
-rw-r--r--test/background/operators/impls/FindPrevOperator.test.ts30
2 files changed, 28 insertions, 32 deletions
diff --git a/test/background/operators/impls/FindNextOperator.test.ts b/test/background/operators/impls/FindNextOperator.test.ts
index 0bee3f5..7509ef4 100644
--- a/test/background/operators/impls/FindNextOperator.test.ts
+++ b/test/background/operators/impls/FindNextOperator.test.ts
@@ -4,7 +4,7 @@ import FindNextOperator from "../../../../src/background/operators/impls/FindNex
import MockFindRepository from "../../mock/MockFindRepository";
import MockFindClient from "../../mock/MockFindClient";
import MockConsoleClient from "../../mock/MockConsoleClient";
-import MockFramePresenter from "../../mock/MockFramePresenter";
+import MockReadyFrameRepository from "../../mock/MockReadyFrameRepository";
describe("FindNextOperator", () => {
const keyword = "hello";
@@ -14,13 +14,13 @@ describe("FindNextOperator", () => {
const findRepository = new MockFindRepository();
const findClient = new MockFindClient();
const consoleClient = new MockConsoleClient();
- const framePresenter = new MockFramePresenter();
+ const frameRepository = new MockReadyFrameRepository();
const sut = new FindNextOperator(
tabPresenter,
findRepository,
findClient,
consoleClient,
- framePresenter
+ frameRepository
);
let currentTabId: number;
@@ -32,6 +32,10 @@ describe("FindNextOperator", () => {
active: true,
});
currentTabId = currentTab.id!;
+
+ sinon
+ .stub(frameRepository, "getFrameIds")
+ .returns(Promise.resolve(frameIds));
});
describe("#run", () => {
@@ -54,8 +58,7 @@ describe("FindNextOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 1,
+ frameId: 100,
})
);
@@ -68,7 +71,7 @@ describe("FindNextOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 1 });
+ .withArgs(currentTabId, { keyword, frameId: 100 });
await sut.run();
@@ -80,8 +83,7 @@ describe("FindNextOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 1,
+ frameId: 100,
})
);
@@ -102,7 +104,7 @@ describe("FindNextOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+ .withArgs(currentTabId, { keyword, frameId: 101 });
await sut.run();
@@ -114,8 +116,7 @@ describe("FindNextOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 2,
+ frameId: 101,
})
);
@@ -136,7 +137,7 @@ describe("FindNextOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+ .withArgs(currentTabId, { keyword, frameId: 0 });
await sut.run();
@@ -151,9 +152,6 @@ describe("FindNextOperator", () => {
sinon
.stub(findRepository, "getGlobalKeyword")
.returns(Promise.resolve(keyword));
- sinon
- .stub(framePresenter, "getAllFrameIds")
- .returns(Promise.resolve(frameIds));
sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
const mockFindClient = sinon.mock(findClient);
@@ -168,7 +166,7 @@ describe("FindNextOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+ .withArgs(currentTabId, { keyword, frameId: 0 });
await sut.run();
diff --git a/test/background/operators/impls/FindPrevOperator.test.ts b/test/background/operators/impls/FindPrevOperator.test.ts
index ebac0dc..090f815 100644
--- a/test/background/operators/impls/FindPrevOperator.test.ts
+++ b/test/background/operators/impls/FindPrevOperator.test.ts
@@ -4,7 +4,7 @@ import FindPrevOperator from "../../../../src/background/operators/impls/FindPre
import MockFindRepository from "../../mock/MockFindRepository";
import MockFindClient from "../../mock/MockFindClient";
import MockConsoleClient from "../../mock/MockConsoleClient";
-import MockFramePresenter from "../../mock/MockFramePresenter";
+import MockReadyFrameRepository from "../../mock/MockReadyFrameRepository";
describe("FindPrevOperator", () => {
const keyword = "hello";
@@ -14,13 +14,13 @@ describe("FindPrevOperator", () => {
const findRepository = new MockFindRepository();
const findClient = new MockFindClient();
const consoleClient = new MockConsoleClient();
- const framePresenter = new MockFramePresenter();
+ const frameRepository = new MockReadyFrameRepository();
const sut = new FindPrevOperator(
tabPresenter,
findRepository,
findClient,
consoleClient,
- framePresenter
+ frameRepository
);
let currentTabId: number;
@@ -32,6 +32,10 @@ describe("FindPrevOperator", () => {
active: true,
});
currentTabId = currentTab.id!;
+
+ sinon
+ .stub(frameRepository, "getFrameIds")
+ .returns(Promise.resolve(frameIds.slice(0)));
});
describe("#run", () => {
@@ -54,8 +58,7 @@ describe("FindPrevOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 1,
+ frameId: 100,
})
);
@@ -68,7 +71,7 @@ describe("FindPrevOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 1 });
+ .withArgs(currentTabId, { keyword, frameId: 100 });
await sut.run();
@@ -80,8 +83,7 @@ describe("FindPrevOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 1,
+ frameId: 100,
})
);
@@ -102,7 +104,7 @@ describe("FindPrevOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 0 });
+ .withArgs(currentTabId, { keyword, frameId: 0 });
await sut.run();
@@ -114,8 +116,7 @@ describe("FindPrevOperator", () => {
sinon.stub(findRepository, "getLocalState").returns(
Promise.resolve({
keyword,
- frameIds,
- framePos: 0,
+ frameId: 0,
})
);
@@ -136,7 +137,7 @@ describe("FindPrevOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+ .withArgs(currentTabId, { keyword, frameId: 101 });
await sut.run();
@@ -151,9 +152,6 @@ describe("FindPrevOperator", () => {
sinon
.stub(findRepository, "getGlobalKeyword")
.returns(Promise.resolve(keyword));
- sinon
- .stub(framePresenter, "getAllFrameIds")
- .returns(Promise.resolve(frameIds));
sinon.stub(consoleClient, "showInfo").returns(Promise.resolve());
const mockFindClient = sinon.mock(findClient);
@@ -168,7 +166,7 @@ describe("FindPrevOperator", () => {
const mockFindRepository = sinon.mock(findRepository);
mockFindRepository
.expects("setLocalState")
- .withArgs(currentTabId, { keyword, frameIds, framePos: 2 });
+ .withArgs(currentTabId, { keyword, frameId: 101 });
await sut.run();