From c60d0e7392fc708e961614d6b756a045de74f458 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:00:07 +0900 Subject: Rename .js/.jsx to .ts/.tsx --- test/shared/blacklists.test.js | 49 ---------- test/shared/blacklists.test.ts | 49 ++++++++++ test/shared/settings/validator.test.js | 81 ---------------- test/shared/settings/validator.test.ts | 81 ++++++++++++++++ test/shared/settings/values.test.js | 138 --------------------------- test/shared/settings/values.test.ts | 138 +++++++++++++++++++++++++++ test/shared/urls.test.js | 48 ---------- test/shared/urls.test.ts | 48 ++++++++++ test/shared/utils/keys.test.js | 164 --------------------------------- test/shared/utils/keys.test.ts | 164 +++++++++++++++++++++++++++++++++ test/shared/utils/re.test.js | 19 ---- test/shared/utils/re.test.ts | 19 ++++ 12 files changed, 499 insertions(+), 499 deletions(-) delete mode 100644 test/shared/blacklists.test.js create mode 100644 test/shared/blacklists.test.ts delete mode 100644 test/shared/settings/validator.test.js create mode 100644 test/shared/settings/validator.test.ts delete mode 100644 test/shared/settings/values.test.js create mode 100644 test/shared/settings/values.test.ts delete mode 100644 test/shared/urls.test.js create mode 100644 test/shared/urls.test.ts delete mode 100644 test/shared/utils/keys.test.js create mode 100644 test/shared/utils/keys.test.ts delete mode 100644 test/shared/utils/re.test.js create mode 100644 test/shared/utils/re.test.ts (limited to 'test/shared') diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.js deleted file mode 100644 index 289ea0f..0000000 --- a/test/shared/blacklists.test.js +++ /dev/null @@ -1,49 +0,0 @@ -import { includes } from 'shared/blacklists'; - -describe("shared/blacklist", () => { - it('matches by *', () => { - let blacklist = ['*']; - - expect(includes(blacklist, 'https://github.com/abc')).to.be.true; - }) - - it('matches by hostname', () => { - let blacklist = ['github.com']; - - expect(includes(blacklist, 'https://github.com')).to.be.true; - expect(includes(blacklist, 'https://gist.github.com')).to.be.false; - expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true; - expect(includes(blacklist, 'https://github.org')).to.be.false; - expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false; - }) - - it('matches by hostname with wildcard', () => { - let blacklist = ['*.github.com']; - - expect(includes(blacklist, 'https://github.com')).to.be.false; - expect(includes(blacklist, 'https://gist.github.com')).to.be.true; - }) - - it('matches by path', () => { - let blacklist = ['github.com/abc']; - - expect(includes(blacklist, 'https://github.com/abc')).to.be.true; - expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false; - expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false; - }) - - it('matches by path with wildcard', () => { - let blacklist = ['github.com/abc*']; - - expect(includes(blacklist, 'https://github.com/abc')).to.be.true; - expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true; - expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false; - }) - - it('matches address and port', () => { - let blacklist = ['127.0.0.1:8888']; - - expect(includes(blacklist, 'http://127.0.0.1:8888/')).to.be.true; - expect(includes(blacklist, 'http://127.0.0.1:8888/hello')).to.be.true; - }) -}); diff --git a/test/shared/blacklists.test.ts b/test/shared/blacklists.test.ts new file mode 100644 index 0000000..289ea0f --- /dev/null +++ b/test/shared/blacklists.test.ts @@ -0,0 +1,49 @@ +import { includes } from 'shared/blacklists'; + +describe("shared/blacklist", () => { + it('matches by *', () => { + let blacklist = ['*']; + + expect(includes(blacklist, 'https://github.com/abc')).to.be.true; + }) + + it('matches by hostname', () => { + let blacklist = ['github.com']; + + expect(includes(blacklist, 'https://github.com')).to.be.true; + expect(includes(blacklist, 'https://gist.github.com')).to.be.false; + expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true; + expect(includes(blacklist, 'https://github.org')).to.be.false; + expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false; + }) + + it('matches by hostname with wildcard', () => { + let blacklist = ['*.github.com']; + + expect(includes(blacklist, 'https://github.com')).to.be.false; + expect(includes(blacklist, 'https://gist.github.com')).to.be.true; + }) + + it('matches by path', () => { + let blacklist = ['github.com/abc']; + + expect(includes(blacklist, 'https://github.com/abc')).to.be.true; + expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false; + expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false; + }) + + it('matches by path with wildcard', () => { + let blacklist = ['github.com/abc*']; + + expect(includes(blacklist, 'https://github.com/abc')).to.be.true; + expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true; + expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false; + }) + + it('matches address and port', () => { + let blacklist = ['127.0.0.1:8888']; + + expect(includes(blacklist, 'http://127.0.0.1:8888/')).to.be.true; + expect(includes(blacklist, 'http://127.0.0.1:8888/hello')).to.be.true; + }) +}); diff --git a/test/shared/settings/validator.test.js b/test/shared/settings/validator.test.js deleted file mode 100644 index 9bbfa3e..0000000 --- a/test/shared/settings/validator.test.js +++ /dev/null @@ -1,81 +0,0 @@ -import { validate } from 'shared/settings/validator'; - -describe("setting validator", () => { - describe("unknown top keys", () => { - it('throws an error for unknown settings', () => { - let settings = { keymaps: {}, poison: 123 }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'poison'); - }) - }); - - describe("keymaps settings", () => { - it('throws an error for unknown operation', () => { - let settings = { - keymaps: { - a: { 'type': 'scroll.home' }, - b: { 'type': 'poison.dressing' }, - } - }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'poison.dressing'); - }); - }); - - describe("search settings", () => { - it('throws an error for invalid search engine name', () => { - let settings = { - search: { - default: 'google', - engines: { - 'google': 'https://google.com/search?q={}', - 'cherry pie': 'https://cherypie.com/search?q={}', - } - } - }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'cherry pie'); - }); - - it('throws an error for no {}-placeholder', () => { - let settings = { - search: { - default: 'google', - engines: { - 'google': 'https://google.com/search?q={}', - 'yahoo': 'https://search.yahoo.com/search', - } - } - }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'yahoo'); - }); - - it('throws an error for no default engines', () => { - let settings = { - search: { - engines: { - 'google': 'https://google.com/search?q={}', - 'yahoo': 'https://search.yahoo.com/search?q={}', - } - } - }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'Default engine'); - }); - - it('throws an error for invalid default engine', () => { - let settings = { - search: { - default: 'twitter', - engines: { - 'google': 'https://google.com/search?q={}', - 'yahoo': 'https://search.yahoo.com/search?q={}', - } - } - }; - let fn = validate.bind(undefined, settings) - expect(fn).to.throw(Error, 'twitter'); - }); - }); -}); diff --git a/test/shared/settings/validator.test.ts b/test/shared/settings/validator.test.ts new file mode 100644 index 0000000..9bbfa3e --- /dev/null +++ b/test/shared/settings/validator.test.ts @@ -0,0 +1,81 @@ +import { validate } from 'shared/settings/validator'; + +describe("setting validator", () => { + describe("unknown top keys", () => { + it('throws an error for unknown settings', () => { + let settings = { keymaps: {}, poison: 123 }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'poison'); + }) + }); + + describe("keymaps settings", () => { + it('throws an error for unknown operation', () => { + let settings = { + keymaps: { + a: { 'type': 'scroll.home' }, + b: { 'type': 'poison.dressing' }, + } + }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'poison.dressing'); + }); + }); + + describe("search settings", () => { + it('throws an error for invalid search engine name', () => { + let settings = { + search: { + default: 'google', + engines: { + 'google': 'https://google.com/search?q={}', + 'cherry pie': 'https://cherypie.com/search?q={}', + } + } + }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'cherry pie'); + }); + + it('throws an error for no {}-placeholder', () => { + let settings = { + search: { + default: 'google', + engines: { + 'google': 'https://google.com/search?q={}', + 'yahoo': 'https://search.yahoo.com/search', + } + } + }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'yahoo'); + }); + + it('throws an error for no default engines', () => { + let settings = { + search: { + engines: { + 'google': 'https://google.com/search?q={}', + 'yahoo': 'https://search.yahoo.com/search?q={}', + } + } + }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'Default engine'); + }); + + it('throws an error for invalid default engine', () => { + let settings = { + search: { + default: 'twitter', + engines: { + 'google': 'https://google.com/search?q={}', + 'yahoo': 'https://search.yahoo.com/search?q={}', + } + } + }; + let fn = validate.bind(undefined, settings) + expect(fn).to.throw(Error, 'twitter'); + }); + }); +}); diff --git a/test/shared/settings/values.test.js b/test/shared/settings/values.test.js deleted file mode 100644 index c72824d..0000000 --- a/test/shared/settings/values.test.js +++ /dev/null @@ -1,138 +0,0 @@ -import * as values from 'shared/settings/values'; - -describe("settings values", () => { - describe('valueFromJson', () => { - it('return object from json string', () => { - let json = `{ - "keymaps": { "0": {"type": "scroll.home"}}, - "search": { "default": "google", "engines": { "google": "https://google.com/search?q={}" }}, - "blacklist": [ "*.slack.com"], - "properties": { - "mystr": "value", - "mynum": 123, - "mybool": true - } - }`; - let value = values.valueFromJson(json); - - expect(value.keymaps).to.deep.equal({ 0: {type: "scroll.home"}}); - expect(value.search).to.deep.equal({ default: "google", engines: { google: "https://google.com/search?q={}"} }); - expect(value.blacklist).to.deep.equal(["*.slack.com"]); - expect(value.properties).to.have.property('mystr', 'value'); - expect(value.properties).to.have.property('mynum', 123); - expect(value.properties).to.have.property('mybool', true); - }); - }); - - describe('valueFromForm', () => { - it('returns value from form', () => { - let form = { - keymaps: { - 'scroll.vertically?{"count":1}': 'j', - 'scroll.home': '0', - }, - search: { - default: 'google', - engines: [['google', 'https://google.com/search?q={}']], - }, - blacklist: ['*.slack.com'], - "properties": { - "mystr": "value", - "mynum": 123, - "mybool": true, - } - }; - let value = values.valueFromForm(form); - - expect(value.keymaps).to.have.deep.property('j', { type: "scroll.vertically", count: 1 }); - expect(value.keymaps).to.have.deep.property('0', { type: "scroll.home" }); - expect(JSON.stringify(value.search)).to.deep.equal(JSON.stringify({ default: "google", engines: { google: "https://google.com/search?q={}"} })); - expect(value.search).to.deep.equal({ default: "google", engines: { google: "https://google.com/search?q={}"} }); - expect(value.blacklist).to.deep.equal(["*.slack.com"]); - expect(value.properties).to.have.property('mystr', 'value'); - expect(value.properties).to.have.property('mynum', 123); - expect(value.properties).to.have.property('mybool', true); - }); - - it('convert from empty form', () => { - let form = {}; - let value = values.valueFromForm(form); - expect(value).to.not.have.key('keymaps'); - expect(value).to.not.have.key('search'); - expect(value).to.not.have.key('blacklist'); - expect(value).to.not.have.key('properties'); - }); - - it('override keymaps', () => { - let form = { - keymaps: { - 'scroll.vertically?{"count":1}': 'j', - 'scroll.vertically?{"count":-1}': 'j', - } - }; - let value = values.valueFromForm(form); - - expect(value.keymaps).to.have.key('j'); - }); - - it('override search engine', () => { - let form = { - search: { - default: 'google', - engines: [ - ['google', 'https://google.com/search?q={}'], - ['google', 'https://google.co.jp/search?q={}'], - ] - } - }; - let value = values.valueFromForm(form); - - expect(value.search.engines).to.have.property('google', 'https://google.co.jp/search?q={}'); - }); - }); - - describe('jsonFromValue', () => { - }); - - describe('formFromValue', () => { - it('convert empty value to form', () => { - let value = {}; - let form = values.formFromValue(value); - - expect(value).to.not.have.key('keymaps'); - expect(value).to.not.have.key('search'); - expect(value).to.not.have.key('blacklist'); - }); - - it('convert value to form', () => { - let value = { - keymaps: { - j: { type: 'scroll.vertically', count: 1 }, - JJ: { type: 'scroll.vertically', count: 100 }, - 0: { type: 'scroll.home' }, - }, - search: { default: 'google', engines: { google: 'https://google.com/search?q={}' }}, - blacklist: [ '*.slack.com'], - properties: { - "mystr": "value", - "mynum": 123, - "mybool": true, - } - }; - let allowed = ['scroll.vertically?{"count":1}', 'scroll.home' ]; - let form = values.formFromValue(value, allowed); - - expect(form.keymaps).to.have.property('scroll.vertically?{"count":1}', 'j'); - expect(form.keymaps).to.not.have.property('scroll.vertically?{"count":100}'); - expect(form.keymaps).to.have.property('scroll.home', '0'); - expect(Object.keys(form.keymaps)).to.have.lengthOf(2); - expect(form.search).to.have.property('default', 'google'); - expect(form.search).to.have.deep.property('engines', [['google', 'https://google.com/search?q={}']]); - expect(form.blacklist).to.have.lengthOf(1); - expect(form.blacklist).to.include('*.slack.com'); - expect(form.properties).to.have.property('mystr', 'value'); - expect(form.properties).to.have.property('mynum', 123); - expect(form.properties).to.have.property('mybool', true); - }); - }); -}); diff --git a/test/shared/settings/values.test.ts b/test/shared/settings/values.test.ts new file mode 100644 index 0000000..c72824d --- /dev/null +++ b/test/shared/settings/values.test.ts @@ -0,0 +1,138 @@ +import * as values from 'shared/settings/values'; + +describe("settings values", () => { + describe('valueFromJson', () => { + it('return object from json string', () => { + let json = `{ + "keymaps": { "0": {"type": "scroll.home"}}, + "search": { "default": "google", "engines": { "google": "https://google.com/search?q={}" }}, + "blacklist": [ "*.slack.com"], + "properties": { + "mystr": "value", + "mynum": 123, + "mybool": true + } + }`; + let value = values.valueFromJson(json); + + expect(value.keymaps).to.deep.equal({ 0: {type: "scroll.home"}}); + expect(value.search).to.deep.equal({ default: "google", engines: { google: "https://google.com/search?q={}"} }); + expect(value.blacklist).to.deep.equal(["*.slack.com"]); + expect(value.properties).to.have.property('mystr', 'value'); + expect(value.properties).to.have.property('mynum', 123); + expect(value.properties).to.have.property('mybool', true); + }); + }); + + describe('valueFromForm', () => { + it('returns value from form', () => { + let form = { + keymaps: { + 'scroll.vertically?{"count":1}': 'j', + 'scroll.home': '0', + }, + search: { + default: 'google', + engines: [['google', 'https://google.com/search?q={}']], + }, + blacklist: ['*.slack.com'], + "properties": { + "mystr": "value", + "mynum": 123, + "mybool": true, + } + }; + let value = values.valueFromForm(form); + + expect(value.keymaps).to.have.deep.property('j', { type: "scroll.vertically", count: 1 }); + expect(value.keymaps).to.have.deep.property('0', { type: "scroll.home" }); + expect(JSON.stringify(value.search)).to.deep.equal(JSON.stringify({ default: "google", engines: { google: "https://google.com/search?q={}"} })); + expect(value.search).to.deep.equal({ default: "google", engines: { google: "https://google.com/search?q={}"} }); + expect(value.blacklist).to.deep.equal(["*.slack.com"]); + expect(value.properties).to.have.property('mystr', 'value'); + expect(value.properties).to.have.property('mynum', 123); + expect(value.properties).to.have.property('mybool', true); + }); + + it('convert from empty form', () => { + let form = {}; + let value = values.valueFromForm(form); + expect(value).to.not.have.key('keymaps'); + expect(value).to.not.have.key('search'); + expect(value).to.not.have.key('blacklist'); + expect(value).to.not.have.key('properties'); + }); + + it('override keymaps', () => { + let form = { + keymaps: { + 'scroll.vertically?{"count":1}': 'j', + 'scroll.vertically?{"count":-1}': 'j', + } + }; + let value = values.valueFromForm(form); + + expect(value.keymaps).to.have.key('j'); + }); + + it('override search engine', () => { + let form = { + search: { + default: 'google', + engines: [ + ['google', 'https://google.com/search?q={}'], + ['google', 'https://google.co.jp/search?q={}'], + ] + } + }; + let value = values.valueFromForm(form); + + expect(value.search.engines).to.have.property('google', 'https://google.co.jp/search?q={}'); + }); + }); + + describe('jsonFromValue', () => { + }); + + describe('formFromValue', () => { + it('convert empty value to form', () => { + let value = {}; + let form = values.formFromValue(value); + + expect(value).to.not.have.key('keymaps'); + expect(value).to.not.have.key('search'); + expect(value).to.not.have.key('blacklist'); + }); + + it('convert value to form', () => { + let value = { + keymaps: { + j: { type: 'scroll.vertically', count: 1 }, + JJ: { type: 'scroll.vertically', count: 100 }, + 0: { type: 'scroll.home' }, + }, + search: { default: 'google', engines: { google: 'https://google.com/search?q={}' }}, + blacklist: [ '*.slack.com'], + properties: { + "mystr": "value", + "mynum": 123, + "mybool": true, + } + }; + let allowed = ['scroll.vertically?{"count":1}', 'scroll.home' ]; + let form = values.formFromValue(value, allowed); + + expect(form.keymaps).to.have.property('scroll.vertically?{"count":1}', 'j'); + expect(form.keymaps).to.not.have.property('scroll.vertically?{"count":100}'); + expect(form.keymaps).to.have.property('scroll.home', '0'); + expect(Object.keys(form.keymaps)).to.have.lengthOf(2); + expect(form.search).to.have.property('default', 'google'); + expect(form.search).to.have.deep.property('engines', [['google', 'https://google.com/search?q={}']]); + expect(form.blacklist).to.have.lengthOf(1); + expect(form.blacklist).to.include('*.slack.com'); + expect(form.properties).to.have.property('mystr', 'value'); + expect(form.properties).to.have.property('mynum', 123); + expect(form.properties).to.have.property('mybool', true); + }); + }); +}); diff --git a/test/shared/urls.test.js b/test/shared/urls.test.js deleted file mode 100644 index f2950b6..0000000 --- a/test/shared/urls.test.js +++ /dev/null @@ -1,48 +0,0 @@ -import * as parsers from 'shared/urls'; - -describe("shared/commands/parsers", () => { - describe('#searchUrl', () => { - const config = { - default: 'google', - engines: { - google: 'https://google.com/search?q={}', - yahoo: 'https://yahoo.com/search?q={}', - } - }; - - it('convertes search url', () => { - expect(parsers.searchUrl('google.com', config)) - .to.equal('http://google.com'); - expect(parsers.searchUrl('google apple', config)) - .to.equal('https://google.com/search?q=apple'); - expect(parsers.searchUrl('yahoo apple', config)) - .to.equal('https://yahoo.com/search?q=apple'); - expect(parsers.searchUrl('google apple banana', config)) - .to.equal('https://google.com/search?q=apple%20banana'); - expect(parsers.searchUrl('yahoo C++CLI', config)) - .to.equal('https://yahoo.com/search?q=C%2B%2BCLI'); - }); - - it('user default search engine', () => { - expect(parsers.searchUrl('apple banana', config)) - .to.equal('https://google.com/search?q=apple%20banana'); - }); - - it('searches with a word containing a colon', () => { - expect(parsers.searchUrl('foo:', config)) - .to.equal('https://google.com/search?q=foo%3A'); - expect(parsers.searchUrl('std::vector', config)) - .to.equal('https://google.com/search?q=std%3A%3Avector'); - }); - }); - - describe('#normalizeUrl', () => { - it('normalize urls', () => { - expect(parsers.normalizeUrl('https://google.com/')) - .to.equal('https://google.com/'); - expect(parsers.normalizeUrl('google.com')) - .to.equal('http://google.com'); - }); - }); -}); - diff --git a/test/shared/urls.test.ts b/test/shared/urls.test.ts new file mode 100644 index 0000000..f2950b6 --- /dev/null +++ b/test/shared/urls.test.ts @@ -0,0 +1,48 @@ +import * as parsers from 'shared/urls'; + +describe("shared/commands/parsers", () => { + describe('#searchUrl', () => { + const config = { + default: 'google', + engines: { + google: 'https://google.com/search?q={}', + yahoo: 'https://yahoo.com/search?q={}', + } + }; + + it('convertes search url', () => { + expect(parsers.searchUrl('google.com', config)) + .to.equal('http://google.com'); + expect(parsers.searchUrl('google apple', config)) + .to.equal('https://google.com/search?q=apple'); + expect(parsers.searchUrl('yahoo apple', config)) + .to.equal('https://yahoo.com/search?q=apple'); + expect(parsers.searchUrl('google apple banana', config)) + .to.equal('https://google.com/search?q=apple%20banana'); + expect(parsers.searchUrl('yahoo C++CLI', config)) + .to.equal('https://yahoo.com/search?q=C%2B%2BCLI'); + }); + + it('user default search engine', () => { + expect(parsers.searchUrl('apple banana', config)) + .to.equal('https://google.com/search?q=apple%20banana'); + }); + + it('searches with a word containing a colon', () => { + expect(parsers.searchUrl('foo:', config)) + .to.equal('https://google.com/search?q=foo%3A'); + expect(parsers.searchUrl('std::vector', config)) + .to.equal('https://google.com/search?q=std%3A%3Avector'); + }); + }); + + describe('#normalizeUrl', () => { + it('normalize urls', () => { + expect(parsers.normalizeUrl('https://google.com/')) + .to.equal('https://google.com/'); + expect(parsers.normalizeUrl('google.com')) + .to.equal('http://google.com'); + }); + }); +}); + diff --git a/test/shared/utils/keys.test.js b/test/shared/utils/keys.test.js deleted file mode 100644 index b2ad3cb..0000000 --- a/test/shared/utils/keys.test.js +++ /dev/null @@ -1,164 +0,0 @@ -import * as keys from 'shared/utils/keys'; - -describe("keys util", () => { - describe('fromKeyboardEvent', () => { - it('returns from keyboard input Ctrl+X', () => { - let k = keys.fromKeyboardEvent({ - key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true - }); - expect(k.key).to.equal('x'); - expect(k.shiftKey).to.be.false; - expect(k.ctrlKey).to.be.true; - expect(k.altKey).to.be.false; - expect(k.metaKey).to.be.true; - }); - - it('returns from keyboard input Shift+Esc', () => { - let k = keys.fromKeyboardEvent({ - key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true - }); - expect(k.key).to.equal('Esc'); - expect(k.shiftKey).to.be.true; - expect(k.ctrlKey).to.be.false; - expect(k.altKey).to.be.false; - expect(k.metaKey).to.be.true; - }); - - it('returns from keyboard input Ctrl+$', () => { - // $ required shift pressing on most keyboards - let k = keys.fromKeyboardEvent({ - key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false - }); - expect(k.key).to.equal('$'); - expect(k.shiftKey).to.be.false; - expect(k.ctrlKey).to.be.true; - expect(k.altKey).to.be.false; - expect(k.metaKey).to.be.false; - }); - - it('returns from keyboard input Crtl+Space', () => { - let k = keys.fromKeyboardEvent({ - key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false - }); - expect(k.key).to.equal('Space'); - expect(k.shiftKey).to.be.false; - expect(k.ctrlKey).to.be.true; - expect(k.altKey).to.be.false; - expect(k.metaKey).to.be.false; - }); - }); - - describe('fromMapKey', () => { - it('return for X', () => { - let key = keys.fromMapKey('x'); - expect(key.key).to.equal('x'); - expect(key.shiftKey).to.be.false; - expect(key.ctrlKey).to.be.false; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('return for Shift+X', () => { - let key = keys.fromMapKey('X'); - expect(key.key).to.equal('X'); - expect(key.shiftKey).to.be.true; - expect(key.ctrlKey).to.be.false; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('return for Ctrl+X', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('x'); - expect(key.shiftKey).to.be.false; - expect(key.ctrlKey).to.be.true; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('returns for Ctrl+Meta+X', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('x'); - expect(key.shiftKey).to.be.false; - expect(key.ctrlKey).to.be.true; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.true; - }); - - it('returns for Ctrl+Shift+x', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('X'); - expect(key.shiftKey).to.be.true; - expect(key.ctrlKey).to.be.true; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('returns for Shift+Esc', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('Esc'); - expect(key.shiftKey).to.be.true; - expect(key.ctrlKey).to.be.false; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('returns for Ctrl+Esc', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('Esc'); - expect(key.shiftKey).to.be.false; - expect(key.ctrlKey).to.be.true; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - - it('returns for Ctrl+Esc', () => { - let key = keys.fromMapKey(''); - expect(key.key).to.equal('Space'); - expect(key.shiftKey).to.be.false; - expect(key.ctrlKey).to.be.true; - expect(key.altKey).to.be.false; - expect(key.metaKey).to.be.false; - }); - }); - - describe('fromMapKeys', () => { - it('returns mapped keys for Shift+Esc', () => { - let keyArray = keys.fromMapKeys(''); - expect(keyArray).to.have.lengthOf(1); - expect(keyArray[0].key).to.equal('Esc'); - expect(keyArray[0].shiftKey).to.be.true; - }); - - it('returns mapped keys for ad', () => { - let keyArray = keys.fromMapKeys('ad'); - expect(keyArray).to.have.lengthOf(5); - expect(keyArray[0].key).to.equal('a'); - expect(keyArray[1].ctrlKey).to.be.true; - expect(keyArray[1].key).to.equal('b'); - expect(keyArray[2].altKey).to.be.true; - expect(keyArray[2].key).to.equal('c'); - expect(keyArray[3].key).to.equal('d'); - expect(keyArray[4].metaKey).to.be.true; - expect(keyArray[4].key).to.equal('e'); - }); - }) - - describe('equals', () => { - expect(keys.equals({ - key: 'x', - ctrlKey: true, - }, { - key: 'x', - ctrlKey: true, - })).to.be.true; - - expect(keys.equals({ - key: 'X', - shiftKey: true, - }, { - key: 'x', - ctrlKey: true, - })).to.be.false; - }); -}); diff --git a/test/shared/utils/keys.test.ts b/test/shared/utils/keys.test.ts new file mode 100644 index 0000000..b2ad3cb --- /dev/null +++ b/test/shared/utils/keys.test.ts @@ -0,0 +1,164 @@ +import * as keys from 'shared/utils/keys'; + +describe("keys util", () => { + describe('fromKeyboardEvent', () => { + it('returns from keyboard input Ctrl+X', () => { + let k = keys.fromKeyboardEvent({ + key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true + }); + expect(k.key).to.equal('x'); + expect(k.shiftKey).to.be.false; + expect(k.ctrlKey).to.be.true; + expect(k.altKey).to.be.false; + expect(k.metaKey).to.be.true; + }); + + it('returns from keyboard input Shift+Esc', () => { + let k = keys.fromKeyboardEvent({ + key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true + }); + expect(k.key).to.equal('Esc'); + expect(k.shiftKey).to.be.true; + expect(k.ctrlKey).to.be.false; + expect(k.altKey).to.be.false; + expect(k.metaKey).to.be.true; + }); + + it('returns from keyboard input Ctrl+$', () => { + // $ required shift pressing on most keyboards + let k = keys.fromKeyboardEvent({ + key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false + }); + expect(k.key).to.equal('$'); + expect(k.shiftKey).to.be.false; + expect(k.ctrlKey).to.be.true; + expect(k.altKey).to.be.false; + expect(k.metaKey).to.be.false; + }); + + it('returns from keyboard input Crtl+Space', () => { + let k = keys.fromKeyboardEvent({ + key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false + }); + expect(k.key).to.equal('Space'); + expect(k.shiftKey).to.be.false; + expect(k.ctrlKey).to.be.true; + expect(k.altKey).to.be.false; + expect(k.metaKey).to.be.false; + }); + }); + + describe('fromMapKey', () => { + it('return for X', () => { + let key = keys.fromMapKey('x'); + expect(key.key).to.equal('x'); + expect(key.shiftKey).to.be.false; + expect(key.ctrlKey).to.be.false; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('return for Shift+X', () => { + let key = keys.fromMapKey('X'); + expect(key.key).to.equal('X'); + expect(key.shiftKey).to.be.true; + expect(key.ctrlKey).to.be.false; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('return for Ctrl+X', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('x'); + expect(key.shiftKey).to.be.false; + expect(key.ctrlKey).to.be.true; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('returns for Ctrl+Meta+X', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('x'); + expect(key.shiftKey).to.be.false; + expect(key.ctrlKey).to.be.true; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.true; + }); + + it('returns for Ctrl+Shift+x', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('X'); + expect(key.shiftKey).to.be.true; + expect(key.ctrlKey).to.be.true; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('returns for Shift+Esc', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('Esc'); + expect(key.shiftKey).to.be.true; + expect(key.ctrlKey).to.be.false; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('returns for Ctrl+Esc', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('Esc'); + expect(key.shiftKey).to.be.false; + expect(key.ctrlKey).to.be.true; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + + it('returns for Ctrl+Esc', () => { + let key = keys.fromMapKey(''); + expect(key.key).to.equal('Space'); + expect(key.shiftKey).to.be.false; + expect(key.ctrlKey).to.be.true; + expect(key.altKey).to.be.false; + expect(key.metaKey).to.be.false; + }); + }); + + describe('fromMapKeys', () => { + it('returns mapped keys for Shift+Esc', () => { + let keyArray = keys.fromMapKeys(''); + expect(keyArray).to.have.lengthOf(1); + expect(keyArray[0].key).to.equal('Esc'); + expect(keyArray[0].shiftKey).to.be.true; + }); + + it('returns mapped keys for ad', () => { + let keyArray = keys.fromMapKeys('ad'); + expect(keyArray).to.have.lengthOf(5); + expect(keyArray[0].key).to.equal('a'); + expect(keyArray[1].ctrlKey).to.be.true; + expect(keyArray[1].key).to.equal('b'); + expect(keyArray[2].altKey).to.be.true; + expect(keyArray[2].key).to.equal('c'); + expect(keyArray[3].key).to.equal('d'); + expect(keyArray[4].metaKey).to.be.true; + expect(keyArray[4].key).to.equal('e'); + }); + }) + + describe('equals', () => { + expect(keys.equals({ + key: 'x', + ctrlKey: true, + }, { + key: 'x', + ctrlKey: true, + })).to.be.true; + + expect(keys.equals({ + key: 'X', + shiftKey: true, + }, { + key: 'x', + ctrlKey: true, + })).to.be.false; + }); +}); diff --git a/test/shared/utils/re.test.js b/test/shared/utils/re.test.js deleted file mode 100644 index d12ceb7..0000000 --- a/test/shared/utils/re.test.js +++ /dev/null @@ -1,19 +0,0 @@ -import * as re from 'shared/utils/re'; - -describe("re util", () => { - it('matches by pattern', () => { - let regex = re.fromWildcard('*.example.com/*'); - expect('foo.example.com/bar').to.match(regex); - expect('foo.example.com').not.to.match(regex); - expect('example.com/bar').not.to.match(regex); - - regex = re.fromWildcard('example.com/*') - expect('example.com/foo').to.match(regex); - expect('example.com/').to.match(regex); - - regex = re.fromWildcard('example.com/*bar') - expect('example.com/foobar').to.match(regex); - expect('example.com/bar').to.match(regex); - expect('example.com/foobarfoo').not.to.match(regex); - }) -}); diff --git a/test/shared/utils/re.test.ts b/test/shared/utils/re.test.ts new file mode 100644 index 0000000..d12ceb7 --- /dev/null +++ b/test/shared/utils/re.test.ts @@ -0,0 +1,19 @@ +import * as re from 'shared/utils/re'; + +describe("re util", () => { + it('matches by pattern', () => { + let regex = re.fromWildcard('*.example.com/*'); + expect('foo.example.com/bar').to.match(regex); + expect('foo.example.com').not.to.match(regex); + expect('example.com/bar').not.to.match(regex); + + regex = re.fromWildcard('example.com/*') + expect('example.com/foo').to.match(regex); + expect('example.com/').to.match(regex); + + regex = re.fromWildcard('example.com/*bar') + expect('example.com/foobar').to.match(regex); + expect('example.com/bar').to.match(regex); + expect('example.com/foobarfoo').not.to.match(regex); + }) +}); -- cgit v1.2.3