1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
import sinon from "sinon";
import MockTabPresenter from "../../mock/MockTabPresenter";
import FindNextOperator from "../../../../src/background/operators/impls/FindNextOperator";
import { FindState } from "../../../../src/background/repositories/FindRepository";
import MockFindRepository from "../../mock/MockFindRepository";
import MockFindClient from "../../mock/MockFindClient";
describe("FindPrevOperator", () => {
describe("#run", () => {
it("throws an error on no previous keywords", async () => {
const tabPresenter = new MockTabPresenter();
const findRepository = new MockFindRepository();
const findClient = new MockFindClient();
await tabPresenter.create("https://example.com/");
const sut = new FindNextOperator(
tabPresenter,
findRepository,
findClient
);
try {
await sut.run();
} catch (e) {
return;
}
throw new Error("unexpected reach");
});
it("select a next next", async () => {
const tabPresenter = new MockTabPresenter();
const findRepository = new MockFindRepository();
const findClient = new MockFindClient();
const currentTab = await tabPresenter.create("https://example.com/");
const state: FindState = {
keyword: "Hello, world",
rangeData: [
{
framePos: 0,
startOffset: 0,
endOffset: 10,
startTextNodePos: 0,
endTextNodePos: 0,
text: "Hello, world",
},
{
framePos: 1,
startOffset: 0,
endOffset: 10,
startTextNodePos: 1,
endTextNodePos: 1,
text: "Hello, world",
},
{
framePos: 2,
startOffset: 2,
endOffset: 10,
startTextNodePos: 1,
endTextNodePos: 1,
text: "Hello, world",
},
],
highlightPosition: 1,
};
await findRepository.setLocalState(currentTab.id!, state);
const mock = sinon.mock(findClient);
mock
.expects("selectKeyword")
.withArgs(currentTab?.id, state.rangeData[0]);
mock
.expects("selectKeyword")
.withArgs(currentTab?.id, state.rangeData[2]);
mock
.expects("selectKeyword")
.withArgs(currentTab?.id, state.rangeData[1]);
const sut = new FindNextOperator(
tabPresenter,
findRepository,
findClient
);
await sut.run();
await sut.run();
await sut.run();
mock.verify();
});
});
});
|