aboutsummaryrefslogtreecommitdiff
path: root/test/background/usecases
diff options
context:
space:
mode:
Diffstat (limited to 'test/background/usecases')
-rw-r--r--test/background/usecases/filters.test.js113
-rw-r--r--test/background/usecases/parsers.test.js47
2 files changed, 160 insertions, 0 deletions
diff --git a/test/background/usecases/filters.test.js b/test/background/usecases/filters.test.js
new file mode 100644
index 0000000..bdfb0be
--- /dev/null
+++ b/test/background/usecases/filters.test.js
@@ -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' },
+ ]);
+ });
+ })
+});
diff --git a/test/background/usecases/parsers.test.js b/test/background/usecases/parsers.test.js
new file mode 100644
index 0000000..17b034b
--- /dev/null
+++ b/test/background/usecases/parsers.test.js
@@ -0,0 +1,47 @@
+import * as parsers from 'background/usecases/parsers';
+
+describe("shared/commands/parsers", () => {
+ describe("#parsers.parseSetOption", () => {
+ it('parse set string', () => {
+ let [key, value] = parsers.parseSetOption('encoding=utf-8', { encoding: 'string' });
+ expect(key).to.equal('encoding');
+ expect(value).to.equal('utf-8');
+ });
+
+ it('parse set empty string', () => {
+ let [key, value] = parsers.parseSetOption('encoding=', { encoding: 'string' });
+ expect(key).to.equal('encoding');
+ expect(value).to.equal('');
+ });
+
+ it('parse set string', () => {
+ let [key, value] = parsers.parseSetOption('history=50', { history: 'number' });
+ expect(key).to.equal('history');
+ expect(value).to.equal(50);
+ });
+
+ it('parse set boolean', () => {
+ let [key, value] = parsers.parseSetOption('paste', { paste: 'boolean' });
+ expect(key).to.equal('paste');
+ expect(value).to.be.true;
+
+ [key, value] = parsers.parseSetOption('nopaste', { paste: 'boolean' });
+ expect(key).to.equal('paste');
+ expect(value).to.be.false;
+ });
+
+ it('throws error on unknown property', () => {
+ expect(() => parsers.parseSetOption('charset=utf-8', {})).to.throw(Error, 'Unknown');
+ expect(() => parsers.parseSetOption('smoothscroll', {})).to.throw(Error, 'Unknown');
+ expect(() => parsers.parseSetOption('nosmoothscroll', {})).to.throw(Error, 'Unknown');
+ })
+
+ it('throws error on invalid property', () => {
+ expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'number' })).to.throw(Error, 'Not number');
+ expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'boolean' })).to.throw(Error, 'Invalid');
+ expect(() => parsers.parseSetOption('charset=', { charset: 'boolean' })).to.throw(Error, 'Invalid');
+ expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'string' })).to.throw(Error, 'Invalid');
+ expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'number' })).to.throw(Error, 'Invalid');
+ })
+ });
+});