aboutsummaryrefslogtreecommitdiff
path: root/test/background/usecases/FindUseCase.test.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-07-27 21:46:35 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-07-27 21:46:35 +0900
commit6814b7c3e4795c76fc9c0cfdc9de0a9d558d6c8c (patch)
treebedfa8ed7fe9737d3fdb61269e0e56056c3225ce /test/background/usecases/FindUseCase.test.ts
parent98ab2cde0f9e8a718eafd6a0482da25859efdaeb (diff)
Add tests to find
Diffstat (limited to 'test/background/usecases/FindUseCase.test.ts')
-rw-r--r--test/background/usecases/FindUseCase.test.ts121
1 files changed, 0 insertions, 121 deletions
diff --git a/test/background/usecases/FindUseCase.test.ts b/test/background/usecases/FindUseCase.test.ts
deleted file mode 100644
index eef211b..0000000
--- a/test/background/usecases/FindUseCase.test.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-import "reflect-metadata";
-import sinon from "sinon";
-import FindClient from "../../../src/background/clients/FindClient";
-import StartFindUseCase from "../../../src/background/usecases/StartFindUseCase";
-import FindRepository from "../../../src/background/repositories/FindRepository";
-import { expect } from "chai";
-import MockFindClient from "../mock/MockFindClient";
-import MockFindRepository from "../mock/MockFindRepository";
-
-describe("FindUseCase", () => {
- let findClient: FindClient;
- let findRepository: FindRepository;
- let sut: StartFindUseCase;
-
- const rangeData = (count: number): browser.find.RangeData[] => {
- const data = {
- text: "Hello, world",
- framePos: 0,
- startTextNodePos: 0,
- endTextNodePos: 0,
- startOffset: 0,
- endOffset: 0,
- };
- return Array(count).fill(data);
- };
-
- beforeEach(() => {
- findClient = new MockFindClient();
- findRepository = new MockFindRepository();
- sut = new StartFindUseCase(findClient, findRepository);
- });
-
- describe("startFind", function () {
- context("with a search keyword", () => {
- it("starts find and store last used keyword", async () => {
- const startFind = sinon
- .stub(findClient, "startFind")
- .returns(Promise.resolve({ count: 10, rangeData: rangeData(10) }));
- const highlightAll = sinon
- .mock(findClient)
- .expects("highlightAll")
- .once();
- const selectKeyword = sinon
- .mock(findClient)
- .expects("selectKeyword")
- .once();
-
- await sut.startFind(10, "Hello, world");
-
- expect(startFind.calledWith("Hello, world")).to.be.true;
- expect(await findRepository.getGlobalKeyword()).to.equals(
- "Hello, world"
- );
- expect((await findRepository.getLocalState(10))?.keyword).to.equal(
- "Hello, world"
- );
- highlightAll.verify();
- selectKeyword.verify();
- });
-
- it("throws an error if no matched", (done) => {
- sinon
- .stub(findClient, "startFind")
- .returns(Promise.resolve({ count: 0, rangeData: [] }));
-
- sut.startFind(10, "Hello, world").catch((e) => {
- expect(e).instanceof(Error);
- done();
- });
- });
- });
-
- context("without a search keyword", () => {
- it("starts find with last used keyword in the tab", async () => {
- const startFind = sinon
- .stub(findClient, "startFind")
- .returns(Promise.resolve({ count: 10, rangeData: rangeData(10) }));
- await findRepository.setLocalState(10, {
- keyword: "Hello, world",
- rangeData: rangeData(10),
- highlightPosition: 0,
- });
- const highlightAll = sinon
- .mock(findClient)
- .expects("highlightAll")
- .once();
- const selectKeyword = sinon
- .mock(findClient)
- .expects("selectKeyword")
- .once();
-
- await sut.startFind(10, undefined);
-
- expect(startFind.calledWith("Hello, world")).to.be.true;
- highlightAll.verify();
- selectKeyword.verify();
- });
-
- it("starts find with last used keyword in global", async () => {
- const startFind = sinon
- .stub(findClient, "startFind")
- .returns(Promise.resolve({ count: 10, rangeData: rangeData(10) }));
- await findRepository.setGlobalKeyword("Hello, world");
- const highlightAll = sinon
- .mock(findClient)
- .expects("highlightAll")
- .once();
- const selectKeyword = sinon
- .mock(findClient)
- .expects("selectKeyword")
- .once();
-
- await sut.startFind(10, undefined);
-
- expect(startFind.calledWith("Hello, world")).to.be.true;
- highlightAll.verify();
- selectKeyword.verify();
- });
- });
- });
-});