aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/background/completion/CompletionUseCase.test.ts131
-rw-r--r--test/background/completion/impl/filters.test.ts114
-rw-r--r--test/background/usecases/filters.test.ts113
-rw-r--r--test/console/actions/console.test.ts9
4 files changed, 250 insertions, 117 deletions
diff --git a/test/background/completion/CompletionUseCase.test.ts b/test/background/completion/CompletionUseCase.test.ts
new file mode 100644
index 0000000..0d58e45
--- /dev/null
+++ b/test/background/completion/CompletionUseCase.test.ts
@@ -0,0 +1,131 @@
+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 CompletionUseCase from "../../../src/background/completion/CompletionUseCase";
+import CachedSettingRepository from "../../../src/background/repositories/CachedSettingRepository";
+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")
+ }
+}
+
+class MockHistoryRepository implements HistoryRepository {
+ queryHistories(_keywords: string): Promise<HistoryItem[]> {
+ throw new Error("not implemented")
+ }
+}
+
+class MockSettingRepository implements CachedSettingRepository {
+ get(): Promise<Settings> {
+ throw new Error("not implemented")
+ }
+
+ setProperty(_name: string, _value: string | number | boolean): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ update(_value: Settings): Promise<void> {
+ throw new Error("not implemented")
+ }
+}
+
+describe('CompletionUseCase', () => {
+ let bookmarkRepository: MockBookmarkRepository;
+ let historyRepository: MockHistoryRepository;
+ let settingRepository: MockSettingRepository;
+ let sut: CompletionUseCase;
+
+ beforeEach(() => {
+ bookmarkRepository = new MockBookmarkRepository();
+ historyRepository = new MockHistoryRepository();
+ settingRepository = new MockSettingRepository();
+ sut = new CompletionUseCase(bookmarkRepository, historyRepository, settingRepository)
+ });
+
+ 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,
+ })));
+
+ const items = await sut.getCompletionTypes();
+ expect(items).to.deep.equal([
+ CompletionType.SearchEngines,
+ CompletionType.History,
+ CompletionType.Bookmarks
+ ]);
+ });
+ });
+
+ 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,
+ })));
+
+ expect(await sut.requestSearchEngines("")).to.deep.equal([
+ "google",
+ "yahoo",
+ "bing",
+ "google_ja",
+ ]);
+ expect(await sut.requestSearchEngines("go")).to.deep.equal([
+ "google",
+ "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([]));
+
+ expect(await sut.requestBookmarks("site")).to.deep.equal([
+ { title: "site1", url: "https://site1.example.com" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ]);
+ expect(await sut.requestBookmarks("xyz")).to.be.empty;
+ });
+ });
+
+ 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" },
+ { title: "site2", url: "https://site2.example.com/" },
+ ]);
+ expect(await sut.requestHistory("xyz")).to.be.empty;
+ });
+ });
+}); \ No newline at end of file
diff --git a/test/background/completion/impl/filters.test.ts b/test/background/completion/impl/filters.test.ts
new file mode 100644
index 0000000..2b15a9b
--- /dev/null
+++ b/test/background/completion/impl/filters.test.ts
@@ -0,0 +1,114 @@
+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', () => {
+ 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' },
+ ];
+ const filtered = filters.filterHttp(pages);
+
+ 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'
+ ]);
+ })
+ });
+
+ describe('filterBlankTitle', () => {
+ it('filters blank titles', () => {
+ const pages = [
+ { id: '0', title: 'hello' },
+ { id: '1', title: '' },
+ { id: '2' },
+ ];
+ const filtered = filters.filterBlankTitle(pages);
+
+ expect(filtered).to.deep.equal([{ id: '0', title: 'hello' }]);
+ });
+ });
+
+ 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' },
+ ];
+ const filtered = filters.filterByTailingSlash(pages);
+
+ 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',
+ ]);
+ });
+ })
+
+ describe('filterByPathname', () => {
+ it('remains items less than minimam length', () => {
+ 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' },
+ ];
+ const filtered = filters.filterByPathname(pages, 10);
+ expect(filtered).to.have.lengthOf(6);
+ });
+
+ 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' },
+ ];
+ const filtered = filters.filterByPathname(pages, 0);
+ 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' },
+ ]);
+ });
+ });
+
+ describe('filterByOrigin', () => {
+ it('remains items less than minimam length', () => {
+ 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' },
+ ];
+ const filtered = filters.filterByOrigin(pages, 10);
+ expect(filtered).to.have.lengthOf(6);
+ });
+
+ 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' },
+ ];
+ const filtered = filters.filterByOrigin(pages, 0);
+ expect(filtered).to.deep.equal([
+ { id: '0', url: 'http://i-beam.org/search?q=apple' },
+ ]);
+ });
+ });
+});
diff --git a/test/background/usecases/filters.test.ts b/test/background/usecases/filters.test.ts
deleted file mode 100644
index 90541ff..0000000
--- a/test/background/usecases/filters.test.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-import * as filters from 'background/usecases/filters';
-
-describe("background/usecases/filters", () => {
- describe('filterHttp', () => {
- it('filters http URLs duplicates to https hosts', () => {
- const pages = [
- { url: 'http://i-beam.org/foo' },
- { url: 'https://i-beam.org/bar' },
- { url: 'http://i-beam.net/hoge' },
- { url: 'http://i-beam.net/fuga' },
- ];
- const filtered = filters.filterHttp(pages);
-
- 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'
- ]);
- })
- });
-
- describe('filterBlankTitle', () => {
- it('filters blank titles', () => {
- const pages = [
- { title: 'hello' },
- { title: '' },
- {},
- ];
- const filtered = filters.filterBlankTitle(pages);
-
- expect(filtered).to.deep.equal([{ title: 'hello' }]);
- });
- })
-
- describe('filterByTailingSlash', () => {
- it('filters duplicated pathname on tailing slash', () => {
- const pages = [
- { url: 'http://i-beam.org/content' },
- { url: 'http://i-beam.org/content/' },
- { url: 'http://i-beam.org/search' },
- { url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- ];
- const filtered = filters.filterByTailingSlash(pages);
-
- 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',
- ]);
- });
- })
-
- describe('filterByPathname', () => {
- it('remains items less than minimam length', () => {
- const pages = [
- { url: 'http://i-beam.org/search?q=apple' },
- { url: 'http://i-beam.org/search?q=apple_banana' },
- { url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { url: 'http://i-beam.org/request?q=apple' },
- { url: 'http://i-beam.org/request?q=apple_banana' },
- { url: 'http://i-beam.org/request?q=apple_banana_cherry' },
- ];
- const filtered = filters.filterByPathname(pages, 10);
- expect(filtered).to.have.lengthOf(6);
- });
-
- it('filters by length of pathname', () => {
- const pages = [
- { url: 'http://i-beam.org/search?q=apple' },
- { url: 'http://i-beam.org/search?q=apple_banana' },
- { url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { url: 'http://i-beam.net/search?q=apple' },
- { url: 'http://i-beam.net/search?q=apple_banana' },
- { url: 'http://i-beam.net/search?q=apple_banana_cherry' },
- ];
- const filtered = filters.filterByPathname(pages, 0);
- expect(filtered).to.deep.equal([
- { url: 'http://i-beam.org/search?q=apple' },
- { url: 'http://i-beam.net/search?q=apple' },
- ]);
- });
- })
-
- describe('filterByOrigin', () => {
- it('remains items less than minimam length', () => {
- const pages = [
- { url: 'http://i-beam.org/search?q=apple' },
- { url: 'http://i-beam.org/search?q=apple_banana' },
- { url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { url: 'http://i-beam.org/request?q=apple' },
- { url: 'http://i-beam.org/request?q=apple_banana' },
- { url: 'http://i-beam.org/request?q=apple_banana_cherry' },
- ];
- const filtered = filters.filterByOrigin(pages, 10);
- expect(filtered).to.have.lengthOf(6);
- });
-
- it('filters by length of pathname', () => {
- const pages = [
- { url: 'http://i-beam.org/search?q=apple' },
- { url: 'http://i-beam.org/search?q=apple_banana' },
- { url: 'http://i-beam.org/search?q=apple_banana_cherry' },
- { url: 'http://i-beam.org/request?q=apple' },
- { url: 'http://i-beam.org/request?q=apple_banana' },
- { url: 'http://i-beam.org/request?q=apple_banana_cherry' },
- ];
- const filtered = filters.filterByOrigin(pages, 0);
- expect(filtered).to.deep.equal([
- { url: 'http://i-beam.org/search?q=apple' },
- ]);
- });
- })
-});
diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts
index 583c878..e6567b2 100644
--- a/test/console/actions/console.test.ts
+++ b/test/console/actions/console.test.ts
@@ -1,5 +1,6 @@
-import * as actions from 'console/actions';
-import * as consoleActions from 'console/actions/console';
+import * as actions from '../../../src/console/actions';
+import * as consoleActions from '../../../src/console/actions/console';
+import { expect } from 'chai';
describe("console actions", () => {
describe('hide', () => {
@@ -9,8 +10,8 @@ describe("console actions", () => {
});
});
describe("showCommand", () => {
- it('create CONSOLE_SHOW_COMMAND action', () => {
- const action = 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');
});