diff options
Diffstat (limited to 'test/background/completion')
5 files changed, 368 insertions, 191 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" }, ]); }); }); |