aboutsummaryrefslogtreecommitdiff
path: root/test/background/completion
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/completion')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts102
-rw-r--r--test/background/completion/PropertyCompletionUseCase.test.ts5
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts104
-rw-r--r--test/background/completion/impl/filters.test.ts15
4 files changed, 96 insertions, 130 deletions
diff --git a/test/background/completion/OpenCompletionUseCase.test.ts b/test/background/completion/OpenCompletionUseCase.test.ts
index f43e6c1..5ab9d5e 100644
--- a/test/background/completion/OpenCompletionUseCase.test.ts
+++ b/test/background/completion/OpenCompletionUseCase.test.ts
@@ -11,8 +11,6 @@ import CachedSettingRepository from "../../../src/background/repositories/Cached
import Settings, {
DefaultSetting,
} from "../../../src/shared/settings/Settings";
-import { expect } from "chai";
-import sinon from "sinon";
import Properties from "../../../src/shared/settings/Properties";
import Search from "../../../src/shared/settings/Search";
@@ -61,19 +59,17 @@ describe("OpenCompletionUseCase", () => {
describe("#getCompletionTypes", () => {
it("returns completion types from the property", async () => {
- sinon.stub(settingRepository, "get").returns(
- Promise.resolve(
- new Settings({
- keymaps: DefaultSetting.keymaps,
- search: DefaultSetting.search,
- properties: new Properties({ complete: "shb" }),
- blacklist: DefaultSetting.blacklist,
- })
- )
+ jest.spyOn(settingRepository, "get").mockResolvedValueOnce(
+ new Settings({
+ keymaps: DefaultSetting.keymaps,
+ search: DefaultSetting.search,
+ properties: new Properties({ complete: "shb" }),
+ blacklist: DefaultSetting.blacklist,
+ })
);
const items = await sut.getCompletionTypes();
- expect(items).to.deep.equal([
+ expect(items).toEqual([
CompletionType.SearchEngines,
CompletionType.History,
CompletionType.Bookmarks,
@@ -83,77 +79,73 @@ describe("OpenCompletionUseCase", () => {
describe("#requestSearchEngines", () => {
it("returns search engines matches by the query", async () => {
- sinon.stub(settingRepository, "get").returns(
- Promise.resolve(
- new Settings({
- keymaps: DefaultSetting.keymaps,
- search: new Search("google", {
- google: "https://google.com/search?q={}",
- yahoo: "https://search.yahoo.com/search?q={}",
- bing: "https://bing.com/search?q={}",
- googleja: "https://google.co.jp/search?q={}",
- }),
- properties: DefaultSetting.properties,
- blacklist: DefaultSetting.blacklist,
- })
- )
+ jest.spyOn(settingRepository, "get").mockResolvedValue(
+ new Settings({
+ keymaps: DefaultSetting.keymaps,
+ search: new Search("google", {
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?q={}",
+ bing: "https://bing.com/search?q={}",
+ googleja: "https://google.co.jp/search?q={}",
+ }),
+ properties: DefaultSetting.properties,
+ blacklist: DefaultSetting.blacklist,
+ })
);
- expect(await sut.requestSearchEngines("")).to.deep.equal([
+ expect(await sut.requestSearchEngines("")).toEqual([
"google",
"yahoo",
"bing",
"googleja",
]);
- expect(await sut.requestSearchEngines("go")).to.deep.equal([
+ expect(await sut.requestSearchEngines("go")).toEqual([
"google",
"googleja",
]);
- expect(await sut.requestSearchEngines("x")).to.be.empty;
+ expect(await sut.requestSearchEngines("x")).toHaveLength(0);
});
});
describe("#requestBookmarks", () => {
it("returns bookmarks from the repository", async () => {
- sinon
- .stub(bookmarkRepository, "queryBookmarks")
- .withArgs("site")
- .returns(
- Promise.resolve([
- { title: "site1", url: "https://site1.example.com" },
- { title: "site2", url: "https://site2.example.com/" },
- ])
- )
- .withArgs("xyz")
- .returns(Promise.resolve([]));
+ const spy = jest
+ .spyOn(bookmarkRepository, "queryBookmarks")
+ .mockResolvedValueOnce([
+ { title: "site1", url: "https://site1.example.com" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ])
+ .mockResolvedValueOnce([]);
- expect(await sut.requestBookmarks("site")).to.deep.equal([
+ expect(await sut.requestBookmarks("site")).toEqual([
{ title: "site1", url: "https://site1.example.com" },
{ title: "site2", url: "https://site2.example.com/" },
]);
- expect(await sut.requestBookmarks("xyz")).to.be.empty;
+ expect(await sut.requestBookmarks("xyz")).toHaveLength(0);
+ expect(spy).toBeCalledTimes(2);
+ expect(spy.mock.calls[0][0]).toEqual("site");
+ expect(spy.mock.calls[1][0]).toEqual("xyz");
});
});
describe("#requestHistory", () => {
it("returns histories from the repository", async () => {
- sinon
- .stub(historyRepository, "queryHistories")
- .withArgs("site")
- .returns(
- Promise.resolve([
- { title: "site1", url: "https://site1.example.com" },
- { title: "site2", url: "https://site2.example.com/" },
- ])
- )
- .withArgs("xyz")
- .returns(Promise.resolve([]));
+ const spy = jest
+ .spyOn(historyRepository, "queryHistories")
+ .mockResolvedValueOnce([
+ { title: "site1", url: "https://site1.example.com" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ])
+ .mockResolvedValueOnce([]);
- expect(await sut.requestHistory("site")).to.deep.equal([
+ expect(await sut.requestHistory("site")).toEqual([
{ title: "site1", url: "https://site1.example.com" },
{ title: "site2", url: "https://site2.example.com/" },
]);
- expect(await sut.requestHistory("xyz")).to.be.empty;
+ expect(await sut.requestHistory("xyz")).toHaveLength(0);
+ expect(spy).toBeCalledTimes(2);
+ expect(spy.mock.calls[0][0]).toEqual("site");
+ expect(spy.mock.calls[1][0]).toEqual("xyz");
});
});
});
diff --git a/test/background/completion/PropertyCompletionUseCase.test.ts b/test/background/completion/PropertyCompletionUseCase.test.ts
index dfc989f..b008eb5 100644
--- a/test/background/completion/PropertyCompletionUseCase.test.ts
+++ b/test/background/completion/PropertyCompletionUseCase.test.ts
@@ -1,6 +1,5 @@
import "reflect-metadata";
import PropertyCompletionUseCase from "../../../src/background/completion/PropertyCompletionUseCase";
-import { expect } from "chai";
describe("PropertyCompletionUseCase", () => {
describe("getProperties", () => {
@@ -8,11 +7,11 @@ describe("PropertyCompletionUseCase", () => {
const sut = new PropertyCompletionUseCase();
const properties = await sut.getProperties();
- expect(properties).to.deep.contain({
+ expect(properties).toContainEqual({
name: "smoothscroll",
type: "boolean",
});
- expect(properties).to.deep.contain({ name: "complete", type: "string" });
+ expect(properties).toContainEqual({ name: "complete", type: "string" });
});
});
});
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
index 319f217..c006b65 100644
--- a/test/background/completion/TabCompletionUseCase.test.ts
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -3,8 +3,6 @@ import TabRepositoryImpl from "../../../src/background/completion/impl/TabReposi
import { Tab } from "../../../src/background/completion/TabRepository";
import TabPresenter from "../../../src/background/presenters/TabPresenter";
import TabCompletionUseCase from "../../../src/background/completion/TabCompletionUseCase";
-import sinon from "sinon";
-import { expect } from "chai";
import TabFlag from "../../../src/shared/TabFlag";
class MockTabRepository implements TabRepositoryImpl {
@@ -98,43 +96,39 @@ describe("TabCompletionUseCase", () => {
tabPresenter = new MockTabPresenter();
sut = new TabCompletionUseCase(tabRepository, tabPresenter);
- sinon.stub(tabPresenter, "getLastSelectedId").returns(Promise.resolve(12));
- sinon.stub(tabRepository, "getAllTabs").returns(
- Promise.resolve([
- {
- id: 10,
- index: 0,
- title: "Google",
- url: "https://google.com/",
- faviconUrl: "https://google.com/favicon.ico",
- active: false,
- },
- {
- id: 11,
- index: 1,
- title: "Yahoo",
- url: "https://yahoo.com/",
- faviconUrl: "https://yahoo.com/favicon.ico",
- active: true,
- },
- {
- id: 12,
- index: 2,
- title: "Bing",
- url: "https://bing.com/",
- active: false,
- },
- ])
- );
+ jest.spyOn(tabPresenter, "getLastSelectedId").mockResolvedValue(12);
+ jest.spyOn(tabRepository, "getAllTabs").mockResolvedValue([
+ {
+ id: 10,
+ index: 0,
+ title: "Google",
+ url: "https://google.com/",
+ faviconUrl: "https://google.com/favicon.ico",
+ active: false,
+ },
+ {
+ id: 11,
+ index: 1,
+ title: "Yahoo",
+ url: "https://yahoo.com/",
+ faviconUrl: "https://yahoo.com/favicon.ico",
+ active: true,
+ },
+ {
+ id: 12,
+ index: 2,
+ title: "Bing",
+ url: "https://bing.com/",
+ active: false,
+ },
+ ]);
});
describe("#queryTabs", () => {
it("returns tab items", async () => {
- sinon
- .stub(tabRepository, "queryTabs")
- .withArgs("", false)
- .returns(
- Promise.resolve([
+ jest.spyOn(tabRepository, "queryTabs").mockImplementation((keyword) =>
+ Promise.resolve(
+ [
{
id: 10,
index: 0,
@@ -158,31 +152,13 @@ describe("TabCompletionUseCase", () => {
url: "https://bing.com/",
active: false,
},
- ])
+ ].filter(
+ (item) => item.title.includes(keyword) || item.url.includes(keyword)
+ )
)
- .withArgs("oo", false)
- .returns(
- Promise.resolve([
- {
- id: 10,
- index: 0,
- title: "Google",
- url: "https://google.com/",
- faviconUrl: "https://google.com/favicon.ico",
- active: false,
- },
- {
- id: 11,
- index: 1,
- title: "Yahoo",
- url: "https://yahoo.com/",
- faviconUrl: "https://yahoo.com/favicon.ico",
- active: true,
- },
- ])
- );
+ );
- expect(await sut.queryTabs("", false)).to.deep.equal([
+ expect(await sut.queryTabs("", false)).toEqual([
{
index: 1,
title: "Google",
@@ -206,7 +182,7 @@ describe("TabCompletionUseCase", () => {
},
]);
- expect(await sut.queryTabs("oo", false)).to.deep.equal([
+ expect(await sut.queryTabs("oo", false)).toEqual([
{
index: 1,
title: "Google",
@@ -225,7 +201,7 @@ describe("TabCompletionUseCase", () => {
});
it("returns a tab by the index", async () => {
- expect(await sut.queryTabs("1", false)).to.deep.equal([
+ expect(await sut.queryTabs("1", false)).toEqual([
{
index: 1,
title: "Google",
@@ -235,12 +211,12 @@ describe("TabCompletionUseCase", () => {
},
]);
- expect(await sut.queryTabs("10", false)).to.be.empty;
- expect(await sut.queryTabs("-1", false)).to.be.empty;
+ expect(await sut.queryTabs("10", false)).toHaveLength(0);
+ expect(await sut.queryTabs("-1", false)).toHaveLength(0);
});
it("returns the current tab by % flag", async () => {
- expect(await sut.queryTabs("%", false)).to.deep.equal([
+ expect(await sut.queryTabs("%", false)).toEqual([
{
index: 2,
title: "Yahoo",
@@ -252,7 +228,7 @@ describe("TabCompletionUseCase", () => {
});
it("returns the current tab by # flag", async () => {
- expect(await sut.queryTabs("#", false)).to.deep.equal([
+ expect(await sut.queryTabs("#", false)).toEqual([
{
index: 3,
title: "Bing",
diff --git a/test/background/completion/impl/filters.test.ts b/test/background/completion/impl/filters.test.ts
index b160944..5dd1a93 100644
--- a/test/background/completion/impl/filters.test.ts
+++ b/test/background/completion/impl/filters.test.ts
@@ -1,5 +1,4 @@
import * as filters from "../../../../src/background/completion/impl/filters";
-import { expect } from "chai";
describe("background/usecases/filters", () => {
describe("filterHttp", () => {
@@ -13,7 +12,7 @@ describe("background/usecases/filters", () => {
const filtered = filters.filterHttp(pages);
const urls = filtered.map((x) => x.url);
- expect(urls).to.deep.equal([
+ expect(urls).toEqual([
"https://i-beam.org/bar",
"http://i-beam.net/hoge",
"http://i-beam.net/fuga",
@@ -30,7 +29,7 @@ describe("background/usecases/filters", () => {
];
const filtered = filters.filterBlankTitle(pages);
- expect(filtered).to.deep.equal([{ id: "0", title: "hello" }]);
+ expect(filtered).toEqual([{ id: "0", title: "hello" }]);
});
});
@@ -45,7 +44,7 @@ describe("background/usecases/filters", () => {
const filtered = filters.filterByTailingSlash(pages);
const urls = filtered.map((x) => x.url);
- expect(urls).to.deep.equal([
+ expect(urls).toEqual([
"http://i-beam.org/content",
"http://i-beam.org/search",
"http://i-beam.org/search?q=apple_banana_cherry",
@@ -64,7 +63,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByPathname(pages, 10);
- expect(filtered).to.have.lengthOf(6);
+ expect(filtered).toHaveLength(6);
});
it("filters by length of pathname", () => {
@@ -77,7 +76,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.net/search?q=apple_banana_cherry" },
];
const filtered = filters.filterByPathname(pages, 0);
- expect(filtered).to.deep.equal([
+ expect(filtered).toEqual([
{ id: "0", url: "http://i-beam.org/search?q=apple" },
{ id: "3", url: "http://i-beam.net/search?q=apple" },
]);
@@ -95,7 +94,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByOrigin(pages, 10);
- expect(filtered).to.have.lengthOf(6);
+ expect(filtered).toHaveLength(6);
});
it("filters by length of pathname", () => {
@@ -108,7 +107,7 @@ describe("background/usecases/filters", () => {
{ id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByOrigin(pages, 0);
- expect(filtered).to.deep.equal([
+ expect(filtered).toEqual([
{ id: "0", url: "http://i-beam.org/search?q=apple" },
]);
});