aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-04-13 20:37:36 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-04-13 20:37:36 +0900
commite1dac618a8b8929f601c7ec8aca3842c5ebf9d03 (patch)
tree6a914a8243c8c02e7752a83667a54d3fa832955c /test
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
Use plugin:prettier/recommended
Diffstat (limited to 'test')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts128
-rw-r--r--test/background/completion/PropertyCompletionUseCase.test.ts21
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts232
-rw-r--r--test/background/completion/impl/PrefetchAndCache.test.ts80
-rw-r--r--test/background/completion/impl/filters.test.ts98
-rw-r--r--test/background/infrastructures/MemoryStorage.test.ts48
-rw-r--r--test/background/repositories/Mark.test.ts16
-rw-r--r--test/background/usecases/NavigateUseCase.test.ts94
-rw-r--r--test/background/usecases/SettingUseCase.test.ts73
-rw-r--r--test/background/usecases/parsers.test.ts47
-rw-r--r--test/console/actions/console.test.ts44
-rw-r--r--test/console/commandline/CommandLineParser.test.ts10
-rw-r--r--test/console/commandline/CommandParser.test.ts10
-rw-r--r--test/console/components/console/Completion.test.tsx195
-rw-r--r--test/console/reducers/console.test.ts149
-rw-r--r--test/content/InputDriver.test.ts161
-rw-r--r--test/content/domains/KeySequence.test.ts209
-rw-r--r--test/content/mock/MockConsoleClient.ts6
-rw-r--r--test/content/mock/MockScrollPresenter.ts7
-rw-r--r--test/content/presenters/Hint.test.ts134
-rw-r--r--test/content/presenters/NavigationPresenter.test.ts272
-rw-r--r--test/content/repositories/AddonEnabledRepository.test.ts9
-rw-r--r--test/content/repositories/FindRepository.test.ts13
-rw-r--r--test/content/repositories/FollowKeyRepository.test.ts26
-rw-r--r--test/content/repositories/FollowMasterRepository.test.ts39
-rw-r--r--test/content/repositories/FollowSlaveRepository.test.ts14
-rw-r--r--test/content/repositories/KeymapRepository.test.ts39
-rw-r--r--test/content/repositories/MarkKeyRepository.test.ts20
-rw-r--r--test/content/repositories/MarkRepository.test.ts15
-rw-r--r--test/content/repositories/SettingRepository.test.ts24
-rw-r--r--test/content/usecases/AddonEnabledUseCase.test.ts28
-rw-r--r--test/content/usecases/ClipboardUseCase.test.ts84
-rw-r--r--test/content/usecases/FindUseCase.test.ts87
-rw-r--r--test/content/usecases/HintKeyProducer.test.ts38
-rw-r--r--test/content/usecases/KeymapUseCase.test.ts274
-rw-r--r--test/content/usecases/MarkUseCase.test.ts75
-rw-r--r--test/content/usecases/SettingUseCaase.test.ts34
-rw-r--r--test/main.ts6
-rw-r--r--test/settings/components/form/BlacklistForm.test.tsx112
-rw-r--r--test/settings/components/form/KeymapsForm.test.tsx68
-rw-r--r--test/settings/components/form/PropertiesForm.test.tsx121
-rw-r--r--test/settings/components/form/SearchEngineForm.test.tsx165
-rw-r--r--test/settings/components/ui/input.test.tsx145
-rw-r--r--test/settings/reducers/setting.test.ts44
-rw-r--r--test/shared/SettingData.test.ts156
-rw-r--r--test/shared/operations.test.ts46
-rw-r--r--test/shared/settings/Blacklist.test.ts210
-rw-r--r--test/shared/settings/Key.test.ts120
-rw-r--r--test/shared/settings/Keymaps.test.ts81
-rw-r--r--test/shared/settings/Properties.test.ts21
-rw-r--r--test/shared/settings/Search.test.ts90
-rw-r--r--test/shared/settings/Settings.test.ts40
-rw-r--r--test/shared/urls.test.ts108
53 files changed, 2480 insertions, 1906 deletions
diff --git a/test/background/completion/OpenCompletionUseCase.test.ts b/test/background/completion/OpenCompletionUseCase.test.ts
index 421ce69..a0d8b44 100644
--- a/test/background/completion/OpenCompletionUseCase.test.ts
+++ b/test/background/completion/OpenCompletionUseCase.test.ts
@@ -1,42 +1,48 @@
import "reflect-metadata";
import CompletionType from "../../../src/shared/CompletionType";
-import BookmarkRepository, {BookmarkItem} from "../../../src/background/completion/BookmarkRepository";
-import HistoryRepository, {HistoryItem} from "../../../src/background/completion/HistoryRepository";
+import BookmarkRepository, {
+ BookmarkItem,
+} from "../../../src/background/completion/BookmarkRepository";
+import HistoryRepository, {
+ HistoryItem,
+} from "../../../src/background/completion/HistoryRepository";
import OpenCompletionUseCase from "../../../src/background/completion/OpenCompletionUseCase";
import CachedSettingRepository from "../../../src/background/repositories/CachedSettingRepository";
-import Settings, {DefaultSetting} from "../../../src/shared/settings/Settings";
-import { expect } from 'chai';
-import sinon from 'sinon';
+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";
class MockBookmarkRepository implements BookmarkRepository {
queryBookmarks(_query: string): Promise<BookmarkItem[]> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
}
class MockHistoryRepository implements HistoryRepository {
queryHistories(_keywords: string): Promise<HistoryItem[]> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
}
class MockSettingRepository implements CachedSettingRepository {
get(): Promise<Settings> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
setProperty(_name: string, _value: string | number | boolean): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
update(_value: Settings): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
}
-describe('OpenCompletionUseCase', () => {
+describe("OpenCompletionUseCase", () => {
let bookmarkRepository: MockBookmarkRepository;
let historyRepository: MockHistoryRepository;
let settingRepository: MockSettingRepository;
@@ -46,40 +52,52 @@ describe('OpenCompletionUseCase', () => {
bookmarkRepository = new MockBookmarkRepository();
historyRepository = new MockHistoryRepository();
settingRepository = new MockSettingRepository();
- sut = new OpenCompletionUseCase(bookmarkRepository, historyRepository, settingRepository)
+ sut = new OpenCompletionUseCase(
+ bookmarkRepository,
+ historyRepository,
+ settingRepository
+ );
});
- describe('#getCompletionTypes', () => {
+ 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,
- })));
+ sinon.stub(settingRepository, "get").returns(
+ Promise.resolve(
+ 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([
CompletionType.SearchEngines,
CompletionType.History,
- CompletionType.Bookmarks
+ CompletionType.Bookmarks,
]);
});
});
- describe('#requestSearchEngines', () => {
+ 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={}",
- "google_ja": "https://google.co.jp/search?q={}",
- }),
- properties: DefaultSetting.properties,
- blacklist: DefaultSetting.blacklist,
- })));
+ 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={}",
+ google_ja: "https://google.co.jp/search?q={}",
+ }),
+ properties: DefaultSetting.properties,
+ blacklist: DefaultSetting.blacklist,
+ })
+ )
+ );
expect(await sut.requestSearchEngines("")).to.deep.equal([
"google",
@@ -92,17 +110,22 @@ describe('OpenCompletionUseCase', () => {
"google_ja",
]);
expect(await sut.requestSearchEngines("x")).to.be.empty;
- })
+ });
});
- 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([]));
+ 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([]));
expect(await sut.requestBookmarks("site")).to.deep.equal([
{ title: "site1", url: "https://site1.example.com" },
@@ -112,14 +135,19 @@ describe('OpenCompletionUseCase', () => {
});
});
- 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([]));
+ 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([]));
expect(await sut.requestHistory("site")).to.deep.equal([
{ title: "site1", url: "https://site1.example.com" },
@@ -128,4 +156,4 @@ describe('OpenCompletionUseCase', () => {
expect(await sut.requestHistory("xyz")).to.be.empty;
});
});
-}); \ No newline at end of file
+});
diff --git a/test/background/completion/PropertyCompletionUseCase.test.ts b/test/background/completion/PropertyCompletionUseCase.test.ts
index 57f5bff..dfc989f 100644
--- a/test/background/completion/PropertyCompletionUseCase.test.ts
+++ b/test/background/completion/PropertyCompletionUseCase.test.ts
@@ -1,15 +1,18 @@
-import 'reflect-metadata';
+import "reflect-metadata";
import PropertyCompletionUseCase from "../../../src/background/completion/PropertyCompletionUseCase";
-import { expect } from 'chai';
+import { expect } from "chai";
-describe('PropertyCompletionUseCase', () => {
- describe('getProperties', () => {
- it('returns property types', async () => {
+describe("PropertyCompletionUseCase", () => {
+ describe("getProperties", () => {
+ it("returns property types", async () => {
const sut = new PropertyCompletionUseCase();
const properties = await sut.getProperties();
- expect(properties).to.deep.contain({ name: 'smoothscroll', type: 'boolean' });
- expect(properties).to.deep.contain({ name: 'complete', type: 'string' });
- })
+ expect(properties).to.deep.contain({
+ name: "smoothscroll",
+ type: "boolean",
+ });
+ expect(properties).to.deep.contain({ name: "complete", type: "string" });
+ });
});
-}); \ No newline at end of file
+});
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
index b9dc60b..d8aa385 100644
--- a/test/background/completion/TabCompletionUseCase.test.ts
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -1,85 +1,90 @@
-import "reflect-metadata"
+import "reflect-metadata";
import TabRepositoryImpl from "../../../src/background/completion/impl/TabRepositoryImpl";
-import {Tab} from "../../../src/background/completion/TabRepository";
+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 sinon from "sinon";
+import { expect } from "chai";
import TabFlag from "../../../src/shared/TabFlag";
class MockTabRepository implements TabRepositoryImpl {
async queryTabs(_query: string, _excludePinned: boolean): Promise<Tab[]> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
async getAllTabs(_excludePinned: boolean): Promise<Tab[]> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
}
class MockTabPresenter implements TabPresenter {
create(_url: string, _opts?: object): Promise<browser.tabs.Tab> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
duplicate(_id: number): Promise<browser.tabs.Tab> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
getAll(): Promise<browser.tabs.Tab[]> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
- getByKeyword(_keyword: string, _excludePinned: boolean): Promise<browser.tabs.Tab[]> {
- throw new Error("not implemented")
+ getByKeyword(
+ _keyword: string,
+ _excludePinned: boolean
+ ): Promise<browser.tabs.Tab[]> {
+ throw new Error("not implemented");
}
getCurrent(): Promise<browser.tabs.Tab> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
getLastSelectedId(): Promise<number | undefined> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
getZoom(_tabId: number): Promise<number> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
- onSelected(_listener: (arg: { tabId: number; windowId: number }) => void): void {
- throw new Error("not implemented")
+ onSelected(
+ _listener: (arg: { tabId: number; windowId: number }) => void
+ ): void {
+ throw new Error("not implemented");
}
open(_url: string, _tabId?: number): Promise<browser.tabs.Tab> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
reload(_tabId: number, _cache: boolean): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
remove(_ids: number[]): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
reopen(): Promise<any> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
select(_tabId: number): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
setPinned(_tabId: number, _pinned: boolean): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
setZoom(_tabId: number, _factor: number): Promise<void> {
- throw new Error("not implemented")
+ throw new Error("not implemented");
}
}
-describe('TabCompletionUseCase', () => {
+describe("TabCompletionUseCase", () => {
let tabRepository: MockTabRepository;
let tabPresenter: TabPresenter;
let sut: TabCompletionUseCase;
@@ -89,56 +94,169 @@ 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 },
- ]));
+ 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,
+ },
+ ])
+ );
});
- describe('#queryTabs', () => {
+ describe("#queryTabs", () => {
it("returns tab items", async () => {
- sinon.stub(tabRepository, 'queryTabs').withArgs('', 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 },
- { id: 12, index: 2, title: 'Bing', url: 'https://bing.com/', active: false },
- ])).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([
- { index: 1, title: 'Google', url: 'https://google.com/', faviconUrl: 'https://google.com/favicon.ico', flag: TabFlag.None },
- { index: 2, title: 'Yahoo', url: 'https://yahoo.com/', faviconUrl: 'https://yahoo.com/favicon.ico', flag: TabFlag.CurrentTab },
- { index: 3, title: 'Bing', url: 'https://bing.com/', faviconUrl: undefined, flag: TabFlag.LastTab },
+ sinon
+ .stub(tabRepository, "queryTabs")
+ .withArgs("", 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,
+ },
+ {
+ id: 12,
+ index: 2,
+ title: "Bing",
+ url: "https://bing.com/",
+ active: false,
+ },
+ ])
+ )
+ .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([
+ {
+ index: 1,
+ title: "Google",
+ url: "https://google.com/",
+ faviconUrl: "https://google.com/favicon.ico",
+ flag: TabFlag.None,
+ },
+ {
+ index: 2,
+ title: "Yahoo",
+ url: "https://yahoo.com/",
+ faviconUrl: "https://yahoo.com/favicon.ico",
+ flag: TabFlag.CurrentTab,
+ },
+ {
+ index: 3,
+ title: "Bing",
+ url: "https://bing.com/",
+ faviconUrl: undefined,
+ flag: TabFlag.LastTab,
+ },
]);
- expect(await sut.queryTabs('oo', false)).to.deep.equal([
- { index: 1, title: 'Google', url: 'https://google.com/', faviconUrl: 'https://google.com/favicon.ico', flag: TabFlag.None },
- { index: 2, title: 'Yahoo', url: 'https://yahoo.com/', faviconUrl: 'https://yahoo.com/favicon.ico', flag: TabFlag.CurrentTab },
+ expect(await sut.queryTabs("oo", false)).to.deep.equal([
+ {
+ index: 1,
+ title: "Google",
+ url: "https://google.com/",
+ faviconUrl: "https://google.com/favicon.ico",
+ flag: TabFlag.None,
+ },
+ {
+ index: 2,
+ title: "Yahoo",
+ url: "https://yahoo.com/",
+ faviconUrl: "https://yahoo.com/favicon.ico",
+ flag: TabFlag.CurrentTab,
+ },
]);
});
it("returns a tab by the index", async () => {
- expect(await sut.queryTabs('1', false)).to.deep.equal([
- { index: 1, title: 'Google', url: 'https://google.com/', faviconUrl: 'https://google.com/favicon.ico', flag: TabFlag.None },
+ expect(await sut.queryTabs("1", false)).to.deep.equal([
+ {
+ index: 1,
+ title: "Google",
+ url: "https://google.com/",
+ faviconUrl: "https://google.com/favicon.ico",
+ flag: TabFlag.None,
+ },
]);
- expect(await sut.queryTabs('10', false)).to.be.empty;
- expect(await sut.queryTabs('-1', false)).to.be.empty;
+ expect(await sut.queryTabs("10", false)).to.be.empty;
+ expect(await sut.queryTabs("-1", false)).to.be.empty;
});
it("returns the current tab by % flag", async () => {
- expect(await sut.queryTabs('%', false)).to.deep.equal([
- { index: 2, title: 'Yahoo', url: 'https://yahoo.com/', faviconUrl: 'https://yahoo.com/favicon.ico', flag: TabFlag.CurrentTab },
+ expect(await sut.queryTabs("%", false)).to.deep.equal([
+ {
+ index: 2,
+ title: "Yahoo",
+ url: "https://yahoo.com/",
+ faviconUrl: "https://yahoo.com/favicon.ico",
+ flag: TabFlag.CurrentTab,
+ },
]);
});
it("returns the current tab by # flag", async () => {
- expect(await sut.queryTabs('#', false)).to.deep.equal([
- { index: 3, title: 'Bing', url: 'https://bing.com/', faviconUrl: undefined, flag: TabFlag.LastTab },
+ expect(await sut.queryTabs("#", false)).to.deep.equal([
+ {
+ index: 3,
+ title: "Bing",
+ url: "https://bing.com/",
+ faviconUrl: undefined,
+ flag: TabFlag.LastTab,
+ },
]);
- })
+ });
});
-}); \ No newline at end of file
+});
diff --git a/test/background/completion/impl/PrefetchAndCache.test.ts b/test/background/completion/impl/PrefetchAndCache.test.ts
index 23e3879..b24dfa9 100644
--- a/test/background/completion/impl/PrefetchAndCache.test.ts
+++ b/test/background/completion/impl/PrefetchAndCache.test.ts
@@ -1,39 +1,39 @@
-import PrefetchAndCache, {shortKey} from "../../../../src/background/completion/impl/PrefetchAndCache";
-import { expect } from 'chai';
+import PrefetchAndCache, {
+ shortKey,
+} from "../../../../src/background/completion/impl/PrefetchAndCache";
+import { expect } from "chai";
class MockRepository {
public history: string[] = [];
- constructor(
- private items: string[],
- ) {
- }
+ constructor(private items: string[]) {}
get(query: string): Promise<string[]> {
this.history.push(query);
if (query.length === 0) {
return Promise.resolve(this.items);
} else {
- return Promise.resolve(this.items.filter(item => item.includes(query)));
+ return Promise.resolve(this.items.filter((item) => item.includes(query)));
}
}
}
-const filter = (items: string[], query: string) => query.length === 0 ? items : items.filter(item => item.includes(query));
+const filter = (items: string[], query: string) =>
+ query.length === 0 ? items : items.filter((item) => item.includes(query));
-describe('shortKey', () => {
- it('returns query excluding the last word', () => {
- const query = "hello\t world good bye";
- const shorten = shortKey(query);
- expect(shorten).to.equal("hello world good")
+describe("shortKey", () => {
+ it("returns query excluding the last word", () => {
+ const query = "hello\t world good bye";
+ const shorten = shortKey(query);
+ expect(shorten).to.equal("hello world good");
});
- it('returns half-length of the query', () => {
+ it("returns half-length of the query", () => {
const query = "the-query-with-super-long-word";
const shorten = shortKey(query);
- expect(shorten).to.equal("the-query-with-")
+ expect(shorten).to.equal("the-query-with-");
});
- it('returns shorten URL', () => {
+ it("returns shorten URL", () => {
let query = "https://example.com/path/to/resource?q=hello";
let shorten = shortKey(query);
expect(shorten).to.equal("https://example.com/path/to/");
@@ -45,20 +45,39 @@ describe('shortKey', () => {
query = "https://www.google.c";
shorten = shortKey(query);
expect(shorten).to.equal("https://ww");
- })
+ });
});
-describe('PrefetchAndCache', () => {
- describe('get', () => {
- it('returns cached request', async() => {
- const repo = new MockRepository(["apple", "apple pie", "apple juice", "banana", "banana pudding", "cherry"]);
+describe("PrefetchAndCache", () => {
+ describe("get", () => {
+ it("returns cached request", async () => {
+ const repo = new MockRepository([
+ "apple",
+ "apple pie",
+ "apple juice",
+ "banana",
+ "banana pudding",
+ "cherry",
+ ]);
const sut = new PrefetchAndCache(repo.get.bind(repo), filter);
expect(await sut.get("apple pie")).deep.equal(["apple pie"]);
- expect(await sut.get("apple ")).deep.equal(["apple", "apple pie", "apple juice"]);
- expect(await sut.get("apple")).deep.equal(["apple", "apple pie", "apple juice"]);
- expect(await sut.get("appl")).deep.equal(["apple", "apple pie", "apple juice"]);
- expect(repo.history).to.deep.equal(["apple", 'ap']);
+ expect(await sut.get("apple ")).deep.equal([
+ "apple",
+ "apple pie",
+ "apple juice",
+ ]);
+ expect(await sut.get("apple")).deep.equal([
+ "apple",
+ "apple pie",
+ "apple juice",
+ ]);
+ expect(await sut.get("appl")).deep.equal([
+ "apple",
+ "apple pie",
+ "apple juice",
+ ]);
+ expect(repo.history).to.deep.equal(["apple", "ap"]);
expect(await sut.get("banana")).deep.equal(["banana", "banana pudding"]);
expect(repo.history).to.deep.equal(["apple", "ap", "ban"]);
@@ -68,7 +87,14 @@ describe('PrefetchAndCache', () => {
expect(repo.history).to.deep.equal(["apple", "ap", "ban", "banana", "b"]);
expect(await sut.get("")).to.have.lengthOf(6);
- expect(repo.history).to.deep.equal(["apple", "ap", "ban", "banana", "b", ""]);
+ expect(repo.history).to.deep.equal([
+ "apple",
+ "ap",
+ "ban",
+ "banana",
+ "b",
+ "",
+ ]);
});
});
-}); \ No newline at end of file
+});
diff --git a/test/background/completion/impl/filters.test.ts b/test/background/completion/impl/filters.test.ts
index a181f60..70c2663 100644
--- a/test/background/completion/impl/filters.test.ts
+++ b/test/background/completion/impl/filters.test.ts
@@ -1,87 +1,89 @@
-import * as filters from '../../../../src/background/completion/impl/filters'
-import { expect } from 'chai';
+import * as filters from "../../../../src/background/completion/impl/filters";
+import { expect } from "chai";
-describe('background/usecases/filters', () => {
- describe('filterHttp', () => {
- it('filters http URLs duplicates to https hosts', () => {
+describe("background/usecases/filters", () => {
+ describe("filterHttp", () => {
+ it("filters http URLs duplicates to https hosts", () => {
const pages = [
- { id: '0', url: 'http://i-beam.org/foo' },
- { id: '1', url: 'https://i-beam.org/bar' },
- { id: '2', url: 'http://i-beam.net/hoge' },
- { id: '3', url: 'http://i-beam.net/fuga' },
+ { id: "0", url: "http://i-beam.org/foo" },
+ { id: "1", url: "https://i-beam.org/bar" },
+ { id: "2", url: "http://i-beam.net/hoge" },
+ { id: "3", url: "http://i-beam.net/fuga" },
];
const filtered = filters.filterHttp(pages);
- const urls = filtered.map(x => x.url);
+ const urls = filtered.map((x) => x.url);
expect(urls).to.deep.equal([
- 'https://i-beam.org/bar', 'http://i-beam.net/hoge', 'http://i-beam.net/fuga'
+ "https://i-beam.org/bar",
+ "http://i-beam.net/hoge",
+ "http://i-beam.net/fuga",
]);
- })
+ });
});
- describe('filterBlankTitle', () => {
- it('filters blank titles', () => {
+ describe("filterBlankTitle", () => {
+ it("filters blank titles", () => {
const pages = [
- { id: '0', title: 'hello' },
- { id: '1', title: '' },
- { id: '2' },
+ { id: "0", title: "hello" },
+ { id: "1", title: "" },
+ { id: "2" },
];
const filtered = filters.filterBlankTitle(pages);
- expect(filtered).to.deep.equal([{ id: '0', title: 'hello' }]);
+ expect(filtered).to.deep.equal([{ id: "0", title: "hello" }]);
});
});
- describe('filterByTailingSlash', () => {
- it('filters duplicated pathname on tailing slash', () => {
+ describe("filterByTailingSlash", () => {
+ it("filters duplicated pathname on tailing slash", () => {
const pages = [
- { id: '0', url: 'http://i-beam.org/content' },
- { id: '1', url: 'http://i-beam.org/content/' },
- { id: '2', url: 'http://i-beam.org/search' },
- { id: '3', url: 'http://i-beam.org/search?q=apple_banana_cherry' },
+ { id: "0", url: "http://i-beam.org/content" },
+ { id: "1", url: "http://i-beam.org/content/" },
+ { id: "2", url: "http://i-beam.org/search" },
+ { id: "3", url: "http://i-beam.org/search?q=apple_banana_cherry" },
];
const filtered = filters.filterByTailingSlash(pages);
- const urls = filtered.map(x => x.url);
+ const urls = filtered.map((x) => x.url);
expect(urls).to.deep.equal([
- 'http://i-beam.org/content',
- 'http://i-beam.org/search',
- 'http://i-beam.org/search?q=apple_banana_cherry',
+ "http://i-beam.org/content",
+ "http://i-beam.org/search",
+ "http://i-beam.org/search?q=apple_banana_cherry",
]);
});
- })
+ });
- describe('filterByPathname', () => {
- it('filters by length of pathname', () => {
+ describe("filterByPathname", () => {
+ it("filters by length of pathname", () => {
const pages = [
- { id: '0', url: 'http://i-beam.org/search?q=apple' },
- { id: '1', url: 'http://i-beam.org/search?q=apple_banana' },
- { id: '2', url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { id: '3', url: 'http://i-beam.net/search?q=apple' },
- { id: '4', url: 'http://i-beam.net/search?q=apple_banana' },
- { id: '5', url: 'http://i-beam.net/search?q=apple_banana_cherry' },
+ { id: "0", url: "http://i-beam.org/search?q=apple" },
+ { id: "1", url: "http://i-beam.org/search?q=apple_banana" },
+ { id: "2", url: "http://i-beam.org/search?q=apple_banana_cherry" },
+ { id: "3", url: "http://i-beam.net/search?q=apple" },
+ { id: "4", url: "http://i-beam.net/search?q=apple_banana" },
+ { id: "5", url: "http://i-beam.net/search?q=apple_banana_cherry" },
];
const filtered = filters.filterByPathname(pages);
expect(filtered).to.deep.equal([
- { id: '0', url: 'http://i-beam.org/search?q=apple' },
- { id: '3', url: 'http://i-beam.net/search?q=apple' },
+ { id: "0", url: "http://i-beam.org/search?q=apple" },
+ { id: "3", url: "http://i-beam.net/search?q=apple" },
]);
});
});
- describe('filterByOrigin', () => {
- it('filters by length of pathname', () => {
+ describe("filterByOrigin", () => {
+ it("filters by length of pathname", () => {
const pages = [
- { id: '0', url: 'http://i-beam.org/search?q=apple' },
- { id: '1', url: 'http://i-beam.org/search?q=apple_banana' },
- { id: '2', url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { id: '3', url: 'http://i-beam.org/request?q=apple' },
- { id: '4', url: 'http://i-beam.org/request?q=apple_banana' },
- { id: '5', url: 'http://i-beam.org/request?q=apple_banana_cherry' },
+ { id: "0", url: "http://i-beam.org/search?q=apple" },
+ { id: "1", url: "http://i-beam.org/search?q=apple_banana" },
+ { id: "2", url: "http://i-beam.org/search?q=apple_banana_cherry" },
+ { id: "3", url: "http://i-beam.org/request?q=apple" },
+ { id: "4", url: "http://i-beam.org/request?q=apple_banana" },
+ { id: "5", url: "http://i-beam.org/request?q=apple_banana_cherry" },
];
const filtered = filters.filterByOrigin(pages);
expect(filtered).to.deep.equal([
- { id: '0', url: 'http://i-beam.org/search?q=apple' },
+ { id: "0", url: "http://i-beam.org/search?q=apple" },
]);
});
});
diff --git a/test/background/infrastructures/MemoryStorage.test.ts b/test/background/infrastructures/MemoryStorage.test.ts
index ccdf9f0..5f8be2a 100644
--- a/test/background/infrastructures/MemoryStorage.test.ts
+++ b/test/background/infrastructures/MemoryStorage.test.ts
@@ -1,44 +1,44 @@
-import MemoryStorage from 'background/infrastructures/MemoryStorage';
+import MemoryStorage from "background/infrastructures/MemoryStorage";
describe("background/infrastructures/memory-storage", () => {
- it('stores values', () => {
+ it("stores values", () => {
const cache = new MemoryStorage();
- cache.set('number', 123);
- expect(cache.get('number')).to.equal(123);
+ cache.set("number", 123);
+ expect(cache.get("number")).to.equal(123);
- cache.set('string', '123');
- expect(cache.get('string')).to.equal('123');
+ cache.set("string", "123");
+ expect(cache.get("string")).to.equal("123");
- cache.set('object', { hello: '123' });
- expect(cache.get('object')).to.deep.equal({ hello: '123' });
+ cache.set("object", { hello: "123" });
+ expect(cache.get("object")).to.deep.equal({ hello: "123" });
});
- it('returns undefined if no keys', () => {
+ it("returns undefined if no keys", () => {
const cache = new MemoryStorage();
- expect(cache.get('no-keys')).to.be.undefined;
- })
+ expect(cache.get("no-keys")).to.be.undefined;
+ });
- it('stored on shared memory', () => {
+ it("stored on shared memory", () => {
let cache = new MemoryStorage();
- cache.set('red', 'apple');
+ cache.set("red", "apple");
cache = new MemoryStorage();
- const got = cache.get('red');
- expect(got).to.equal('apple');
+ const got = cache.get("red");
+ expect(got).to.equal("apple");
});
- it('stored cloned objects', () => {
+ it("stored cloned objects", () => {
const cache = new MemoryStorage();
- const recipe = { sugar: '300g' };
- cache.set('recipe', recipe);
+ const recipe = { sugar: "300g" };
+ cache.set("recipe", recipe);
- recipe.salt = '20g'
- const got = cache.get('recipe', recipe);
- expect(got).to.deep.equal({ sugar: '300g' });
+ recipe.salt = "20g";
+ const got = cache.get("recipe", recipe);
+ expect(got).to.deep.equal({ sugar: "300g" });
});
- it('throws an error with unserializable objects', () => {
+ it("throws an error with unserializable objects", () => {
const cache = new MemoryStorage();
- expect(() => cache.set('fn', setTimeout)).to.throw();
- })
+ expect(() => cache.set("fn", setTimeout)).to.throw();
+ });
});
diff --git a/test/background/repositories/Mark.test.ts b/test/background/repositories/Mark.test.ts
index ed1a68e..b1bbcf1 100644
--- a/test/background/repositories/Mark.test.ts
+++ b/test/background/repositories/Mark.test.ts
@@ -1,24 +1,24 @@
-import MarkRepository from 'background/repositories/MarkRepository';
+import MarkRepository from "background/repositories/MarkRepository";
-describe('background/repositories/mark', () => {
+describe("background/repositories/mark", () => {
let repository: MarkRepository;
beforeEach(() => {
repository = new MarkRepository();
});
- it('get and set', async() => {
- const mark = { tabId: 1, url: 'http://example.com', x: 10, y: 30 };
+ it("get and set", async () => {
+ const mark = { tabId: 1, url: "http://example.com", x: 10, y: 30 };
- repository.setMark('A', mark);
+ repository.setMark("A", mark);
- let got = await repository.getMark('A');
+ let got = await repository.getMark("A");
expect(got.tabId).to.equal(1);
- expect(got.url).to.equal('http://example.com');
+ expect(got.url).to.equal("http://example.com");
expect(got.x).to.equal(10);
expect(got.y).to.equal(30);
- got = await repository.getMark('B');
+ got = await repository.getMark("B");
expect(got).to.be.undefined;
});
});
diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts
index 7ad0e4f..7263627 100644
--- a/test/background/usecases/NavigateUseCase.test.ts
+++ b/test/background/usecases/NavigateUseCase.test.ts
@@ -1,8 +1,8 @@
import "reflect-metadata";
-import TabPresenter from '../../../src/background/presenters/TabPresenter';
-import NavigateUseCase from '../../../src/background/usecases/NavigateUseCase';
-import NavigateClient from '../../../src/background/clients/NavigateClient';
-import * as sinon from 'sinon';
+import TabPresenter from "../../../src/background/presenters/TabPresenter";
+import NavigateUseCase from "../../../src/background/usecases/NavigateUseCase";
+import NavigateClient from "../../../src/background/clients/NavigateClient";
+import * as sinon from "sinon";
class MockTabPresenter implements TabPresenter {
create(_url: string, _opts?: object): Promise<browser.tabs.Tab> {
@@ -17,7 +17,10 @@ class MockTabPresenter implements TabPresenter {
throw new Error("not implemented");
}
- getByKeyword(_keyword: string, _excludePinned: boolean): Promise<browser.tabs.Tab[]> {
+ getByKeyword(
+ _keyword: string,
+ _excludePinned: boolean
+ ): Promise<browser.tabs.Tab[]> {
throw new Error("not implemented");
}
@@ -33,7 +36,9 @@ class MockTabPresenter implements TabPresenter {
throw new Error("not implemented");
}
- onSelected(_listener: (arg: { tabId: number; windowId: number }) => void): void {
+ onSelected(
+ _listener: (arg: { tabId: number; windowId: number }) => void
+ ): void {
throw new Error("not implemented");
}
@@ -66,7 +71,7 @@ class MockTabPresenter implements TabPresenter {
}
}
-describe('NavigateUseCase', () => {
+describe("NavigateUseCase", () => {
let sut: NavigateUseCase;
let tabPresenter: TabPresenter;
let navigateClient: NavigateClient;
@@ -80,7 +85,7 @@ describe('NavigateUseCase', () => {
const newTab = (url: string): browser.tabs.Tab => {
return {
index: 0,
- title: 'dummy title',
+ title: "dummy title",
url: url,
active: true,
hidden: false,
@@ -91,53 +96,67 @@ describe('NavigateUseCase', () => {
lastAccessed: 1585446733000,
pinned: false,
selected: false,
- windowId: 0
+ windowId: 0,
};
};
- describe('#openParent()', async () => {
- it('opens parent directory of file', async() => {
- sinon.stub(tabPresenter, 'getCurrent')
- .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/banana')));
+ describe("#openParent()", async () => {
+ it("opens parent directory of file", async () => {
+ sinon
+ .stub(tabPresenter, "getCurrent")
+ .returns(
+ Promise.resolve(newTab("https://google.com/fruits/yellow/banana"))
+ );
- const mock = sinon.mock(tabPresenter)
- .expects('open').withArgs('https://google.com/fruits/yellow/');
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("open")
+ .withArgs("https://google.com/fruits/yellow/");
await sut.openParent();
mock.verify();
});
- it('opens parent directory of directory', async() => {
- sinon.stub(tabPresenter, 'getCurrent')
- .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/')));
+ it("opens parent directory of directory", async () => {
+ sinon
+ .stub(tabPresenter, "getCurrent")
+ .returns(Promise.resolve(newTab("https://google.com/fruits/yellow/")));
- const mock = sinon.mock(tabPresenter)
- .expects('open').withArgs('https://google.com/fruits/');
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("open")
+ .withArgs("https://google.com/fruits/");
await sut.openParent();
mock.verify();
});
- it('removes hash', async() => {
- sinon.stub(tabPresenter, 'getCurrent')
- .returns(Promise.resolve(newTab('https://google.com/#top')));
+ it("removes hash", async () => {
+ sinon
+ .stub(tabPresenter, "getCurrent")
+ .returns(Promise.resolve(newTab("https://google.com/#top")));
- const mock = sinon.mock(tabPresenter)
- .expects('open').withArgs('https://google.com/');
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("open")
+ .withArgs("https://google.com/");
await sut.openParent();
mock.verify();
});
- it('removes search query', async() => {
- sinon.stub(tabPresenter, 'getCurrent')
- .returns(Promise.resolve(newTab('https://google.com/search?q=apple')));
+ it("removes search query", async () => {
+ sinon
+ .stub(tabPresenter, "getCurrent")
+ .returns(Promise.resolve(newTab("https://google.com/search?q=apple")));
- const mock = sinon.mock(tabPresenter)
- .expects('open').withArgs('https://google.com/search');
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("open")
+ .withArgs("https://google.com/search");
await sut.openParent();
@@ -145,13 +164,16 @@ describe('NavigateUseCase', () => {
});
});
- describe('#openRoot()', () => {
- it('opens root direectory', async() => {
- sinon.stub(tabPresenter, 'getCurrent')
- .returns(Promise.resolve(newTab('https://google.com/seach?q=apple')));
+ describe("#openRoot()", () => {
+ it("opens root direectory", async () => {
+ sinon
+ .stub(tabPresenter, "getCurrent")
+ .returns(Promise.resolve(newTab("https://google.com/seach?q=apple")));
- const mock = sinon.mock(tabPresenter)
- .expects('open').withArgs('https://google.com');
+ const mock = sinon
+ .mock(tabPresenter)
+ .expects("open")
+ .withArgs("https://google.com");
await sut.openRoot();
diff --git a/test/background/usecases/SettingUseCase.test.ts b/test/background/usecases/SettingUseCase.test.ts
index bfa599c..c604e91 100644
--- a/test/background/usecases/SettingUseCase.test.ts
+++ b/test/background/usecases/SettingUseCase.test.ts
@@ -1,21 +1,22 @@
import "reflect-metadata";
import SettingUseCase from "../../../src/background/usecases/SettingUseCase";
import SettingRepository from "../../../src/background/repositories/SettingRepository";
-import SettingData, {JSONTextSettings} from "../../../src/shared/SettingData";
+import SettingData, { JSONTextSettings } from "../../../src/shared/SettingData";
import CachedSettingRepository from "../../../src/background/repositories/CachedSettingRepository";
-import Settings, {DefaultSetting} from "../../../src/shared/settings/Settings";
+import Settings, {
+ DefaultSetting,
+} from "../../../src/shared/settings/Settings";
import Notifier from "../../../src/background/presenters/Notifier";
-import {expect} from "chai";
+import { expect } from "chai";
import Properties from "../../../src/shared/settings/Properties";
-import sinon from 'sinon';
+import sinon from "sinon";
class MockSettingRepository implements SettingRepository {
load(): Promise<SettingData | null> {
throw new Error("not implemented");
}
- onChange(_: () => void): void {
- }
+ onChange(_: () => void): void {}
}
class MockCachedSettingRepository implements CachedSettingRepository {
@@ -46,12 +47,12 @@ class NopNotifier implements Notifier {
}
}
-describe('SettingUseCase', () => {
- let localSettingRepository : SettingRepository;
- let syncSettingRepository : SettingRepository;
- let cachedSettingRepository : CachedSettingRepository;
+describe("SettingUseCase", () => {
+ let localSettingRepository: SettingRepository;
+ let syncSettingRepository: SettingRepository;
+ let cachedSettingRepository: CachedSettingRepository;
let notifier: Notifier;
- let sut : SettingUseCase;
+ let sut: SettingUseCase;
beforeEach(() => {
localSettingRepository = new MockSettingRepository();
@@ -66,34 +67,34 @@ describe('SettingUseCase', () => {
);
});
- describe('getCached', () => {
+ describe("getCached", () => {
it("returns cached settings", async () => {
const settings = new Settings({
keymaps: DefaultSetting.keymaps,
search: DefaultSetting.search,
blacklist: DefaultSetting.blacklist,
properties: new Properties({
- hintchars: "abcd1234"
+ hintchars: "abcd1234",
}),
});
- sinon.stub(cachedSettingRepository, "get")
+ sinon
+ .stub(cachedSettingRepository, "get")
.returns(Promise.resolve(settings));
const got = await sut.getCached();
expect(got.properties.hintchars).to.equal("abcd1234");
-
});
});
describe("reload", () => {
context("when sync is not set", () => {
- it("loads settings from local storage", async() => {
+ it("loads settings from local storage", async () => {
const settings = new Settings({
keymaps: DefaultSetting.keymaps,
search: DefaultSetting.search,
blacklist: DefaultSetting.blacklist,
properties: new Properties({
- hintchars: "abcd1234"
+ hintchars: "abcd1234",
}),
});
const settingData = SettingData.fromJSON({
@@ -101,9 +102,11 @@ describe('SettingUseCase', () => {
json: JSONTextSettings.fromSettings(settings).toJSONText(),
});
- sinon.stub(syncSettingRepository, "load")
+ sinon
+ .stub(syncSettingRepository, "load")
.returns(Promise.resolve(null));
- sinon.stub(localSettingRepository, "load")
+ sinon
+ .stub(localSettingRepository, "load")
.returns(Promise.resolve(settingData));
await sut.reload();
@@ -114,13 +117,13 @@ describe('SettingUseCase', () => {
});
context("when local is not set", () => {
- it("loads settings from sync storage", async() => {
+ it("loads settings from sync storage", async () => {
const settings = new Settings({
keymaps: DefaultSetting.keymaps,
search: DefaultSetting.search,
blacklist: DefaultSetting.blacklist,
properties: new Properties({
- hintchars: "aaaa1111"
+ hintchars: "aaaa1111",
}),
});
const settingData = SettingData.fromJSON({
@@ -128,9 +131,11 @@ describe('SettingUseCase', () => {
json: JSONTextSettings.fromSettings(settings).toJSONText(),
});
- sinon.stub(syncSettingRepository, "load")
+ sinon
+ .stub(syncSettingRepository, "load")
.returns(Promise.resolve(settingData));
- sinon.stub(localSettingRepository, "load")
+ sinon
+ .stub(localSettingRepository, "load")
.returns(Promise.resolve(null));
await sut.reload();
@@ -141,21 +146,23 @@ describe('SettingUseCase', () => {
});
context("neither local nor sync not set", () => {
- it("loads default settings", async() => {
- it("loads settings from sync storage", async() => {
- sinon.stub(syncSettingRepository, "load")
+ it("loads default settings", async () => {
+ it("loads settings from sync storage", async () => {
+ sinon
+ .stub(syncSettingRepository, "load")
.returns(Promise.resolve(null));
- sinon.stub(localSettingRepository, "load")
+ sinon
+ .stub(localSettingRepository, "load")
.returns(Promise.resolve(null));
await sut.reload();
const current = await cachedSettingRepository.get();
- expect(current.properties.hintchars).to.equal(DefaultSetting.properties.hintchars);
+ expect(current.properties.hintchars).to.equal(
+ DefaultSetting.properties.hintchars
+ );
});
-
- })
- })
- })
+ });
+ });
+ });
});
-
diff --git a/test/background/usecases/parsers.test.ts b/test/background/usecases/parsers.test.ts
index d08de0d..bee0d07 100644
--- a/test/background/usecases/parsers.test.ts
+++ b/test/background/usecases/parsers.test.ts
@@ -1,34 +1,43 @@
-import * as parsers from 'background/usecases/parsers';
+import * as parsers from "background/usecases/parsers";
describe("shared/commands/parsers", () => {
describe("#parsers.parseSetOption", () => {
- it('parse set string', () => {
- const [key, value] = parsers.parseSetOption('hintchars=abcdefgh');
- expect(key).to.equal('hintchars');
- expect(value).to.equal('abcdefgh');
+ it("parse set string", () => {
+ const [key, value] = parsers.parseSetOption("hintchars=abcdefgh");
+ expect(key).to.equal("hintchars");
+ expect(value).to.equal("abcdefgh");
});
- it('parse set empty string', () => {
- const [key, value] = parsers.parseSetOption('hintchars=');
- expect(key).to.equal('hintchars');
- expect(value).to.equal('');
+ it("parse set empty string", () => {
+ const [key, value] = parsers.parseSetOption("hintchars=");
+ expect(key).to.equal("hintchars");
+ expect(value).to.equal("");
});
- it('parse set boolean', () => {
- let [key, value] = parsers.parseSetOption('smoothscroll');
- expect(key).to.equal('smoothscroll');
+ it("parse set boolean", () => {
+ let [key, value] = parsers.parseSetOption("smoothscroll");
+ expect(key).to.equal("smoothscroll");
expect(value).to.be.true;
- [key, value] = parsers.parseSetOption('nosmoothscroll');
- expect(key).to.equal('smoothscroll');
+ [key, value] = parsers.parseSetOption("nosmoothscroll");
+ expect(key).to.equal("smoothscroll");
expect(value).to.be.false;
});
- it('throws error on unknown property', () => {
- expect(() => parsers.parseSetOption('encoding=utf-8')).to.throw(Error, 'Unknown');
- expect(() => parsers.parseSetOption('paste')).to.throw(Error, 'Unknown');
- expect(() => parsers.parseSetOption('nopaste')).to.throw(Error, 'Unknown');
- expect(() => parsers.parseSetOption('smoothscroll=yes')).to.throw(Error, 'Invalid argument');
+ it("throws error on unknown property", () => {
+ expect(() => parsers.parseSetOption("encoding=utf-8")).to.throw(
+ Error,
+ "Unknown"
+ );
+ expect(() => parsers.parseSetOption("paste")).to.throw(Error, "Unknown");
+ expect(() => parsers.parseSetOption("nopaste")).to.throw(
+ Error,
+ "Unknown"
+ );
+ expect(() => parsers.parseSetOption("smoothscroll=yes")).to.throw(
+ Error,
+ "Invalid argument"
+ );
});
});
});
diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts
index e6567b2..5a531a6 100644
--- a/test/console/actions/console.test.ts
+++ b/test/console/actions/console.test.ts
@@ -1,69 +1,69 @@
-import * as actions from '../../../src/console/actions';
-import * as consoleActions from '../../../src/console/actions/console';
-import { expect } from 'chai';
+import * as actions from "../../../src/console/actions";
+import * as consoleActions from "../../../src/console/actions/console";
+import { expect } from "chai";
describe("console actions", () => {
- describe('hide', () => {
- it('create CONSOLE_HIDE action', () => {
+ describe("hide", () => {
+ it("create CONSOLE_HIDE action", () => {
const action = consoleActions.hide();
expect(action.type).to.equal(actions.CONSOLE_HIDE);
});
});
describe("showCommand", () => {
- it('create CONSOLE_SHOW_COMMAND action', async () => {
- const action = await consoleActions.showCommand('hello');
+ it("create CONSOLE_SHOW_COMMAND action", async () => {
+ const action = await consoleActions.showCommand("hello");
expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND);
- expect(action.text).to.equal('hello');
+ expect(action.text).to.equal("hello");
});
});
describe("showFind", () => {
- it('create CONSOLE_SHOW_FIND action', () => {
+ it("create CONSOLE_SHOW_FIND action", () => {
const action = consoleActions.showFind();
expect(action.type).to.equal(actions.CONSOLE_SHOW_FIND);
});
});
describe("showError", () => {
- it('create CONSOLE_SHOW_ERROR action', () => {
- const action = consoleActions.showError('an error');
+ it("create CONSOLE_SHOW_ERROR action", () => {
+ const action = consoleActions.showError("an error");
expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR);
- expect(action.text).to.equal('an error');
+ expect(action.text).to.equal("an error");
});
});
describe("showInfo", () => {
- it('create CONSOLE_SHOW_INFO action', () => {
- const action = consoleActions.showInfo('an info');
+ it("create CONSOLE_SHOW_INFO action", () => {
+ const action = consoleActions.showInfo("an info");
expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO);
- expect(action.text).to.equal('an info');
+ expect(action.text).to.equal("an info");
});
});
describe("hideCommand", () => {
- it('create CONSOLE_HIDE_COMMAND action', () => {
+ it("create CONSOLE_HIDE_COMMAND action", () => {
const action = consoleActions.hideCommand();
expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND);
});
});
- describe('setConsoleText', () => {
- it('create CONSOLE_SET_CONSOLE_TEXT action', () => {
- const action = consoleActions.setConsoleText('hello world');
+ describe("setConsoleText", () => {
+ it("create CONSOLE_SET_CONSOLE_TEXT action", () => {
+ const action = consoleActions.setConsoleText("hello world");
expect(action.type).to.equal(actions.CONSOLE_SET_CONSOLE_TEXT);
- expect(action.consoleText).to.equal('hello world');
+ expect(action.consoleText).to.equal("hello world");
});
});
describe("completionPrev", () => {
- it('create CONSOLE_COMPLETION_PREV action', () => {
+ it("create CONSOLE_COMPLETION_PREV action", () => {
const action = consoleActions.completionPrev();
expect(action.type).to.equal(actions.CONSOLE_COMPLETION_PREV);
});
});
describe("completionNext", () => {
- it('create CONSOLE_COMPLETION_NEXT action', () => {
+ it("create CONSOLE_COMPLETION_NEXT action", () => {
const action = consoleActions.completionNext();
expect(action.type).to.equal(actions.CONSOLE_COMPLETION_NEXT);
});
diff --git a/test/console/commandline/CommandLineParser.test.ts b/test/console/commandline/CommandLineParser.test.ts
index 6aec682..7cba04c 100644
--- a/test/console/commandline/CommandLineParser.test.ts
+++ b/test/console/commandline/CommandLineParser.test.ts
@@ -1,4 +1,6 @@
-import CommandLineParser, {InputPhase} from "../../../src/console/commandline/CommandLineParser";
+import CommandLineParser, {
+ InputPhase,
+} from "../../../src/console/commandline/CommandLineParser";
import { Command } from "../../../src/shared/Command";
import { expect } from "chai";
@@ -9,7 +11,7 @@ describe("CommandLineParser", () => {
expect(sut.inputPhase("")).to.equal(InputPhase.OnCommand);
expect(sut.inputPhase("op")).to.equal(InputPhase.OnCommand);
expect(sut.inputPhase("open ")).to.equal(InputPhase.OnArgs);
- expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs)
+ expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs);
});
});
describe("#parse", () => {
@@ -24,6 +26,6 @@ describe("CommandLineParser", () => {
command: Command.QuitAll,
args: "",
});
- })
- })
+ });
+ });
});
diff --git a/test/console/commandline/CommandParser.test.ts b/test/console/commandline/CommandParser.test.ts
index 4ad78fd..f72afd6 100644
--- a/test/console/commandline/CommandParser.test.ts
+++ b/test/console/commandline/CommandParser.test.ts
@@ -1,6 +1,8 @@
-import CommandParser, { UnknownCommandError } from "../../../src/console/commandline/CommandParser";
+import CommandParser, {
+ UnknownCommandError,
+} from "../../../src/console/commandline/CommandParser";
import { Command } from "../../../src/shared/Command";
-import { expect } from "chai"
+import { expect } from "chai";
describe("CommandParser", () => {
describe("#parse", () => {
@@ -10,6 +12,6 @@ describe("CommandParser", () => {
expect(sut.parse("w")).to.equal(Command.WindowOpen);
expect(sut.parse("bdelete!")).to.equal(Command.BufferDeleteForce);
expect(() => sut.parse("harakiri")).to.throw(UnknownCommandError);
- })
- })
+ });
+ });
});
diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx
index e411c4a..200bb1a 100644
--- a/test/console/components/console/Completion.test.tsx
+++ b/test/console/components/console/Completion.test.tsx
@@ -1,53 +1,59 @@
-import React from 'react';
-import Completion from 'console/components/console/Completion'
-import ReactTestRenderer from 'react-test-renderer';
+import React from "react";
+import Completion from "console/components/console/Completion";
+import ReactTestRenderer from "react-test-renderer";
describe("console/components/console/completion", () => {
- const completions = [{
- name: "Fruit",
- items: [{ caption: "apple" }, { caption: "banana" }, { caption: "cherry" }],
- }, {
- name: "Element",
- items: [{ caption: "argon" }, { caption: "boron" }, { caption: "carbon" }],
- }];
-
- it('renders Completion component', () => {
- const root = ReactTestRenderer.create(<Completion
- completions={completions}
- size={30}
- />).root;
+ const completions = [
+ {
+ name: "Fruit",
+ items: [
+ { caption: "apple" },
+ { caption: "banana" },
+ { caption: "cherry" },
+ ],
+ },
+ {
+ name: "Element",
+ items: [
+ { caption: "argon" },
+ { caption: "boron" },
+ { caption: "carbon" },
+ ],
+ },
+ ];
+
+ it("renders Completion component", () => {
+ const root = ReactTestRenderer.create(
+ <Completion completions={completions} size={30} />
+ ).root;
expect(root.children).to.have.lengthOf(1);
const children = root.children[0].children;
expect(children).to.have.lengthOf(8);
- expect(children[0].props.title).to.equal('Fruit');
- expect(children[1].props.caption).to.equal('apple');
- expect(children[2].props.caption).to.equal('banana');
- expect(children[3].props.caption).to.equal('cherry');
- expect(children[4].props.title).to.equal('Element');
- expect(children[5].props.caption).to.equal('argon');
- expect(children[6].props.caption).to.equal('boron');
- expect(children[7].props.caption).to.equal('carbon');
+ expect(children[0].props.title).to.equal("Fruit");
+ expect(children[1].props.caption).to.equal("apple");
+ expect(children[2].props.caption).to.equal("banana");
+ expect(children[3].props.caption).to.equal("cherry");
+ expect(children[4].props.title).to.equal("Element");
+ expect(children[5].props.caption).to.equal("argon");
+ expect(children[6].props.caption).to.equal("boron");
+ expect(children[7].props.caption).to.equal("carbon");
});
- it('highlight current item', () => {
- const root = ReactTestRenderer.create(<Completion
- completions={completions}
- size={30}
- select={3}
- />).root;
+ it("highlight current item", () => {
+ const root = ReactTestRenderer.create(
+ <Completion completions={completions} size={30} select={3} />
+ ).root;
const children = root.children[0].children;
expect(children[5].props.highlight).to.be.true;
});
- it('does not highlight any items', () => {
- const root = ReactTestRenderer.create(<Completion
- completions={completions}
- size={30}
- select={-1}
- />).root;
+ it("does not highlight any items", () => {
+ const root = ReactTestRenderer.create(
+ <Completion completions={completions} size={30} select={-1} />
+ ).root;
const children = root.children[0].children;
for (const li of children[0].children) {
@@ -55,112 +61,95 @@ describe("console/components/console/completion", () => {
}
});
- it('limits completion items', () => {
- let root = ReactTestRenderer.create(<Completion
- completions={completions}
- size={3}
- select={-1}
- />).root;
+ it("limits completion items", () => {
+ let root = ReactTestRenderer.create(
+ <Completion completions={completions} size={3} select={-1} />
+ ).root;
let children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].props.title).to.equal('Fruit');
- expect(children[1].props.caption).to.equal('apple');
- expect(children[2].props.caption).to.equal('banana');
+ expect(children[0].props.title).to.equal("Fruit");
+ expect(children[1].props.caption).to.equal("apple");
+ expect(children[2].props.caption).to.equal("banana");
- root = ReactTestRenderer.create(<Completion
- completions={completions}
- size={3} select={0}
- />).root;
+ root = ReactTestRenderer.create(
+ <Completion completions={completions} size={3} select={0} />
+ ).root;
children = root.children[0].children;
expect(children[1].props.highlight).to.be.true;
- })
-
- it('scrolls up to down with select', () => {
- const component = ReactTestRenderer.create(<Completion
- completions={completions}
- size={3}
- select={1}
- />);
+ });
+
+ it("scrolls up to down with select", () => {
+ const component = ReactTestRenderer.create(
+ <Completion completions={completions} size={3} select={1} />
+ );
const root = component.root;
let children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].props.title).to.equal('Fruit');
- expect(children[1].props.caption).to.equal('apple');
- expect(children[2].props.caption).to.equal('banana');
+ expect(children[0].props.title).to.equal("Fruit");
+ expect(children[1].props.caption).to.equal("apple");
+ expect(children[2].props.caption).to.equal("banana");
- component.update(<Completion
- completions={completions}
- size={3}
- select={2}
- />);
+ component.update(
+ <Completion completions={completions} size={3} select={2} />
+ );
children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].props.caption).to.equal('apple');
- expect(children[1].props.caption).to.equal('banana');
- expect(children[2].props.caption).to.equal('cherry');
+ expect(children[0].props.caption).to.equal("apple");
+ expect(children[1].props.caption).to.equal("banana");
+ expect(children[2].props.caption).to.equal("cherry");
expect(children[2].props.highlight).to.be.true;
- component.update(<Completion
- completions={completions}
- size={3}
- select={3}
- />);
+ component.update(
+ <Completion completions={completions} size={3} select={3} />
+ );
children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].props.caption).to.equal('cherry');
- expect(children[1].props.title).to.equal('Element');
- expect(children[2].props.caption).to.equal('argon');
+ expect(children[0].props.caption).to.equal("cherry");
+ expect(children[1].props.title).to.equal("Element");
+ expect(children[2].props.caption).to.equal("argon");
expect(children[2].props.highlight).to.be.true;
});
- it('scrolls down to up with select', () => {
- const component = ReactTestRenderer.create(<Completion
- completions={completions}
- size={3}
- select={5}
- />);
+ it("scrolls down to up with select", () => {
+ const component = ReactTestRenderer.create(
+ <Completion completions={completions} size={3} select={5} />
+ );
const root = component.root;
let children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].props.caption).to.equal('argon');
- expect(children[1].props.caption).to.equal('boron');
- expect(children[2].props.caption).to.equal('carbon');
+ expect(children[0].props.caption).to.equal("argon");
+ expect(children[1].props.caption).to.equal("boron");
+ expect(children[2].props.caption).to.equal("carbon");
- component.update(<Completion
- completions={completions}
- size={3}
- select={4}
- />);
+ component.update(
+ <Completion completions={completions} size={3} select={4} />
+ );
children = root.children[0].children;
expect(children[1].props.highlight).to.be.true;
- component.update(<Completion
- completions={completions}
- size={3}
- select={3}
- />);
+ component.update(
+ <Completion completions={completions} size={3} select={3} />
+ );
children = root.children[0].children;
expect(children[0].props.highlight).to.be.true;
- component.update(<Completion
- completions={completions}
- size={3}
- select={2}
- />);
+ component.update(
+ <Completion completions={completions} size={3} select={2} />
+ );
children = root.children[0].children;
- expect(children[0].props.caption).to.equal('cherry');
- expect(children[1].props.title).to.equal('Element');
- expect(children[2].props.caption).to.equal('argon');
+ expect(children[0].props.caption).to.equal("cherry");
+ expect(children[1].props.title).to.equal("Element");
+ expect(children[2].props.caption).to.equal("argon");
expect(children[0].props.highlight).to.be.true;
});
});
diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts
index 038e712..e8432c5 100644
--- a/test/console/reducers/console.test.ts
+++ b/test/console/reducers/console.test.ts
@@ -1,131 +1,140 @@
-import * as actions from 'console/actions';
-import reducer from 'console/reducers';
+import * as actions from "console/actions";
+import reducer from "console/reducers";
describe("console reducer", () => {
- it('return the initial state', () => {
+ it("return the initial state", () => {
const state = reducer(undefined, {});
- expect(state).to.have.property('mode', '');
- expect(state).to.have.property('messageText', '');
- expect(state).to.have.property('consoleText', '');
- expect(state).to.have.deep.property('completions', []);
- expect(state).to.have.property('select', -1);
+ expect(state).to.have.property("mode", "");
+ expect(state).to.have.property("messageText", "");
+ expect(state).to.have.property("consoleText", "");
+ expect(state).to.have.deep.property("completions", []);
+ expect(state).to.have.property("select", -1);
});
- it('return next state for CONSOLE_HIDE', () => {
+ it("return next state for CONSOLE_HIDE", () => {
const action = { type: actions.CONSOLE_HIDE };
- const state = reducer({ mode: 'error' }, action);
- expect(state).to.have.property('mode', '');
- })
+ const state = reducer({ mode: "error" }, action);
+ expect(state).to.have.property("mode", "");
+ });
- it('return next state for CONSOLE_SHOW_COMMAND', () => {
- const action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
+ it("return next state for CONSOLE_SHOW_COMMAND", () => {
+ const action = { type: actions.CONSOLE_SHOW_COMMAND, text: "open " };
const state = reducer({}, action);
- expect(state).to.have.property('mode', 'command');
- expect(state).to.have.property('consoleText', 'open ');
+ expect(state).to.have.property("mode", "command");
+ expect(state).to.have.property("consoleText", "open ");
});
- it('return next state for CONSOLE_SHOW_INFO', () => {
- const action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' };
+ it("return next state for CONSOLE_SHOW_INFO", () => {
+ const action = { type: actions.CONSOLE_SHOW_INFO, text: "an info" };
const state = reducer({}, action);
- expect(state).to.have.property('mode', 'info');
- expect(state).to.have.property('messageText', 'an info');
+ expect(state).to.have.property("mode", "info");
+ expect(state).to.have.property("messageText", "an info");
});
- it('return next state for CONSOLE_SHOW_ERROR', () => {
- const action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' };
+ it("return next state for CONSOLE_SHOW_ERROR", () => {
+ const action = { type: actions.CONSOLE_SHOW_ERROR, text: "an error" };
const state = reducer({}, action);
- expect(state).to.have.property('mode', 'error');
- expect(state).to.have.property('messageText', 'an error');
+ expect(state).to.have.property("mode", "error");
+ expect(state).to.have.property("messageText", "an error");
});
- it('return next state for CONSOLE_HIDE_COMMAND', () => {
+ it("return next state for CONSOLE_HIDE_COMMAND", () => {
const action = { type: actions.CONSOLE_HIDE_COMMAND };
- let state = reducer({ mode: 'command' }, action);
- expect(state).to.have.property('mode', '');
+ let state = reducer({ mode: "command" }, action);
+ expect(state).to.have.property("mode", "");
- state = reducer({ mode: 'error' }, action);
- expect(state).to.have.property('mode', 'error');
+ state = reducer({ mode: "error" }, action);
+ expect(state).to.have.property("mode", "error");
});
- it('return next state for CONSOLE_SET_CONSOLE_TEXT', () => {
+ it("return next state for CONSOLE_SET_CONSOLE_TEXT", () => {
const action = {
type: actions.CONSOLE_SET_CONSOLE_TEXT,
- consoleText: 'hello world'
- }
- const state = reducer({}, action)
+ consoleText: "hello world",
+ };
+ const state = reducer({}, action);
- expect(state).to.have.property('consoleText', 'hello world');
+ expect(state).to.have.property("consoleText", "hello world");
});
- it ('return next state for CONSOLE_SET_COMPLETIONS', () => {
+ it("return next state for CONSOLE_SET_COMPLETIONS", () => {
let state = {
select: 0,
completions: [],
- }
+ };
const action = {
type: actions.CONSOLE_SET_COMPLETIONS,
- completions: [{
- name: 'Apple',
- items: [1, 2, 3]
- }, {
- name: 'Banana',
- items: [4, 5, 6]
- }]
- }
+ completions: [
+ {
+ name: "Apple",
+ items: [1, 2, 3],
+ },
+ {
+ name: "Banana",
+ items: [4, 5, 6],
+ },
+ ],
+ };
state = reducer(state, action);
- expect(state).to.have.property('completions', action.completions);
- expect(state).to.have.property('select', -1);
+ expect(state).to.have.property("completions", action.completions);
+ expect(state).to.have.property("select", -1);
});
- it ('return next state for CONSOLE_COMPLETION_NEXT', () => {
+ it("return next state for CONSOLE_COMPLETION_NEXT", () => {
const action = { type: actions.CONSOLE_COMPLETION_NEXT };
let state = {
select: -1,
- completions: [{
- name: 'Apple',
- items: [1, 2]
- }, {
- name: 'Banana',
- items: [3]
- }]
+ completions: [
+ {
+ name: "Apple",
+ items: [1, 2],
+ },
+ {
+ name: "Banana",
+ items: [3],
+ },
+ ],
};
state = reducer(state, action);
- expect(state).to.have.property('select', 0);
+ expect(state).to.have.property("select", 0);
state = reducer(state, action);
- expect(state).to.have.property('select', 1);
+ expect(state).to.have.property("select", 1);
state = reducer(state, action);
- expect(state).to.have.property('select', 2);
+ expect(state).to.have.property("select", 2);
state = reducer(state, action);
- expect(state).to.have.property('select', -1);
+ expect(state).to.have.property("select", -1);
});
- it ('return next state for CONSOLE_COMPLETION_PREV', () => {
+ it("return next state for CONSOLE_COMPLETION_PREV", () => {
const action = { type: actions.CONSOLE_COMPLETION_PREV };
let state = {
select: -1,
- completions: [{
- name: 'Apple',
- items: [1, 2]
- }, {
- name: 'Banana',
- items: [3]
- }]
+ completions: [
+ {
+ name: "Apple",
+ items: [1, 2],
+ },
+ {
+ name: "Banana",
+ items: [3],
+ },
+ ],
};
state = reducer(state, action);
- expect(state).to.have.property('select', 2);
+ expect(state).to.have.property("select", 2);
state = reducer(state, action);
- expect(state).to.have.property('select', 1);
+ expect(state).to.have.property("select", 1);
state = reducer(state, action);
- expect(state).to.have.property('select', 0);
+ expect(state).to.have.property("select", 0);
state = reducer(state, action);
- expect(state).to.have.property('select', -1);
+ expect(state).to.have.property("select", -1);
});
});
diff --git a/test/content/InputDriver.test.ts b/test/content/InputDriver.test.ts
index d3a55dd..bfada87 100644
--- a/test/content/InputDriver.test.ts
+++ b/test/content/InputDriver.test.ts
@@ -1,13 +1,15 @@
-import InputDriver, {keyFromKeyboardEvent} from '../../src/content/InputDriver';
-import { expect } from 'chai';
-import Key from '../../src/shared/settings/Key';
+import InputDriver, {
+ keyFromKeyboardEvent,
+} from "../../src/content/InputDriver";
+import { expect } from "chai";
+import Key from "../../src/shared/settings/Key";
-describe('InputDriver', () => {
+describe("InputDriver", () => {
let target: HTMLElement;
let driver: InputDriver;
beforeEach(() => {
- target = document.createElement('div');
+ target = document.createElement("div");
document.body.appendChild(target);
driver = new InputDriver(target);
});
@@ -18,9 +20,9 @@ describe('InputDriver', () => {
driver = null;
});
- it('register callbacks', (done) => {
+ it("register callbacks", (done) => {
driver.onKey((key: Key): boolean => {
- expect(key.key).to.equal('a');
+ expect(key.key).to.equal("a");
expect(key.ctrl).to.be.true;
expect(key.shift).to.be.false;
expect(key.alt).to.be.false;
@@ -29,34 +31,37 @@ describe('InputDriver', () => {
return true;
});
- target.dispatchEvent(new KeyboardEvent('keydown', {
- key: 'a',
- ctrlKey: true,
- shiftKey: false,
- altKey: false,
- metaKey: false,
- }));
+ target.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "a",
+ ctrlKey: true,
+ shiftKey: false,
+ altKey: false,
+ metaKey: false,
+ })
+ );
});
- it('invoke callback once', () => {
- let a = 0, b = 0;
+ it("invoke callback once", () => {
+ let a = 0,
+ b = 0;
driver.onKey((key: Key): boolean => {
- if (key.key == 'a') {
+ if (key.key == "a") {
++a;
} else {
- key.key == 'b'
+ key.key == "b";
++b;
}
return true;
});
const events = [
- new KeyboardEvent('keydown', { key: 'a' }),
- new KeyboardEvent('keydown', { key: 'b' }),
- new KeyboardEvent('keypress', { key: 'a' }),
- new KeyboardEvent('keyup', { key: 'a' }),
- new KeyboardEvent('keypress', { key: 'b' }),
- new KeyboardEvent('keyup', { key: 'b' }),
+ new KeyboardEvent("keydown", { key: "a" }),
+ new KeyboardEvent("keydown", { key: "b" }),
+ new KeyboardEvent("keypress", { key: "a" }),
+ new KeyboardEvent("keyup", { key: "a" }),
+ new KeyboardEvent("keypress", { key: "b" }),
+ new KeyboardEvent("keyup", { key: "b" }),
];
for (const e of events) {
target.dispatchEvent(e);
@@ -64,10 +69,12 @@ describe('InputDriver', () => {
expect(a).to.equal(1);
expect(b).to.equal(1);
- })
+ });
- it('propagates and stop handler chain', () => {
- let a = 0, b = 0, c = 0;
+ it("propagates and stop handler chain", () => {
+ let a = 0,
+ b = 0,
+ c = 0;
driver.onKey((_key: Key): boolean => {
a++;
return false;
@@ -81,93 +88,117 @@ describe('InputDriver', () => {
return true;
});
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'b' }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "b" }));
expect(a).to.equal(1);
expect(b).to.equal(1);
expect(c).to.equal(0);
- })
+ });
- it('does not invoke only meta keys', () => {
- driver.onKey((_key: Key): boolean=> {
+ it("does not invoke only meta keys", () => {
+ driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Control' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'Alt' }));
- target.dispatchEvent(new KeyboardEvent('keydown', { key: 'OS' }));
- })
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Shift" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Control" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "Alt" }));
+ target.dispatchEvent(new KeyboardEvent("keydown", { key: "OS" }));
+ });
- it('ignores events from input elements', () => {
- ['input', 'textarea', 'select'].forEach((name) => {
+ it("ignores events from input elements", () => {
+ ["input", "textarea", "select"].forEach((name) => {
const input = window.document.createElement(name);
const driver = new InputDriver(input);
driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- input.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ input.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
});
});
- it('ignores events from contenteditable elements', () => {
- const div = window.document.createElement('div');
+ it("ignores events from contenteditable elements", () => {
+ const div = window.document.createElement("div");
const driver = new InputDriver(div);
driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
- div.setAttribute('contenteditable', '');
- div.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ div.setAttribute("contenteditable", "");
+ div.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
- div.setAttribute('contenteditable', 'true');
- div.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
+ div.setAttribute("contenteditable", "true");
+ div.dispatchEvent(new KeyboardEvent("keydown", { key: "x" }));
});
});
describe("#keyFromKeyboardEvent", () => {
- it('returns from keyboard input Ctrl+X', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true,
- }));
- expect(k.key).to.equal('x');
+ it("returns from keyboard input Ctrl+X", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "x",
+ shiftKey: false,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: true,
+ })
+ );
+ expect(k.key).to.equal("x");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
expect(k.meta).to.be.true;
});
- it('returns from keyboard input Shift+Esc', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true
- }));
- expect(k.key).to.equal('Esc');
+ it("returns from keyboard input Shift+Esc", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "Escape",
+ shiftKey: true,
+ ctrlKey: false,
+ altKey: false,
+ metaKey: true,
+ })
+ );
+ expect(k.key).to.equal("Esc");
expect(k.shift).to.be.true;
expect(k.ctrl).to.be.false;
expect(k.alt).to.be.false;
expect(k.meta).to.be.true;
});
- it('returns from keyboard input Ctrl+$', () => {
+ it("returns from keyboard input Ctrl+$", () => {
// $ required shift pressing on most keyboards
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('$');
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: "$",
+ shiftKey: true,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: false,
+ })
+ );
+ expect(k.key).to.equal("$");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
expect(k.meta).to.be.false;
});
- it('returns from keyboard input Crtl+Space', () => {
- const k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
- key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('Space');
+ it("returns from keyboard input Crtl+Space", () => {
+ const k = keyFromKeyboardEvent(
+ new KeyboardEvent("keydown", {
+ key: " ",
+ shiftKey: false,
+ ctrlKey: true,
+ altKey: false,
+ metaKey: false,
+ })
+ );
+ expect(k.key).to.equal("Space");
expect(k.shift).to.be.false;
expect(k.ctrl).to.be.true;
expect(k.alt).to.be.false;
diff --git a/test/content/domains/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts
index 5df5217..1d1debe 100644
--- a/test/content/domains/KeySequence.test.ts
+++ b/test/content/domains/KeySequence.test.ts
@@ -1,166 +1,179 @@
-import KeySequence from '../../../src/content/domains/KeySequence';
-import { expect } from 'chai'
+import KeySequence from "../../../src/content/domains/KeySequence";
+import { expect } from "chai";
import Key from "../../../src/shared/settings/Key";
describe("KeySequence", () => {
- describe('#push', () => {
- it('append a key to the sequence', () => {
+ describe("#push", () => {
+ it("append a key to the sequence", () => {
const seq = new KeySequence([]);
- seq.push(Key.fromMapKey('g'));
- seq.push(Key.fromMapKey('<S-U>'));
+ seq.push(Key.fromMapKey("g"));
+ seq.push(Key.fromMapKey("<S-U>"));
- expect(seq.keys[0].key).to.equal('g');
- expect(seq.keys[1].key).to.equal('U');
+ expect(seq.keys[0].key).to.equal("g");
+ expect(seq.keys[1].key).to.equal("U");
expect(seq.keys[1].shift).to.be.true;
- })
+ });
});
- describe('#startsWith', () => {
- it('returns true if the key sequence starts with param', () => {
+ describe("#startsWith", () => {
+ it("returns true if the key sequence starts with param", () => {
const seq = new KeySequence([
- Key.fromMapKey('g'),
- Key.fromMapKey('<S-U>'),
+ Key.fromMapKey("g"),
+ Key.fromMapKey("<S-U>"),
]);
- expect(seq.startsWith(new KeySequence([
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'),
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'), Key.fromMapKey('<S-U>'),
- ]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('g'), Key.fromMapKey('<S-U>'), Key.fromMapKey('x'),
- ]))).to.be.false;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('h'),
- ]))).to.be.false;
+ expect(seq.startsWith(new KeySequence([]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("g")]))).to.be.true;
+ expect(
+ seq.startsWith(
+ new KeySequence([Key.fromMapKey("g"), Key.fromMapKey("<S-U>")])
+ )
+ ).to.be.true;
+ expect(
+ seq.startsWith(
+ new KeySequence([
+ Key.fromMapKey("g"),
+ Key.fromMapKey("<S-U>"),
+ Key.fromMapKey("x"),
+ ])
+ )
+ ).to.be.false;
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be
+ .false;
});
- it('returns true if the empty sequence starts with an empty sequence', () => {
+ it("returns true if the empty sequence starts with an empty sequence", () => {
const seq = new KeySequence([]);
expect(seq.startsWith(new KeySequence([]))).to.be.true;
- expect(seq.startsWith(new KeySequence([
- Key.fromMapKey('h'),
- ]))).to.be.false;
- })
+ expect(seq.startsWith(new KeySequence([Key.fromMapKey("h")]))).to.be
+ .false;
+ });
});
- describe('#isDigitOnly', () => {
- it('returns true the keys are only digits', () => {
- expect(new KeySequence([
- new Key({ key: '4' }),
- new Key({ key: '0' }),
- ]).isDigitOnly()).to.be.true;
- expect(new KeySequence([
- new Key({ key: '4' }),
- new Key({ key: '0' }),
- new Key({ key: 'z' }),
- ]).isDigitOnly()).to.be.false;
- })
+ describe("#isDigitOnly", () => {
+ it("returns true the keys are only digits", () => {
+ expect(
+ new KeySequence([
+ new Key({ key: "4" }),
+ new Key({ key: "0" }),
+ ]).isDigitOnly()
+ ).to.be.true;
+ expect(
+ new KeySequence([
+ new Key({ key: "4" }),
+ new Key({ key: "0" }),
+ new Key({ key: "z" }),
+ ]).isDigitOnly()
+ ).to.be.false;
+ });
});
- describe('#repeatCount', () => {
- it('returns repeat count with a numeric prefix', () => {
+ describe("#repeatCount", () => {
+ it("returns repeat count with a numeric prefix", () => {
let seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
]);
expect(seq.repeatCount()).to.equal(10);
seq = new KeySequence([
- new Key({ key: '0' }), new Key({ key: '5' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
+ new Key({ key: "0" }),
+ new Key({ key: "5" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
]);
expect(seq.repeatCount()).to.equal(5);
});
- it('returns 1 if no numeric prefix', () => {
- let seq = new KeySequence([
- new Key({ key: 'g' }), new Key({ key: 'g' }) ,
- ]);
+ it("returns 1 if no numeric prefix", () => {
+ let seq = new KeySequence([new Key({ key: "g" }), new Key({ key: "g" })]);
expect(seq.repeatCount()).to.equal(1);
seq = new KeySequence([]);
expect(seq.repeatCount()).to.equal(1);
});
- it('returns whole keys if digits only sequence', () => {
- let seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- ]);
+ it("returns whole keys if digits only sequence", () => {
+ let seq = new KeySequence([new Key({ key: "1" }), new Key({ key: "0" })]);
expect(seq.repeatCount()).to.equal(10);
- seq = new KeySequence([
- new Key({ key: '0' }), new Key({ key: '5' }) ,
- ]);
+ seq = new KeySequence([new Key({ key: "0" }), new Key({ key: "5" })]);
expect(seq.repeatCount()).to.equal(5);
});
});
- describe('#trimNumericPrefix', () => {
- it('removes numeric prefix', () => {
+ describe("#trimNumericPrefix", () => {
+ it("removes numeric prefix", () => {
const seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
- new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
+ new Key({ key: "3" }),
]).trimNumericPrefix();
- expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]);
});
- it('returns empty if keys contains only digis', () => {
+ it("returns empty if keys contains only digis", () => {
const seq = new KeySequence([
- new Key({ key: '1' }), new Key({ key: '0' }) ,
+ new Key({ key: "1" }),
+ new Key({ key: "0" }),
]).trimNumericPrefix();
expect(seq.trimNumericPrefix().keys).to.be.empty;
});
- it('returns itself if no numeric prefix', () => {
+ it("returns itself if no numeric prefix", () => {
const seq = new KeySequence([
- new Key({ key: 'g' }), new Key({ key: 'g' }) , new Key({ key: '3' }) ,
+ new Key({ key: "g" }),
+ new Key({ key: "g" }),
+ new Key({ key: "3" }),
]).trimNumericPrefix();
- expect(seq.keys.map(key => key.key)).to.deep.equal(['g', 'g', '3']);
+ expect(seq.keys.map((key) => key.key)).to.deep.equal(["g", "g", "3"]);
});
});
- describe('#splitNumericPrefix', () => {
- it('splits numeric prefix', () => {
- expect(KeySequence.fromMapKeys('10gg').splitNumericPrefix()).to.deep.equal([
- KeySequence.fromMapKeys('10'),
- KeySequence.fromMapKeys('gg'),
- ]);
- expect(KeySequence.fromMapKeys('10').splitNumericPrefix()).to.deep.equal([
- KeySequence.fromMapKeys('10'),
- new KeySequence([]),
- ]);
- expect(KeySequence.fromMapKeys('gg').splitNumericPrefix()).to.deep.equal([
- new KeySequence([]),
- KeySequence.fromMapKeys('gg'),
- ]);
- });
+ describe("#splitNumericPrefix", () => {
+ it("splits numeric prefix", () => {
+ expect(
+ KeySequence.fromMapKeys("10gg").splitNumericPrefix()
+ ).to.deep.equal([
+ KeySequence.fromMapKeys("10"),
+ KeySequence.fromMapKeys("gg"),
+ ]);
+ expect(KeySequence.fromMapKeys("10").splitNumericPrefix()).to.deep.equal([
+ KeySequence.fromMapKeys("10"),
+ new KeySequence([]),
+ ]);
+ expect(KeySequence.fromMapKeys("gg").splitNumericPrefix()).to.deep.equal([
+ new KeySequence([]),
+ KeySequence.fromMapKeys("gg"),
+ ]);
+ });
});
- describe('#fromMapKeys', () => {
- it('returns mapped keys for Shift+Esc', () => {
- const keys = KeySequence.fromMapKeys('<S-Esc>').keys;
+ describe("#fromMapKeys", () => {
+ it("returns mapped keys for Shift+Esc", () => {
+ const keys = KeySequence.fromMapKeys("<S-Esc>").keys;
expect(keys).to.have.lengthOf(1);
- expect(keys[0].key).to.equal('Esc');
+ expect(keys[0].key).to.equal("Esc");
expect(keys[0].shift).to.be.true;
});
- it('returns mapped keys for a<C-B><A-C>d<M-e>', () => {
- const keys = KeySequence.fromMapKeys('a<C-B><A-C>d<M-e>').keys;
+ it("returns mapped keys for a<C-B><A-C>d<M-e>", () => {
+ const keys = KeySequence.fromMapKeys("a<C-B><A-C>d<M-e>").keys;
expect(keys).to.have.lengthOf(5);
- expect(keys[0].key).to.equal('a');
+ expect(keys[0].key).to.equal("a");
expect(keys[1].ctrl).to.be.true;
- expect(keys[1].key).to.equal('b');
+ expect(keys[1].key).to.equal("b");
expect(keys[2].alt).to.be.true;
- expect(keys[2].key).to.equal('c');
- expect(keys[3].key).to.equal('d');
+ expect(keys[2].key).to.equal("c");
+ expect(keys[3].key).to.equal("d");
expect(keys[4].meta).to.be.true;
- expect(keys[4].key).to.equal('e');
+ expect(keys[4].key).to.equal("e");
});
- })
+ });
});
diff --git a/test/content/mock/MockConsoleClient.ts b/test/content/mock/MockConsoleClient.ts
index 8de2d83..849c00d 100644
--- a/test/content/mock/MockConsoleClient.ts
+++ b/test/content/mock/MockConsoleClient.ts
@@ -1,4 +1,4 @@
-import ConsoleClient from '../../../src/content/client/ConsoleClient';
+import ConsoleClient from "../../../src/content/client/ConsoleClient";
export default class MockConsoleClient implements ConsoleClient {
public isError: boolean;
@@ -7,7 +7,7 @@ export default class MockConsoleClient implements ConsoleClient {
constructor() {
this.isError = false;
- this.text = '';
+ this.text = "";
}
info(text: string): Promise<void> {
@@ -22,5 +22,3 @@ export default class MockConsoleClient implements ConsoleClient {
return Promise.resolve();
}
}
-
-
diff --git a/test/content/mock/MockScrollPresenter.ts b/test/content/mock/MockScrollPresenter.ts
index 819569a..c802227 100644
--- a/test/content/mock/MockScrollPresenter.ts
+++ b/test/content/mock/MockScrollPresenter.ts
@@ -1,8 +1,10 @@
-import ScrollPresenter, { Point } from '../../../src/content/presenters/ScrollPresenter';
+import ScrollPresenter, {
+ Point,
+} from "../../../src/content/presenters/ScrollPresenter";
export default class MockScrollPresenter implements ScrollPresenter {
private pos: Point;
-
+
constructor() {
this.pos = { x: 0, y: 0 };
}
@@ -44,4 +46,3 @@ export default class MockScrollPresenter implements ScrollPresenter {
this.pos.x = Infinity;
}
}
-
diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts
index 7daa63d..e64c39f 100644
--- a/test/content/presenters/Hint.test.ts
+++ b/test/content/presenters/Hint.test.ts
@@ -1,53 +1,55 @@
-import AbstractHint, { LinkHint, InputHint } from '../../../src/content/presenters/Hint';
-import { expect } from 'chai';
+import AbstractHint, {
+ LinkHint,
+ InputHint,
+} from "../../../src/content/presenters/Hint";
+import { expect } from "chai";
-class Hint extends AbstractHint {
-}
+class Hint extends AbstractHint {}
-describe('Hint', () => {
+describe("Hint", () => {
beforeEach(() => {
document.body.innerHTML = `<a id='test-link' href='#'>link</a>`;
});
- describe('#constructor', () => {
- it('creates a hint element with tag name', () => {
- const link = document.getElementById('test-link');
- new Hint(link, 'abc');
+ describe("#constructor", () => {
+ it("creates a hint element with tag name", () => {
+ const link = document.getElementById("test-link");
+ new Hint(link, "abc");
- const elem = document.querySelector('.vimvixen-hint');
- expect(elem.textContent.trim()).to.be.equal('abc');
+ const elem = document.querySelector(".vimvixen-hint");
+ expect(elem.textContent.trim()).to.be.equal("abc");
});
});
- describe('#show', () => {
- it('shows an element', () => {
- const link = document.getElementById('test-link');
- const hint = new Hint(link, 'abc');
+ describe("#show", () => {
+ it("shows an element", () => {
+ const link = document.getElementById("test-link");
+ const hint = new Hint(link, "abc");
hint.hide();
hint.show();
- const elem = document.querySelector('.vimvixen-hint') as HTMLElement;
- expect(elem.style.display).to.not.equal('none');
+ const elem = document.querySelector(".vimvixen-hint") as HTMLElement;
+ expect(elem.style.display).to.not.equal("none");
});
});
- describe('#hide', () => {
- it('hides an element', () => {
- const link = document.getElementById('test-link') as HTMLElement;
- const hint = new Hint(link, 'abc');
+ describe("#hide", () => {
+ it("hides an element", () => {
+ const link = document.getElementById("test-link") as HTMLElement;
+ const hint = new Hint(link, "abc");
hint.hide();
- const elem = document.querySelector('.vimvixen-hint') as HTMLElement;
- expect(elem.style.display).to.equal('none');
+ const elem = document.querySelector(".vimvixen-hint") as HTMLElement;
+ expect(elem.style.display).to.equal("none");
});
});
- describe('#remove', () => {
- it('removes an element', () => {
- const link = document.getElementById('test-link');
- const hint = new Hint(link, 'abc');
+ describe("#remove", () => {
+ it("removes an element", () => {
+ const link = document.getElementById("test-link");
+ const hint = new Hint(link, "abc");
- const elem = document.querySelector('.vimvixen-hint');
+ const elem = document.querySelector(".vimvixen-hint");
expect(elem.parentElement).to.not.be.null;
hint.remove();
expect(elem.parentElement).to.be.null;
@@ -55,7 +57,7 @@ describe('Hint', () => {
});
});
-describe('LinkHint', () => {
+describe("LinkHint", () => {
beforeEach(() => {
document.body.innerHTML = `
<a id='test-link1' href='https://google.com/'>link</a>
@@ -64,50 +66,52 @@ describe('LinkHint', () => {
`;
});
- describe('#getLink()', () => {
+ describe("#getLink()", () => {
it('returns value of "href" attribute', () => {
- const link = document.getElementById('test-link1') as HTMLAnchorElement;
- const hint = new LinkHint(link, 'abc');
+ const link = document.getElementById("test-link1") as HTMLAnchorElement;
+ const hint = new LinkHint(link, "abc");
- expect(hint.getLink()).to.equal('https://google.com/');
+ expect(hint.getLink()).to.equal("https://google.com/");
});
});
- describe('#getLinkTarget()', () => {
+ describe("#getLinkTarget()", () => {
it('returns value of "target" attribute', () => {
- let link = document.getElementById('test-link1') as HTMLAnchorElement;
- let hint = new LinkHint(link, 'abc');
+ let link = document.getElementById("test-link1") as HTMLAnchorElement;
+ let hint = new LinkHint(link, "abc");
expect(hint.getLinkTarget()).to.be.null;
- link = document.getElementById('test-link2') as HTMLAnchorElement;
- hint = new LinkHint(link, 'abc');
+ link = document.getElementById("test-link2") as HTMLAnchorElement;
+ hint = new LinkHint(link, "abc");
- expect(hint.getLinkTarget()).to.equal('_blank');
+ expect(hint.getLinkTarget()).to.equal("_blank");
});
});
- describe('#click()', () => {
- it('clicks a element', (done) => {
- const link = document.getElementById('test-link3') as HTMLAnchorElement;
- const hint = new LinkHint(link, 'abc');
- link.onclick = () => { done() };
+ describe("#click()", () => {
+ it("clicks a element", (done) => {
+ const link = document.getElementById("test-link3") as HTMLAnchorElement;
+ const hint = new LinkHint(link, "abc");
+ link.onclick = () => {
+ done();
+ };
hint.click();
});
});
});
-describe('InputHint', () => {
- describe('#activate()', () => {
- context('<input>', () => {
+describe("InputHint", () => {
+ describe("#activate()", () => {
+ context("<input>", () => {
beforeEach(() => {
document.body.innerHTML = `<input id='test-input'></input>`;
});
- it('focuses to the input', () => {
- const input = document.getElementById('test-input') as HTMLInputElement;
- const hint = new InputHint(input, 'abc');
+ it("focuses to the input", () => {
+ const input = document.getElementById("test-input") as HTMLInputElement;
+ const hint = new InputHint(input, "abc");
hint.activate();
expect(document.activeElement).to.equal(input);
@@ -119,38 +123,44 @@ describe('InputHint', () => {
document.body.innerHTML = `<input type="checkbox" id='test-input'></input>`;
});
- it('checks and focuses to the input', () => {
- const input = document.getElementById('test-input') as HTMLInputElement;
- const hint = new InputHint(input, 'abc');
+ it("checks and focuses to the input", () => {
+ const input = document.getElementById("test-input") as HTMLInputElement;
+ const hint = new InputHint(input, "abc");
hint.activate();
expect(input.checked).to.be.true;
});
});
- context('<textarea>', () => {
+ context("<textarea>", () => {
beforeEach(() => {
document.body.innerHTML = `<textarea id='test-textarea'></textarea>`;
});
- it('focuses to the textarea', () => {
- const textarea = document.getElementById('test-textarea') as HTMLTextAreaElement;
- const hint = new InputHint(textarea, 'abc');
+ it("focuses to the textarea", () => {
+ const textarea = document.getElementById(
+ "test-textarea"
+ ) as HTMLTextAreaElement;
+ const hint = new InputHint(textarea, "abc");
hint.activate();
expect(document.activeElement).to.equal(textarea);
});
});
- context('<button>', () => {
+ context("<button>", () => {
beforeEach(() => {
document.body.innerHTML = `<button id='test-button'></button>`;
});
- it('clicks the button', (done) => {
- const button = document.getElementById('test-button') as HTMLButtonElement;
- button.onclick = () => { done() };
+ it("clicks the button", (done) => {
+ const button = document.getElementById(
+ "test-button"
+ ) as HTMLButtonElement;
+ button.onclick = () => {
+ done();
+ };
- const hint = new InputHint(button, 'abc');
+ const hint = new InputHint(button, "abc");
hint.activate();
});
});
diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts
index 6aa057b..b362d8d 100644
--- a/test/content/presenters/NavigationPresenter.test.ts
+++ b/test/content/presenters/NavigationPresenter.test.ts
@@ -1,11 +1,12 @@
-import { NavigationPresenterImpl } from '../../../src/content/presenters/NavigationPresenter';
-import { expect } from 'chai';
+import { NavigationPresenterImpl } from "../../../src/content/presenters/NavigationPresenter";
+import { expect } from "chai";
-describe('NavigationPresenterImpl', () => {
+describe("NavigationPresenterImpl", () => {
let sut: NavigationPresenterImpl;
const testRel = (done, rel, html) => {
- const method = rel === 'prev' ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut);
+ const method =
+ rel === "prev" ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut);
document.body.innerHTML = html;
method();
setTimeout(() => {
@@ -13,122 +14,165 @@ describe('NavigationPresenterImpl', () => {
done();
}, 0);
};
- const testPrev = html => done => testRel(done, 'prev', html);
- const testNext = html => done => testRel(done, 'next', html);
+ const testPrev = (html) => (done) => testRel(done, "prev", html);
+ const testNext = (html) => (done) => testRel(done, "next", html);
before(() => {
sut = new NavigationPresenterImpl();
});
- describe('#linkPrev', () => {
- it('navigates to <link> elements whose rel attribute is "prev"', testPrev(
- '<link rel="prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "prev"', testPrev(
- '<link rel="prev bar" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "prev"', testPrev(
- '<link rel="foo prev" href="#prev" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "prev"', testPrev(
- '<link rel="foo prev bar" href="#prev" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "prev"', testPrev(
- '<a rel="prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "prev"', testPrev(
- '<a rel="prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "prev"', testPrev(
- '<a rel="foo prev" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "prev"', testPrev(
- '<a rel="foo prev bar" href="#prev">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "prev"', testPrev(
- '<a href="#dummy">preview</a><a href="#prev">go to prev</a>'
- ));
-
- it('navigates to <a> elements whose text matches "previous"', testPrev(
- '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches "<<"', testPrev(
- '<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testPrev(
- `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
- ));
-
- it('prefers link[rel~=prev] to a[rel~=prev]', testPrev(
- '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
- ));
-
- it('prefers a[rel~=prev] to a::text(pattern)', testPrev(
- '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
- ));
+ describe("#linkPrev", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "prev"',
+ testPrev('<link rel="prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "prev"',
+ testPrev('<link rel="prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "prev"',
+ testPrev('<link rel="foo prev" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "prev"',
+ testPrev('<link rel="foo prev bar" href="#prev" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "prev"',
+ testPrev('<a rel="prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "prev"',
+ testPrev('<a rel="prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "prev"',
+ testPrev('<a rel="foo prev" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "prev"',
+ testPrev('<a rel="foo prev bar" href="#prev">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "prev"',
+ testPrev('<a href="#dummy">preview</a><a href="#prev">go to prev</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "previous"',
+ testPrev(
+ '<a href="#dummy">previously</a><a href="#prev">previous page</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches "<<"',
+ testPrev('<a href="#dummy">click me</a><a href="#prev">&lt;&lt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testPrev(
+ `<a rel="prev" href="#dummy" onclick="return location = '#prev', false">go to prev</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=prev] to a[rel~=prev]",
+ testPrev(
+ '<a rel="prev" href="#dummy">click me</a><link rel="prev" href="#prev" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=prev] to a::text(pattern)",
+ testPrev(
+ '<a href="#dummy">go to prev</a><a rel="prev" href="#prev">click me</a>'
+ )
+ );
});
- describe('#linkNext', () => {
- it('navigates to <link> elements whose rel attribute is "next"', testNext(
- '<link rel="next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute starts with "next"', testNext(
- '<link rel="next bar" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute ends with "next"', testNext(
- '<link rel="foo next" href="#next" />'
- ));
-
- it('navigates to <link> elements whose rel attribute contains "next"', testNext(
- '<link rel="foo next bar" href="#next" />'
- ));
-
- it('navigates to <a> elements whose rel attribute is "next"', testNext(
- '<a rel="next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute starts with "next"', testNext(
- '<a rel="next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute ends with "next"', testNext(
- '<a rel="foo next" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose rel attribute contains "next"', testNext(
- '<a rel="foo next bar" href="#next">click me</a>'
- ));
-
- it('navigates to <a> elements whose text matches "next"', testNext(
- '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
- ));
-
- it('navigates to <a> elements whose decoded text matches ">>"', testNext(
- '<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>'
- ));
-
- it('navigates to matching <a> elements by clicking', testNext(
- `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
- ));
-
- it('prefers link[rel~=next] to a[rel~=next]', testNext(
- '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
- ));
-
- it('prefers a[rel~=next] to a::text(pattern)', testNext(
- '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
- ));
+ describe("#linkNext", () => {
+ it(
+ 'navigates to <link> elements whose rel attribute is "next"',
+ testNext('<link rel="next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute starts with "next"',
+ testNext('<link rel="next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute ends with "next"',
+ testNext('<link rel="foo next" href="#next" />')
+ );
+
+ it(
+ 'navigates to <link> elements whose rel attribute contains "next"',
+ testNext('<link rel="foo next bar" href="#next" />')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute is "next"',
+ testNext('<a rel="next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute starts with "next"',
+ testNext('<a rel="next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute ends with "next"',
+ testNext('<a rel="foo next" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose rel attribute contains "next"',
+ testNext('<a rel="foo next bar" href="#next">click me</a>')
+ );
+
+ it(
+ 'navigates to <a> elements whose text matches "next"',
+ testNext(
+ '<a href="#dummy">inextricable</a><a href="#next">go to next</a>'
+ )
+ );
+
+ it(
+ 'navigates to <a> elements whose decoded text matches ">>"',
+ testNext('<a href="#dummy">click me</a><a href="#next">&gt;&gt;</a>')
+ );
+
+ it(
+ "navigates to matching <a> elements by clicking",
+ testNext(
+ `<a rel="next" href="#dummy" onclick="return location = '#next', false">go to next</a>`
+ )
+ );
+
+ it(
+ "prefers link[rel~=next] to a[rel~=next]",
+ testNext(
+ '<a rel="next" href="#dummy">click me</a><link rel="next" href="#next" />'
+ )
+ );
+
+ it(
+ "prefers a[rel~=next] to a::text(pattern)",
+ testNext(
+ '<a href="#dummy">next page</a><a rel="next" href="#next">click me</a>'
+ )
+ );
});
});
diff --git a/test/content/repositories/AddonEnabledRepository.test.ts b/test/content/repositories/AddonEnabledRepository.test.ts
index 7edd50e..13dff76 100644
--- a/test/content/repositories/AddonEnabledRepository.test.ts
+++ b/test/content/repositories/AddonEnabledRepository.test.ts
@@ -1,8 +1,8 @@
-import { AddonEnabledRepositoryImpl } from '../../../src/content/repositories/AddonEnabledRepository';
-import { expect } from 'chai';
+import { AddonEnabledRepositoryImpl } from "../../../src/content/repositories/AddonEnabledRepository";
+import { expect } from "chai";
-describe('AddonEnabledRepositoryImpl', () => {
- it('updates and gets current value', () => {
+describe("AddonEnabledRepositoryImpl", () => {
+ it("updates and gets current value", () => {
const sut = new AddonEnabledRepositoryImpl();
sut.set(true);
@@ -12,4 +12,3 @@ describe('AddonEnabledRepositoryImpl', () => {
expect(sut.get()).to.be.false;
});
});
-
diff --git a/test/content/repositories/FindRepository.test.ts b/test/content/repositories/FindRepository.test.ts
index 0e50b0a..e0abb9d 100644
--- a/test/content/repositories/FindRepository.test.ts
+++ b/test/content/repositories/FindRepository.test.ts
@@ -1,15 +1,14 @@
-import { FindRepositoryImpl } from '../../../src/content/repositories/FindRepository';
-import { expect } from 'chai';
+import { FindRepositoryImpl } from "../../../src/content/repositories/FindRepository";
+import { expect } from "chai";
-describe('FindRepositoryImpl', () => {
- it('updates and gets last keyword', () => {
+describe("FindRepositoryImpl", () => {
+ it("updates and gets last keyword", () => {
const sut = new FindRepositoryImpl();
expect(sut.getLastKeyword()).to.be.null;
- sut.setLastKeyword('monkey');
+ sut.setLastKeyword("monkey");
- expect(sut.getLastKeyword()).to.equal('monkey');
+ expect(sut.getLastKeyword()).to.equal("monkey");
});
});
-
diff --git a/test/content/repositories/FollowKeyRepository.test.ts b/test/content/repositories/FollowKeyRepository.test.ts
index eae58b9..6608662 100644
--- a/test/content/repositories/FollowKeyRepository.test.ts
+++ b/test/content/repositories/FollowKeyRepository.test.ts
@@ -1,31 +1,29 @@
-import FollowKeyRepository, { FollowKeyRepositoryImpl }
- from '../../../src/content/repositories/FollowKeyRepository';
-import { expect } from 'chai';
+import FollowKeyRepository, {
+ FollowKeyRepositoryImpl,
+} from "../../../src/content/repositories/FollowKeyRepository";
+import { expect } from "chai";
-describe('FollowKeyRepositoryImpl', () => {
+describe("FollowKeyRepositoryImpl", () => {
let sut: FollowKeyRepository;
before(() => {
sut = new FollowKeyRepositoryImpl();
});
- describe('#getKeys()/#pushKey()/#popKey()', () => {
- it('enqueues keys', () => {
+ describe("#getKeys()/#pushKey()/#popKey()", () => {
+ it("enqueues keys", () => {
expect(sut.getKeys()).to.be.empty;
- sut.pushKey('a');
- sut.pushKey('b');
- sut.pushKey('c');
- expect(sut.getKeys()).to.deep.equal(['a', 'b', 'c']);
+ sut.pushKey("a");
+ sut.pushKey("b");
+ sut.pushKey("c");
+ expect(sut.getKeys()).to.deep.equal(["a", "b", "c"]);
sut.popKey();
- expect(sut.getKeys()).to.deep.equal(['a', 'b']);
+ expect(sut.getKeys()).to.deep.equal(["a", "b"]);
sut.clearKeys();
expect(sut.getKeys()).to.be.empty;
});
});
});
-
-
-
diff --git a/test/content/repositories/FollowMasterRepository.test.ts b/test/content/repositories/FollowMasterRepository.test.ts
index 3eb172f..9b5e151 100644
--- a/test/content/repositories/FollowMasterRepository.test.ts
+++ b/test/content/repositories/FollowMasterRepository.test.ts
@@ -1,42 +1,43 @@
-import FollowMasterRepository, { FollowMasterRepositoryImpl }
- from '../../../src/content/repositories/FollowMasterRepository';
-import { expect } from 'chai';
+import FollowMasterRepository, {
+ FollowMasterRepositoryImpl,
+} from "../../../src/content/repositories/FollowMasterRepository";
+import { expect } from "chai";
-describe('FollowMasterRepositoryImpl', () => {
+describe("FollowMasterRepositoryImpl", () => {
let sut: FollowMasterRepository;
before(() => {
sut = new FollowMasterRepositoryImpl();
});
- describe('#getTags()/#addTag()/#clearTags()', () => {
- it('gets, adds and clears tags', () => {
+ describe("#getTags()/#addTag()/#clearTags()", () => {
+ it("gets, adds and clears tags", () => {
expect(sut.getTags()).to.be.empty;
- sut.addTag('a');
- sut.addTag('b');
- sut.addTag('c');
- expect(sut.getTags()).to.deep.equal(['a', 'b', 'c']);
+ sut.addTag("a");
+ sut.addTag("b");
+ sut.addTag("c");
+ expect(sut.getTags()).to.deep.equal(["a", "b", "c"]);
sut.clearTags();
expect(sut.getTags()).to.be.empty;
});
});
- describe('#getTagsByPrefix', () => {
- it('gets tags matched by prefix', () => {
- for (const tag of ['a', 'aa', 'ab', 'b', 'ba', 'bb']) {
+ describe("#getTagsByPrefix", () => {
+ it("gets tags matched by prefix", () => {
+ for (const tag of ["a", "aa", "ab", "b", "ba", "bb"]) {
sut.addTag(tag);
}
- expect(sut.getTagsByPrefix('a')).to.deep.equal(['a', 'aa', 'ab']);
- expect(sut.getTagsByPrefix('aa')).to.deep.equal(['aa']);
- expect(sut.getTagsByPrefix('b')).to.deep.equal(['b', 'ba', 'bb']);
- expect(sut.getTagsByPrefix('c')).to.be.empty;
+ expect(sut.getTagsByPrefix("a")).to.deep.equal(["a", "aa", "ab"]);
+ expect(sut.getTagsByPrefix("aa")).to.deep.equal(["aa"]);
+ expect(sut.getTagsByPrefix("b")).to.deep.equal(["b", "ba", "bb"]);
+ expect(sut.getTagsByPrefix("c")).to.be.empty;
});
});
- describe('#setCurrentFollowMode()/#getCurrentNewTabMode()/#getCurrentBackgroundMode', () => {
- it('updates and gets follow mode', () => {
+ describe("#setCurrentFollowMode()/#getCurrentNewTabMode()/#getCurrentBackgroundMode", () => {
+ it("updates and gets follow mode", () => {
sut.setCurrentFollowMode(false, true);
expect(sut.getCurrentNewTabMode()).to.be.false;
expect(sut.getCurrentBackgroundMode()).to.be.true;
diff --git a/test/content/repositories/FollowSlaveRepository.test.ts b/test/content/repositories/FollowSlaveRepository.test.ts
index 10cf094..0f829b2 100644
--- a/test/content/repositories/FollowSlaveRepository.test.ts
+++ b/test/content/repositories/FollowSlaveRepository.test.ts
@@ -1,16 +1,17 @@
-import FollowSlaveRepository, { FollowSlaveRepositoryImpl }
- from '../../../src/content/repositories/FollowSlaveRepository';
-import { expect } from 'chai';
+import FollowSlaveRepository, {
+ FollowSlaveRepositoryImpl,
+} from "../../../src/content/repositories/FollowSlaveRepository";
+import { expect } from "chai";
-describe('FollowSlaveRepository', () => {
+describe("FollowSlaveRepository", () => {
let sut: FollowSlaveRepository;
before(() => {
sut = new FollowSlaveRepositoryImpl();
});
- describe('#isFollowMode()/#enableFollowMode()/#disableFollowMode()', () => {
- it('gets, adds updates follow mode', () => {
+ describe("#isFollowMode()/#enableFollowMode()/#disableFollowMode()", () => {
+ it("gets, adds updates follow mode", () => {
expect(sut.isFollowMode()).to.be.false;
sut.enableFollowMode();
@@ -21,4 +22,3 @@ describe('FollowSlaveRepository', () => {
});
});
});
-
diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts
index 68f515c..0e01a73 100644
--- a/test/content/repositories/KeymapRepository.test.ts
+++ b/test/content/repositories/KeymapRepository.test.ts
@@ -1,39 +1,38 @@
-import KeymapRepository, { KeymapRepositoryImpl }
- from '../../../src/content/repositories/KeymapRepository';
-import { expect } from 'chai';
+import KeymapRepository, {
+ KeymapRepositoryImpl,
+} from "../../../src/content/repositories/KeymapRepository";
+import { expect } from "chai";
import Key from "../../../src/shared/settings/Key";
-describe('KeymapRepositoryImpl', () => {
+describe("KeymapRepositoryImpl", () => {
let sut: KeymapRepository;
before(() => {
sut = new KeymapRepositoryImpl();
});
- describe('#enqueueKey()', () => {
- it('enqueues keys', () => {
- sut.enqueueKey(Key.fromMapKey('a'));
- sut.enqueueKey(Key.fromMapKey('b'));
- const sequence = sut.enqueueKey(Key.fromMapKey('c'));
+ describe("#enqueueKey()", () => {
+ it("enqueues keys", () => {
+ sut.enqueueKey(Key.fromMapKey("a"));
+ sut.enqueueKey(Key.fromMapKey("b"));
+ const sequence = sut.enqueueKey(Key.fromMapKey("c"));
const keys = sequence.keys;
- expect(keys[0].equals(Key.fromMapKey('a'))).to.be.true;
- expect(keys[1].equals(Key.fromMapKey('b'))).to.be.true;
- expect(keys[2].equals(Key.fromMapKey('c'))).to.be.true;
+ expect(keys[0].equals(Key.fromMapKey("a"))).to.be.true;
+ expect(keys[1].equals(Key.fromMapKey("b"))).to.be.true;
+ expect(keys[2].equals(Key.fromMapKey("c"))).to.be.true;
});
});
- describe('#clear()', () => {
- it('clears keys', () => {
- sut.enqueueKey(Key.fromMapKey('a'));
- sut.enqueueKey(Key.fromMapKey('b'));
- sut.enqueueKey(Key.fromMapKey('c'));
+ describe("#clear()", () => {
+ it("clears keys", () => {
+ sut.enqueueKey(Key.fromMapKey("a"));
+ sut.enqueueKey(Key.fromMapKey("b"));
+ sut.enqueueKey(Key.fromMapKey("c"));
sut.clear();
- const sequence = sut.enqueueKey(Key.fromMapKey('a'));
+ const sequence = sut.enqueueKey(Key.fromMapKey("a"));
expect(sequence.length()).to.equal(1);
});
});
});
-
-
diff --git a/test/content/repositories/MarkKeyRepository.test.ts b/test/content/repositories/MarkKeyRepository.test.ts
index 8592332..473b4dc 100644
--- a/test/content/repositories/MarkKeyRepository.test.ts
+++ b/test/content/repositories/MarkKeyRepository.test.ts
@@ -1,16 +1,17 @@
-import MarkRepository, { MarkKeyRepositoryImpl }
- from '../../../src/content/repositories/MarkKeyRepository';
-import { expect } from 'chai';
+import MarkRepository, {
+ MarkKeyRepositoryImpl,
+} from "../../../src/content/repositories/MarkKeyRepository";
+import { expect } from "chai";
-describe('MarkKeyRepositoryImpl', () => {
+describe("MarkKeyRepositoryImpl", () => {
let sut: MarkRepository;
before(() => {
sut = new MarkKeyRepositoryImpl();
- })
+ });
- describe('#isSetMode/#enableSetMode/#disabeSetMode', () => {
- it('enables and disables set mode', () => {
+ describe("#isSetMode/#enableSetMode/#disabeSetMode", () => {
+ it("enables and disables set mode", () => {
expect(sut.isSetMode()).to.be.false;
sut.enableSetMode();
@@ -21,8 +22,8 @@ describe('MarkKeyRepositoryImpl', () => {
});
});
- describe('#isJumpMode/#enableJumpMode/#disabeJumpMode', () => {
- it('enables and disables jump mode', () => {
+ describe("#isJumpMode/#enableJumpMode/#disabeJumpMode", () => {
+ it("enables and disables jump mode", () => {
expect(sut.isJumpMode()).to.be.false;
sut.enableJumpMode();
@@ -33,4 +34,3 @@ describe('MarkKeyRepositoryImpl', () => {
});
});
});
-
diff --git a/test/content/repositories/MarkRepository.test.ts b/test/content/repositories/MarkRepository.test.ts
index 6ddd38d..f2a7326 100644
--- a/test/content/repositories/MarkRepository.test.ts
+++ b/test/content/repositories/MarkRepository.test.ts
@@ -1,13 +1,12 @@
-import { MarkRepositoryImpl } from '../../../src/content/repositories/MarkRepository';
-import { expect } from 'chai';
+import { MarkRepositoryImpl } from "../../../src/content/repositories/MarkRepository";
+import { expect } from "chai";
-describe('MarkRepositoryImpl', () => {
- it('save and load marks', () => {
+describe("MarkRepositoryImpl", () => {
+ it("save and load marks", () => {
const sut = new MarkRepositoryImpl();
- sut.set('a', { x: 10, y: 20 });
- expect(sut.get('a')).to.deep.equal({ x: 10, y: 20 });
- expect(sut.get('b')).to.be.null;
+ sut.set("a", { x: 10, y: 20 });
+ expect(sut.get("a")).to.deep.equal({ x: 10, y: 20 });
+ expect(sut.get("b")).to.be.null;
});
});
-
diff --git a/test/content/repositories/SettingRepository.test.ts b/test/content/repositories/SettingRepository.test.ts
index e45d7c4..99247a9 100644
--- a/test/content/repositories/SettingRepository.test.ts
+++ b/test/content/repositories/SettingRepository.test.ts
@@ -1,23 +1,23 @@
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import { expect } from 'chai';
-import Settings from '../../../src/shared/settings/Settings';
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import { expect } from "chai";
+import Settings from "../../../src/shared/settings/Settings";
-describe('SettingRepositoryImpl', () => {
- it('updates and gets current value', () => {
+describe("SettingRepositoryImpl", () => {
+ it("updates and gets current value", () => {
const sut = new SettingRepositoryImpl();
const settings = Settings.fromJSON({
keymaps: {},
- search:{
- default: 'google',
+ search: {
+ default: "google",
engines: {
- google: 'https://google.com/?q={}',
- }
+ google: "https://google.com/?q={}",
+ },
},
properties: {
- hintchars: 'abcd1234',
+ hintchars: "abcd1234",
smoothscroll: false,
- complete: 'sbh',
+ complete: "sbh",
},
blacklist: [],
});
@@ -25,6 +25,6 @@ describe('SettingRepositoryImpl', () => {
sut.set(settings);
const actual = sut.get();
- expect(actual.properties.hintchars).to.equal('abcd1234');
+ expect(actual.properties.hintchars).to.equal("abcd1234");
});
});
diff --git a/test/content/usecases/AddonEnabledUseCase.test.ts b/test/content/usecases/AddonEnabledUseCase.test.ts
index 8c15099..885da83 100644
--- a/test/content/usecases/AddonEnabledUseCase.test.ts
+++ b/test/content/usecases/AddonEnabledUseCase.test.ts
@@ -1,7 +1,7 @@
-import AddonEnabledRepository from '../../../src/content/repositories/AddonEnabledRepository';
-import AddonEnabledUseCase from '../../../src/content/usecases/AddonEnabledUseCase';
-import AddonIndicatorClient from '../../../src/content/client/AddonIndicatorClient';
-import { expect } from 'chai';
+import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
+import AddonEnabledUseCase from "../../../src/content/usecases/AddonEnabledUseCase";
+import AddonIndicatorClient from "../../../src/content/client/AddonIndicatorClient";
+import { expect } from "chai";
class MockAddonEnabledRepository implements AddonEnabledRepository {
private enabled: boolean;
@@ -28,11 +28,11 @@ class MockAddonIndicatorClient implements AddonIndicatorClient {
async setEnabled(enabled: boolean): Promise<void> {
this.enabled = enabled;
- return
+ return;
}
}
-describe('AddonEnabledUseCase', () => {
+describe("AddonEnabledUseCase", () => {
let repository: MockAddonEnabledRepository;
let indicator: MockAddonIndicatorClient;
let sut: AddonEnabledUseCase;
@@ -43,8 +43,8 @@ describe('AddonEnabledUseCase', () => {
sut = new AddonEnabledUseCase(indicator, repository);
});
- describe('#enable', () => {
- it('store and indicate as enabled', async() => {
+ describe("#enable", () => {
+ it("store and indicate as enabled", async () => {
await sut.enable();
expect(repository.get()).to.be.true;
@@ -52,8 +52,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#disable', async() => {
- it('store and indicate as disabled', async() => {
+ describe("#disable", async () => {
+ it("store and indicate as disabled", async () => {
await sut.disable();
expect(repository.get()).to.be.false;
@@ -61,8 +61,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#toggle', () => {
- it('toggled enabled and disabled', async() => {
+ describe("#toggle", () => {
+ it("toggled enabled and disabled", async () => {
repository.set(true);
await sut.toggle();
@@ -78,8 +78,8 @@ describe('AddonEnabledUseCase', () => {
});
});
- describe('#getEnabled', () => {
- it('returns current addon enabled', () => {
+ describe("#getEnabled", () => {
+ it("returns current addon enabled", () => {
repository.set(true);
expect(sut.getEnabled()).to.be.true;
diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts
index 3cc82fe..5de3e69 100644
--- a/test/content/usecases/ClipboardUseCase.test.ts
+++ b/test/content/usecases/ClipboardUseCase.test.ts
@@ -1,14 +1,14 @@
-import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository';
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase';
-import OperationClient from '../../../src/content/client/OperationClient';
-import ConsoleClient from '../../../src/content/client/ConsoleClient';
+import ClipboardRepository from "../../../src/content/repositories/ClipboardRepository";
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import ClipboardUseCase from "../../../src/content/usecases/ClipboardUseCase";
+import OperationClient from "../../../src/content/client/OperationClient";
+import ConsoleClient from "../../../src/content/client/ConsoleClient";
-import * as sinon from 'sinon';
-import { expect } from 'chai';
-import {Operation} from "../../../src/shared/operations";
+import * as sinon from "sinon";
+import { expect } from "chai";
+import { Operation } from "../../../src/shared/operations";
-describe('ClipboardUseCase', () => {
+describe("ClipboardUseCase", () => {
let clipboardRepository: ClipboardRepository;
let operationClient: OperationClient;
@@ -18,34 +18,48 @@ describe('ClipboardUseCase', () => {
let sut: ClipboardUseCase;
beforeEach(() => {
- clipboardRepository = new class implements ClipboardRepository {
- read(): string { return ""; }
+ clipboardRepository = new (class implements ClipboardRepository {
+ read(): string {
+ return "";
+ }
write(_text: string) {}
- };
- operationClient = new class implements OperationClient {
- execBackgroundOp(_repeat: number, _op: Operation): Promise<void> { return Promise.resolve() }
- internalOpenUrl(_url: string, _newTab?: boolean, _background?: boolean): Promise<void> { return Promise.resolve() }
- };
- consoleClient = new class implements ConsoleClient {
- error(_text: string): Promise<void> { return Promise.resolve() }
- info(_text: string): Promise<void> { return Promise.resolve() }
- };
+ })();
+ operationClient = new (class implements OperationClient {
+ execBackgroundOp(_repeat: number, _op: Operation): Promise<void> {
+ return Promise.resolve();
+ }
+ internalOpenUrl(
+ _url: string,
+ _newTab?: boolean,
+ _background?: boolean
+ ): Promise<void> {
+ return Promise.resolve();
+ }
+ })();
+ consoleClient = new (class implements ConsoleClient {
+ error(_text: string): Promise<void> {
+ return Promise.resolve();
+ }
+ info(_text: string): Promise<void> {
+ return Promise.resolve();
+ }
+ })();
sut = new ClipboardUseCase(
clipboardRepository,
new SettingRepositoryImpl(),
consoleClient,
- operationClient,
- );
+ operationClient
+ );
});
- describe('#yankCurrentURL', () => {
- it('yanks current url', async () => {
+ describe("#yankCurrentURL", () => {
+ it("yanks current url", async () => {
const href = window.location.href;
const mockRepository = sinon.mock(clipboardRepository);
- mockRepository.expects('write').withArgs(href);
+ mockRepository.expects("write").withArgs(href);
const mockConsoleClient = sinon.mock(consoleClient);
- mockConsoleClient.expects('info').withArgs('Yanked ' + href);
+ mockConsoleClient.expects("info").withArgs("Yanked " + href);
const yanked = await sut.yankCurrentURL();
@@ -55,23 +69,23 @@ describe('ClipboardUseCase', () => {
});
});
- describe('#openOrSearch', () => {
- it('opens url from the clipboard', async () => {
- const url = 'https://github.com/ueokande/vim-vixen'
- sinon.stub(clipboardRepository, 'read').returns(url);
+ describe("#openOrSearch", () => {
+ it("opens url from the clipboard", async () => {
+ const url = "https://github.com/ueokande/vim-vixen";
+ sinon.stub(clipboardRepository, "read").returns(url);
const mockOperationClient = sinon.mock(operationClient);
- mockOperationClient.expects('internalOpenUrl').withArgs(url, true);
+ mockOperationClient.expects("internalOpenUrl").withArgs(url, true);
await sut.openOrSearch(true);
mockOperationClient.verify();
});
- it('opens search results from the clipboard', async () => {
- const url = 'https://google.com/search?q=banana';
- sinon.stub(clipboardRepository, 'read').returns('banana');
+ it("opens search results from the clipboard", async () => {
+ const url = "https://google.com/search?q=banana";
+ sinon.stub(clipboardRepository, "read").returns("banana");
const mockOperationClient = sinon.mock(operationClient);
- mockOperationClient.expects('internalOpenUrl').withArgs(url, true);
+ mockOperationClient.expects("internalOpenUrl").withArgs(url, true);
await sut.openOrSearch(true);
diff --git a/test/content/usecases/FindUseCase.test.ts b/test/content/usecases/FindUseCase.test.ts
index 3978dbc..b53ef74 100644
--- a/test/content/usecases/FindUseCase.test.ts
+++ b/test/content/usecases/FindUseCase.test.ts
@@ -1,9 +1,9 @@
-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';
+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;
@@ -27,7 +27,7 @@ class MockFindPresenter implements FindPresenter {
public highlighted: boolean;
constructor() {
- this.document = '';
+ this.document = "";
this.highlighted = false;
}
@@ -59,7 +59,7 @@ class MockFindClient implements FindClient {
}
}
-describe('FindUseCase', () => {
+describe("FindUseCase", () => {
let repository: MockFindRepository;
let presenter: MockFindPresenter;
let client: MockFindClient;
@@ -74,88 +74,87 @@ describe('FindUseCase', () => {
sut = new FindUseCase(presenter, repository, client, consoleClient);
});
- describe('#startFind', () => {
- it('find next by ketword', async() => {
- presenter.document = 'monkey punch';
+ describe("#startFind", () => {
+ it("find next by ketword", async () => {
+ presenter.document = "monkey punch";
- await sut.startFind('monkey');
+ 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');
+ 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';
+ 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');
+ 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';
+ it("find next by global last keyword", async () => {
+ presenter.document = "chimpanzee typing";
repository.keyword = null;
- client.keyword = 'chimpanzee';
+ 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');
+ 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';
+ it("find not found error", async () => {
+ presenter.document = "zoo";
- await sut.startFind('giraffe');
+ 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');
+ 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() => {
+ 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.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';
+ 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');
+ expect(await consoleClient.text).to.equal("Pattern found: monkey");
});
- it('show errors when no last keywords', async() => {
+ 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.text).to.equal("No previous search keywords");
expect(await consoleClient.isError).to.be.true;
});
});
- describe('#findPrev', () => {
- });
+ describe("#findPrev", () => {});
});
diff --git a/test/content/usecases/HintKeyProducer.test.ts b/test/content/usecases/HintKeyProducer.test.ts
index 5841ae9..f7e02ea 100644
--- a/test/content/usecases/HintKeyProducer.test.ts
+++ b/test/content/usecases/HintKeyProducer.test.ts
@@ -1,20 +1,34 @@
-import HintKeyProducer from '../../../src/content/usecases/HintKeyProducer';
-import { expect } from 'chai';
+import HintKeyProducer from "../../../src/content/usecases/HintKeyProducer";
+import { expect } from "chai";
-describe('HintKeyProducer class', () => {
- describe('#constructor', () => {
- it('throws an exception on empty charset', () => {
- expect(() => new HintKeyProducer('')).to.throw(TypeError);
+describe("HintKeyProducer class", () => {
+ describe("#constructor", () => {
+ it("throws an exception on empty charset", () => {
+ expect(() => new HintKeyProducer("")).to.throw(TypeError);
});
});
- describe('#produce', () => {
- it('produce incremented keys', () => {
- const charset = 'abc';
+ describe("#produce", () => {
+ it("produce incremented keys", () => {
+ const charset = "abc";
const sequences = [
- 'a', 'b', 'c',
- 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc',
- 'aaa', 'aab', 'aac', 'aba']
+ "a",
+ "b",
+ "c",
+ "aa",
+ "ab",
+ "ac",
+ "ba",
+ "bb",
+ "bc",
+ "ca",
+ "cb",
+ "cc",
+ "aaa",
+ "aab",
+ "aac",
+ "aba",
+ ];
const producer = new HintKeyProducer(charset);
for (let i = 0; i < sequences.length; ++i) {
diff --git a/test/content/usecases/KeymapUseCase.test.ts b/test/content/usecases/KeymapUseCase.test.ts
index 032d4fc..24ac6d8 100644
--- a/test/content/usecases/KeymapUseCase.test.ts
+++ b/test/content/usecases/KeymapUseCase.test.ts
@@ -1,62 +1,52 @@
import "reflect-metadata";
-import KeymapUseCase from '../../../src/content/usecases/KeymapUseCase';
-import {expect} from 'chai';
+import KeymapUseCase from "../../../src/content/usecases/KeymapUseCase";
+import { expect } from "chai";
import SettingRepository from "../../../src/content/repositories/SettingRepository";
import Settings from "../../../src/shared/settings/Settings";
import AddonEnabledRepository from "../../../src/content/repositories/AddonEnabledRepository";
-import {KeymapRepositoryImpl} from "../../../src/content/repositories/KeymapRepository";
+import { KeymapRepositoryImpl } from "../../../src/content/repositories/KeymapRepository";
import Key from "../../../src/shared/settings/Key";
import AddressRepository from "../../../src/content/repositories/AddressRepository";
class MockSettingRepository implements SettingRepository {
- constructor(
- private readonly settings: Settings,
- ) {
- }
+ constructor(private readonly settings: Settings) {}
get(): Settings {
return this.settings;
}
set(_setting: Settings): void {
- throw new Error('TODO');
+ throw new Error("TODO");
}
}
class MockAddonEnabledRepository implements AddonEnabledRepository {
- constructor(
- private readonly enabled: boolean,
- ) {
- }
+ constructor(private readonly enabled: boolean) {}
get(): boolean {
return this.enabled;
}
set(_on: boolean): void {
- throw new Error('TODO');
+ throw new Error("TODO");
}
}
class MockAddressRepository implements AddressRepository {
- constructor(
- private url: URL,
- ) {
- }
+ constructor(private url: URL) {}
getCurrentURL(): URL {
return this.url;
}
}
-
-describe('KeymapUseCase', () => {
- context('with no-digis keymaps', () => {
+describe("KeymapUseCase", () => {
+ context("with no-digis keymaps", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- j: {type: 'scroll.vertically', count: 1},
- gg: {type: 'scroll.top'},
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ gg: { type: "scroll.top" },
},
});
@@ -64,34 +54,46 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns matched operation', () => {
- expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: -1}});
- expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: 1}});
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}});
- expect(sut.nextOps(Key.fromMapKey('z'))).to.be.null;
+ it("returns matched operation", () => {
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: -1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: 1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("z"))).to.be.null;
});
- it('repeats n-times by numeric prefix and multiple key operations', () => {
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}});
+ it("repeats n-times by numeric prefix and multiple key operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 10,
+ op: { type: "scroll.top" },
+ });
});
});
- context('when keymaps containing numeric mappings', () => {
+ context("when keymaps containing numeric mappings", () => {
const settings = Settings.fromJSON({
keymaps: {
- 20: {type: "scroll.top"},
- g5: {type: 'scroll.bottom'},
+ 20: { type: "scroll.top" },
+ g5: { type: "scroll.bottom" },
},
});
@@ -99,43 +101,55 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns the matched operation ends with digit', () => {
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 1, op: { type: 'scroll.bottom'}});
+ it("returns the matched operation ends with digit", () => {
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.bottom" },
+ });
});
- it('returns an operation matched the operation with digit keymaps', () => {
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.deep.equal({ repeat: 1, op: { type: 'scroll.top'}});
+ it("returns an operation matched the operation with digit keymaps", () => {
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
});
- it('returns operations repeated by numeric prefix', () => {
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 2, op: { type: 'scroll.bottom'}});
+ it("returns operations repeated by numeric prefix", () => {
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 2,
+ op: { type: "scroll.bottom" },
+ });
});
- it('does not matches with digit operation with numeric prefix', () => {
- expect(sut.nextOps(Key.fromMapKey('3'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('2'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('5'))).to.be.deep.equal({ repeat: 320, op: { type: 'scroll.bottom'}});
+ it("does not matches with digit operation with numeric prefix", () => {
+ expect(sut.nextOps(Key.fromMapKey("3"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("2"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("5"))).to.be.deep.equal({
+ repeat: 320,
+ op: { type: "scroll.bottom" },
+ });
});
});
- context('when the keys are mismatched with the operations', () => {
+ context("when the keys are mismatched with the operations", () => {
const settings = Settings.fromJSON({
keymaps: {
- gg: {type: "scroll.top"},
- G: {type: "scroll.bottom"},
+ gg: { type: "scroll.top" },
+ G: { type: "scroll.bottom" },
},
});
@@ -143,38 +157,44 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('clears input keys with no-matched operations', () => {
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('x'))).to.be.null; // clear
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({repeat: 1, op: {type: "scroll.top"}});
+ it("clears input keys with no-matched operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
});
- it('clears input keys and the prefix with no-matched operations', () => {
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('x'))).to.be.null; // clear
- expect(sut.nextOps(Key.fromMapKey('1'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('0'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 10, op: {type: "scroll.top"}});
+ it("clears input keys and the prefix with no-matched operations", () => {
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("x"))).to.be.null; // clear
+ expect(sut.nextOps(Key.fromMapKey("1"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("0"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 10,
+ op: { type: "scroll.top" },
+ });
});
});
- context('when the site matches to the blacklist', () => {
+ context("when the site matches to the blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- a: {type: 'addon.enable'},
- b: {type: 'addon.toggle.enabled'},
+ k: { type: "scroll.vertically", count: -1 },
+ a: { type: "addon.enable" },
+ b: { type: "addon.toggle.enabled" },
},
});
@@ -182,58 +202,76 @@ describe('KeymapUseCase', () => {
before(() => {
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(false),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(false),
+ new MockAddressRepository(new URL("https://example.com"))
);
});
- it('returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation', () => {
- expect(sut.nextOps(Key.fromMapKey('k'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('a'))).to.deep.equal({ repeat: 1, op: {type: 'addon.enable'}});
- expect(sut.nextOps(Key.fromMapKey('b'))).to.deep.equal({ repeat: 1, op: {type: 'addon.toggle.enabled'}});
+ it("returns only ADDON_ENABLE and ADDON_TOGGLE_ENABLED operation", () => {
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("a"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "addon.enable" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("b"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "addon.toggle.enabled" },
+ });
});
});
- context('when the site matches to the partial blacklist', () => {
+ context("when the site matches to the partial blacklist", () => {
const settings = Settings.fromJSON({
keymaps: {
- k: {type: 'scroll.vertically', count: -1},
- j: {type: 'scroll.vertically', count: 1},
- gg: {type: "scroll.top"},
- G: {type: "scroll.bottom"},
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ gg: { type: "scroll.top" },
+ G: { type: "scroll.bottom" },
},
blacklist: [
- { url: "example.com", keys: ['g'] },
- { url: "example.org", keys: ['<S-G>'] }
+ { url: "example.com", keys: ["g"] },
+ { url: "example.org", keys: ["<S-G>"] },
],
});
- it('blocks keys in the partial blacklist', () => {
+ it("blocks keys in the partial blacklist", () => {
let sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.com')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.com"))
);
- expect(sut.nextOps(Key.fromMapKey('k'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: -1}});
- expect(sut.nextOps(Key.fromMapKey('j'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.vertically', count: 1}});
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('G'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.bottom'}});
+ expect(sut.nextOps(Key.fromMapKey("k"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: -1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("j"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.vertically", count: 1 },
+ });
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("G"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.bottom" },
+ });
sut = new KeymapUseCase(
- new KeymapRepositoryImpl(),
- new MockSettingRepository(settings),
- new MockAddonEnabledRepository(true),
- new MockAddressRepository(new URL('https://example.org')),
+ new KeymapRepositoryImpl(),
+ new MockSettingRepository(settings),
+ new MockAddonEnabledRepository(true),
+ new MockAddressRepository(new URL("https://example.org"))
);
- expect(sut.nextOps(Key.fromMapKey('g'))).to.be.null;
- expect(sut.nextOps(Key.fromMapKey('g'))).to.deep.equal({ repeat: 1, op: {type: 'scroll.top'}});
- expect(sut.nextOps(Key.fromMapKey('G'))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.be.null;
+ expect(sut.nextOps(Key.fromMapKey("g"))).to.deep.equal({
+ repeat: 1,
+ op: { type: "scroll.top" },
+ });
+ expect(sut.nextOps(Key.fromMapKey("G"))).to.be.null;
});
});
});
diff --git a/test/content/usecases/MarkUseCase.test.ts b/test/content/usecases/MarkUseCase.test.ts
index 494497a..df3f7bf 100644
--- a/test/content/usecases/MarkUseCase.test.ts
+++ b/test/content/usecases/MarkUseCase.test.ts
@@ -1,14 +1,14 @@
-import MarkRepository from '../../../src/content/repositories/MarkRepository';
-import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
-import MarkUseCase from '../../../src/content/usecases/MarkUseCase';
-import MarkClient from '../../../src/content/client/MarkClient';
-import MockConsoleClient from '../mock/MockConsoleClient';
-import MockScrollPresenter from '../mock/MockScrollPresenter';
-import Mark from '../../../src/content/domains/Mark';
-import { expect } from 'chai';
+import MarkRepository from "../../../src/content/repositories/MarkRepository";
+import { SettingRepositoryImpl } from "../../../src/content/repositories/SettingRepository";
+import MarkUseCase from "../../../src/content/usecases/MarkUseCase";
+import MarkClient from "../../../src/content/client/MarkClient";
+import MockConsoleClient from "../mock/MockConsoleClient";
+import MockScrollPresenter from "../mock/MockScrollPresenter";
+import Mark from "../../../src/content/domains/Mark";
+import { expect } from "chai";
class MockMarkRepository implements MarkRepository {
- private current: {[key: string]: Mark};
+ private current: { [key: string]: Mark };
constructor() {
this.current = {};
@@ -24,12 +24,12 @@ class MockMarkRepository implements MarkRepository {
}
class MockMarkClient implements MarkClient {
- public marks: {[key: string]: Mark};
+ public marks: { [key: string]: Mark };
public last: string;
constructor() {
this.marks = {};
- this.last = '';
+ this.last = "";
}
setGloablMark(key: string, mark: Mark): Promise<void> {
@@ -38,12 +38,12 @@ class MockMarkClient implements MarkClient {
}
jumpGlobalMark(key: string): Promise<void> {
- this.last = key
+ this.last = key;
return Promise.resolve();
}
}
-describe('MarkUseCase', () => {
+describe("MarkUseCase", () => {
let repository: MockMarkRepository;
let client: MockMarkClient;
let consoleClient: MockConsoleClient;
@@ -60,53 +60,56 @@ describe('MarkUseCase', () => {
client,
repository,
new SettingRepositoryImpl(),
- consoleClient,
+ consoleClient
);
});
- describe('#set', () => {
- it('sets local mark', async() => {
+ describe("#set", () => {
+ it("sets local mark", async () => {
scrollPresenter.scrollTo(10, 20, false);
- await sut.set('x');
+ await sut.set("x");
- expect(repository.get('x')).to.deep.equals({ x: 10, y: 20 });
+ expect(repository.get("x")).to.deep.equals({ x: 10, y: 20 });
expect(consoleClient.text).to.equal("Set local mark to 'x'");
});
- it('sets global mark', async() => {
+ it("sets global mark", async () => {
scrollPresenter.scrollTo(30, 40, false);
- await sut.set('Z');
+ await sut.set("Z");
- expect(client.marks['Z']).to.deep.equals({ x: 30, y: 40 });
+ expect(client.marks["Z"]).to.deep.equals({ x: 30, y: 40 });
expect(consoleClient.text).to.equal("Set global mark to 'Z'");
});
});
- describe('#jump', () => {
- it('jumps to local mark', async() => {
- repository.set('x', { x: 20, y: 40 });
+ describe("#jump", () => {
+ it("jumps to local mark", async () => {
+ repository.set("x", { x: 20, y: 40 });
- await sut.jump('x');
+ await sut.jump("x");
expect(scrollPresenter.getScroll()).to.deep.equals({ x: 20, y: 40 });
});
- it('throws an error when no local marks', () => {
- return sut.jump('a').then(() => {
- throw new Error('error');
- }).catch((e) => {
- expect(e).to.be.instanceof(Error);
- })
- })
+ it("throws an error when no local marks", () => {
+ return sut
+ .jump("a")
+ .then(() => {
+ throw new Error("error");
+ })
+ .catch((e) => {
+ expect(e).to.be.instanceof(Error);
+ });
+ });
- it('jumps to global mark', async() => {
- client.marks['Z'] = { x: 20, y: 0 };
+ it("jumps to global mark", async () => {
+ client.marks["Z"] = { x: 20, y: 0 };
- await sut.jump('Z');
+ await sut.jump("Z");
- expect(client.last).to.equal('Z')
+ expect(client.last).to.equal("Z");
});
});
});
diff --git a/test/content/usecases/SettingUseCaase.test.ts b/test/content/usecases/SettingUseCaase.test.ts
index cf14e6e..19a167a 100644
--- a/test/content/usecases/SettingUseCaase.test.ts
+++ b/test/content/usecases/SettingUseCaase.test.ts
@@ -1,8 +1,10 @@
-import SettingRepository from '../../../src/content/repositories/SettingRepository';
-import SettingClient from '../../../src/content/client/SettingClient';
-import SettingUseCase from '../../../src/content/usecases/SettingUseCase';
-import Settings, { DefaultSetting } from '../../../src/shared/settings/Settings';
-import { expect } from 'chai';
+import SettingRepository from "../../../src/content/repositories/SettingRepository";
+import SettingClient from "../../../src/content/client/SettingClient";
+import SettingUseCase from "../../../src/content/usecases/SettingUseCase";
+import Settings, {
+ DefaultSetting,
+} from "../../../src/shared/settings/Settings";
+import { expect } from "chai";
class MockSettingRepository implements SettingRepository {
private current: Settings;
@@ -12,7 +14,7 @@ class MockSettingRepository implements SettingRepository {
}
set(settings: Settings): void {
- this.current= settings;
+ this.current = settings;
}
get(): Settings {
@@ -32,7 +34,7 @@ class MockSettingClient implements SettingClient {
}
}
-describe('AddonEnabledUseCase', () => {
+describe("AddonEnabledUseCase", () => {
let repository: MockSettingRepository;
let client: MockSettingClient;
let sut: SettingUseCase;
@@ -41,15 +43,15 @@ describe('AddonEnabledUseCase', () => {
const testSettings = {
keymaps: {},
search: {
- default: 'google',
+ default: "google",
engines: {
- google: 'https://google.com/?q={}',
- }
+ google: "https://google.com/?q={}",
+ },
},
properties: {
- hintchars: 'abcd1234',
+ hintchars: "abcd1234",
smoothscroll: false,
- complete: 'sbh',
+ complete: "sbh",
},
blacklist: [],
};
@@ -59,13 +61,13 @@ describe('AddonEnabledUseCase', () => {
sut = new SettingUseCase(repository, client);
});
- describe('#reload', () => {
- it('loads settings and store to repository', async() => {
+ describe("#reload", () => {
+ it("loads settings and store to repository", async () => {
const settings = await sut.reload();
- expect(settings.properties.hintchars).to.equal('abcd1234');
+ expect(settings.properties.hintchars).to.equal("abcd1234");
const saved = repository.get();
- expect(saved.properties.hintchars).to.equal('abcd1234');
+ expect(saved.properties.hintchars).to.equal("abcd1234");
});
});
});
diff --git a/test/main.ts b/test/main.ts
index c985546..8097975 100644
--- a/test/main.ts
+++ b/test/main.ts
@@ -1,6 +1,6 @@
-import 'reflect-metadata';
-import { expect } from 'chai';
-import browserFake from 'webextensions-api-fake';
+import "reflect-metadata";
+import { expect } from "chai";
+import browserFake from "webextensions-api-fake";
global.expect = expect;
global.browser = browserFake();
diff --git a/test/settings/components/form/BlacklistForm.test.tsx b/test/settings/components/form/BlacklistForm.test.tsx
index 6c329ff..4d79383 100644
--- a/test/settings/components/form/BlacklistForm.test.tsx
+++ b/test/settings/components/form/BlacklistForm.test.tsx
@@ -1,40 +1,44 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestRenderer from 'react-test-renderer';
-import ReactTestUtils from 'react-dom/test-utils';
-import { expect } from 'chai'
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactTestRenderer from "react-test-renderer";
+import ReactTestUtils from "react-dom/test-utils";
+import { expect } from "chai";
-import BlacklistForm from '../../../../src/settings/components/form/BlacklistForm'
-import Blacklist from '../../../../src/shared/settings/Blacklist';
+import BlacklistForm from "../../../../src/settings/components/form/BlacklistForm";
+import Blacklist from "../../../../src/shared/settings/Blacklist";
describe("settings/form/BlacklistForm", () => {
- describe('render', () => {
- it('renders BlacklistForm', () => {
+ describe("render", () => {
+ it("renders BlacklistForm", () => {
const root = ReactTestRenderer.create(
- <BlacklistForm value={Blacklist.fromJSON(['*.slack.com', 'www.google.com/maps'])} />,
+ <BlacklistForm
+ value={Blacklist.fromJSON(["*.slack.com", "www.google.com/maps"])}
+ />
).root;
const children = root.children[0].children;
expect(children).to.have.lengthOf(3);
- expect(children[0].children[0].props.value).to.equal('*.slack.com');
- expect(children[1].children[0].props.value).to.equal('www.google.com/maps');
- expect(children[2].props.name).to.equal('add');
+ expect(children[0].children[0].props.value).to.equal("*.slack.com");
+ expect(children[1].children[0].props.value).to.equal(
+ "www.google.com/maps"
+ );
+ expect(children[2].props.name).to.equal("add");
});
- it('renders blank value', () => {
+ it("renders blank value", () => {
const root = ReactTestRenderer.create(<BlacklistForm />).root;
const children = root.children[0].children;
expect(children).to.have.lengthOf(1);
- expect(children[0].props.name).to.equal('add');
+ expect(children[0].props.name).to.equal("add");
});
});
- describe('onChange', () => {
+ describe("onChange", () => {
let container;
beforeEach(() => {
- container = document.createElement('div');
+ container = document.createElement("div");
document.body.appendChild(container);
});
@@ -43,52 +47,64 @@ describe("settings/form/BlacklistForm", () => {
container = null;
});
- it('invokes onChange event on edit', (done) => {
+ it("invokes onChange event on edit", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<BlacklistForm
- value={Blacklist.fromJSON(['*.slack.com', 'www.google.com/maps*'])}
- onChange={value => {
- const urls = value.items.map(item => item.pattern);
- expect(urls).to.have.members(['gitter.im', 'www.google.com/maps*']);
- done();
- }}
- />, container)
+ ReactDOM.render(
+ <BlacklistForm
+ value={Blacklist.fromJSON(["*.slack.com", "www.google.com/maps*"])}
+ onChange={(value) => {
+ const urls = value.items.map((item) => item.pattern);
+ expect(urls).to.have.members([
+ "gitter.im",
+ "www.google.com/maps*",
+ ]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelectorAll('input[type=text]')[0];
- input.value = 'gitter.im';
+ const input = document.querySelectorAll("input[type=text]")[0];
+ input.value = "gitter.im";
ReactTestUtils.Simulate.change(input);
});
- it('invokes onChange event on delete', (done) => {
+ it("invokes onChange event on delete", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<BlacklistForm
- value={Blacklist.fromJSON(['*.slack.com', 'www.google.com/maps*'])}
- onChange={value => {
- const urls = value.items.map(item => item.pattern);
- expect(urls).to.have.members(['www.google.com/maps*']);
- done();
- }}
- />, container)
+ ReactDOM.render(
+ <BlacklistForm
+ value={Blacklist.fromJSON(["*.slack.com", "www.google.com/maps*"])}
+ onChange={(value) => {
+ const urls = value.items.map((item) => item.pattern);
+ expect(urls).to.have.members(["www.google.com/maps*"]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const button = document.querySelectorAll('input[type=button]')[0];
+ const button = document.querySelectorAll("input[type=button]")[0];
ReactTestUtils.Simulate.click(button);
});
- it('invokes onChange event on add', (done) => {
+ it("invokes onChange event on add", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<BlacklistForm
- value={Blacklist.fromJSON(['*.slack.com'])}
- onChange={value => {
- const urls = value.items.map(item => item.pattern);
- expect(urls).to.have.members(['*.slack.com', '']);
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <BlacklistForm
+ value={Blacklist.fromJSON(["*.slack.com"])}
+ onChange={(value) => {
+ const urls = value.items.map((item) => item.pattern);
+ expect(urls).to.have.members(["*.slack.com", ""]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const button = document.querySelector('input[type=button].ui-add-button');
+ const button = document.querySelector("input[type=button].ui-add-button");
ReactTestUtils.Simulate.click(button);
});
});
diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx
index ccc772c..0a88db5 100644
--- a/test/settings/components/form/KeymapsForm.test.tsx
+++ b/test/settings/components/form/KeymapsForm.test.tsx
@@ -1,27 +1,31 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestRenderer from 'react-test-renderer';
-import ReactTestUtils from 'react-dom/test-utils';
-import KeymapsForm from '../../../../src/settings/components/form/KeymapsForm'
-import { FormKeymaps } from 'shared/SettingData';
-import { expect } from 'chai';
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactTestRenderer from "react-test-renderer";
+import ReactTestUtils from "react-dom/test-utils";
+import KeymapsForm from "../../../../src/settings/components/form/KeymapsForm";
+import { FormKeymaps } from "shared/SettingData";
+import { expect } from "chai";
describe("settings/form/KeymapsForm", () => {
- describe('render', () => {
- it('renders keymap fields', () => {
- const root = ReactTestRenderer.create(<KeymapsForm value={FormKeymaps.fromJSON({
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.vertically?{"count":-1}': 'k',
- })} />).root
+ describe("render", () => {
+ it("renders keymap fields", () => {
+ const root = ReactTestRenderer.create(
+ <KeymapsForm
+ value={FormKeymaps.fromJSON({
+ 'scroll.vertically?{"count":1}': "j",
+ 'scroll.vertically?{"count":-1}': "k",
+ })}
+ />
+ ).root;
const inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' });
const inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' });
- expect(inputj.props.value).to.equal('j');
- expect(inputk.props.value).to.equal('k');
+ expect(inputj.props.value).to.equal("j");
+ expect(inputk.props.value).to.equal("k");
});
- it('renders blank value', () => {
+ it("renders blank value", () => {
const root = ReactTestRenderer.create(<KeymapsForm />).root;
const inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' });
@@ -32,11 +36,11 @@ describe("settings/form/KeymapsForm", () => {
});
});
- describe('onChange event', () => {
+ describe("onChange event", () => {
let container;
beforeEach(() => {
- container = document.createElement('div');
+ container = document.createElement("div");
document.body.appendChild(container);
});
@@ -45,21 +49,27 @@ describe("settings/form/KeymapsForm", () => {
container = null;
});
- it('invokes onChange event on edit', (done) => {
+ it("invokes onChange event on edit", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<KeymapsForm
- value={FormKeymaps.fromJSON({
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.vertically?{"count":-1}': 'k',
- })}
- onChange={value => {
- expect(value.toJSON()['scroll.vertically?{"count":1}']).to.equal('jjj');
- done();
- }} />, container);
+ ReactDOM.render(
+ <KeymapsForm
+ value={FormKeymaps.fromJSON({
+ 'scroll.vertically?{"count":1}': "j",
+ 'scroll.vertically?{"count":-1}': "k",
+ })}
+ onChange={(value) => {
+ expect(value.toJSON()['scroll.vertically?{"count":1}']).to.equal(
+ "jjj"
+ );
+ done();
+ }}
+ />,
+ container
+ );
});
const input = document.getElementById('scroll.vertically?{"count":1}');
- input.value = 'jjj';
+ input.value = "jjj";
ReactTestUtils.Simulate.change(input);
});
});
diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx
index 4a0e25a..4dc00a2 100644
--- a/test/settings/components/form/PropertiesForm.test.tsx
+++ b/test/settings/components/form/PropertiesForm.test.tsx
@@ -1,47 +1,47 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestRenderer from 'react-test-renderer';
-import ReactTestUtils from 'react-dom/test-utils';
-import PropertiesForm from 'settings/components/form/PropertiesForm'
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactTestRenderer from "react-test-renderer";
+import ReactTestUtils from "react-dom/test-utils";
+import PropertiesForm from "settings/components/form/PropertiesForm";
describe("settings/form/PropertiesForm", () => {
- describe('render', () => {
- it('renders PropertiesForm', () => {
+ describe("render", () => {
+ it("renders PropertiesForm", () => {
const types = {
- mystr: 'string',
- mynum: 'number',
- mybool: 'boolean',
- empty: 'string',
- }
+ mystr: "string",
+ mynum: "number",
+ mybool: "boolean",
+ empty: "string",
+ };
const values = {
- mystr: 'abc',
+ mystr: "abc",
mynum: 123,
mybool: true,
};
const root = ReactTestRenderer.create(
- <PropertiesForm types={types} value={values} />,
- ).root
+ <PropertiesForm types={types} value={values} />
+ ).root;
- let input = root.findByProps({ name: 'mystr' });
- expect(input.props.type).to.equals('text');
- expect(input.props.value).to.equal('abc');
+ let input = root.findByProps({ name: "mystr" });
+ expect(input.props.type).to.equals("text");
+ expect(input.props.value).to.equal("abc");
- input = root.findByProps({ name: 'mynum' });
- expect(input.props.type).to.equals('number');
+ input = root.findByProps({ name: "mynum" });
+ expect(input.props.type).to.equals("number");
expect(input.props.value).to.equal(123);
- input = root.findByProps({ name: 'mybool' });
- expect(input.props.type).to.equals('checkbox');
+ input = root.findByProps({ name: "mybool" });
+ expect(input.props.type).to.equals("checkbox");
expect(input.props.value).to.equal(true);
});
});
- describe('onChange', () => {
+ describe("onChange", () => {
let container;
beforeEach(() => {
- container = document.createElement('div');
+ container = document.createElement("div");
document.body.appendChild(container);
});
@@ -50,53 +50,62 @@ describe("settings/form/PropertiesForm", () => {
container = null;
});
- it('invokes onChange event on text changed', (done) => {
+ it("invokes onChange event on text changed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'string' }}
- value={{ 'myvalue': 'abc' }}
- onChange={value => {
- expect(value).to.have.property('myvalue', 'abcd');
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "string" }}
+ value={{ myvalue: "abc" }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", "abcd");
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
- input.value = 'abcd'
+ const input = document.querySelector("input[name=myvalue]");
+ input.value = "abcd";
ReactTestUtils.Simulate.change(input);
});
- it('invokes onChange event on number changeed', (done) => {
+ it("invokes onChange event on number changeed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'number' }}
- value={{ '': 123 }}
- onChange={value => {
- expect(value).to.have.property('myvalue', 1234);
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "number" }}
+ value={{ "": 123 }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", 1234);
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
- input.value = '1234'
+ const input = document.querySelector("input[name=myvalue]");
+ input.value = "1234";
ReactTestUtils.Simulate.change(input);
});
- it('invokes onChange event on checkbox changed', (done) => {
+ it("invokes onChange event on checkbox changed", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<PropertiesForm
- types={{ 'myvalue': 'boolean' }}
- value={{ 'myvalue': false }}
- onChange={value => {
- expect(value).to.have.property('myvalue', true);
- done();
- }}
- />, container);
+ ReactDOM.render(
+ <PropertiesForm
+ types={{ myvalue: "boolean" }}
+ value={{ myvalue: false }}
+ onChange={(value) => {
+ expect(value).to.have.property("myvalue", true);
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input[name=myvalue]');
+ const input = document.querySelector("input[name=myvalue]");
input.checked = true;
ReactTestUtils.Simulate.change(input);
});
diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx
index b918203..ccbd197 100644
--- a/test/settings/components/form/SearchEngineForm.test.tsx
+++ b/test/settings/components/form/SearchEngineForm.test.tsx
@@ -1,35 +1,42 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestRenderer from 'react-test-renderer';
-import ReactTestUtils from 'react-dom/test-utils';
-import SearchForm from 'settings/components/form/SearchForm'
-import { FormSearch } from 'shared/SettingData';
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactTestRenderer from "react-test-renderer";
+import ReactTestUtils from "react-dom/test-utils";
+import SearchForm from "settings/components/form/SearchForm";
+import { FormSearch } from "shared/SettingData";
describe("settings/form/SearchForm", () => {
- describe('render', () => {
- it('renders SearchForm', () => {
- const root = ReactTestRenderer.create(<SearchForm value={FormSearch.fromJSON({
- default: 'google',
- engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']],
- })} />).root;
+ describe("render", () => {
+ it("renders SearchForm", () => {
+ const root = ReactTestRenderer.create(
+ <SearchForm
+ value={FormSearch.fromJSON({
+ default: "google",
+ engines: [
+ ["google", "google.com"],
+ ["yahoo", "yahoo.com"],
+ ],
+ })}
+ />
+ ).root;
- const names = root.findAllByProps({ name: 'name' });
+ const names = root.findAllByProps({ name: "name" });
expect(names).to.have.lengthOf(2);
- expect(names[0].props.value).to.equal('google');
- expect(names[1].props.value).to.equal('yahoo');
+ expect(names[0].props.value).to.equal("google");
+ expect(names[1].props.value).to.equal("yahoo");
- const urls = root.findAllByProps({ name: 'url' });
+ const urls = root.findAllByProps({ name: "url" });
expect(urls).to.have.lengthOf(2);
- expect(urls[0].props.value).to.equal('google.com');
- expect(urls[1].props.value).to.equal('yahoo.com');
+ expect(urls[0].props.value).to.equal("google.com");
+ expect(urls[1].props.value).to.equal("yahoo.com");
});
});
- describe('onChange event', () => {
+ describe("onChange event", () => {
let container;
beforeEach(() => {
- container = document.createElement('div');
+ container = document.createElement("div");
document.body.appendChild(container);
});
@@ -38,72 +45,94 @@ describe("settings/form/SearchForm", () => {
container = null;
});
- it('invokes onChange event on edit', (done) => {
+ it("invokes onChange event on edit", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<SearchForm
- value={FormSearch.fromJSON({
- default: 'google',
- engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']]
- })}
- onChange={value => {
- const json = value.toJSON();
- expect(json.default).to.equal('louvre');
- expect(json.engines).to.have.lengthOf(2)
- expect(json.engines).to.have.deep.members(
- [['louvre', 'google.com'], ['yahoo', 'yahoo.com']]
- );
- done();
- }} />, container);
+ ReactDOM.render(
+ <SearchForm
+ value={FormSearch.fromJSON({
+ default: "google",
+ engines: [
+ ["google", "google.com"],
+ ["yahoo", "yahoo.com"],
+ ],
+ })}
+ onChange={(value) => {
+ const json = value.toJSON();
+ expect(json.default).to.equal("louvre");
+ expect(json.engines).to.have.lengthOf(2);
+ expect(json.engines).to.have.deep.members([
+ ["louvre", "google.com"],
+ ["yahoo", "yahoo.com"],
+ ]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const radio = document.querySelectorAll('input[type=radio]');
+ const radio = document.querySelectorAll("input[type=radio]");
radio.checked = true;
- const name = document.querySelector('input[name=name]');
- name.value = 'louvre';
+ const name = document.querySelector("input[name=name]");
+ name.value = "louvre";
ReactTestUtils.Simulate.change(name);
});
- it('invokes onChange event on delete', (done) => {
+ it("invokes onChange event on delete", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<SearchForm value={FormSearch.fromJSON({
- default: 'yahoo',
- engines: [['louvre', 'google.com'], ['yahoo', 'yahoo.com']]
- })}
- onChange={value => {
- const json = value.toJSON();
- expect(json.default).to.equal('yahoo');
- expect(json.engines).to.have.lengthOf(1)
- expect(json.engines).to.have.deep.members(
- [['yahoo', 'yahoo.com']]
- );
- done();
- }} />, container);
+ ReactDOM.render(
+ <SearchForm
+ value={FormSearch.fromJSON({
+ default: "yahoo",
+ engines: [
+ ["louvre", "google.com"],
+ ["yahoo", "yahoo.com"],
+ ],
+ })}
+ onChange={(value) => {
+ const json = value.toJSON();
+ expect(json.default).to.equal("yahoo");
+ expect(json.engines).to.have.lengthOf(1);
+ expect(json.engines).to.have.deep.members([
+ ["yahoo", "yahoo.com"],
+ ]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const button = document.querySelector('input[type=button]');
+ const button = document.querySelector("input[type=button]");
ReactTestUtils.Simulate.click(button);
});
- it('invokes onChange event on add', (done) => {
+ it("invokes onChange event on add", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<SearchForm value={FormSearch.fromJSON({
- default: 'yahoo',
- engines: [['google', 'google.com']]
- })}
- onChange={value => {
- const json = value.toJSON();
- expect(json.default).to.equal('yahoo');
- expect(json.engines).to.have.lengthOf(2)
- expect(json.engines).to.have.deep.members(
- [['google', 'google.com'], ['', '']],
- );
- done();
- }} />, container);
+ ReactDOM.render(
+ <SearchForm
+ value={FormSearch.fromJSON({
+ default: "yahoo",
+ engines: [["google", "google.com"]],
+ })}
+ onChange={(value) => {
+ const json = value.toJSON();
+ expect(json.default).to.equal("yahoo");
+ expect(json.engines).to.have.lengthOf(2);
+ expect(json.engines).to.have.deep.members([
+ ["google", "google.com"],
+ ["", ""],
+ ]);
+ done();
+ }}
+ />,
+ container
+ );
});
- const button = document.querySelector('input[type=button].ui-add-button');
+ const button = document.querySelector("input[type=button].ui-add-button");
ReactTestUtils.Simulate.click(button);
});
});
diff --git a/test/settings/components/ui/input.test.tsx b/test/settings/components/ui/input.test.tsx
index a3e7ff4..2f2b075 100644
--- a/test/settings/components/ui/input.test.tsx
+++ b/test/settings/components/ui/input.test.tsx
@@ -1,13 +1,13 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestUtils from 'react-dom/test-utils';
-import Input from 'settings/components/ui/Input'
+import React from "react";
+import ReactDOM from "react-dom";
+import ReactTestUtils from "react-dom/test-utils";
+import Input from "settings/components/ui/Input";
describe("settings/ui/Input", () => {
let container;
beforeEach(() => {
- container = document.createElement('div');
+ container = document.createElement("div");
document.body.appendChild(container);
});
@@ -17,94 +17,129 @@ describe("settings/ui/Input", () => {
});
context("type=text", () => {
- it('renders text input', () => {
+ it("renders text input", () => {
ReactTestUtils.act(() => {
ReactDOM.render(
- <Input type='text' name='myname' label='myfield' value='myvalue'/>,
- container);
+ <Input type="text" name="myname" label="myfield" value="myvalue" />,
+ container
+ );
});
- const label = document.querySelector('label');
- const input = document.querySelector('input');
- expect(label.textContent).to.contain('myfield');
- expect(input.type).to.contain('text');
- expect(input.name).to.contain('myname');
- expect(input.value).to.contain('myvalue');
+ const label = document.querySelector("label");
+ const input = document.querySelector("input");
+ expect(label.textContent).to.contain("myfield");
+ expect(input.type).to.contain("text");
+ expect(input.name).to.contain("myname");
+ expect(input.value).to.contain("myvalue");
});
- it('invoke onChange', (done) => {
+ it("invoke onChange", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<Input type='text' name='myname' label='myfield' value='myvalue' onChange={(e) => {
- expect(e.target.value).to.equal('newvalue');
- done();
- }}/>, container);
+ ReactDOM.render(
+ <Input
+ type="text"
+ name="myname"
+ label="myfield"
+ value="myvalue"
+ onChange={(e) => {
+ expect(e.target.value).to.equal("newvalue");
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input');
- input.value = 'newvalue';
+ const input = document.querySelector("input");
+ input.value = "newvalue";
ReactTestUtils.Simulate.change(input);
});
});
context("type=radio", () => {
- it('renders radio button', () => {
+ it("renders radio button", () => {
ReactTestUtils.act(() => {
ReactDOM.render(
- <Input type='radio' name='myname' label='myfield' value='myvalue'/>,
- container);
+ <Input type="radio" name="myname" label="myfield" value="myvalue" />,
+ container
+ );
});
- const label = document.querySelector('label');
- const input = document.querySelector('input');
- expect(label.textContent).to.contain('myfield');
- expect(input.type).to.contain('radio');
- expect(input.name).to.contain('myname');
- expect(input.value).to.contain('myvalue');
+ const label = document.querySelector("label");
+ const input = document.querySelector("input");
+ expect(label.textContent).to.contain("myfield");
+ expect(input.type).to.contain("radio");
+ expect(input.name).to.contain("myname");
+ expect(input.value).to.contain("myvalue");
});
- it('invoke onChange', (done) => {
+ it("invoke onChange", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<Input type='text' name='radio' label='myfield' value='myvalue' onChange={(e) => {
- expect(e.target.checked).to.be.true;
- done();
- }}/>,
- container);
+ ReactDOM.render(
+ <Input
+ type="text"
+ name="radio"
+ label="myfield"
+ value="myvalue"
+ onChange={(e) => {
+ expect(e.target.checked).to.be.true;
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('input');
+ const input = document.querySelector("input");
input.checked = true;
ReactTestUtils.Simulate.change(input);
});
});
context("type=textarea", () => {
- it('renders textarea button', () => {
+ it("renders textarea button", () => {
ReactTestUtils.act(() => {
ReactDOM.render(
- <Input type='textarea' name='myname' label='myfield' value='myvalue' error='myerror' />,
- container);
+ <Input
+ type="textarea"
+ name="myname"
+ label="myfield"
+ value="myvalue"
+ error="myerror"
+ />,
+ container
+ );
});
- const label = document.querySelector('label');
- const textarea = document.querySelector('textarea');
- const error = document.querySelector('.settings-ui-input-error');
- expect(label.textContent).to.contain('myfield');
- expect(textarea.nodeName).to.contain('TEXTAREA');
- expect(textarea.name).to.contain('myname');
- expect(textarea.value).to.contain('myvalue');
- expect(error.textContent).to.contain('myerror');
+ const label = document.querySelector("label");
+ const textarea = document.querySelector("textarea");
+ const error = document.querySelector(".settings-ui-input-error");
+ expect(label.textContent).to.contain("myfield");
+ expect(textarea.nodeName).to.contain("TEXTAREA");
+ expect(textarea.name).to.contain("myname");
+ expect(textarea.value).to.contain("myvalue");
+ expect(error.textContent).to.contain("myerror");
});
- it('invoke onChange', (done) => {
+ it("invoke onChange", (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<Input type='textarea' name='myname' label='myfield' value='myvalue' onChange={(e) => {
- expect(e.target.value).to.equal('newvalue');
- done();
- }}/>, container);
+ ReactDOM.render(
+ <Input
+ type="textarea"
+ name="myname"
+ label="myfield"
+ value="myvalue"
+ onChange={(e) => {
+ expect(e.target.value).to.equal("newvalue");
+ done();
+ }}
+ />,
+ container
+ );
});
- const input = document.querySelector('textarea');
- input.value = 'newvalue'
+ const input = document.querySelector("textarea");
+ input.value = "newvalue";
ReactTestUtils.Simulate.change(input);
});
});
diff --git a/test/settings/reducers/setting.test.ts b/test/settings/reducers/setting.test.ts
index 60df061..bb5cfa5 100644
--- a/test/settings/reducers/setting.test.ts
+++ b/test/settings/reducers/setting.test.ts
@@ -1,54 +1,54 @@
-import * as actions from 'settings/actions';
-import settingReducer from 'settings/reducers/setting';
+import * as actions from "settings/actions";
+import settingReducer from "settings/reducers/setting";
describe("settings setting reducer", () => {
- it('return the initial state', () => {
+ it("return the initial state", () => {
const state = settingReducer(undefined, {});
- expect(state).to.have.deep.property('source', 'json');
- expect(state).to.have.deep.property('error', '');
+ expect(state).to.have.deep.property("source", "json");
+ expect(state).to.have.deep.property("error", "");
});
- it('return next state for SETTING_SET_SETTINGS', () => {
+ it("return next state for SETTING_SET_SETTINGS", () => {
const action = {
type: actions.SETTING_SET_SETTINGS,
- source: 'json',
+ source: "json",
json: '{ "key": "value" }',
form: {},
};
const state = settingReducer(undefined, action);
- expect(state).to.have.deep.property('source', 'json');
- expect(state).to.have.deep.property('json', '{ "key": "value" }');
- expect(state).to.have.deep.property('form', {});
+ expect(state).to.have.deep.property("source", "json");
+ expect(state).to.have.deep.property("json", '{ "key": "value" }');
+ expect(state).to.have.deep.property("form", {});
});
- it('return next state for SETTING_SHOW_ERROR', () => {
+ it("return next state for SETTING_SHOW_ERROR", () => {
const action = {
type: actions.SETTING_SHOW_ERROR,
- error: 'bad value',
- json: '{}',
+ error: "bad value",
+ json: "{}",
};
const state = settingReducer(undefined, action);
- expect(state).to.have.deep.property('error', 'bad value');
- expect(state).to.have.deep.property('json', '{}');
+ expect(state).to.have.deep.property("error", "bad value");
+ expect(state).to.have.deep.property("json", "{}");
});
- it('return next state for SETTING_SWITCH_TO_FORM', () => {
+ it("return next state for SETTING_SWITCH_TO_FORM", () => {
const action = {
type: actions.SETTING_SWITCH_TO_FORM,
form: {},
};
const state = settingReducer(undefined, action);
- expect(state).to.have.deep.property('form', {});
- expect(state).to.have.deep.property('source', 'form');
+ expect(state).to.have.deep.property("form", {});
+ expect(state).to.have.deep.property("source", "form");
});
- it('return next state for SETTING_SWITCH_TO_JSON', () => {
+ it("return next state for SETTING_SWITCH_TO_JSON", () => {
const action = {
type: actions.SETTING_SWITCH_TO_JSON,
- json: '{}',
+ json: "{}",
};
const state = settingReducer(undefined, action);
- expect(state).to.have.deep.property('json', '{}');
- expect(state).to.have.deep.property('source', 'json');
+ expect(state).to.have.deep.property("json", "{}");
+ expect(state).to.have.deep.property("source", "json");
});
});
diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts
index 0632176..283daa5 100644
--- a/test/shared/SettingData.test.ts
+++ b/test/shared/SettingData.test.ts
@@ -1,46 +1,48 @@
import SettingData, {
- FormKeymaps, JSONTextSettings, FormSettings,
-} from '../../src/shared/SettingData';
-import Settings from '../../src/shared/settings/Settings';
-import { expect } from 'chai';
-import Keymaps from '../../src/shared/settings/Keymaps';
+ FormKeymaps,
+ JSONTextSettings,
+ FormSettings,
+} from "../../src/shared/SettingData";
+import Settings from "../../src/shared/settings/Settings";
+import { expect } from "chai";
+import Keymaps from "../../src/shared/settings/Keymaps";
-describe('shared/SettingData', () => {
- describe('FormKeymaps', () => {
- describe('#valueOF to #toKeymaps', () => {
- it('parses form keymaps and convert to operations', () => {
+describe("shared/SettingData", () => {
+ describe("FormKeymaps", () => {
+ describe("#valueOF to #toKeymaps", () => {
+ it("parses form keymaps and convert to operations", () => {
const data = {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
};
const keymaps = FormKeymaps.fromJSON(data).toKeymaps().toJSON();
expect(keymaps).to.deep.equal({
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
});
});
});
- describe('#fromKeymaps to #toJSON', () => {
- it('create from a Keymaps and create a JSON object', () => {
+ describe("#fromKeymaps to #toJSON", () => {
+ it("create from a Keymaps and create a JSON object", () => {
const keymaps: Keymaps = Keymaps.fromJSON({
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
});
const form = FormKeymaps.fromKeymaps(keymaps).toJSON();
expect(form).to.deep.equal({
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
});
});
});
});
- describe('JSONSettings', () => {
- describe('#valueOf to #toSettings', () => {
- it('parse object and create a Settings', () => {
+ describe("JSONSettings", () => {
+ describe("#valueOf to #toSettings", () => {
+ it("parse object and create a Settings", () => {
const o = `{
"keymaps": {},
"search": {
@@ -62,8 +64,8 @@ describe('shared/SettingData', () => {
});
});
- describe('#fromSettings to #toJSON', () => {
- it('create from a Settings and create a JSON string', () => {
+ describe("#fromSettings to #toJSON", () => {
+ it("create from a Settings and create a JSON string", () => {
const o = Settings.fromJSON({
keymaps: {},
search: {
@@ -75,7 +77,7 @@ describe('shared/SettingData', () => {
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -86,67 +88,65 @@ describe('shared/SettingData', () => {
});
});
- describe('FormSettings', () => {
- describe('#valueOf to #toSettings', () => {
- it('parse object and create a Settings', () => {
+ describe("FormSettings", () => {
+ describe("#valueOf to #toSettings", () => {
+ it("parse object and create a Settings", () => {
const data = {
keymaps: {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
},
search: {
default: "google",
- engines: [
- ["google", "https://google.com/search?q={}"],
- ]
+ engines: [["google", "https://google.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
};
const settings = FormSettings.fromJSON(data).toSettings();
expect(settings.toJSON()).to.deep.equal({
keymaps: {
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
},
search: {
default: "google",
engines: {
- "google": "https://google.com/search?q={}"
- }
+ google: "https://google.com/search?q={}",
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
});
});
});
- describe('#fromSettings to #toJSON', () => {
- it('create from a Settings and create a JSON string', () => {
+ describe("#fromSettings to #toJSON", () => {
+ it("create from a Settings and create a JSON string", () => {
const data: Settings = Settings.fromJSON({
keymaps: {
- 'j': { type: 'scroll.vertically', count: 1 },
- '0': { type: 'scroll.home' },
+ j: { type: "scroll.vertically", count: 1 },
+ "0": { type: "scroll.home" },
},
search: {
default: "google",
engines: {
- "google": "https://google.com/search?q={}"
- }
+ google: "https://google.com/search?q={}",
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -154,19 +154,17 @@ describe('shared/SettingData', () => {
const json = FormSettings.fromSettings(data).toJSON();
expect(json).to.deep.equal({
keymaps: {
- 'scroll.vertically?{"count":1}': 'j',
- 'scroll.home': '0',
+ 'scroll.vertically?{"count":1}': "j",
+ "scroll.home": "0",
},
search: {
default: "google",
- engines: [
- ["google", "https://google.com/search?q={}"],
- ]
+ engines: [["google", "https://google.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
@@ -174,11 +172,11 @@ describe('shared/SettingData', () => {
});
});
- describe('SettingData', () => {
- describe('#valueOf to #toJSON', () => {
- it('parse object from json source', () => {
+ describe("SettingData", () => {
+ describe("#valueOf to #toJSON", () => {
+ it("parse object from json source", () => {
const data = {
- source: 'json',
+ source: "json",
json: `{
"keymaps": {},
"search": {
@@ -197,54 +195,50 @@ describe('shared/SettingData', () => {
};
const j = SettingData.fromJSON(data).toJSON();
- expect(j.source).to.equal('json');
- expect(j.json).to.be.a('string');
+ expect(j.source).to.equal("json");
+ expect(j.json).to.be.a("string");
});
- it('parse object from form source', () => {
+ it("parse object from form source", () => {
const data = {
- source: 'form',
+ source: "form",
form: {
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
},
};
const j = SettingData.fromJSON(data).toJSON();
- expect(j.source).to.equal('form');
+ expect(j.source).to.equal("form");
expect(j.form).to.deep.equal({
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
});
});
});
- describe('#toSettings', () => {
- it('parse object from json source', () => {
+ describe("#toSettings", () => {
+ it("parse object from json source", () => {
const data = {
- source: 'json',
+ source: "json",
json: `{
"keymaps": {},
"search": {
@@ -263,31 +257,29 @@ describe('shared/SettingData', () => {
};
const settings = SettingData.fromJSON(data).toSettings();
- expect(settings.search.defaultEngine).to.equal('google');
+ expect(settings.search.defaultEngine).to.equal("google");
});
- it('parse object from form source', () => {
+ it("parse object from form source", () => {
const data = {
- source: 'form',
+ source: "form",
form: {
keymaps: {},
search: {
default: "yahoo",
- engines: [
- ['yahoo', 'https://yahoo.com/search?q={}'],
- ],
+ engines: [["yahoo", "https://yahoo.com/search?q={}"]],
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
blacklist: [],
},
};
const settings = SettingData.fromJSON(data).toSettings();
- expect(settings.search.defaultEngine).to.equal('yahoo');
+ expect(settings.search.defaultEngine).to.equal("yahoo");
});
});
});
diff --git a/test/shared/operations.test.ts b/test/shared/operations.test.ts
index fbb6193..94986ac 100644
--- a/test/shared/operations.test.ts
+++ b/test/shared/operations.test.ts
@@ -1,8 +1,8 @@
-import * as operations from 'shared/operations';
+import * as operations from "shared/operations";
-describe('operations', () => {
- describe('#valueOf', () => {
- it('returns an Operation', () => {
+describe("operations", () => {
+ describe("#valueOf", () => {
+ it("returns an Operation", () => {
const op: operations.Operation = operations.valueOf({
type: operations.SCROLL_VERTICALLY,
count: 10,
@@ -11,31 +11,37 @@ describe('operations', () => {
expect(op.count).to.equal(10);
});
- it('throws an Error on missing required parameter', () => {
- expect(() => operations.valueOf({
- type: operations.SCROLL_VERTICALLY,
- })).to.throw(TypeError);
+ it("throws an Error on missing required parameter", () => {
+ expect(() =>
+ operations.valueOf({
+ type: operations.SCROLL_VERTICALLY,
+ })
+ ).to.throw(TypeError);
});
- it('fills default valus of optional parameter', () => {
+ it("fills default valus of optional parameter", () => {
const op: operations.Operation = operations.valueOf({
type: operations.COMMAND_SHOW_OPEN,
});
- expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN)
+ expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN);
expect(op.alter).to.be.false;
});
- it('throws an Error on mismatch of parameter', () => {
- expect(() => operations.valueOf({
- type: operations.SCROLL_VERTICALLY,
- count: '10',
- })).to.throw(TypeError);
+ it("throws an Error on mismatch of parameter", () => {
+ expect(() =>
+ operations.valueOf({
+ type: operations.SCROLL_VERTICALLY,
+ count: "10",
+ })
+ ).to.throw(TypeError);
- expect(() => valueOf({
- type: operations.COMMAND_SHOW_OPEN,
- alter: 'true',
- })).to.throw(TypeError);
+ expect(() =>
+ valueOf({
+ type: operations.COMMAND_SHOW_OPEN,
+ alter: "true",
+ })
+ ).to.throw(TypeError);
});
});
-})
+});
diff --git a/test/shared/settings/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts
index bcddf18..1ccb32a 100644
--- a/test/shared/settings/Blacklist.test.ts
+++ b/test/shared/settings/Blacklist.test.ts
@@ -1,140 +1,178 @@
-import Blacklist, { BlacklistItem } from '../../../src/shared/settings/Blacklist';
-import { expect } from 'chai';
-import Key from '../../../src/shared/settings/Key';
-
-describe('BlacklistItem', () => {
- describe('#fromJSON', () => {
- it('parses string pattern', () => {
- const item = BlacklistItem.fromJSON('example.com');
- expect(item.pattern).to.equal('example.com');
+import Blacklist, {
+ BlacklistItem,
+} from "../../../src/shared/settings/Blacklist";
+import { expect } from "chai";
+import Key from "../../../src/shared/settings/Key";
+
+describe("BlacklistItem", () => {
+ describe("#fromJSON", () => {
+ it("parses string pattern", () => {
+ const item = BlacklistItem.fromJSON("example.com");
+ expect(item.pattern).to.equal("example.com");
expect(item.partial).to.be.false;
});
- it('parses partial blacklist item', () => {
- const item = BlacklistItem.fromJSON({ url: 'example.com', keys: ['j', 'k']});
- expect(item.pattern).to.equal('example.com');
+ it("parses partial blacklist item", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "example.com",
+ keys: ["j", "k"],
+ });
+ expect(item.pattern).to.equal("example.com");
expect(item.partial).to.be.true;
- expect(item.keys).to.deep.equal(['j', 'k']);
+ expect(item.keys).to.deep.equal(["j", "k"]);
});
});
- describe('#matches', () => {
+ describe("#matches", () => {
it('matches by "*"', () => {
- const item = BlacklistItem.fromJSON('*');
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
+ const item = BlacklistItem.fromJSON("*");
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
});
- it('matches by hostname', () => {
- const item = BlacklistItem.fromJSON('github.com');
- expect(item.matches(new URL('https://github.com'))).to.be.true;
- expect(item.matches(new URL('https://gist.github.com'))).to.be.false;
- expect(item.matches(new URL('https://github.com/ueokande'))).to.be.true;
- expect(item.matches(new URL('https://github.org'))).to.be.false;
- expect(item.matches(new URL('https://google.com/search?q=github.org'))).to.be.false;
+ it("matches by hostname", () => {
+ const item = BlacklistItem.fromJSON("github.com");
+ expect(item.matches(new URL("https://github.com"))).to.be.true;
+ expect(item.matches(new URL("https://gist.github.com"))).to.be.false;
+ expect(item.matches(new URL("https://github.com/ueokande"))).to.be.true;
+ expect(item.matches(new URL("https://github.org"))).to.be.false;
+ expect(item.matches(new URL("https://google.com/search?q=github.org"))).to
+ .be.false;
});
- it('matches by hostname with wildcard', () => {
- const item = BlacklistItem.fromJSON('*.github.com');
+ it("matches by hostname with wildcard", () => {
+ const item = BlacklistItem.fromJSON("*.github.com");
- expect(item.matches(new URL('https://github.com'))).to.be.false;
- expect(item.matches(new URL('https://gist.github.com'))).to.be.true;
+ expect(item.matches(new URL("https://github.com"))).to.be.false;
+ expect(item.matches(new URL("https://gist.github.com"))).to.be.true;
});
- it('matches by path', () => {
- const item = BlacklistItem.fromJSON('github.com/abc');
+ it("matches by path", () => {
+ const item = BlacklistItem.fromJSON("github.com/abc");
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
- expect(item.matches(new URL('https://github.com/abcdef'))).to.be.false;
- expect(item.matches(new URL('https://gist.github.com/abc'))).to.be.false;
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
+ expect(item.matches(new URL("https://github.com/abcdef"))).to.be.false;
+ expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false;
});
- it('matches by path with wildcard', () => {
- const item = BlacklistItem.fromJSON('github.com/abc*');
+ it("matches by path with wildcard", () => {
+ const item = BlacklistItem.fromJSON("github.com/abc*");
- expect(item.matches(new URL('https://github.com/abc'))).to.be.true;
- expect(item.matches(new URL('https://github.com/abcdef'))).to.be.true;
- expect(item.matches(new URL('https://gist.github.com/abc'))).to.be.false;
+ expect(item.matches(new URL("https://github.com/abc"))).to.be.true;
+ expect(item.matches(new URL("https://github.com/abcdef"))).to.be.true;
+ expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false;
});
- it('matches address and port', () => {
- const item = BlacklistItem.fromJSON('127.0.0.1:8888');
+ it("matches address and port", () => {
+ const item = BlacklistItem.fromJSON("127.0.0.1:8888");
- expect(item.matches(new URL('http://127.0.0.1:8888/'))).to.be.true;
- expect(item.matches(new URL('http://127.0.0.1:8888/hello'))).to.be.true;
+ expect(item.matches(new URL("http://127.0.0.1:8888/"))).to.be.true;
+ expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).to.be.true;
});
- it('matches with partial blacklist', () => {
- const item = BlacklistItem.fromJSON({ url: 'google.com', keys: ['j', 'k'] });
+ it("matches with partial blacklist", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "google.com",
+ keys: ["j", "k"],
+ });
- expect(item.matches(new URL('https://google.com'))).to.be.true;
- expect(item.matches(new URL('https://yahoo.com'))).to.be.false;
- })
+ expect(item.matches(new URL("https://google.com"))).to.be.true;
+ expect(item.matches(new URL("https://yahoo.com"))).to.be.false;
+ });
});
- describe('#includesPartialKeys', () => {
- it('matches with partial keys', () => {
- const item = BlacklistItem.fromJSON({url: 'google.com', keys: ['j', 'k', '<C-U>']});
-
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('j'))).to.be.true;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('<C-U>'))).to.be.true;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('z'))).to.be.false;
- expect(item.includeKey(new URL('http://google.com/maps'), Key.fromMapKey('u'))).to.be.false;
- expect(item.includeKey(new URL('http://maps.google.com/'), Key.fromMapKey('j'))).to.be.false;
- })
+ describe("#includesPartialKeys", () => {
+ it("matches with partial keys", () => {
+ const item = BlacklistItem.fromJSON({
+ url: "google.com",
+ keys: ["j", "k", "<C-U>"],
+ });
+
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("j"))
+ ).to.be.true;
+ expect(
+ item.includeKey(
+ new URL("http://google.com/maps"),
+ Key.fromMapKey("<C-U>")
+ )
+ ).to.be.true;
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("z"))
+ ).to.be.false;
+ expect(
+ item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("u"))
+ ).to.be.false;
+ expect(
+ item.includeKey(new URL("http://maps.google.com/"), Key.fromMapKey("j"))
+ ).to.be.false;
+ });
});
});
-describe('Blacklist', () => {
- describe('#fromJSON', () => {
- it('parses string list', () => {
- const blacklist = Blacklist.fromJSON(['example.com', 'example.org']);
- expect(blacklist.toJSON()).to.deep.equals([
- 'example.com', 'example.org',
- ]);
+describe("Blacklist", () => {
+ describe("#fromJSON", () => {
+ it("parses string list", () => {
+ const blacklist = Blacklist.fromJSON(["example.com", "example.org"]);
+ expect(blacklist.toJSON()).to.deep.equals(["example.com", "example.org"]);
});
- it('parses mixed blacklist', () => {
+ it("parses mixed blacklist", () => {
const blacklist = Blacklist.fromJSON([
- { url: 'example.com', keys: ['j', 'k']},
- 'example.org',
+ { url: "example.com", keys: ["j", "k"] },
+ "example.org",
]);
expect(blacklist.toJSON()).to.deep.equals([
- { url: 'example.com', keys: ['j', 'k']},
- 'example.org',
+ { url: "example.com", keys: ["j", "k"] },
+ "example.org",
]);
});
- it('parses empty blacklist', () => {
+ it("parses empty blacklist", () => {
const blacklist = Blacklist.fromJSON([]);
expect(blacklist.toJSON()).to.deep.equals([]);
});
});
- describe('#includesEntireBlacklist', () => {
- it('matches a url with entire blacklist', () => {
- const blacklist = Blacklist.fromJSON(['google.com', '*.github.com']);
- expect(blacklist.includesEntireBlacklist(new URL('https://google.com'))).to.be.true;
- expect(blacklist.includesEntireBlacklist(new URL('https://github.com'))).to.be.false;
- expect(blacklist.includesEntireBlacklist(new URL('https://gist.github.com'))).to.be.true;
+ describe("#includesEntireBlacklist", () => {
+ it("matches a url with entire blacklist", () => {
+ const blacklist = Blacklist.fromJSON(["google.com", "*.github.com"]);
+ expect(blacklist.includesEntireBlacklist(new URL("https://google.com")))
+ .to.be.true;
+ expect(blacklist.includesEntireBlacklist(new URL("https://github.com")))
+ .to.be.false;
+ expect(
+ blacklist.includesEntireBlacklist(new URL("https://gist.github.com"))
+ ).to.be.true;
});
- it('does not matches with partial blacklist', () => {
- const blacklist = Blacklist.fromJSON(['google.com', { url: 'yahoo.com', keys: ['j', 'k'] }]);
- expect(blacklist.includesEntireBlacklist(new URL('https://google.com'))).to.be.true;
- expect(blacklist.includesEntireBlacklist(new URL('https://yahoo.com'))).to.be.false;
+ it("does not matches with partial blacklist", () => {
+ const blacklist = Blacklist.fromJSON([
+ "google.com",
+ { url: "yahoo.com", keys: ["j", "k"] },
+ ]);
+ expect(blacklist.includesEntireBlacklist(new URL("https://google.com")))
+ .to.be.true;
+ expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))).to
+ .be.false;
});
});
- describe('#includesKeys', () => {
- it('matches with entire blacklist or keys in the partial blacklist', () => {
+ describe("#includesKeys", () => {
+ it("matches with entire blacklist or keys in the partial blacklist", () => {
const blacklist = Blacklist.fromJSON([
- 'google.com',
- { url: 'github.com', keys: ['j', 'k'] },
+ "google.com",
+ { url: "github.com", keys: ["j", "k"] },
]);
- expect(blacklist.includeKey(new URL('https://google.com'), Key.fromMapKey('j'))).to.be.false;
- expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('j'))).to.be.true;
- expect(blacklist.includeKey(new URL('https://github.com'), Key.fromMapKey('a'))).to.be.false;
+ expect(
+ blacklist.includeKey(new URL("https://google.com"), Key.fromMapKey("j"))
+ ).to.be.false;
+ expect(
+ blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("j"))
+ ).to.be.true;
+ expect(
+ blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("a"))
+ ).to.be.false;
});
});
});
diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts
index b8538f8..47af1d9 100644
--- a/test/shared/settings/Key.test.ts
+++ b/test/shared/settings/Key.test.ts
@@ -1,74 +1,74 @@
-import { expect } from 'chai'
-import Key from '../../../src/shared/settings/Key';
+import { expect } from "chai";
+import Key from "../../../src/shared/settings/Key";
describe("Key", () => {
- describe('fromMapKey', () => {
- it('return for X', () => {
- const key = Key.fromMapKey('x');
- expect(key.key).to.equal('x');
+ describe("fromMapKey", () => {
+ it("return for X", () => {
+ const key = Key.fromMapKey("x");
+ expect(key.key).to.equal("x");
expect(key.shift).to.be.false;
expect(key.ctrl).to.be.false;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('return for Shift+X', () => {
- const key = Key.fromMapKey('X');
- expect(key.key).to.equal('X');
+ it("return for Shift+X", () => {
+ const key = Key.fromMapKey("X");
+ expect(key.key).to.equal("X");
expect(key.shift).to.be.true;
expect(key.ctrl).to.be.false;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('return for Ctrl+X', () => {
- const key = Key.fromMapKey('<C-X>');
- expect(key.key).to.equal('x');
+ it("return for Ctrl+X", () => {
+ const key = Key.fromMapKey("<C-X>");
+ expect(key.key).to.equal("x");
expect(key.shift).to.be.false;
expect(key.ctrl).to.be.true;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('returns for Ctrl+Meta+X', () => {
- const key = Key.fromMapKey('<C-M-X>');
- expect(key.key).to.equal('x');
+ it("returns for Ctrl+Meta+X", () => {
+ const key = Key.fromMapKey("<C-M-X>");
+ expect(key.key).to.equal("x");
expect(key.shift).to.be.false;
expect(key.ctrl).to.be.true;
expect(key.alt).to.be.false;
expect(key.meta).to.be.true;
});
- it('returns for Ctrl+Shift+x', () => {
- const key = Key.fromMapKey('<C-S-x>');
- expect(key.key).to.equal('X');
+ it("returns for Ctrl+Shift+x", () => {
+ const key = Key.fromMapKey("<C-S-x>");
+ expect(key.key).to.equal("X");
expect(key.shift).to.be.true;
expect(key.ctrl).to.be.true;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('returns for Shift+Esc', () => {
- const key = Key.fromMapKey('<S-Esc>');
- expect(key.key).to.equal('Esc');
+ it("returns for Shift+Esc", () => {
+ const key = Key.fromMapKey("<S-Esc>");
+ expect(key.key).to.equal("Esc");
expect(key.shift).to.be.true;
expect(key.ctrl).to.be.false;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('returns for Ctrl+Esc', () => {
- const key = Key.fromMapKey('<C-Esc>');
- expect(key.key).to.equal('Esc');
+ it("returns for Ctrl+Esc", () => {
+ const key = Key.fromMapKey("<C-Esc>");
+ expect(key.key).to.equal("Esc");
expect(key.shift).to.be.false;
expect(key.ctrl).to.be.true;
expect(key.alt).to.be.false;
expect(key.meta).to.be.false;
});
- it('returns for Ctrl+Esc', () => {
- const key = Key.fromMapKey('<C-Space>');
- expect(key.key).to.equal('Space');
+ it("returns for Ctrl+Esc", () => {
+ const key = Key.fromMapKey("<C-Space>");
+ expect(key.key).to.equal("Space");
expect(key.shift).to.be.false;
expect(key.ctrl).to.be.true;
expect(key.alt).to.be.false;
@@ -76,30 +76,54 @@ describe("Key", () => {
});
});
- describe('idDigit', () => {
- it('returns true if the key is a digit', () => {
- expect(new Key({ key: '0' }).isDigit()).to.be.true;
- expect(new Key({ key: '9' }).isDigit()).to.be.true;
- expect(new Key({ key: '9', alt: true }).isDigit()).to.be.false;
+ describe("idDigit", () => {
+ it("returns true if the key is a digit", () => {
+ expect(new Key({ key: "0" }).isDigit()).to.be.true;
+ expect(new Key({ key: "9" }).isDigit()).to.be.true;
+ expect(new Key({ key: "9", alt: true }).isDigit()).to.be.false;
- expect(new Key({ key: 'a' }).isDigit()).to.be.false;
- expect(new Key({ key: '0' }).isDigit()).to.be.false;
- })
+ expect(new Key({ key: "a" }).isDigit()).to.be.false;
+ expect(new Key({ key: "0" }).isDigit()).to.be.false;
+ });
});
- describe('equals', () => {
- it('returns true if the keys are equivalent', () => {
- expect(new Key({
- key: 'x', shift: false, ctrl: true, alt: false, meta: false,
- }).equals(new Key({
- key: 'x', shift: false, ctrl: true, alt: false, meta: false,
- }))).to.be.true;
+ describe("equals", () => {
+ it("returns true if the keys are equivalent", () => {
+ expect(
+ new Key({
+ key: "x",
+ shift: false,
+ ctrl: true,
+ alt: false,
+ meta: false,
+ }).equals(
+ new Key({
+ key: "x",
+ shift: false,
+ ctrl: true,
+ alt: false,
+ meta: false,
+ })
+ )
+ ).to.be.true;
- expect(new Key({
- key: 'x', shift: false, ctrl: false, alt: false, meta: false,
- }).equals(new Key({
- key: 'X', shift: true, ctrl: false, alt: false, meta: false,
- }))).to.be.false;
- })
+ expect(
+ new Key({
+ key: "x",
+ shift: false,
+ ctrl: false,
+ alt: false,
+ meta: false,
+ }).equals(
+ new Key({
+ key: "X",
+ shift: true,
+ ctrl: false,
+ alt: false,
+ meta: false,
+ })
+ )
+ ).to.be.false;
+ });
});
});
diff --git a/test/shared/settings/Keymaps.test.ts b/test/shared/settings/Keymaps.test.ts
index dcea6e4..264684d 100644
--- a/test/shared/settings/Keymaps.test.ts
+++ b/test/shared/settings/Keymaps.test.ts
@@ -1,65 +1,80 @@
-import Keymaps from '../../../src/shared/settings/Keymaps';
-import { expect } from 'chai';
+import Keymaps from "../../../src/shared/settings/Keymaps";
+import { expect } from "chai";
-describe('Keymaps', () => {
- describe('#valueOf', () => {
- it('returns empty object by empty settings', () => {
+describe("Keymaps", () => {
+ describe("#valueOf", () => {
+ it("returns empty object by empty settings", () => {
const keymaps = Keymaps.fromJSON({}).toJSON();
expect(keymaps).to.be.empty;
});
- it('returns keymaps by valid settings', () => {
+ it("returns keymaps by valid settings", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
}).toJSON();
- expect(keymaps['k']).to.deep.equal({ type: "scroll.vertically", count: -1 });
- expect(keymaps['j']).to.deep.equal({ type: "scroll.vertically", count: 1 });
+ expect(keymaps["k"]).to.deep.equal({
+ type: "scroll.vertically",
+ count: -1,
+ });
+ expect(keymaps["j"]).to.deep.equal({
+ type: "scroll.vertically",
+ count: 1,
+ });
});
- it('throws a TypeError by invalid settings', () => {
- expect(() => Keymaps.fromJSON({
- k: { type: "invalid.operation" },
- })).to.throw(TypeError);
+ it("throws a TypeError by invalid settings", () => {
+ expect(() =>
+ Keymaps.fromJSON({
+ k: { type: "invalid.operation" },
+ })
+ ).to.throw(TypeError);
});
});
- describe('#combine', () => {
- it('returns combined keymaps', () => {
+ describe("#combine", () => {
+ it("returns combined keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
- }).combine(Keymaps.fromJSON({
- n: { type: "find.next" },
- N: { type: "find.prev" },
- }));
+ }).combine(
+ Keymaps.fromJSON({
+ n: { type: "find.next" },
+ N: { type: "find.prev" },
+ })
+ );
- const entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ const entries = keymaps
+ .entries()
+ .sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).deep.equals([
- ['j', { type: "scroll.vertically", count: 1 }],
- ['k', { type: "scroll.vertically", count: -1 }],
- ['n', { type: "find.next" }],
- ['N', { type: "find.prev" }],
+ ["j", { type: "scroll.vertically", count: 1 }],
+ ["k", { type: "scroll.vertically", count: -1 }],
+ ["n", { type: "find.next" }],
+ ["N", { type: "find.prev" }],
]);
});
- it('overrides current keymaps', () => {
+ it("overrides current keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
- }).combine(Keymaps.fromJSON({
- n: { type: "find.next" },
- j: { type: "find.prev" },
- }));
+ }).combine(
+ Keymaps.fromJSON({
+ n: { type: "find.next" },
+ j: { type: "find.prev" },
+ })
+ );
- const entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ const entries = keymaps
+ .entries()
+ .sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).deep.equals([
- ['j', { type: "find.prev" }],
- ['k', { type: "scroll.vertically", count: -1 }],
- ['n', { type: "find.next" }],
+ ["j", { type: "find.prev" }],
+ ["k", { type: "scroll.vertically", count: -1 }],
+ ["n", { type: "find.next" }],
]);
});
});
});
-
diff --git a/test/shared/settings/Properties.test.ts b/test/shared/settings/Properties.test.ts
index 4639839..6007e84 100644
--- a/test/shared/settings/Properties.test.ts
+++ b/test/shared/settings/Properties.test.ts
@@ -1,30 +1,29 @@
-import Properties from '../../../src/shared/settings/Properties';
-import { expect } from 'chai';
+import Properties from "../../../src/shared/settings/Properties";
+import { expect } from "chai";
-describe('Properties', () => {
- describe('#propertiesValueOf', () => {
- it('returns with default properties by empty settings', () => {
+describe("Properties", () => {
+ describe("#propertiesValueOf", () => {
+ it("returns with default properties by empty settings", () => {
const props = Properties.fromJSON({});
expect(props).to.deep.equal({
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
- })
+ complete: "sbh",
+ });
});
- it('returns properties by valid settings', () => {
+ it("returns properties by valid settings", () => {
const props = Properties.fromJSON({
hintchars: "abcdefgh",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
});
expect(props).to.deep.equal({
hintchars: "abcdefgh",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
});
});
});
});
-
diff --git a/test/shared/settings/Search.test.ts b/test/shared/settings/Search.test.ts
index 8bd8d89..1feb14b 100644
--- a/test/shared/settings/Search.test.ts
+++ b/test/shared/settings/Search.test.ts
@@ -1,55 +1,63 @@
-import Search from '../../../src/shared/settings/Search';
-import { expect } from 'chai';
+import Search from "../../../src/shared/settings/Search";
+import { expect } from "chai";
-describe('Search', () => {
- it('returns search settings by valid settings', () => {
+describe("Search", () => {
+ it("returns search settings by valid settings", () => {
const search = Search.fromJSON({
- default: 'google',
+ default: "google",
engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
});
- expect(search.defaultEngine).to.equal('google')
+ expect(search.defaultEngine).to.equal("google");
expect(search.engines).to.deep.equals({
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
});
expect(search.toJSON()).to.deep.equal({
- default: 'google',
+ default: "google",
engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
});
});
- it('throws a TypeError by invalid settings', () => {
- expect(() => Search.fromJSON({
- default: 'wikipedia',
- engines: {
- 'google': 'https://google.com/search?q={}',
- 'yahoo': 'https://search.yahoo.com/search?p={}',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'g o o g l e',
- engines: {
- 'g o o g l e': 'https://google.com/search?q={}',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'google',
- engines: {
- 'google': 'https://google.com/search',
- }
- })).to.throw(TypeError);
- expect(() => Search.fromJSON({
- default: 'google',
- engines: {
- 'google': 'https://google.com/search?q={}&r={}',
- }
- })).to.throw(TypeError);
+ it("throws a TypeError by invalid settings", () => {
+ expect(() =>
+ Search.fromJSON({
+ default: "wikipedia",
+ engines: {
+ google: "https://google.com/search?q={}",
+ yahoo: "https://search.yahoo.com/search?p={}",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "g o o g l e",
+ engines: {
+ "g o o g l e": "https://google.com/search?q={}",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "google",
+ engines: {
+ google: "https://google.com/search",
+ },
+ })
+ ).to.throw(TypeError);
+ expect(() =>
+ Search.fromJSON({
+ default: "google",
+ engines: {
+ google: "https://google.com/search?q={}&r={}",
+ },
+ })
+ ).to.throw(TypeError);
});
});
diff --git a/test/shared/settings/Settings.test.ts b/test/shared/settings/Settings.test.ts
index 658132c..4ecfe77 100644
--- a/test/shared/settings/Settings.test.ts
+++ b/test/shared/settings/Settings.test.ts
@@ -1,19 +1,19 @@
-import Settings from '../../../src/shared/settings/Settings';
-import { expect } from 'chai';
+import Settings from "../../../src/shared/settings/Settings";
+import { expect } from "chai";
-describe('Settings', () => {
- describe('#valueOf', () => {
- it('returns settings by valid settings', () => {
+describe("Settings", () => {
+ describe("#valueOf", () => {
+ it("returns settings by valid settings", () => {
const x = Settings.fromJSON({
keymaps: {},
- "search": {
- "default": "google",
- "engines": {
- "google": "https://google.com/search?q={}",
- }
+ search: {
+ default: "google",
+ engines: {
+ google: "https://google.com/search?q={}",
+ },
},
- "properties": {},
- "blacklist": []
+ properties: {},
+ blacklist: [],
});
expect({
@@ -27,28 +27,28 @@ describe('Settings', () => {
default: "google",
engines: {
google: "https://google.com/search?q={}",
- }
+ },
},
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
- complete: "sbh"
+ complete: "sbh",
},
- blacklist: []
+ blacklist: [],
});
});
- it('sets default settings', () => {
+ it("sets default settings", () => {
const value = Settings.fromJSON({});
expect(value.keymaps.toJSON()).to.not.be.empty;
expect(value.properties.toJSON()).to.not.be.empty;
- expect(value.search.defaultEngine).to.be.a('string');
- expect(value.search.engines).to.be.an('object');
+ expect(value.search.defaultEngine).to.be.a("string");
+ expect(value.search.engines).to.be.an("object");
expect(value.blacklist.toJSON()).to.be.empty;
});
- it('throws a TypeError with an unknown field', () => {
- expect(() => Settings.fromJSON({ name: 'alice' })).to.throw(TypeError)
+ it("throws a TypeError with an unknown field", () => {
+ expect(() => Settings.fromJSON({ name: "alice" })).to.throw(TypeError);
});
});
});
diff --git a/test/shared/urls.test.ts b/test/shared/urls.test.ts
index 6206d03..f264ad9 100644
--- a/test/shared/urls.test.ts
+++ b/test/shared/urls.test.ts
@@ -1,64 +1,78 @@
-import * as parsers from '../../src/shared/urls';
-import { expect } from 'chai';
-import Search from '../../src/shared/settings/Search';
+import * as parsers from "../../src/shared/urls";
+import { expect } from "chai";
+import Search from "../../src/shared/settings/Search";
describe("shared/commands/parsers", () => {
- describe('#searchUrl', () => {
+ describe("#searchUrl", () => {
const config = Search.fromJSON({
- default: 'google',
+ default: "google",
engines: {
- google: 'https://google.com/search?q={}',
- yahoo: 'https://yahoo.com/search?q={}',
- }
+ google: "https://google.com/search?q={}",
+ yahoo: "https://yahoo.com/search?q={}",
+ },
});
- it('convertes search url', () => {
- expect(parsers.searchUrl('google.com', config))
- .to.equal('http://google.com');
- expect(parsers.searchUrl('google apple', config))
- .to.equal('https://google.com/search?q=apple');
- expect(parsers.searchUrl('yahoo apple', config))
- .to.equal('https://yahoo.com/search?q=apple');
- expect(parsers.searchUrl('google apple banana', config))
- .to.equal('https://google.com/search?q=apple%20banana');
- expect(parsers.searchUrl('yahoo C++CLI', config))
- .to.equal('https://yahoo.com/search?q=C%2B%2BCLI');
+ it("convertes search url", () => {
+ expect(parsers.searchUrl("google.com", config)).to.equal(
+ "http://google.com"
+ );
+ expect(parsers.searchUrl("google apple", config)).to.equal(
+ "https://google.com/search?q=apple"
+ );
+ expect(parsers.searchUrl("yahoo apple", config)).to.equal(
+ "https://yahoo.com/search?q=apple"
+ );
+ expect(parsers.searchUrl("google apple banana", config)).to.equal(
+ "https://google.com/search?q=apple%20banana"
+ );
+ expect(parsers.searchUrl("yahoo C++CLI", config)).to.equal(
+ "https://yahoo.com/search?q=C%2B%2BCLI"
+ );
});
- it('user default search engine', () => {
- expect(parsers.searchUrl('apple banana', config))
- .to.equal('https://google.com/search?q=apple%20banana');
+ it("user default search engine", () => {
+ expect(parsers.searchUrl("apple banana", config)).to.equal(
+ "https://google.com/search?q=apple%20banana"
+ );
});
- it('searches with a word containing a colon', () => {
- expect(parsers.searchUrl('foo:', config))
- .to.equal('https://google.com/search?q=foo%3A');
- expect(parsers.searchUrl('std::vector', config))
- .to.equal('https://google.com/search?q=std%3A%3Avector');
+ it("searches with a word containing a colon", () => {
+ expect(parsers.searchUrl("foo:", config)).to.equal(
+ "https://google.com/search?q=foo%3A"
+ );
+ expect(parsers.searchUrl("std::vector", config)).to.equal(
+ "https://google.com/search?q=std%3A%3Avector"
+ );
});
- it('localhost urls', () => {
- expect(parsers.searchUrl('localhost', config))
- .to.equal('http://localhost');
- expect(parsers.searchUrl('http://localhost', config))
- .to.equal('http://localhost/');
- expect(parsers.searchUrl('localhost:8080', config))
- .to.equal('http://localhost:8080');
- expect(parsers.searchUrl('localhost:80nan', config))
- .to.equal('https://google.com/search?q=localhost%3A80nan');
- expect(parsers.searchUrl('localhost 8080', config))
- .to.equal('https://google.com/search?q=localhost%208080');
- expect(parsers.searchUrl('localhost:80/build', config))
- .to.equal('http://localhost:80/build')
- })
+ it("localhost urls", () => {
+ expect(parsers.searchUrl("localhost", config)).to.equal(
+ "http://localhost"
+ );
+ expect(parsers.searchUrl("http://localhost", config)).to.equal(
+ "http://localhost/"
+ );
+ expect(parsers.searchUrl("localhost:8080", config)).to.equal(
+ "http://localhost:8080"
+ );
+ expect(parsers.searchUrl("localhost:80nan", config)).to.equal(
+ "https://google.com/search?q=localhost%3A80nan"
+ );
+ expect(parsers.searchUrl("localhost 8080", config)).to.equal(
+ "https://google.com/search?q=localhost%208080"
+ );
+ expect(parsers.searchUrl("localhost:80/build", config)).to.equal(
+ "http://localhost:80/build"
+ );
+ });
});
- describe('#normalizeUrl', () => {
- it('normalize urls', () => {
- expect(parsers.normalizeUrl('https://google.com/'))
- .to.equal('https://google.com/');
- expect(parsers.normalizeUrl('google.com'))
- .to.equal('http://google.com');
+ describe("#normalizeUrl", () => {
+ it("normalize urls", () => {
+ expect(parsers.normalizeUrl("https://google.com/")).to.equal(
+ "https://google.com/"
+ );
+ expect(parsers.normalizeUrl("google.com")).to.equal("http://google.com");
});
});
});