aboutsummaryrefslogtreecommitdiff
path: root/test/background/usecases/filters.test.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-07 21:16:47 +0900
committerGitHub <noreply@github.com>2019-05-07 21:16:47 +0900
commit05ef6a8ca35aaa801c11eb6b4896caa3690058af (patch)
tree2c7708ca91ac2b462cc86aa28612e3d3943496f3 /test/background/usecases/filters.test.ts
parent457d954e08923b4accd28a919c72d0b61db1bb98 (diff)
parent27d0a7f37d24a0ad68a8ccb7dee18fc1d00eea58 (diff)
Merge pull request #578 from ueokande/move-to-typescript
Move to TypeScript
Diffstat (limited to 'test/background/usecases/filters.test.ts')
-rw-r--r--test/background/usecases/filters.test.ts113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/background/usecases/filters.test.ts b/test/background/usecases/filters.test.ts
new file mode 100644
index 0000000..bdfb0be
--- /dev/null
+++ b/test/background/usecases/filters.test.ts
@@ -0,0 +1,113 @@
+import * as filters from 'background/usecases/filters';
+
+describe("background/usecases/filters", () => {
+ describe('filterHttp', () => {
+ it('filters http URLs duplicates to https hosts', () => {
+ let 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' },
+ ];
+ let filtered = filters.filterHttp(pages);
+
+ let 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', () => {
+ let pages = [
+ { title: 'hello' },
+ { title: '' },
+ {},
+ ];
+ let filtered = filters.filterBlankTitle(pages);
+
+ expect(filtered).to.deep.equal([{ title: 'hello' }]);
+ });
+ })
+
+ describe('filterByTailingSlash', () => {
+ it('filters duplicated pathname on tailing slash', () => {
+ let 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' },
+ ];
+ let filtered = filters.filterByTailingSlash(pages);
+
+ let 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', () => {
+ let 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' },
+ ];
+ let filtered = filters.filterByPathname(pages, 10);
+ expect(filtered).to.have.lengthOf(6);
+ });
+
+ it('filters by length of pathname', () => {
+ let 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' },
+ ];
+ let 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', () => {
+ let 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' },
+ ];
+ let filtered = filters.filterByOrigin(pages, 10);
+ expect(filtered).to.have.lengthOf(6);
+ });
+
+ it('filters by length of pathname', () => {
+ let 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' },
+ ];
+ let filtered = filters.filterByOrigin(pages, 0);
+ expect(filtered).to.deep.equal([
+ { url: 'http://i-beam.org/search?q=apple' },
+ ]);
+ });
+ })
+});