diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-09 10:38:37 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 10:38:37 +0900 |
commit | 1656d52d2cefb3846d968c6117484e6aefe7dabe (patch) | |
tree | ab58a99b832d2571e2168f2ee0e328bc12d9580e /test/background/completion/impl | |
parent | c6c2da8547891b50aef2f08e5f36d258183831ff (diff) | |
parent | 5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff) |
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
Diffstat (limited to 'test/background/completion/impl')
-rw-r--r-- | test/background/completion/impl/filters.test.ts | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/test/background/completion/impl/filters.test.ts b/test/background/completion/impl/filters.test.ts new file mode 100644 index 0000000..2b15a9b --- /dev/null +++ b/test/background/completion/impl/filters.test.ts @@ -0,0 +1,114 @@ +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('remains items less than minimam length', () => { + 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.filterByPathname(pages, 10); + expect(filtered).to.have.lengthOf(6); + }); + + 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, 0); + 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('remains items less than minimam length', () => { + 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, 10); + expect(filtered).to.have.lengthOf(6); + }); + + 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, 0); + expect(filtered).to.deep.equal([ + { id: '0', url: 'http://i-beam.org/search?q=apple' }, + ]); + }); + }); +}); |