aboutsummaryrefslogtreecommitdiff
path: root/test/background/completion/impl
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/completion/impl')
-rw-r--r--test/background/completion/impl/PrefetchAndCache.test.ts80
-rw-r--r--test/background/completion/impl/filters.test.ts98
2 files changed, 103 insertions, 75 deletions
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" },
]);
});
});