1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
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' },
]);
});
})
});
|