aboutsummaryrefslogtreecommitdiff
path: root/test/background
diff options
context:
space:
mode:
Diffstat (limited to 'test/background')
-rw-r--r--test/background/completion/OpenCompletionUseCase.test.ts131
-rw-r--r--test/background/completion/PropertyCompletionUseCase.test.ts15
-rw-r--r--test/background/completion/TabCompletionUseCase.test.ts144
-rw-r--r--test/background/completion/impl/PrefetchAndCache.test.ts74
-rw-r--r--test/background/completion/impl/filters.test.ts88
-rw-r--r--test/background/usecases/NavigateUseCase.test.ts127
-rw-r--r--test/background/usecases/filters.test.ts113
7 files changed, 555 insertions, 137 deletions
diff --git a/test/background/completion/OpenCompletionUseCase.test.ts b/test/background/completion/OpenCompletionUseCase.test.ts
new file mode 100644
index 0000000..421ce69
--- /dev/null
+++ b/test/background/completion/OpenCompletionUseCase.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 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 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('OpenCompletionUseCase', () => {
+ let bookmarkRepository: MockBookmarkRepository;
+ let historyRepository: MockHistoryRepository;
+ let settingRepository: MockSettingRepository;
+ let sut: OpenCompletionUseCase;
+
+ beforeEach(() => {
+ bookmarkRepository = new MockBookmarkRepository();
+ historyRepository = new MockHistoryRepository();
+ settingRepository = new MockSettingRepository();
+ sut = new OpenCompletionUseCase(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/PropertyCompletionUseCase.test.ts b/test/background/completion/PropertyCompletionUseCase.test.ts
new file mode 100644
index 0000000..57f5bff
--- /dev/null
+++ b/test/background/completion/PropertyCompletionUseCase.test.ts
@@ -0,0 +1,15 @@
+import 'reflect-metadata';
+import PropertyCompletionUseCase from "../../../src/background/completion/PropertyCompletionUseCase";
+import { expect } from 'chai';
+
+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' });
+ })
+ });
+}); \ No newline at end of file
diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts
new file mode 100644
index 0000000..b9dc60b
--- /dev/null
+++ b/test/background/completion/TabCompletionUseCase.test.ts
@@ -0,0 +1,144 @@
+import "reflect-metadata"
+import TabRepositoryImpl from "../../../src/background/completion/impl/TabRepositoryImpl";
+import {Tab} from "../../../src/background/completion/TabRepository";
+import TabPresenter from "../../../src/background/presenters/TabPresenter";
+import TabCompletionUseCase from "../../../src/background/completion/TabCompletionUseCase";
+import sinon from 'sinon';
+import { expect } from 'chai';
+import TabFlag from "../../../src/shared/TabFlag";
+
+class MockTabRepository implements TabRepositoryImpl {
+ async queryTabs(_query: string, _excludePinned: boolean): Promise<Tab[]> {
+ throw new Error("not implemented")
+ }
+
+ async getAllTabs(_excludePinned: boolean): Promise<Tab[]> {
+ throw new Error("not implemented")
+ }
+}
+
+class MockTabPresenter implements TabPresenter {
+ create(_url: string, _opts?: object): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ duplicate(_id: number): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented")
+ }
+
+ getAll(): 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")
+ }
+
+ getLastSelectedId(): Promise<number | undefined> {
+ throw new Error("not implemented")
+ }
+
+ getZoom(_tabId: number): Promise<number> {
+ 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")
+ }
+
+ reload(_tabId: number, _cache: boolean): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ remove(_ids: number[]): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ reopen(): Promise<any> {
+ throw new Error("not implemented")
+ }
+
+ select(_tabId: number): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ setPinned(_tabId: number, _pinned: boolean): Promise<void> {
+ throw new Error("not implemented")
+ }
+
+ setZoom(_tabId: number, _factor: number): Promise<void> {
+ throw new Error("not implemented")
+ }
+}
+
+describe('TabCompletionUseCase', () => {
+ let tabRepository: MockTabRepository;
+ let tabPresenter: TabPresenter;
+ let sut: TabCompletionUseCase;
+
+ beforeEach(() => {
+ tabRepository = new MockTabRepository();
+ 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 },
+ ]));
+ });
+
+ 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 },
+ ]);
+
+ 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('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 },
+ ]);
+ });
+
+ 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 },
+ ]);
+ })
+ });
+}); \ No newline at end of file
diff --git a/test/background/completion/impl/PrefetchAndCache.test.ts b/test/background/completion/impl/PrefetchAndCache.test.ts
new file mode 100644
index 0000000..23e3879
--- /dev/null
+++ b/test/background/completion/impl/PrefetchAndCache.test.ts
@@ -0,0 +1,74 @@
+import PrefetchAndCache, {shortKey} from "../../../../src/background/completion/impl/PrefetchAndCache";
+import { expect } from 'chai';
+
+class MockRepository {
+ public history: 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)));
+ }
+ }
+}
+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")
+ });
+
+ 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-")
+ });
+
+ 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/");
+
+ query = "https://example.com/path/to/resource/#id1";
+ shorten = shortKey(query);
+ expect(shorten).to.equal("https://example.com/path/to/");
+
+ 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"]);
+ 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("banana")).deep.equal(["banana", "banana pudding"]);
+ expect(repo.history).to.deep.equal(["apple", "ap", "ban"]);
+ expect(await sut.get("banana p")).deep.equal(["banana pudding"]);
+ expect(repo.history).to.deep.equal(["apple", "ap", "ban", "banana"]);
+ expect(await sut.get("ba")).deep.equal(["banana", "banana pudding"]);
+ 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", ""]);
+ });
+ });
+}); \ 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..a181f60
--- /dev/null
+++ b/test/background/completion/impl/filters.test.ts
@@ -0,0 +1,88 @@
+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('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);
+ 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('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);
+ expect(filtered).to.deep.equal([
+ { id: '0', url: 'http://i-beam.org/search?q=apple' },
+ ]);
+ });
+ });
+});
diff --git a/test/background/usecases/NavigateUseCase.test.ts b/test/background/usecases/NavigateUseCase.test.ts
index 48a1c5b..7ad0e4f 100644
--- a/test/background/usecases/NavigateUseCase.test.ts
+++ b/test/background/usecases/NavigateUseCase.test.ts
@@ -1,26 +1,107 @@
+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 { expect } from 'chai';
import * as sinon from 'sinon';
+class MockTabPresenter implements TabPresenter {
+ create(_url: string, _opts?: object): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented");
+ }
+
+ duplicate(_id: number): Promise<browser.tabs.Tab> {
+ throw new Error("not implemented");
+ }
+
+ getAll(): 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");
+ }
+
+ getLastSelectedId(): Promise<number | undefined> {
+ throw new Error("not implemented");
+ }
+
+ getZoom(_tabId: number): Promise<number> {
+ 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");
+ }
+
+ reload(_tabId: number, _cache: boolean): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ remove(_ids: number[]): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ reopen(): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ select(_tabId: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ setPinned(_tabId: number, _pinned: boolean): Promise<void> {
+ throw new Error("not implemented");
+ }
+
+ setZoom(_tabId: number, _factor: number): Promise<void> {
+ throw new Error("not implemented");
+ }
+}
+
describe('NavigateUseCase', () => {
let sut: NavigateUseCase;
let tabPresenter: TabPresenter;
let navigateClient: NavigateClient;
+
beforeEach(() => {
- tabPresenter = new TabPresenter();
+ tabPresenter = new MockTabPresenter();
navigateClient = new NavigateClient();
sut = new NavigateUseCase(tabPresenter, navigateClient);
});
+ const newTab = (url: string): browser.tabs.Tab => {
+ return {
+ index: 0,
+ title: 'dummy title',
+ url: url,
+ active: true,
+ hidden: false,
+ highlighted: false,
+ incognito: false,
+ isArticle: false,
+ isInReaderMode: false,
+ lastAccessed: 1585446733000,
+ pinned: false,
+ selected: false,
+ windowId: 0
+ };
+ };
+
describe('#openParent()', async () => {
it('opens parent directory of file', async() => {
- const stub = sinon.stub(tabPresenter, 'getCurrent');
- stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/banana' }))
+ sinon.stub(tabPresenter, 'getCurrent')
+ .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/banana')));
- const mock = sinon.mock(tabPresenter);
- mock.expects('open').withArgs('https://google.com/fruits/yellow/');
+ const mock = sinon.mock(tabPresenter)
+ .expects('open').withArgs('https://google.com/fruits/yellow/');
await sut.openParent();
@@ -28,11 +109,11 @@ describe('NavigateUseCase', () => {
});
it('opens parent directory of directory', async() => {
- const stub = sinon.stub(tabPresenter, 'getCurrent');
- stub.returns(Promise.resolve({ url: 'https://google.com/fruits/yellow/' }))
+ sinon.stub(tabPresenter, 'getCurrent')
+ .returns(Promise.resolve(newTab('https://google.com/fruits/yellow/')));
- const mock = sinon.mock(tabPresenter);
- mock.expects('open').withArgs('https://google.com/fruits/');
+ const mock = sinon.mock(tabPresenter)
+ .expects('open').withArgs('https://google.com/fruits/');
await sut.openParent();
@@ -40,11 +121,11 @@ describe('NavigateUseCase', () => {
});
it('removes hash', async() => {
- const stub = sinon.stub(tabPresenter, 'getCurrent');
- stub.returns(Promise.resolve({ url: 'https://google.com/#top' }))
+ sinon.stub(tabPresenter, 'getCurrent')
+ .returns(Promise.resolve(newTab('https://google.com/#top')));
- const mock = sinon.mock(tabPresenter);
- mock.expects('open').withArgs('https://google.com/');
+ const mock = sinon.mock(tabPresenter)
+ .expects('open').withArgs('https://google.com/');
await sut.openParent();
@@ -52,11 +133,11 @@ describe('NavigateUseCase', () => {
});
it('removes search query', async() => {
- const stub = sinon.stub(tabPresenter, 'getCurrent');
- stub.returns(Promise.resolve({ url: 'https://google.com/search?q=apple' }))
+ sinon.stub(tabPresenter, 'getCurrent')
+ .returns(Promise.resolve(newTab('https://google.com/search?q=apple')));
- const mock = sinon.mock(tabPresenter);
- mock.expects('open').withArgs('https://google.com/search');
+ const mock = sinon.mock(tabPresenter)
+ .expects('open').withArgs('https://google.com/search');
await sut.openParent();
@@ -66,13 +147,11 @@ describe('NavigateUseCase', () => {
describe('#openRoot()', () => {
it('opens root direectory', async() => {
- const stub = sinon.stub(tabPresenter, 'getCurrent');
- stub.returns(Promise.resolve({
- url: 'https://google.com/seach?q=apple',
- }))
+ sinon.stub(tabPresenter, 'getCurrent')
+ .returns(Promise.resolve(newTab('https://google.com/seach?q=apple')));
- const mock = sinon.mock(tabPresenter);
- mock.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/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' },
- ]);
- });
- })
-});