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/background/domains/GlobalMark.test.js | 11 -- test/background/domains/GlobalMark.test.ts | 11 ++ .../infrastructures/MemoryStorage.test.js | 44 ------ .../infrastructures/MemoryStorage.test.ts | 44 ++++++ test/background/repositories/Mark.test.js | 26 ---- test/background/repositories/Mark.test.ts | 26 ++++ test/background/repositories/Version.js | 34 ----- test/background/repositories/Version.ts | 34 +++++ test/background/usecases/filters.test.js | 113 -------------- test/background/usecases/filters.test.ts | 113 ++++++++++++++ test/background/usecases/parsers.test.js | 47 ------ test/background/usecases/parsers.test.ts | 47 ++++++ test/console/actions/console.test.js | 70 --------- test/console/actions/console.test.ts | 70 +++++++++ .../console/components/console/Completion.test.jsx | 168 --------------------- .../console/components/console/Completion.test.tsx | 168 +++++++++++++++++++++ test/console/reducers/console.test.js | 131 ---------------- test/console/reducers/console.test.ts | 131 ++++++++++++++++ test/content/actions/follow-controller.test.js | 34 ----- test/content/actions/follow-controller.test.ts | 34 +++++ test/content/actions/input.test.js | 19 --- test/content/actions/input.test.ts | 19 +++ test/content/actions/mark.test.js | 35 ----- test/content/actions/mark.test.ts | 35 +++++ test/content/actions/setting.test.js | 35 ----- test/content/actions/setting.test.ts | 35 +++++ test/content/components/common/follow.test.js | 25 --- test/content/components/common/follow.test.ts | 25 +++ test/content/components/common/hint.test.js | 57 ------- test/content/components/common/hint.test.ts | 57 +++++++ test/content/components/common/input.test.js | 70 --------- test/content/components/common/input.test.ts | 70 +++++++++ test/content/hint-key-producer.test.js | 24 --- test/content/hint-key-producer.test.ts | 24 +++ test/content/navigates.test.js | 137 ----------------- test/content/navigates.test.ts | 137 +++++++++++++++++ test/content/reducers/addon.test.js | 17 --- test/content/reducers/addon.test.ts | 17 +++ test/content/reducers/find.test.js | 22 --- test/content/reducers/find.test.ts | 22 +++ test/content/reducers/follow-controller.test.js | 47 ------ test/content/reducers/follow-controller.test.ts | 47 ++++++ test/content/reducers/input.test.js | 25 --- test/content/reducers/input.test.ts | 25 +++ test/content/reducers/mark.test.js | 41 ----- test/content/reducers/mark.test.ts | 41 +++++ test/content/reducers/setting.test.js | 17 --- test/content/reducers/setting.test.ts | 17 +++ test/main.js | 6 - test/main.ts | 6 + .../components/form/BlacklistForm.test.jsx | 92 ----------- .../components/form/BlacklistForm.test.tsx | 92 +++++++++++ test/settings/components/form/KeymapsForm.test.jsx | 64 -------- test/settings/components/form/KeymapsForm.test.tsx | 64 ++++++++ .../components/form/PropertiesForm.test.jsx | 104 ------------- .../components/form/PropertiesForm.test.tsx | 104 +++++++++++++ .../components/form/SearchEngineForm.test.jsx | 128 ---------------- .../components/form/SearchEngineForm.test.tsx | 128 ++++++++++++++++ test/settings/components/ui/input.test.jsx | 111 -------------- test/settings/components/ui/input.test.tsx | 111 ++++++++++++++ test/settings/reducers/setting.test.js | 55 ------- test/settings/reducers/setting.test.ts | 55 +++++++ 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 +++ 74 files changed, 2308 insertions(+), 2308 deletions(-) delete mode 100644 test/background/domains/GlobalMark.test.js create mode 100644 test/background/domains/GlobalMark.test.ts delete mode 100644 test/background/infrastructures/MemoryStorage.test.js create mode 100644 test/background/infrastructures/MemoryStorage.test.ts delete mode 100644 test/background/repositories/Mark.test.js create mode 100644 test/background/repositories/Mark.test.ts delete mode 100644 test/background/repositories/Version.js create mode 100644 test/background/repositories/Version.ts delete mode 100644 test/background/usecases/filters.test.js create mode 100644 test/background/usecases/filters.test.ts delete mode 100644 test/background/usecases/parsers.test.js create mode 100644 test/background/usecases/parsers.test.ts delete mode 100644 test/console/actions/console.test.js create mode 100644 test/console/actions/console.test.ts delete mode 100644 test/console/components/console/Completion.test.jsx create mode 100644 test/console/components/console/Completion.test.tsx delete mode 100644 test/console/reducers/console.test.js create mode 100644 test/console/reducers/console.test.ts delete mode 100644 test/content/actions/follow-controller.test.js create mode 100644 test/content/actions/follow-controller.test.ts delete mode 100644 test/content/actions/input.test.js create mode 100644 test/content/actions/input.test.ts delete mode 100644 test/content/actions/mark.test.js create mode 100644 test/content/actions/mark.test.ts delete mode 100644 test/content/actions/setting.test.js create mode 100644 test/content/actions/setting.test.ts delete mode 100644 test/content/components/common/follow.test.js create mode 100644 test/content/components/common/follow.test.ts delete mode 100644 test/content/components/common/hint.test.js create mode 100644 test/content/components/common/hint.test.ts delete mode 100644 test/content/components/common/input.test.js create mode 100644 test/content/components/common/input.test.ts delete mode 100644 test/content/hint-key-producer.test.js create mode 100644 test/content/hint-key-producer.test.ts delete mode 100644 test/content/navigates.test.js create mode 100644 test/content/navigates.test.ts delete mode 100644 test/content/reducers/addon.test.js create mode 100644 test/content/reducers/addon.test.ts delete mode 100644 test/content/reducers/find.test.js create mode 100644 test/content/reducers/find.test.ts delete mode 100644 test/content/reducers/follow-controller.test.js create mode 100644 test/content/reducers/follow-controller.test.ts delete mode 100644 test/content/reducers/input.test.js create mode 100644 test/content/reducers/input.test.ts delete mode 100644 test/content/reducers/mark.test.js create mode 100644 test/content/reducers/mark.test.ts delete mode 100644 test/content/reducers/setting.test.js create mode 100644 test/content/reducers/setting.test.ts delete mode 100644 test/main.js create mode 100644 test/main.ts delete mode 100644 test/settings/components/form/BlacklistForm.test.jsx create mode 100644 test/settings/components/form/BlacklistForm.test.tsx delete mode 100644 test/settings/components/form/KeymapsForm.test.jsx create mode 100644 test/settings/components/form/KeymapsForm.test.tsx delete mode 100644 test/settings/components/form/PropertiesForm.test.jsx create mode 100644 test/settings/components/form/PropertiesForm.test.tsx delete mode 100644 test/settings/components/form/SearchEngineForm.test.jsx create mode 100644 test/settings/components/form/SearchEngineForm.test.tsx delete mode 100644 test/settings/components/ui/input.test.jsx create mode 100644 test/settings/components/ui/input.test.tsx delete mode 100644 test/settings/reducers/setting.test.js create mode 100644 test/settings/reducers/setting.test.ts 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') diff --git a/test/background/domains/GlobalMark.test.js b/test/background/domains/GlobalMark.test.js deleted file mode 100644 index ed636e9..0000000 --- a/test/background/domains/GlobalMark.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import GlobalMark from 'background/domains/GlobalMark'; - -describe('background/domains/global-mark', () => { - describe('constructor and getter', () => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); - expect(mark.tabId).to.equal(1); - expect(mark.url).to.equal('http://example.com'); - expect(mark.x).to.equal(10); - expect(mark.y).to.equal(30); - }); -}); diff --git a/test/background/domains/GlobalMark.test.ts b/test/background/domains/GlobalMark.test.ts new file mode 100644 index 0000000..ed636e9 --- /dev/null +++ b/test/background/domains/GlobalMark.test.ts @@ -0,0 +1,11 @@ +import GlobalMark from 'background/domains/GlobalMark'; + +describe('background/domains/global-mark', () => { + describe('constructor and getter', () => { + let mark = new GlobalMark(1, 'http://example.com', 10, 30); + expect(mark.tabId).to.equal(1); + expect(mark.url).to.equal('http://example.com'); + expect(mark.x).to.equal(10); + expect(mark.y).to.equal(30); + }); +}); diff --git a/test/background/infrastructures/MemoryStorage.test.js b/test/background/infrastructures/MemoryStorage.test.js deleted file mode 100644 index 95d3780..0000000 --- a/test/background/infrastructures/MemoryStorage.test.js +++ /dev/null @@ -1,44 +0,0 @@ -import MemoryStorage from 'background/infrastructures/MemoryStorage'; - -describe("background/infrastructures/memory-storage", () => { - it('stores values', () => { - let cache = new MemoryStorage(); - cache.set('number', 123); - expect(cache.get('number')).to.equal(123); - - cache.set('string', '123'); - expect(cache.get('string')).to.equal('123'); - - cache.set('object', { hello: '123' }); - expect(cache.get('object')).to.deep.equal({ hello: '123' }); - }); - - it('returns undefined if no keys', () => { - let cache = new MemoryStorage(); - expect(cache.get('no-keys')).to.be.undefined; - }) - - it('stored on shared memory', () => { - let cache = new MemoryStorage(); - cache.set('red', 'apple'); - - cache = new MemoryStorage(); - let got = cache.get('red'); - expect(got).to.equal('apple'); - }); - - it('stored cloned objects', () => { - let cache = new MemoryStorage(); - let recipe = { sugar: '300g' }; - cache.set('recipe', recipe); - - recipe.salt = '20g' - let got = cache.get('recipe', recipe); - expect(got).to.deep.equal({ sugar: '300g' }); - }); - - it('throws an error with unserializable objects', () => { - let cache = new MemoryStorage(); - expect(() => cache.set('fn', setTimeout)).to.throw(); - }) -}); diff --git a/test/background/infrastructures/MemoryStorage.test.ts b/test/background/infrastructures/MemoryStorage.test.ts new file mode 100644 index 0000000..95d3780 --- /dev/null +++ b/test/background/infrastructures/MemoryStorage.test.ts @@ -0,0 +1,44 @@ +import MemoryStorage from 'background/infrastructures/MemoryStorage'; + +describe("background/infrastructures/memory-storage", () => { + it('stores values', () => { + let cache = new MemoryStorage(); + cache.set('number', 123); + expect(cache.get('number')).to.equal(123); + + cache.set('string', '123'); + expect(cache.get('string')).to.equal('123'); + + cache.set('object', { hello: '123' }); + expect(cache.get('object')).to.deep.equal({ hello: '123' }); + }); + + it('returns undefined if no keys', () => { + let cache = new MemoryStorage(); + expect(cache.get('no-keys')).to.be.undefined; + }) + + it('stored on shared memory', () => { + let cache = new MemoryStorage(); + cache.set('red', 'apple'); + + cache = new MemoryStorage(); + let got = cache.get('red'); + expect(got).to.equal('apple'); + }); + + it('stored cloned objects', () => { + let cache = new MemoryStorage(); + let recipe = { sugar: '300g' }; + cache.set('recipe', recipe); + + recipe.salt = '20g' + let got = cache.get('recipe', recipe); + expect(got).to.deep.equal({ sugar: '300g' }); + }); + + it('throws an error with unserializable objects', () => { + let cache = new MemoryStorage(); + expect(() => cache.set('fn', setTimeout)).to.throw(); + }) +}); diff --git a/test/background/repositories/Mark.test.js b/test/background/repositories/Mark.test.js deleted file mode 100644 index 2a5b099..0000000 --- a/test/background/repositories/Mark.test.js +++ /dev/null @@ -1,26 +0,0 @@ -import MarkRepository from 'background/repositories/MarkRepository'; -import GlobalMark from 'background/domains/GlobalMark'; - -describe('background/repositories/mark', () => { - let repository; - - beforeEach(() => { - repository = new MarkRepository; - }); - - it('get and set', async() => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); - - repository.setMark('A', mark); - - let got = await repository.getMark('A'); - expect(got).to.be.a('object'); - expect(got.tabId).to.equal(1); - expect(got.url).to.equal('http://example.com'); - expect(got.x).to.equal(10); - expect(got.y).to.equal(30); - - got = await repository.getMark('B'); - expect(got).to.be.undefined; - }); -}); diff --git a/test/background/repositories/Mark.test.ts b/test/background/repositories/Mark.test.ts new file mode 100644 index 0000000..2a5b099 --- /dev/null +++ b/test/background/repositories/Mark.test.ts @@ -0,0 +1,26 @@ +import MarkRepository from 'background/repositories/MarkRepository'; +import GlobalMark from 'background/domains/GlobalMark'; + +describe('background/repositories/mark', () => { + let repository; + + beforeEach(() => { + repository = new MarkRepository; + }); + + it('get and set', async() => { + let mark = new GlobalMark(1, 'http://example.com', 10, 30); + + repository.setMark('A', mark); + + let got = await repository.getMark('A'); + expect(got).to.be.a('object'); + expect(got.tabId).to.equal(1); + expect(got.url).to.equal('http://example.com'); + expect(got.x).to.equal(10); + expect(got.y).to.equal(30); + + got = await repository.getMark('B'); + expect(got).to.be.undefined; + }); +}); diff --git a/test/background/repositories/Version.js b/test/background/repositories/Version.js deleted file mode 100644 index c7fa88b..0000000 --- a/test/background/repositories/Version.js +++ /dev/null @@ -1,34 +0,0 @@ -import VersionRepository from 'background/repositories/Version'; - -describe("background/repositories/version", () => { - let versionRepository; - - beforeEach(() => { - versionRepository = new VersionRepository; - }); - - describe('#get', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('loads saved version', async() => { - await browser.storage.local.set({ version: '1.2.3' }); - let version = await this.versionRepository.get(); - expect(version).to.equal('1.2.3'); - }); - - it('returns undefined if no versions in storage', async() => { - let version = await storage.load(); - expect(version).to.be.a('undefined'); - }); - }); - - describe('#update', () => { - it('saves version string', async() => { - await versionRepository.update('2.3.4'); - let { version } = await browser.storage.local.get('version'); - expect(version).to.equal('2.3.4'); - }); - }); -}); diff --git a/test/background/repositories/Version.ts b/test/background/repositories/Version.ts new file mode 100644 index 0000000..c7fa88b --- /dev/null +++ b/test/background/repositories/Version.ts @@ -0,0 +1,34 @@ +import VersionRepository from 'background/repositories/Version'; + +describe("background/repositories/version", () => { + let versionRepository; + + beforeEach(() => { + versionRepository = new VersionRepository; + }); + + describe('#get', () => { + beforeEach(() => { + return browser.storage.local.remove('version'); + }); + + it('loads saved version', async() => { + await browser.storage.local.set({ version: '1.2.3' }); + let version = await this.versionRepository.get(); + expect(version).to.equal('1.2.3'); + }); + + it('returns undefined if no versions in storage', async() => { + let version = await storage.load(); + expect(version).to.be.a('undefined'); + }); + }); + + describe('#update', () => { + it('saves version string', async() => { + await versionRepository.update('2.3.4'); + let { version } = await browser.storage.local.get('version'); + expect(version).to.equal('2.3.4'); + }); + }); +}); diff --git a/test/background/usecases/filters.test.js b/test/background/usecases/filters.test.js deleted file mode 100644 index bdfb0be..0000000 --- a/test/background/usecases/filters.test.js +++ /dev/null @@ -1,113 +0,0 @@ -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/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' }, + ]); + }); + }) +}); diff --git a/test/background/usecases/parsers.test.js b/test/background/usecases/parsers.test.js deleted file mode 100644 index 17b034b..0000000 --- a/test/background/usecases/parsers.test.js +++ /dev/null @@ -1,47 +0,0 @@ -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'); - }) - }); -}); diff --git a/test/background/usecases/parsers.test.ts b/test/background/usecases/parsers.test.ts new file mode 100644 index 0000000..17b034b --- /dev/null +++ b/test/background/usecases/parsers.test.ts @@ -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'); + }) + }); +}); diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.js deleted file mode 100644 index 10cd9fe..0000000 --- a/test/console/actions/console.test.js +++ /dev/null @@ -1,70 +0,0 @@ -import actions from 'console/actions'; -import * as consoleActions from 'console/actions/console'; - -describe("console actions", () => { - describe('hide', () => { - it('create CONSOLE_HIDE action', () => { - let action = consoleActions.hide(); - expect(action.type).to.equal(actions.CONSOLE_HIDE); - }); - }); - describe("showCommand", () => { - it('create CONSOLE_SHOW_COMMAND action', () => { - let action = consoleActions.showCommand('hello'); - expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND); - expect(action.text).to.equal('hello'); - }); - }); - - describe("showFind", () => { - it('create CONSOLE_SHOW_FIND action', () => { - let action = consoleActions.showFind(); - expect(action.type).to.equal(actions.CONSOLE_SHOW_FIND); - }); - }); - - describe("showError", () => { - it('create CONSOLE_SHOW_ERROR action', () => { - let action = consoleActions.showError('an error'); - expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR); - expect(action.text).to.equal('an error'); - }); - }); - - describe("showInfo", () => { - it('create CONSOLE_SHOW_INFO action', () => { - let action = consoleActions.showInfo('an info'); - expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO); - expect(action.text).to.equal('an info'); - }); - }); - - describe("hideCommand", () => { - it('create CONSOLE_HIDE_COMMAND action', () => { - let action = consoleActions.hideCommand(); - expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND); - }); - }); - - describe('setConsoleText', () => { - it('create CONSOLE_SET_CONSOLE_TEXT action', () => { - let action = consoleActions.setConsoleText('hello world'); - expect(action.type).to.equal(actions.CONSOLE_SET_CONSOLE_TEXT); - expect(action.consoleText).to.equal('hello world'); - }); - }); - - describe("completionPrev", () => { - it('create CONSOLE_COMPLETION_PREV action', () => { - let action = consoleActions.completionPrev(); - expect(action.type).to.equal(actions.CONSOLE_COMPLETION_PREV); - }); - }); - - describe("completionNext", () => { - it('create CONSOLE_COMPLETION_NEXT action', () => { - let action = consoleActions.completionNext(); - expect(action.type).to.equal(actions.CONSOLE_COMPLETION_NEXT); - }); - }); -}); diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts new file mode 100644 index 0000000..10cd9fe --- /dev/null +++ b/test/console/actions/console.test.ts @@ -0,0 +1,70 @@ +import actions from 'console/actions'; +import * as consoleActions from 'console/actions/console'; + +describe("console actions", () => { + describe('hide', () => { + it('create CONSOLE_HIDE action', () => { + let action = consoleActions.hide(); + expect(action.type).to.equal(actions.CONSOLE_HIDE); + }); + }); + describe("showCommand", () => { + it('create CONSOLE_SHOW_COMMAND action', () => { + let action = consoleActions.showCommand('hello'); + expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND); + expect(action.text).to.equal('hello'); + }); + }); + + describe("showFind", () => { + it('create CONSOLE_SHOW_FIND action', () => { + let action = consoleActions.showFind(); + expect(action.type).to.equal(actions.CONSOLE_SHOW_FIND); + }); + }); + + describe("showError", () => { + it('create CONSOLE_SHOW_ERROR action', () => { + let action = consoleActions.showError('an error'); + expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR); + expect(action.text).to.equal('an error'); + }); + }); + + describe("showInfo", () => { + it('create CONSOLE_SHOW_INFO action', () => { + let action = consoleActions.showInfo('an info'); + expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO); + expect(action.text).to.equal('an info'); + }); + }); + + describe("hideCommand", () => { + it('create CONSOLE_HIDE_COMMAND action', () => { + let action = consoleActions.hideCommand(); + expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND); + }); + }); + + describe('setConsoleText', () => { + it('create CONSOLE_SET_CONSOLE_TEXT action', () => { + let action = consoleActions.setConsoleText('hello world'); + expect(action.type).to.equal(actions.CONSOLE_SET_CONSOLE_TEXT); + expect(action.consoleText).to.equal('hello world'); + }); + }); + + describe("completionPrev", () => { + it('create CONSOLE_COMPLETION_PREV action', () => { + let action = consoleActions.completionPrev(); + expect(action.type).to.equal(actions.CONSOLE_COMPLETION_PREV); + }); + }); + + describe("completionNext", () => { + it('create CONSOLE_COMPLETION_NEXT action', () => { + let action = consoleActions.completionNext(); + expect(action.type).to.equal(actions.CONSOLE_COMPLETION_NEXT); + }); + }); +}); diff --git a/test/console/components/console/Completion.test.jsx b/test/console/components/console/Completion.test.jsx deleted file mode 100644 index 16bf11a..0000000 --- a/test/console/components/console/Completion.test.jsx +++ /dev/null @@ -1,168 +0,0 @@ -import React from 'react'; -import Completion from 'console/components/console/Completion' -import ReactTestRenderer from 'react-test-renderer'; - -describe("console/components/console/completion", () => { - let completions = [{ - name: "Fruit", - items: [{ caption: "apple" }, { caption: "banana" }, { caption: "cherry" }], - }, { - name: "Element", - items: [{ caption: "argon" }, { caption: "boron" }, { caption: "carbon" }], - }]; - - it('renders Completion component', () => { - let root = ReactTestRenderer.create().root; - - expect(root.children).to.have.lengthOf(1); - - let children = root.children[0].children; - expect(children).to.have.lengthOf(8); - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); - expect(children[3].props.caption).to.equal('cherry'); - expect(children[4].props.title).to.equal('Element'); - expect(children[5].props.caption).to.equal('argon'); - expect(children[6].props.caption).to.equal('boron'); - expect(children[7].props.caption).to.equal('carbon'); - }); - - it('highlight current item', () => { - let root = ReactTestRenderer.create().root; - - let children = root.children[0].children; - expect(children[5].props.highlight).to.be.true; - }); - - it('does not highlight any items', () => { - let root = ReactTestRenderer.create().root; - - let children = root.children[0].children; - for (let li of children[0].children) { - expect(li.props.highlight).not.to.be.ok; - } - }); - - it('limits completion items', () => { - let root = ReactTestRenderer.create().root; - - let children = root.children[0].children; - expect(children).to.have.lengthOf(3); - - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); - - root = ReactTestRenderer.create().root; - - children = root.children[0].children; - expect(children[1].props.highlight).to.be.true; - }) - - it('scrolls up to down with select', () => { - let component = ReactTestRenderer.create(); - let instance = component.getInstance(); - let root = component.root; - - let children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].props.title).to.equal('Fruit'); - expect(children[1].props.caption).to.equal('apple'); - expect(children[2].props.caption).to.equal('banana'); - - component.update(); - - children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('apple'); - expect(children[1].props.caption).to.equal('banana'); - expect(children[2].props.caption).to.equal('cherry'); - expect(children[2].props.highlight).to.be.true; - - component.update(); - - children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('cherry'); - expect(children[1].props.title).to.equal('Element'); - expect(children[2].props.caption).to.equal('argon'); - expect(children[2].props.highlight).to.be.true; - }); - - it('scrolls down to up with select', () => { - let component = ReactTestRenderer.create(); - let root = component.root; - let instance = component.getInstance(); - - let children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].props.caption).to.equal('argon'); - expect(children[1].props.caption).to.equal('boron'); - expect(children[2].props.caption).to.equal('carbon'); - - component.update(); - - children = root.children[0].children; - expect(children[1].props.highlight).to.be.true; - - component.update(); - - children = root.children[0].children; - expect(children[0].props.highlight).to.be.true; - - component.update(); - - children = root.children[0].children; - expect(children[0].props.caption).to.equal('cherry'); - expect(children[1].props.title).to.equal('Element'); - expect(children[2].props.caption).to.equal('argon'); - expect(children[0].props.highlight).to.be.true; - }); -}); diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx new file mode 100644 index 0000000..16bf11a --- /dev/null +++ b/test/console/components/console/Completion.test.tsx @@ -0,0 +1,168 @@ +import React from 'react'; +import Completion from 'console/components/console/Completion' +import ReactTestRenderer from 'react-test-renderer'; + +describe("console/components/console/completion", () => { + let completions = [{ + name: "Fruit", + items: [{ caption: "apple" }, { caption: "banana" }, { caption: "cherry" }], + }, { + name: "Element", + items: [{ caption: "argon" }, { caption: "boron" }, { caption: "carbon" }], + }]; + + it('renders Completion component', () => { + let root = ReactTestRenderer.create().root; + + expect(root.children).to.have.lengthOf(1); + + let children = root.children[0].children; + expect(children).to.have.lengthOf(8); + expect(children[0].props.title).to.equal('Fruit'); + expect(children[1].props.caption).to.equal('apple'); + expect(children[2].props.caption).to.equal('banana'); + expect(children[3].props.caption).to.equal('cherry'); + expect(children[4].props.title).to.equal('Element'); + expect(children[5].props.caption).to.equal('argon'); + expect(children[6].props.caption).to.equal('boron'); + expect(children[7].props.caption).to.equal('carbon'); + }); + + it('highlight current item', () => { + let root = ReactTestRenderer.create().root; + + let children = root.children[0].children; + expect(children[5].props.highlight).to.be.true; + }); + + it('does not highlight any items', () => { + let root = ReactTestRenderer.create().root; + + let children = root.children[0].children; + for (let li of children[0].children) { + expect(li.props.highlight).not.to.be.ok; + } + }); + + it('limits completion items', () => { + let root = ReactTestRenderer.create().root; + + let children = root.children[0].children; + expect(children).to.have.lengthOf(3); + + expect(children[0].props.title).to.equal('Fruit'); + expect(children[1].props.caption).to.equal('apple'); + expect(children[2].props.caption).to.equal('banana'); + + root = ReactTestRenderer.create().root; + + children = root.children[0].children; + expect(children[1].props.highlight).to.be.true; + }) + + it('scrolls up to down with select', () => { + let component = ReactTestRenderer.create(); + let instance = component.getInstance(); + let root = component.root; + + let children = root.children[0].children; + expect(children).to.have.lengthOf(3); + expect(children[0].props.title).to.equal('Fruit'); + expect(children[1].props.caption).to.equal('apple'); + expect(children[2].props.caption).to.equal('banana'); + + component.update(); + + children = root.children[0].children; + expect(children).to.have.lengthOf(3); + expect(children[0].props.caption).to.equal('apple'); + expect(children[1].props.caption).to.equal('banana'); + expect(children[2].props.caption).to.equal('cherry'); + expect(children[2].props.highlight).to.be.true; + + component.update(); + + children = root.children[0].children; + expect(children).to.have.lengthOf(3); + expect(children[0].props.caption).to.equal('cherry'); + expect(children[1].props.title).to.equal('Element'); + expect(children[2].props.caption).to.equal('argon'); + expect(children[2].props.highlight).to.be.true; + }); + + it('scrolls down to up with select', () => { + let component = ReactTestRenderer.create(); + let root = component.root; + let instance = component.getInstance(); + + let children = root.children[0].children; + expect(children).to.have.lengthOf(3); + expect(children[0].props.caption).to.equal('argon'); + expect(children[1].props.caption).to.equal('boron'); + expect(children[2].props.caption).to.equal('carbon'); + + component.update(); + + children = root.children[0].children; + expect(children[1].props.highlight).to.be.true; + + component.update(); + + children = root.children[0].children; + expect(children[0].props.highlight).to.be.true; + + component.update(); + + children = root.children[0].children; + expect(children[0].props.caption).to.equal('cherry'); + expect(children[1].props.title).to.equal('Element'); + expect(children[2].props.caption).to.equal('argon'); + expect(children[0].props.highlight).to.be.true; + }); +}); diff --git a/test/console/reducers/console.test.js b/test/console/reducers/console.test.js deleted file mode 100644 index d5a38cf..0000000 --- a/test/console/reducers/console.test.js +++ /dev/null @@ -1,131 +0,0 @@ -import actions from 'console/actions'; -import reducer from 'console/reducers'; - -describe("console reducer", () => { - it('return the initial state', () => { - let state = reducer(undefined, {}); - expect(state).to.have.property('mode', ''); - expect(state).to.have.property('messageText', ''); - expect(state).to.have.property('consoleText', ''); - expect(state).to.have.deep.property('completions', []); - expect(state).to.have.property('select', -1); - }); - - it('return next state for CONSOLE_HIDE', () => { - let action = { type: actions.CONSOLE_HIDE }; - let state = reducer({ mode: 'error' }, action); - expect(state).to.have.property('mode', ''); - }) - - it('return next state for CONSOLE_SHOW_COMMAND', () => { - let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; - let state = reducer({}, action); - expect(state).to.have.property('mode', 'command'); - expect(state).to.have.property('consoleText', 'open '); - }); - - it('return next state for CONSOLE_SHOW_INFO', () => { - let action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' }; - let state = reducer({}, action); - expect(state).to.have.property('mode', 'info'); - expect(state).to.have.property('messageText', 'an info'); - }); - - it('return next state for CONSOLE_SHOW_ERROR', () => { - let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; - let state = reducer({}, action); - expect(state).to.have.property('mode', 'error'); - expect(state).to.have.property('messageText', 'an error'); - }); - - it('return next state for CONSOLE_HIDE_COMMAND', () => { - let action = { type: actions.CONSOLE_HIDE_COMMAND }; - let state = reducer({ mode: 'command' }, action); - expect(state).to.have.property('mode', ''); - - state = reducer({ mode: 'error' }, action); - expect(state).to.have.property('mode', 'error'); - }); - - it('return next state for CONSOLE_SET_CONSOLE_TEXT', () => { - let action = { - type: actions.CONSOLE_SET_CONSOLE_TEXT, - consoleText: 'hello world' - } - let state = reducer({}, action) - - expect(state).to.have.property('consoleText', 'hello world'); - }); - - it ('return next state for CONSOLE_SET_COMPLETIONS', () => { - let state = { - select: 0, - completions: [], - } - let action = { - type: actions.CONSOLE_SET_COMPLETIONS, - completions: [{ - name: 'Apple', - items: [1, 2, 3] - }, { - name: 'Banana', - items: [4, 5, 6] - }] - } - state = reducer(state, action); - expect(state).to.have.property('completions', action.completions); - expect(state).to.have.property('select', -1); - }); - - it ('return next state for CONSOLE_COMPLETION_NEXT', () => { - let action = { type: actions.CONSOLE_COMPLETION_NEXT }; - let state = { - select: -1, - completions: [{ - name: 'Apple', - items: [1, 2] - }, { - name: 'Banana', - items: [3] - }] - }; - - state = reducer(state, action); - expect(state).to.have.property('select', 0); - - state = reducer(state, action); - expect(state).to.have.property('select', 1); - - state = reducer(state, action); - expect(state).to.have.property('select', 2); - - state = reducer(state, action); - expect(state).to.have.property('select', -1); - }); - - it ('return next state for CONSOLE_COMPLETION_PREV', () => { - let action = { type: actions.CONSOLE_COMPLETION_PREV }; - let state = { - select: -1, - completions: [{ - name: 'Apple', - items: [1, 2] - }, { - name: 'Banana', - items: [3] - }] - }; - - state = reducer(state, action); - expect(state).to.have.property('select', 2); - - state = reducer(state, action); - expect(state).to.have.property('select', 1); - - state = reducer(state, action); - expect(state).to.have.property('select', 0); - - state = reducer(state, action); - expect(state).to.have.property('select', -1); - }); -}); diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts new file mode 100644 index 0000000..d5a38cf --- /dev/null +++ b/test/console/reducers/console.test.ts @@ -0,0 +1,131 @@ +import actions from 'console/actions'; +import reducer from 'console/reducers'; + +describe("console reducer", () => { + it('return the initial state', () => { + let state = reducer(undefined, {}); + expect(state).to.have.property('mode', ''); + expect(state).to.have.property('messageText', ''); + expect(state).to.have.property('consoleText', ''); + expect(state).to.have.deep.property('completions', []); + expect(state).to.have.property('select', -1); + }); + + it('return next state for CONSOLE_HIDE', () => { + let action = { type: actions.CONSOLE_HIDE }; + let state = reducer({ mode: 'error' }, action); + expect(state).to.have.property('mode', ''); + }) + + it('return next state for CONSOLE_SHOW_COMMAND', () => { + let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; + let state = reducer({}, action); + expect(state).to.have.property('mode', 'command'); + expect(state).to.have.property('consoleText', 'open '); + }); + + it('return next state for CONSOLE_SHOW_INFO', () => { + let action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' }; + let state = reducer({}, action); + expect(state).to.have.property('mode', 'info'); + expect(state).to.have.property('messageText', 'an info'); + }); + + it('return next state for CONSOLE_SHOW_ERROR', () => { + let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; + let state = reducer({}, action); + expect(state).to.have.property('mode', 'error'); + expect(state).to.have.property('messageText', 'an error'); + }); + + it('return next state for CONSOLE_HIDE_COMMAND', () => { + let action = { type: actions.CONSOLE_HIDE_COMMAND }; + let state = reducer({ mode: 'command' }, action); + expect(state).to.have.property('mode', ''); + + state = reducer({ mode: 'error' }, action); + expect(state).to.have.property('mode', 'error'); + }); + + it('return next state for CONSOLE_SET_CONSOLE_TEXT', () => { + let action = { + type: actions.CONSOLE_SET_CONSOLE_TEXT, + consoleText: 'hello world' + } + let state = reducer({}, action) + + expect(state).to.have.property('consoleText', 'hello world'); + }); + + it ('return next state for CONSOLE_SET_COMPLETIONS', () => { + let state = { + select: 0, + completions: [], + } + let action = { + type: actions.CONSOLE_SET_COMPLETIONS, + completions: [{ + name: 'Apple', + items: [1, 2, 3] + }, { + name: 'Banana', + items: [4, 5, 6] + }] + } + state = reducer(state, action); + expect(state).to.have.property('completions', action.completions); + expect(state).to.have.property('select', -1); + }); + + it ('return next state for CONSOLE_COMPLETION_NEXT', () => { + let action = { type: actions.CONSOLE_COMPLETION_NEXT }; + let state = { + select: -1, + completions: [{ + name: 'Apple', + items: [1, 2] + }, { + name: 'Banana', + items: [3] + }] + }; + + state = reducer(state, action); + expect(state).to.have.property('select', 0); + + state = reducer(state, action); + expect(state).to.have.property('select', 1); + + state = reducer(state, action); + expect(state).to.have.property('select', 2); + + state = reducer(state, action); + expect(state).to.have.property('select', -1); + }); + + it ('return next state for CONSOLE_COMPLETION_PREV', () => { + let action = { type: actions.CONSOLE_COMPLETION_PREV }; + let state = { + select: -1, + completions: [{ + name: 'Apple', + items: [1, 2] + }, { + name: 'Banana', + items: [3] + }] + }; + + state = reducer(state, action); + expect(state).to.have.property('select', 2); + + state = reducer(state, action); + expect(state).to.have.property('select', 1); + + state = reducer(state, action); + expect(state).to.have.property('select', 0); + + state = reducer(state, action); + expect(state).to.have.property('select', -1); + }); +}); diff --git a/test/content/actions/follow-controller.test.js b/test/content/actions/follow-controller.test.js deleted file mode 100644 index 718a90a..0000000 --- a/test/content/actions/follow-controller.test.js +++ /dev/null @@ -1,34 +0,0 @@ -import actions from 'content/actions'; -import * as followControllerActions from 'content/actions/follow-controller'; - -describe('follow-controller actions', () => { - describe('enable', () => { - it('creates FOLLOW_CONTROLLER_ENABLE action', () => { - let action = followControllerActions.enable(true); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_ENABLE); - expect(action.newTab).to.equal(true); - }); - }); - - describe('disable', () => { - it('creates FOLLOW_CONTROLLER_DISABLE action', () => { - let action = followControllerActions.disable(true); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_DISABLE); - }); - }); - - describe('keyPress', () => { - it('creates FOLLOW_CONTROLLER_KEY_PRESS action', () => { - let action = followControllerActions.keyPress(100); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_KEY_PRESS); - expect(action.key).to.equal(100); - }); - }); - - describe('backspace', () => { - it('creates FOLLOW_CONTROLLER_BACKSPACE action', () => { - let action = followControllerActions.backspace(100); - expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_BACKSPACE); - }); - }); -}); diff --git a/test/content/actions/follow-controller.test.ts b/test/content/actions/follow-controller.test.ts new file mode 100644 index 0000000..718a90a --- /dev/null +++ b/test/content/actions/follow-controller.test.ts @@ -0,0 +1,34 @@ +import actions from 'content/actions'; +import * as followControllerActions from 'content/actions/follow-controller'; + +describe('follow-controller actions', () => { + describe('enable', () => { + it('creates FOLLOW_CONTROLLER_ENABLE action', () => { + let action = followControllerActions.enable(true); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_ENABLE); + expect(action.newTab).to.equal(true); + }); + }); + + describe('disable', () => { + it('creates FOLLOW_CONTROLLER_DISABLE action', () => { + let action = followControllerActions.disable(true); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_DISABLE); + }); + }); + + describe('keyPress', () => { + it('creates FOLLOW_CONTROLLER_KEY_PRESS action', () => { + let action = followControllerActions.keyPress(100); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_KEY_PRESS); + expect(action.key).to.equal(100); + }); + }); + + describe('backspace', () => { + it('creates FOLLOW_CONTROLLER_BACKSPACE action', () => { + let action = followControllerActions.backspace(100); + expect(action.type).to.equal(actions.FOLLOW_CONTROLLER_BACKSPACE); + }); + }); +}); diff --git a/test/content/actions/input.test.js b/test/content/actions/input.test.js deleted file mode 100644 index fe9db5f..0000000 --- a/test/content/actions/input.test.js +++ /dev/null @@ -1,19 +0,0 @@ -import actions from 'content/actions'; -import * as inputActions from 'content/actions/input'; - -describe("input actions", () => { - describe("keyPress", () => { - it('create INPUT_KEY_PRESS action', () => { - let action = inputActions.keyPress('a'); - expect(action.type).to.equal(actions.INPUT_KEY_PRESS); - expect(action.key).to.equal('a'); - }); - }); - - describe("clearKeys", () => { - it('create INPUT_CLEAR_KEYSaction', () => { - let action = inputActions.clearKeys(); - expect(action.type).to.equal(actions.INPUT_CLEAR_KEYS); - }); - }); -}); diff --git a/test/content/actions/input.test.ts b/test/content/actions/input.test.ts new file mode 100644 index 0000000..fe9db5f --- /dev/null +++ b/test/content/actions/input.test.ts @@ -0,0 +1,19 @@ +import actions from 'content/actions'; +import * as inputActions from 'content/actions/input'; + +describe("input actions", () => { + describe("keyPress", () => { + it('create INPUT_KEY_PRESS action', () => { + let action = inputActions.keyPress('a'); + expect(action.type).to.equal(actions.INPUT_KEY_PRESS); + expect(action.key).to.equal('a'); + }); + }); + + describe("clearKeys", () => { + it('create INPUT_CLEAR_KEYSaction', () => { + let action = inputActions.clearKeys(); + expect(action.type).to.equal(actions.INPUT_CLEAR_KEYS); + }); + }); +}); diff --git a/test/content/actions/mark.test.js b/test/content/actions/mark.test.js deleted file mode 100644 index adbf06b..0000000 --- a/test/content/actions/mark.test.js +++ /dev/null @@ -1,35 +0,0 @@ -import actions from 'content/actions'; -import * as markActions from 'content/actions/mark'; - -describe('mark actions', () => { - describe('startSet', () => { - it('create MARK_START_SET action', () => { - let action = markActions.startSet(); - expect(action.type).to.equal(actions.MARK_START_SET); - }); - }); - - describe('startJump', () => { - it('create MARK_START_JUMP action', () => { - let action = markActions.startJump(); - expect(action.type).to.equal(actions.MARK_START_JUMP); - }); - }); - - describe('cancel', () => { - it('create MARK_CANCEL action', () => { - let action = markActions.cancel(); - expect(action.type).to.equal(actions.MARK_CANCEL); - }); - }); - - describe('setLocal', () => { - it('create setLocal action', () => { - let action = markActions.setLocal('a', 20, 30); - expect(action.type).to.equal(actions.MARK_SET_LOCAL); - expect(action.key).to.equal('a'); - expect(action.x).to.equal(20); - expect(action.y).to.equal(30); - }); - }); -}); diff --git a/test/content/actions/mark.test.ts b/test/content/actions/mark.test.ts new file mode 100644 index 0000000..adbf06b --- /dev/null +++ b/test/content/actions/mark.test.ts @@ -0,0 +1,35 @@ +import actions from 'content/actions'; +import * as markActions from 'content/actions/mark'; + +describe('mark actions', () => { + describe('startSet', () => { + it('create MARK_START_SET action', () => { + let action = markActions.startSet(); + expect(action.type).to.equal(actions.MARK_START_SET); + }); + }); + + describe('startJump', () => { + it('create MARK_START_JUMP action', () => { + let action = markActions.startJump(); + expect(action.type).to.equal(actions.MARK_START_JUMP); + }); + }); + + describe('cancel', () => { + it('create MARK_CANCEL action', () => { + let action = markActions.cancel(); + expect(action.type).to.equal(actions.MARK_CANCEL); + }); + }); + + describe('setLocal', () => { + it('create setLocal action', () => { + let action = markActions.setLocal('a', 20, 30); + expect(action.type).to.equal(actions.MARK_SET_LOCAL); + expect(action.key).to.equal('a'); + expect(action.x).to.equal(20); + expect(action.y).to.equal(30); + }); + }); +}); diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.js deleted file mode 100644 index 10f6807..0000000 --- a/test/content/actions/setting.test.js +++ /dev/null @@ -1,35 +0,0 @@ -import actions from 'content/actions'; -import * as settingActions from 'content/actions/setting'; - -describe("setting actions", () => { - describe("set", () => { - it('create SETTING_SET action', () => { - let action = settingActions.set({ red: 'apple', yellow: 'banana' }); - expect(action.type).to.equal(actions.SETTING_SET); - expect(action.value.red).to.equal('apple'); - expect(action.value.yellow).to.equal('banana'); - expect(action.value.keymaps).to.be.empty; - }); - - it('converts keymaps', () => { - let action = settingActions.set({ - keymaps: { - 'dd': 'remove current tab', - 'z': 'increment', - } - }); - let keymaps = action.value.keymaps; - let map = new Map(keymaps); - expect(map).to.have.deep.all.keys( - [ - [{ key: 'Esc', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], - [{ key: '[', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], - [{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, - { key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], - [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, - { key: 'a', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], - ] - ); - }); - }); -}); diff --git a/test/content/actions/setting.test.ts b/test/content/actions/setting.test.ts new file mode 100644 index 0000000..10f6807 --- /dev/null +++ b/test/content/actions/setting.test.ts @@ -0,0 +1,35 @@ +import actions from 'content/actions'; +import * as settingActions from 'content/actions/setting'; + +describe("setting actions", () => { + describe("set", () => { + it('create SETTING_SET action', () => { + let action = settingActions.set({ red: 'apple', yellow: 'banana' }); + expect(action.type).to.equal(actions.SETTING_SET); + expect(action.value.red).to.equal('apple'); + expect(action.value.yellow).to.equal('banana'); + expect(action.value.keymaps).to.be.empty; + }); + + it('converts keymaps', () => { + let action = settingActions.set({ + keymaps: { + 'dd': 'remove current tab', + 'z': 'increment', + } + }); + let keymaps = action.value.keymaps; + let map = new Map(keymaps); + expect(map).to.have.deep.all.keys( + [ + [{ key: 'Esc', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], + [{ key: '[', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], + [{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, + { key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], + [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, + { key: 'a', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false }], + ] + ); + }); + }); +}); diff --git a/test/content/components/common/follow.test.js b/test/content/components/common/follow.test.js deleted file mode 100644 index 90d6cf5..0000000 --- a/test/content/components/common/follow.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import FollowComponent from 'content/components/common/follow'; - -describe('FollowComponent', () => { - describe('#getTargetElements', () => { - beforeEach(() => { - document.body.innerHTML = __html__['test/content/components/common/follow.html']; - }); - - it('returns visible links', () => { - let targets = FollowComponent.getTargetElements( - window, - { width: window.innerWidth, height: window.innerHeight }, - { x: 0, y: 0 }); - expect(targets).to.have.lengthOf(4); - - let ids = Array.prototype.map.call(targets, (e) => e.id); - expect(ids).to.include.members([ - 'visible_a', - 'editable_div_1', - 'editable_div_2', - 'summary_1', - ]); - }); - }); -}); diff --git a/test/content/components/common/follow.test.ts b/test/content/components/common/follow.test.ts new file mode 100644 index 0000000..90d6cf5 --- /dev/null +++ b/test/content/components/common/follow.test.ts @@ -0,0 +1,25 @@ +import FollowComponent from 'content/components/common/follow'; + +describe('FollowComponent', () => { + describe('#getTargetElements', () => { + beforeEach(() => { + document.body.innerHTML = __html__['test/content/components/common/follow.html']; + }); + + it('returns visible links', () => { + let targets = FollowComponent.getTargetElements( + window, + { width: window.innerWidth, height: window.innerHeight }, + { x: 0, y: 0 }); + expect(targets).to.have.lengthOf(4); + + let ids = Array.prototype.map.call(targets, (e) => e.id); + expect(ids).to.include.members([ + 'visible_a', + 'editable_div_1', + 'editable_div_2', + 'summary_1', + ]); + }); + }); +}); diff --git a/test/content/components/common/hint.test.js b/test/content/components/common/hint.test.js deleted file mode 100644 index 42d571f..0000000 --- a/test/content/components/common/hint.test.js +++ /dev/null @@ -1,57 +0,0 @@ -import Hint from 'content/components/common/hint'; - -describe('Hint class', () => { - beforeEach(() => { - document.body.innerHTML = __html__['test/content/components/common/hint.html']; - }); - - describe('#constructor', () => { - it('creates a hint element with tag name', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - expect(hint.element.textContent.trim()).to.be.equal('abc'); - }); - - it('throws an exception when non-element given', () => { - expect(() => new Hint(window, 'abc')).to.throw(TypeError); - }); - }); - - describe('#show', () => { - it('shows an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - hint.hide(); - hint.show(); - - expect(hint.element.style.display).to.not.equal('none'); - }); - }); - - describe('#hide', () => { - it('hides an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - hint.hide(); - - expect(hint.element.style.display).to.equal('none'); - }); - }); - - describe('#remove', () => { - it('removes an element', () => { - let link = document.getElementById('test-link'); - let hint = new Hint(link, 'abc'); - - expect(hint.element.parentElement).to.not.be.null; - hint.remove(); - expect(hint.element.parentElement).to.be.null; - }); - }); - - describe('#activate', () => { - // TODO test activations - }); -}); - - diff --git a/test/content/components/common/hint.test.ts b/test/content/components/common/hint.test.ts new file mode 100644 index 0000000..42d571f --- /dev/null +++ b/test/content/components/common/hint.test.ts @@ -0,0 +1,57 @@ +import Hint from 'content/components/common/hint'; + +describe('Hint class', () => { + beforeEach(() => { + document.body.innerHTML = __html__['test/content/components/common/hint.html']; + }); + + describe('#constructor', () => { + it('creates a hint element with tag name', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + expect(hint.element.textContent.trim()).to.be.equal('abc'); + }); + + it('throws an exception when non-element given', () => { + expect(() => new Hint(window, 'abc')).to.throw(TypeError); + }); + }); + + describe('#show', () => { + it('shows an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + hint.hide(); + hint.show(); + + expect(hint.element.style.display).to.not.equal('none'); + }); + }); + + describe('#hide', () => { + it('hides an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + hint.hide(); + + expect(hint.element.style.display).to.equal('none'); + }); + }); + + describe('#remove', () => { + it('removes an element', () => { + let link = document.getElementById('test-link'); + let hint = new Hint(link, 'abc'); + + expect(hint.element.parentElement).to.not.be.null; + hint.remove(); + expect(hint.element.parentElement).to.be.null; + }); + }); + + describe('#activate', () => { + // TODO test activations + }); +}); + + diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.js deleted file mode 100644 index 2ba5507..0000000 --- a/test/content/components/common/input.test.js +++ /dev/null @@ -1,70 +0,0 @@ -import InputComponent from 'content/components/common/input'; - -describe('InputComponent', () => { - it('register callbacks', () => { - let component = new InputComponent(window.document); - let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false }; - component.onKey((key) => { - expect(key).to.deep.equal(key); - }); - component.onKeyDown(key); - }); - - it('invoke callback once', () => { - let component = new InputComponent(window.document); - let a = 0, b = 0; - component.onKey((key) => { - if (key.key == 'a') { - ++a; - } else { - key.key == 'b' - ++b; - } - }); - component.onKeyDown({ key: 'a' }); - component.onKeyDown({ key: 'b' }); - component.onKeyPress({ key: 'a' }); - component.onKeyUp({ key: 'a' }); - component.onKeyPress({ key: 'b' }); - component.onKeyUp({ key: 'b' }); - - expect(a).is.equals(1); - expect(b).is.equals(1); - }) - - it('does not invoke only meta keys', () => { - let component = new InputComponent(window.document); - component.onKey((key) => { - expect.fail(); - }); - component.onKeyDown({ key: 'Shift' }); - component.onKeyDown({ key: 'Control' }); - component.onKeyDown({ key: 'Alt' }); - component.onKeyDown({ key: 'OS' }); - }) - - it('ignores events from input elements', () => { - ['input', 'textarea', 'select'].forEach((name) => { - let target = window.document.createElement(name); - let component = new InputComponent(target); - component.onKey((key) => { - expect.fail(); - }); - component.onKeyDown({ key: 'x', target }); - }); - }); - - it('ignores events from contenteditable elements', () => { - let target = window.document.createElement('div'); - let component = new InputComponent(target); - component.onKey((key) => { - expect.fail(); - }); - - target.setAttribute('contenteditable', ''); - component.onKeyDown({ key: 'x', target }); - - target.setAttribute('contenteditable', 'true'); - component.onKeyDown({ key: 'x', target }); - }) -}); diff --git a/test/content/components/common/input.test.ts b/test/content/components/common/input.test.ts new file mode 100644 index 0000000..2ba5507 --- /dev/null +++ b/test/content/components/common/input.test.ts @@ -0,0 +1,70 @@ +import InputComponent from 'content/components/common/input'; + +describe('InputComponent', () => { + it('register callbacks', () => { + let component = new InputComponent(window.document); + let key = { key: 'a', ctrlKey: true, shiftKey: false, altKey: false, metaKey: false }; + component.onKey((key) => { + expect(key).to.deep.equal(key); + }); + component.onKeyDown(key); + }); + + it('invoke callback once', () => { + let component = new InputComponent(window.document); + let a = 0, b = 0; + component.onKey((key) => { + if (key.key == 'a') { + ++a; + } else { + key.key == 'b' + ++b; + } + }); + component.onKeyDown({ key: 'a' }); + component.onKeyDown({ key: 'b' }); + component.onKeyPress({ key: 'a' }); + component.onKeyUp({ key: 'a' }); + component.onKeyPress({ key: 'b' }); + component.onKeyUp({ key: 'b' }); + + expect(a).is.equals(1); + expect(b).is.equals(1); + }) + + it('does not invoke only meta keys', () => { + let component = new InputComponent(window.document); + component.onKey((key) => { + expect.fail(); + }); + component.onKeyDown({ key: 'Shift' }); + component.onKeyDown({ key: 'Control' }); + component.onKeyDown({ key: 'Alt' }); + component.onKeyDown({ key: 'OS' }); + }) + + it('ignores events from input elements', () => { + ['input', 'textarea', 'select'].forEach((name) => { + let target = window.document.createElement(name); + let component = new InputComponent(target); + component.onKey((key) => { + expect.fail(); + }); + component.onKeyDown({ key: 'x', target }); + }); + }); + + it('ignores events from contenteditable elements', () => { + let target = window.document.createElement('div'); + let component = new InputComponent(target); + component.onKey((key) => { + expect.fail(); + }); + + target.setAttribute('contenteditable', ''); + component.onKeyDown({ key: 'x', target }); + + target.setAttribute('contenteditable', 'true'); + component.onKeyDown({ key: 'x', target }); + }) +}); diff --git a/test/content/hint-key-producer.test.js b/test/content/hint-key-producer.test.js deleted file mode 100644 index dcf477d..0000000 --- a/test/content/hint-key-producer.test.js +++ /dev/null @@ -1,24 +0,0 @@ -import HintKeyProducer from 'content/hint-key-producer'; - -describe('HintKeyProducer class', () => { - describe('#constructor', () => { - it('throws an exception on empty charset', () => { - expect(() => new HintKeyProducer([])).to.throw(TypeError); - }); - }); - - describe('#produce', () => { - it('produce incremented keys', () => { - let charset = 'abc'; - let sequences = [ - 'a', 'b', 'c', - 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', - 'aaa', 'aab', 'aac', 'aba'] - - let producer = new HintKeyProducer(charset); - for (let i = 0; i < sequences.length; ++i) { - expect(producer.produce()).to.equal(sequences[i]); - } - }); - }); -}); diff --git a/test/content/hint-key-producer.test.ts b/test/content/hint-key-producer.test.ts new file mode 100644 index 0000000..dcf477d --- /dev/null +++ b/test/content/hint-key-producer.test.ts @@ -0,0 +1,24 @@ +import HintKeyProducer from 'content/hint-key-producer'; + +describe('HintKeyProducer class', () => { + describe('#constructor', () => { + it('throws an exception on empty charset', () => { + expect(() => new HintKeyProducer([])).to.throw(TypeError); + }); + }); + + describe('#produce', () => { + it('produce incremented keys', () => { + let charset = 'abc'; + let sequences = [ + 'a', 'b', 'c', + 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc', + 'aaa', 'aab', 'aac', 'aba'] + + let producer = new HintKeyProducer(charset); + for (let i = 0; i < sequences.length; ++i) { + expect(producer.produce()).to.equal(sequences[i]); + } + }); + }); +}); diff --git a/test/content/navigates.test.js b/test/content/navigates.test.js deleted file mode 100644 index 1d73344..0000000 --- a/test/content/navigates.test.js +++ /dev/null @@ -1,137 +0,0 @@ -import * as navigates from 'content/navigates'; - -const testRel = (done, rel, html) => { - const method = rel === 'prev' ? 'linkPrev' : 'linkNext'; - document.body.innerHTML = html; - navigates[method](window); - setTimeout(() => { - expect(document.location.hash).to.equal(`#${rel}`); - done(); - }, 0); -}; - -const testPrev = html => done => testRel(done, 'prev', html); -const testNext = html => done => testRel(done, 'next', html); - -describe('navigates module', () => { - describe('#linkPrev', () => { - it('navigates to elements whose rel attribute is "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute starts with "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute ends with "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute contains "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute is "prev"', testPrev( - '' - )); - - it('navigates to elements whose rel attribute starts with "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose rel attribute ends with "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose rel attribute contains "prev"', testPrev( - 'click me' - )); - - it('navigates to elements whose text matches "prev"', testPrev( - 'previewgo to prev' - )); - - it('navigates to elements whose text matches "previous"', testPrev( - 'previouslyprevious page' - )); - - it('navigates to elements whose decoded text matches "<<"', testPrev( - 'click me<<' - )); - - it('navigates to matching elements by clicking', testPrev( - `` - )); - - it('prefers link[rel~=prev] to a[rel~=prev]', testPrev( - '' - )); - - it('prefers a[rel~=prev] to a::text(pattern)', testPrev( - 'go to prev' - )); - }); - - describe('#linkNext', () => { - it('navigates to elements whose rel attribute is "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute starts with "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute ends with "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute contains "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute is "next"', testNext( - '' - )); - - it('navigates to elements whose rel attribute starts with "next"', testNext( - 'click me' - )); - - it('navigates to elements whose rel attribute ends with "next"', testNext( - 'click me' - )); - - it('navigates to elements whose rel attribute contains "next"', testNext( - 'click me' - )); - - it('navigates to elements whose text matches "next"', testNext( - 'inextricablego to next' - )); - - it('navigates to elements whose decoded text matches ">>"', testNext( - 'click me>>' - )); - - it('navigates to matching elements by clicking', testNext( - `` - )); - - it('prefers link[rel~=next] to a[rel~=next]', testNext( - '' - )); - - it('prefers a[rel~=next] to a::text(pattern)', testNext( - 'next page' - )); - }); - - describe('#parent', () => { - // NOTE: not able to test location - it('removes hash', () => { - window.location.hash = '#section-1'; - navigates.parent(window); - expect(document.location.hash).to.be.empty; - }); - }); -}); diff --git a/test/content/navigates.test.ts b/test/content/navigates.test.ts new file mode 100644 index 0000000..1d73344 --- /dev/null +++ b/test/content/navigates.test.ts @@ -0,0 +1,137 @@ +import * as navigates from 'content/navigates'; + +const testRel = (done, rel, html) => { + const method = rel === 'prev' ? 'linkPrev' : 'linkNext'; + document.body.innerHTML = html; + navigates[method](window); + setTimeout(() => { + expect(document.location.hash).to.equal(`#${rel}`); + done(); + }, 0); +}; + +const testPrev = html => done => testRel(done, 'prev', html); +const testNext = html => done => testRel(done, 'next', html); + +describe('navigates module', () => { + describe('#linkPrev', () => { + it('navigates to elements whose rel attribute is "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute starts with "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute ends with "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute contains "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute is "prev"', testPrev( + '' + )); + + it('navigates to elements whose rel attribute starts with "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose rel attribute ends with "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose rel attribute contains "prev"', testPrev( + 'click me' + )); + + it('navigates to elements whose text matches "prev"', testPrev( + 'previewgo to prev' + )); + + it('navigates to elements whose text matches "previous"', testPrev( + 'previouslyprevious page' + )); + + it('navigates to elements whose decoded text matches "<<"', testPrev( + 'click me<<' + )); + + it('navigates to matching elements by clicking', testPrev( + `` + )); + + it('prefers link[rel~=prev] to a[rel~=prev]', testPrev( + '' + )); + + it('prefers a[rel~=prev] to a::text(pattern)', testPrev( + 'go to prev' + )); + }); + + describe('#linkNext', () => { + it('navigates to elements whose rel attribute is "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute starts with "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute ends with "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute contains "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute is "next"', testNext( + '' + )); + + it('navigates to elements whose rel attribute starts with "next"', testNext( + 'click me' + )); + + it('navigates to elements whose rel attribute ends with "next"', testNext( + 'click me' + )); + + it('navigates to elements whose rel attribute contains "next"', testNext( + 'click me' + )); + + it('navigates to elements whose text matches "next"', testNext( + 'inextricablego to next' + )); + + it('navigates to elements whose decoded text matches ">>"', testNext( + 'click me>>' + )); + + it('navigates to matching elements by clicking', testNext( + `` + )); + + it('prefers link[rel~=next] to a[rel~=next]', testNext( + '' + )); + + it('prefers a[rel~=next] to a::text(pattern)', testNext( + 'next page' + )); + }); + + describe('#parent', () => { + // NOTE: not able to test location + it('removes hash', () => { + window.location.hash = '#section-1'; + navigates.parent(window); + expect(document.location.hash).to.be.empty; + }); + }); +}); diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.js deleted file mode 100644 index d4eb845..0000000 --- a/test/content/reducers/addon.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import actions from 'content/actions'; -import addonReducer from 'content/reducers/addon'; - -describe("addon reducer", () => { - it('return the initial state', () => { - let state = addonReducer(undefined, {}); - expect(state).to.have.property('enabled', true); - }); - - it('return next state for ADDON_SET_ENABLED', () => { - let action = { type: actions.ADDON_SET_ENABLED, enabled: true }; - let prev = { enabled: false }; - let state = addonReducer(prev, action); - - expect(state.enabled).is.equal(true); - }); -}); diff --git a/test/content/reducers/addon.test.ts b/test/content/reducers/addon.test.ts new file mode 100644 index 0000000..d4eb845 --- /dev/null +++ b/test/content/reducers/addon.test.ts @@ -0,0 +1,17 @@ +import actions from 'content/actions'; +import addonReducer from 'content/reducers/addon'; + +describe("addon reducer", () => { + it('return the initial state', () => { + let state = addonReducer(undefined, {}); + expect(state).to.have.property('enabled', true); + }); + + it('return next state for ADDON_SET_ENABLED', () => { + let action = { type: actions.ADDON_SET_ENABLED, enabled: true }; + let prev = { enabled: false }; + let state = addonReducer(prev, action); + + expect(state.enabled).is.equal(true); + }); +}); diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.js deleted file mode 100644 index a8c30d7..0000000 --- a/test/content/reducers/find.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import actions from 'content/actions'; -import findReducer from 'content/reducers/find'; - -describe("find reducer", () => { - it('return the initial state', () => { - let state = findReducer(undefined, {}); - expect(state).to.have.property('keyword', null); - expect(state).to.have.property('found', false); - }); - - it('return next state for FIND_SET_KEYWORD', () => { - let action = { - type: actions.FIND_SET_KEYWORD, - keyword: 'xyz', - found: true, - }; - let state = findReducer({}, action); - - expect(state.keyword).is.equal('xyz'); - expect(state.found).to.be.true; - }); -}); diff --git a/test/content/reducers/find.test.ts b/test/content/reducers/find.test.ts new file mode 100644 index 0000000..a8c30d7 --- /dev/null +++ b/test/content/reducers/find.test.ts @@ -0,0 +1,22 @@ +import actions from 'content/actions'; +import findReducer from 'content/reducers/find'; + +describe("find reducer", () => { + it('return the initial state', () => { + let state = findReducer(undefined, {}); + expect(state).to.have.property('keyword', null); + expect(state).to.have.property('found', false); + }); + + it('return next state for FIND_SET_KEYWORD', () => { + let action = { + type: actions.FIND_SET_KEYWORD, + keyword: 'xyz', + found: true, + }; + let state = findReducer({}, action); + + expect(state.keyword).is.equal('xyz'); + expect(state.found).to.be.true; + }); +}); diff --git a/test/content/reducers/follow-controller.test.js b/test/content/reducers/follow-controller.test.js deleted file mode 100644 index 8a4c2d4..0000000 --- a/test/content/reducers/follow-controller.test.js +++ /dev/null @@ -1,47 +0,0 @@ -import actions from 'content/actions'; -import followControllerReducer from 'content/reducers/follow-controller'; - -describe('follow-controller reducer', () => { - it ('returns the initial state', () => { - let state = followControllerReducer(undefined, {}); - expect(state).to.have.property('enabled', false); - expect(state).to.have.property('newTab'); - expect(state).to.have.deep.property('keys', ''); - }); - - it ('returns next state for FOLLOW_CONTROLLER_ENABLE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab: true }; - let state = followControllerReducer({ enabled: false, newTab: false }, action); - expect(state).to.have.property('enabled', true); - expect(state).to.have.property('newTab', true); - expect(state).to.have.property('keys', ''); - }); - - it ('returns next state for FOLLOW_CONTROLLER_DISABLE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_DISABLE }; - let state = followControllerReducer({ enabled: true }, action); - expect(state).to.have.property('enabled', false); - }); - - it ('returns next state for FOLLOW_CONTROLLER_KEY_PRESS', () => { - let action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'a'}; - let state = followControllerReducer({ keys: '' }, action); - expect(state).to.have.deep.property('keys', 'a'); - - action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'b'}; - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', 'ab'); - }); - - it ('returns next state for FOLLOW_CONTROLLER_BACKSPACE', () => { - let action = { type: actions.FOLLOW_CONTROLLER_BACKSPACE }; - let state = followControllerReducer({ keys: 'ab' }, action); - expect(state).to.have.deep.property('keys', 'a'); - - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', ''); - - state = followControllerReducer(state, action); - expect(state).to.have.deep.property('keys', ''); - }); -}); diff --git a/test/content/reducers/follow-controller.test.ts b/test/content/reducers/follow-controller.test.ts new file mode 100644 index 0000000..8a4c2d4 --- /dev/null +++ b/test/content/reducers/follow-controller.test.ts @@ -0,0 +1,47 @@ +import actions from 'content/actions'; +import followControllerReducer from 'content/reducers/follow-controller'; + +describe('follow-controller reducer', () => { + it ('returns the initial state', () => { + let state = followControllerReducer(undefined, {}); + expect(state).to.have.property('enabled', false); + expect(state).to.have.property('newTab'); + expect(state).to.have.deep.property('keys', ''); + }); + + it ('returns next state for FOLLOW_CONTROLLER_ENABLE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab: true }; + let state = followControllerReducer({ enabled: false, newTab: false }, action); + expect(state).to.have.property('enabled', true); + expect(state).to.have.property('newTab', true); + expect(state).to.have.property('keys', ''); + }); + + it ('returns next state for FOLLOW_CONTROLLER_DISABLE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_DISABLE }; + let state = followControllerReducer({ enabled: true }, action); + expect(state).to.have.property('enabled', false); + }); + + it ('returns next state for FOLLOW_CONTROLLER_KEY_PRESS', () => { + let action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'a'}; + let state = followControllerReducer({ keys: '' }, action); + expect(state).to.have.deep.property('keys', 'a'); + + action = { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: 'b'}; + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', 'ab'); + }); + + it ('returns next state for FOLLOW_CONTROLLER_BACKSPACE', () => { + let action = { type: actions.FOLLOW_CONTROLLER_BACKSPACE }; + let state = followControllerReducer({ keys: 'ab' }, action); + expect(state).to.have.deep.property('keys', 'a'); + + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', ''); + + state = followControllerReducer(state, action); + expect(state).to.have.deep.property('keys', ''); + }); +}); diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.js deleted file mode 100644 index 0011943..0000000 --- a/test/content/reducers/input.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import actions from 'content/actions'; -import inputReducer from 'content/reducers/input'; - -describe("input reducer", () => { - it('return the initial state', () => { - let state = inputReducer(undefined, {}); - expect(state).to.have.deep.property('keys', []); - }); - - it('return next state for INPUT_KEY_PRESS', () => { - let action = { type: actions.INPUT_KEY_PRESS, key: 'a' }; - let state = inputReducer(undefined, action); - expect(state).to.have.deep.property('keys', ['a']); - - action = { type: actions.INPUT_KEY_PRESS, key: 'b' }; - state = inputReducer(state, action); - expect(state).to.have.deep.property('keys', ['a', 'b']); - }); - - it('return next state for INPUT_CLEAR_KEYS', () => { - let action = { type: actions.INPUT_CLEAR_KEYS }; - let state = inputReducer({ keys: [1, 2, 3] }, action); - expect(state).to.have.deep.property('keys', []); - }); -}); diff --git a/test/content/reducers/input.test.ts b/test/content/reducers/input.test.ts new file mode 100644 index 0000000..0011943 --- /dev/null +++ b/test/content/reducers/input.test.ts @@ -0,0 +1,25 @@ +import actions from 'content/actions'; +import inputReducer from 'content/reducers/input'; + +describe("input reducer", () => { + it('return the initial state', () => { + let state = inputReducer(undefined, {}); + expect(state).to.have.deep.property('keys', []); + }); + + it('return next state for INPUT_KEY_PRESS', () => { + let action = { type: actions.INPUT_KEY_PRESS, key: 'a' }; + let state = inputReducer(undefined, action); + expect(state).to.have.deep.property('keys', ['a']); + + action = { type: actions.INPUT_KEY_PRESS, key: 'b' }; + state = inputReducer(state, action); + expect(state).to.have.deep.property('keys', ['a', 'b']); + }); + + it('return next state for INPUT_CLEAR_KEYS', () => { + let action = { type: actions.INPUT_CLEAR_KEYS }; + let state = inputReducer({ keys: [1, 2, 3] }, action); + expect(state).to.have.deep.property('keys', []); + }); +}); diff --git a/test/content/reducers/mark.test.js b/test/content/reducers/mark.test.js deleted file mode 100644 index 76efbf7..0000000 --- a/test/content/reducers/mark.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import actions from 'content/actions'; -import reducer from 'content/reducers/mark'; - -describe("mark reducer", () => { - it('return the initial state', () => { - let state = reducer(undefined, {}); - expect(state.setMode).to.be.false; - expect(state.jumpMode).to.be.false; - expect(state.marks).to.be.empty; - }); - - it('starts set mode', () => { - let action = { type: actions.MARK_START_SET }; - let state = reducer(undefined, action); - expect(state.setMode).to.be.true; - }); - - it('starts jump mode', () => { - let action = { type: actions.MARK_START_JUMP }; - let state = reducer(undefined, action); - expect(state.jumpMode).to.be.true; - }); - - it('cancels set and jump mode', () => { - let action = { type: actions.MARK_CANCEL }; - let state = reducer({ setMode: true }, action); - expect(state.setMode).to.be.false; - - state = reducer({ jumpMode: true }, action); - expect(state.jumpMode).to.be.false; - }); - - it('stores local mark', () => { - let action = { type: actions.MARK_SET_LOCAL, key: 'a', x: 20, y: 30}; - let state = reducer({ setMode: true }, action); - expect(state.setMode).to.be.false; - expect(state.marks['a']).to.be.an('object') - expect(state.marks['a'].x).to.equal(20) - expect(state.marks['a'].y).to.equal(30) - }); -}); diff --git a/test/content/reducers/mark.test.ts b/test/content/reducers/mark.test.ts new file mode 100644 index 0000000..76efbf7 --- /dev/null +++ b/test/content/reducers/mark.test.ts @@ -0,0 +1,41 @@ +import actions from 'content/actions'; +import reducer from 'content/reducers/mark'; + +describe("mark reducer", () => { + it('return the initial state', () => { + let state = reducer(undefined, {}); + expect(state.setMode).to.be.false; + expect(state.jumpMode).to.be.false; + expect(state.marks).to.be.empty; + }); + + it('starts set mode', () => { + let action = { type: actions.MARK_START_SET }; + let state = reducer(undefined, action); + expect(state.setMode).to.be.true; + }); + + it('starts jump mode', () => { + let action = { type: actions.MARK_START_JUMP }; + let state = reducer(undefined, action); + expect(state.jumpMode).to.be.true; + }); + + it('cancels set and jump mode', () => { + let action = { type: actions.MARK_CANCEL }; + let state = reducer({ setMode: true }, action); + expect(state.setMode).to.be.false; + + state = reducer({ jumpMode: true }, action); + expect(state.jumpMode).to.be.false; + }); + + it('stores local mark', () => { + let action = { type: actions.MARK_SET_LOCAL, key: 'a', x: 20, y: 30}; + let state = reducer({ setMode: true }, action); + expect(state.setMode).to.be.false; + expect(state.marks['a']).to.be.an('object') + expect(state.marks['a'].x).to.equal(20) + expect(state.marks['a'].y).to.equal(30) + }); +}); diff --git a/test/content/reducers/setting.test.js b/test/content/reducers/setting.test.js deleted file mode 100644 index 4e4c095..0000000 --- a/test/content/reducers/setting.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import actions from 'content/actions'; -import settingReducer from 'content/reducers/setting'; - -describe("content setting reducer", () => { - it('return the initial state', () => { - let state = settingReducer(undefined, {}); - expect(state.keymaps).to.be.empty; - }); - - it('return next state for SETTING_SET', () => { - let newSettings = { red: 'apple', yellow: 'banana' }; - let action = { type: actions.SETTING_SET, value: newSettings }; - let state = settingReducer(undefined, action); - expect(state).to.deep.equal(newSettings); - expect(state).not.to.equal(newSettings); // assert deep copy - }); -}); diff --git a/test/content/reducers/setting.test.ts b/test/content/reducers/setting.test.ts new file mode 100644 index 0000000..4e4c095 --- /dev/null +++ b/test/content/reducers/setting.test.ts @@ -0,0 +1,17 @@ +import actions from 'content/actions'; +import settingReducer from 'content/reducers/setting'; + +describe("content setting reducer", () => { + it('return the initial state', () => { + let state = settingReducer(undefined, {}); + expect(state.keymaps).to.be.empty; + }); + + it('return next state for SETTING_SET', () => { + let newSettings = { red: 'apple', yellow: 'banana' }; + let action = { type: actions.SETTING_SET, value: newSettings }; + let state = settingReducer(undefined, action); + expect(state).to.deep.equal(newSettings); + expect(state).not.to.equal(newSettings); // assert deep copy + }); +}); diff --git a/test/main.js b/test/main.js deleted file mode 100644 index 3aeae69..0000000 --- a/test/main.js +++ /dev/null @@ -1,6 +0,0 @@ -import chai from 'chai'; -const browserFake = require('webextensions-api-fake'); -const browser = browserFake(); - -global.expect = chai.expect; -global.browser = browser; diff --git a/test/main.ts b/test/main.ts new file mode 100644 index 0000000..3aeae69 --- /dev/null +++ b/test/main.ts @@ -0,0 +1,6 @@ +import chai from 'chai'; +const browserFake = require('webextensions-api-fake'); +const browser = browserFake(); + +global.expect = chai.expect; +global.browser = browser; diff --git a/test/settings/components/form/BlacklistForm.test.jsx b/test/settings/components/form/BlacklistForm.test.jsx deleted file mode 100644 index 2be5d96..0000000 --- a/test/settings/components/form/BlacklistForm.test.jsx +++ /dev/null @@ -1,92 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestRenderer from 'react-test-renderer'; -import ReactTestUtils from 'react-dom/test-utils'; -import BlacklistForm from 'settings/components/form/BlacklistForm' - -describe("settings/form/BlacklistForm", () => { - describe('render', () => { - it('renders BlacklistForm', () => { - let root = ReactTestRenderer.create( - , - ).root; - - let children = root.children[0].children; - expect(children).to.have.lengthOf(3); - expect(children[0].children[0].props.value).to.equal('*.slack.com'); - expect(children[1].children[0].props.value).to.equal('www.google.com/maps'); - expect(children[2].props.name).to.equal('add'); - }); - - it('renders blank value', () => { - let root = ReactTestRenderer.create().root; - - let children = root.children[0].children; - expect(children).to.have.lengthOf(1); - expect(children[0].props.name).to.equal('add'); - }); - }); - - describe('onChange', () => { - let container; - - beforeEach(() => { - container = document.createElement('div'); - document.body.appendChild(container); - }); - - afterEach(() => { - document.body.removeChild(container); - container = null; - }); - - it('invokes onChange event on edit', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.lengthOf(2); - expect(value).to.have.members(['gitter.im', 'www.google.com/maps*']); - done(); - }} - />, container) - }); - - let input = document.querySelectorAll('input[type=text]')[0]; - input.value = 'gitter.im'; - ReactTestUtils.Simulate.change(input); - }); - - it('invokes onChange event on delete', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.lengthOf(1); - expect(value).to.have.members(['www.google.com/maps*']); - done(); - }} - />, container) - }); - - let button = document.querySelectorAll('input[type=button]')[0]; - ReactTestUtils.Simulate.click(button); - }); - - it('invokes onChange event on add', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.lengthOf(2); - expect(value).to.have.members(['*.slack.com', '']); - done(); - }} - />, container); - }); - - let button = document.querySelector('input[type=button].ui-add-button'); - ReactTestUtils.Simulate.click(button); - }); - }); -}); diff --git a/test/settings/components/form/BlacklistForm.test.tsx b/test/settings/components/form/BlacklistForm.test.tsx new file mode 100644 index 0000000..2be5d96 --- /dev/null +++ b/test/settings/components/form/BlacklistForm.test.tsx @@ -0,0 +1,92 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestRenderer from 'react-test-renderer'; +import ReactTestUtils from 'react-dom/test-utils'; +import BlacklistForm from 'settings/components/form/BlacklistForm' + +describe("settings/form/BlacklistForm", () => { + describe('render', () => { + it('renders BlacklistForm', () => { + let root = ReactTestRenderer.create( + , + ).root; + + let children = root.children[0].children; + expect(children).to.have.lengthOf(3); + expect(children[0].children[0].props.value).to.equal('*.slack.com'); + expect(children[1].children[0].props.value).to.equal('www.google.com/maps'); + expect(children[2].props.name).to.equal('add'); + }); + + it('renders blank value', () => { + let root = ReactTestRenderer.create().root; + + let children = root.children[0].children; + expect(children).to.have.lengthOf(1); + expect(children[0].props.name).to.equal('add'); + }); + }); + + describe('onChange', () => { + let container; + + beforeEach(() => { + container = document.createElement('div'); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + container = null; + }); + + it('invokes onChange event on edit', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.lengthOf(2); + expect(value).to.have.members(['gitter.im', 'www.google.com/maps*']); + done(); + }} + />, container) + }); + + let input = document.querySelectorAll('input[type=text]')[0]; + input.value = 'gitter.im'; + ReactTestUtils.Simulate.change(input); + }); + + it('invokes onChange event on delete', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.lengthOf(1); + expect(value).to.have.members(['www.google.com/maps*']); + done(); + }} + />, container) + }); + + let button = document.querySelectorAll('input[type=button]')[0]; + ReactTestUtils.Simulate.click(button); + }); + + it('invokes onChange event on add', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.lengthOf(2); + expect(value).to.have.members(['*.slack.com', '']); + done(); + }} + />, container); + }); + + let button = document.querySelector('input[type=button].ui-add-button'); + ReactTestUtils.Simulate.click(button); + }); + }); +}); diff --git a/test/settings/components/form/KeymapsForm.test.jsx b/test/settings/components/form/KeymapsForm.test.jsx deleted file mode 100644 index 6ac57c9..0000000 --- a/test/settings/components/form/KeymapsForm.test.jsx +++ /dev/null @@ -1,64 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestRenderer from 'react-test-renderer'; -import ReactTestUtils from 'react-dom/test-utils'; -import KeymapsForm from 'settings/components/form/KeymapsForm' - -describe("settings/form/KeymapsForm", () => { - describe('render', () => { - it('renders keymap fields', () => { - let root = ReactTestRenderer.create().root - - let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); - let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); - - expect(inputj.props.value).to.equal('j'); - expect(inputk.props.value).to.equal('k'); - }); - - it('renders blank value', () => { - let root = ReactTestRenderer.create().root; - - let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); - let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); - - expect(inputj.props.value).to.be.empty; - expect(inputk.props.value).to.be.empty; - }); - }); - - describe('onChange event', () => { - let container; - - beforeEach(() => { - container = document.createElement('div'); - document.body.appendChild(container); - }); - - afterEach(() => { - document.body.removeChild(container); - container = null; - }); - - it('invokes onChange event on edit', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value['scroll.vertically?{"count":1}']).to.equal('jjj'); - done(); - }} />, container); - }); - - let input = document.getElementById('scroll.vertically?{"count":1}'); - input.value = 'jjj'; - ReactTestUtils.Simulate.change(input); - }); - }); -}); diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx new file mode 100644 index 0000000..6ac57c9 --- /dev/null +++ b/test/settings/components/form/KeymapsForm.test.tsx @@ -0,0 +1,64 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestRenderer from 'react-test-renderer'; +import ReactTestUtils from 'react-dom/test-utils'; +import KeymapsForm from 'settings/components/form/KeymapsForm' + +describe("settings/form/KeymapsForm", () => { + describe('render', () => { + it('renders keymap fields', () => { + let root = ReactTestRenderer.create().root + + let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); + let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); + + expect(inputj.props.value).to.equal('j'); + expect(inputk.props.value).to.equal('k'); + }); + + it('renders blank value', () => { + let root = ReactTestRenderer.create().root; + + let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); + let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); + + expect(inputj.props.value).to.be.empty; + expect(inputk.props.value).to.be.empty; + }); + }); + + describe('onChange event', () => { + let container; + + beforeEach(() => { + container = document.createElement('div'); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + container = null; + }); + + it('invokes onChange event on edit', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value['scroll.vertically?{"count":1}']).to.equal('jjj'); + done(); + }} />, container); + }); + + let input = document.getElementById('scroll.vertically?{"count":1}'); + input.value = 'jjj'; + ReactTestUtils.Simulate.change(input); + }); + }); +}); diff --git a/test/settings/components/form/PropertiesForm.test.jsx b/test/settings/components/form/PropertiesForm.test.jsx deleted file mode 100644 index 80f60d2..0000000 --- a/test/settings/components/form/PropertiesForm.test.jsx +++ /dev/null @@ -1,104 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestRenderer from 'react-test-renderer'; -import ReactTestUtils from 'react-dom/test-utils'; -import PropertiesForm from 'settings/components/form/PropertiesForm' - -describe("settings/form/PropertiesForm", () => { - describe('render', () => { - it('renders PropertiesForm', () => { - let types = { - mystr: 'string', - mynum: 'number', - mybool: 'boolean', - empty: 'string', - } - let value = { - mystr: 'abc', - mynum: 123, - mybool: true, - }; - - let root = ReactTestRenderer.create( - , - ).root - - let input = root.findByProps({ name: 'mystr' }); - expect(input.props.type).to.equals('text'); - expect(input.props.value).to.equal('abc'); - - input = root.findByProps({ name: 'mynum' }); - expect(input.props.type).to.equals('number'); - expect(input.props.value).to.equal(123); - - input = root.findByProps({ name: 'mybool' }); - expect(input.props.type).to.equals('checkbox'); - expect(input.props.value).to.equal(true); - }); - }); - - describe('onChange', () => { - let container; - - beforeEach(() => { - container = document.createElement('div'); - document.body.appendChild(container); - }); - - afterEach(() => { - document.body.removeChild(container); - container = null; - }); - - it('invokes onChange event on text changed', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.property('myvalue', 'abcd'); - done(); - }} - />, container); - }); - - let input = document.querySelector('input[name=myvalue]'); - input.value = 'abcd' - ReactTestUtils.Simulate.change(input); - }); - - it('invokes onChange event on number changeed', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.property('myvalue', 1234); - done(); - }} - />, container); - }); - - let input = document.querySelector('input[name=myvalue]'); - input.value = '1234' - ReactTestUtils.Simulate.change(input); - }); - - it('invokes onChange event on checkbox changed', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value).to.have.property('myvalue', true); - done(); - }} - />, container); - }); - - let input = document.querySelector('input[name=myvalue]'); - input.checked = true; - ReactTestUtils.Simulate.change(input); - }); - }); -}); diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx new file mode 100644 index 0000000..80f60d2 --- /dev/null +++ b/test/settings/components/form/PropertiesForm.test.tsx @@ -0,0 +1,104 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestRenderer from 'react-test-renderer'; +import ReactTestUtils from 'react-dom/test-utils'; +import PropertiesForm from 'settings/components/form/PropertiesForm' + +describe("settings/form/PropertiesForm", () => { + describe('render', () => { + it('renders PropertiesForm', () => { + let types = { + mystr: 'string', + mynum: 'number', + mybool: 'boolean', + empty: 'string', + } + let value = { + mystr: 'abc', + mynum: 123, + mybool: true, + }; + + let root = ReactTestRenderer.create( + , + ).root + + let input = root.findByProps({ name: 'mystr' }); + expect(input.props.type).to.equals('text'); + expect(input.props.value).to.equal('abc'); + + input = root.findByProps({ name: 'mynum' }); + expect(input.props.type).to.equals('number'); + expect(input.props.value).to.equal(123); + + input = root.findByProps({ name: 'mybool' }); + expect(input.props.type).to.equals('checkbox'); + expect(input.props.value).to.equal(true); + }); + }); + + describe('onChange', () => { + let container; + + beforeEach(() => { + container = document.createElement('div'); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + container = null; + }); + + it('invokes onChange event on text changed', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.property('myvalue', 'abcd'); + done(); + }} + />, container); + }); + + let input = document.querySelector('input[name=myvalue]'); + input.value = 'abcd' + ReactTestUtils.Simulate.change(input); + }); + + it('invokes onChange event on number changeed', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.property('myvalue', 1234); + done(); + }} + />, container); + }); + + let input = document.querySelector('input[name=myvalue]'); + input.value = '1234' + ReactTestUtils.Simulate.change(input); + }); + + it('invokes onChange event on checkbox changed', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value).to.have.property('myvalue', true); + done(); + }} + />, container); + }); + + let input = document.querySelector('input[name=myvalue]'); + input.checked = true; + ReactTestUtils.Simulate.change(input); + }); + }); +}); diff --git a/test/settings/components/form/SearchEngineForm.test.jsx b/test/settings/components/form/SearchEngineForm.test.jsx deleted file mode 100644 index 06822f2..0000000 --- a/test/settings/components/form/SearchEngineForm.test.jsx +++ /dev/null @@ -1,128 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestRenderer from 'react-test-renderer'; -import ReactTestUtils from 'react-dom/test-utils'; -import SearchForm from 'settings/components/form/SearchForm' - -describe("settings/form/SearchForm", () => { - describe('render', () => { - it('renders SearchForm', () => { - let root = ReactTestRenderer.create().root; - - let names = root.findAllByProps({ name: 'name' }); - expect(names).to.have.lengthOf(2); - expect(names[0].props.value).to.equal('google'); - expect(names[1].props.value).to.equal('yahoo'); - - let urls = root.findAllByProps({ name: 'url' }); - expect(urls).to.have.lengthOf(2); - expect(urls[0].props.value).to.equal('google.com'); - expect(urls[1].props.value).to.equal('yahoo.com'); - }); - - it('renders blank value', () => { - let root = ReactTestRenderer.create().root; - - let names = root.findAllByProps({ name: 'name' }); - expect(names).to.be.empty; - - let urls = root.findAllByProps({ name: 'url' }); - expect(urls).to.be.empty; - }); - - it('renders blank engines', () => { - let root = ReactTestRenderer.create( - , - ).root; - - let names = root.findAllByProps({ name: 'name' }); - expect(names).to.be.empty; - - let urls = root.findAllByProps({ name: 'url' }); - expect(urls).to.be.empty; - }); - }); - - describe('onChange event', () => { - let container; - - beforeEach(() => { - container = document.createElement('div'); - document.body.appendChild(container); - }); - - afterEach(() => { - document.body.removeChild(container); - container = null; - }); - - it('invokes onChange event on edit', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value.default).to.equal('louvre'); - expect(value.engines).to.have.lengthOf(2) - expect(value.engines).to.have.deep.members( - [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] - ); - done(); - }} />, container); - }); - - let radio = document.querySelectorAll('input[type=radio]'); - radio.checked = true; - - let name = document.querySelector('input[name=name]'); - name.value = 'louvre'; - - ReactTestUtils.Simulate.change(name); - }); - - it('invokes onChange event on delete', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value.default).to.equal('yahoo'); - expect(value.engines).to.have.lengthOf(1) - expect(value.engines).to.have.deep.members( - [['yahoo', 'yahoo.com']] - ); - done(); - }} />, container); - }); - - let button = document.querySelector('input[type=button]'); - ReactTestUtils.Simulate.click(button); - }); - - it('invokes onChange event on add', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(value.default).to.equal('yahoo'); - expect(value.engines).to.have.lengthOf(2) - expect(value.engines).to.have.deep.members( - [['google', 'google.com'], ['', '']], - ); - done(); - }} />, container); - }); - - let button = document.querySelector('input[type=button].ui-add-button'); - ReactTestUtils.Simulate.click(button); - }); - }); -}); diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx new file mode 100644 index 0000000..06822f2 --- /dev/null +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -0,0 +1,128 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestRenderer from 'react-test-renderer'; +import ReactTestUtils from 'react-dom/test-utils'; +import SearchForm from 'settings/components/form/SearchForm' + +describe("settings/form/SearchForm", () => { + describe('render', () => { + it('renders SearchForm', () => { + let root = ReactTestRenderer.create().root; + + let names = root.findAllByProps({ name: 'name' }); + expect(names).to.have.lengthOf(2); + expect(names[0].props.value).to.equal('google'); + expect(names[1].props.value).to.equal('yahoo'); + + let urls = root.findAllByProps({ name: 'url' }); + expect(urls).to.have.lengthOf(2); + expect(urls[0].props.value).to.equal('google.com'); + expect(urls[1].props.value).to.equal('yahoo.com'); + }); + + it('renders blank value', () => { + let root = ReactTestRenderer.create().root; + + let names = root.findAllByProps({ name: 'name' }); + expect(names).to.be.empty; + + let urls = root.findAllByProps({ name: 'url' }); + expect(urls).to.be.empty; + }); + + it('renders blank engines', () => { + let root = ReactTestRenderer.create( + , + ).root; + + let names = root.findAllByProps({ name: 'name' }); + expect(names).to.be.empty; + + let urls = root.findAllByProps({ name: 'url' }); + expect(urls).to.be.empty; + }); + }); + + describe('onChange event', () => { + let container; + + beforeEach(() => { + container = document.createElement('div'); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + container = null; + }); + + it('invokes onChange event on edit', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value.default).to.equal('louvre'); + expect(value.engines).to.have.lengthOf(2) + expect(value.engines).to.have.deep.members( + [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] + ); + done(); + }} />, container); + }); + + let radio = document.querySelectorAll('input[type=radio]'); + radio.checked = true; + + let name = document.querySelector('input[name=name]'); + name.value = 'louvre'; + + ReactTestUtils.Simulate.change(name); + }); + + it('invokes onChange event on delete', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value.default).to.equal('yahoo'); + expect(value.engines).to.have.lengthOf(1) + expect(value.engines).to.have.deep.members( + [['yahoo', 'yahoo.com']] + ); + done(); + }} />, container); + }); + + let button = document.querySelector('input[type=button]'); + ReactTestUtils.Simulate.click(button); + }); + + it('invokes onChange event on add', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(value.default).to.equal('yahoo'); + expect(value.engines).to.have.lengthOf(2) + expect(value.engines).to.have.deep.members( + [['google', 'google.com'], ['', '']], + ); + done(); + }} />, container); + }); + + let button = document.querySelector('input[type=button].ui-add-button'); + ReactTestUtils.Simulate.click(button); + }); + }); +}); diff --git a/test/settings/components/ui/input.test.jsx b/test/settings/components/ui/input.test.jsx deleted file mode 100644 index 432efcb..0000000 --- a/test/settings/components/ui/input.test.jsx +++ /dev/null @@ -1,111 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import ReactTestUtils from 'react-dom/test-utils'; -import Input from 'settings/components/ui/Input' - -describe("settings/ui/Input", () => { - let container; - - beforeEach(() => { - container = document.createElement('div'); - document.body.appendChild(container); - }); - - afterEach(() => { - document.body.removeChild(container); - container = null; - }); - - context("type=text", () => { - it('renders text input', () => { - ReactTestUtils.act(() => { - ReactDOM.render( - , - container); - }); - - let label = document.querySelector('label'); - let input = document.querySelector('input'); - expect(label.textContent).to.contain('myfield'); - expect(input.type).to.contain('text'); - expect(input.name).to.contain('myname'); - expect(input.value).to.contain('myvalue'); - }); - - it('invoke onChange', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(e.target.value).to.equal('newvalue'); - done(); - }}/>, container); - }); - - let input = document.querySelector('input'); - input.value = 'newvalue'; - ReactTestUtils.Simulate.change(input); - }); - }); - - context("type=radio", () => { - it('renders radio button', () => { - ReactTestUtils.act(() => { - ReactDOM.render( - , - container); - }); - - let label = document.querySelector('label'); - let input = document.querySelector('input'); - expect(label.textContent).to.contain('myfield'); - expect(input.type).to.contain('radio'); - expect(input.name).to.contain('myname'); - expect(input.value).to.contain('myvalue'); - }); - - it('invoke onChange', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(e.target.checked).to.be.true; - done(); - }}/>, - container); - }); - - let input = document.querySelector('input'); - input.checked = true; - ReactTestUtils.Simulate.change(input); - }); - }); - - context("type=textarea", () => { - it('renders textarea button', () => { - ReactTestUtils.act(() => { - ReactDOM.render( - , - container); - }); - - let label = document.querySelector('label'); - let textarea = document.querySelector('textarea'); - let error = document.querySelector('.settings-ui-input-error'); - expect(label.textContent).to.contain('myfield'); - expect(textarea.nodeName).to.contain('TEXTAREA'); - expect(textarea.name).to.contain('myname'); - expect(textarea.value).to.contain('myvalue'); - expect(error.textContent).to.contain('myerror'); - }); - - it('invoke onChange', (done) => { - ReactTestUtils.act(() => { - ReactDOM.render( { - expect(e.target.value).to.equal('newvalue'); - done(); - }}/>, container); - }); - - let input = document.querySelector('textarea'); - input.value = 'newvalue' - ReactTestUtils.Simulate.change(input); - }); - }); -}); diff --git a/test/settings/components/ui/input.test.tsx b/test/settings/components/ui/input.test.tsx new file mode 100644 index 0000000..432efcb --- /dev/null +++ b/test/settings/components/ui/input.test.tsx @@ -0,0 +1,111 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import ReactTestUtils from 'react-dom/test-utils'; +import Input from 'settings/components/ui/Input' + +describe("settings/ui/Input", () => { + let container; + + beforeEach(() => { + container = document.createElement('div'); + document.body.appendChild(container); + }); + + afterEach(() => { + document.body.removeChild(container); + container = null; + }); + + context("type=text", () => { + it('renders text input', () => { + ReactTestUtils.act(() => { + ReactDOM.render( + , + container); + }); + + let label = document.querySelector('label'); + let input = document.querySelector('input'); + expect(label.textContent).to.contain('myfield'); + expect(input.type).to.contain('text'); + expect(input.name).to.contain('myname'); + expect(input.value).to.contain('myvalue'); + }); + + it('invoke onChange', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(e.target.value).to.equal('newvalue'); + done(); + }}/>, container); + }); + + let input = document.querySelector('input'); + input.value = 'newvalue'; + ReactTestUtils.Simulate.change(input); + }); + }); + + context("type=radio", () => { + it('renders radio button', () => { + ReactTestUtils.act(() => { + ReactDOM.render( + , + container); + }); + + let label = document.querySelector('label'); + let input = document.querySelector('input'); + expect(label.textContent).to.contain('myfield'); + expect(input.type).to.contain('radio'); + expect(input.name).to.contain('myname'); + expect(input.value).to.contain('myvalue'); + }); + + it('invoke onChange', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(e.target.checked).to.be.true; + done(); + }}/>, + container); + }); + + let input = document.querySelector('input'); + input.checked = true; + ReactTestUtils.Simulate.change(input); + }); + }); + + context("type=textarea", () => { + it('renders textarea button', () => { + ReactTestUtils.act(() => { + ReactDOM.render( + , + container); + }); + + let label = document.querySelector('label'); + let textarea = document.querySelector('textarea'); + let error = document.querySelector('.settings-ui-input-error'); + expect(label.textContent).to.contain('myfield'); + expect(textarea.nodeName).to.contain('TEXTAREA'); + expect(textarea.name).to.contain('myname'); + expect(textarea.value).to.contain('myvalue'); + expect(error.textContent).to.contain('myerror'); + }); + + it('invoke onChange', (done) => { + ReactTestUtils.act(() => { + ReactDOM.render( { + expect(e.target.value).to.equal('newvalue'); + done(); + }}/>, container); + }); + + let input = document.querySelector('textarea'); + input.value = 'newvalue' + ReactTestUtils.Simulate.change(input); + }); + }); +}); diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.js deleted file mode 100644 index c1a1648..0000000 --- a/test/settings/reducers/setting.test.js +++ /dev/null @@ -1,55 +0,0 @@ -import actions from 'settings/actions'; -import settingReducer from 'settings/reducers/setting'; - -describe("settings setting reducer", () => { - it('return the initial state', () => { - let state = settingReducer(undefined, {}); - expect(state).to.have.deep.property('json', ''); - expect(state).to.have.deep.property('form', null); - expect(state).to.have.deep.property('error', ''); - }); - - it('return next state for SETTING_SET_SETTINGS', () => { - let action = { - type: actions.SETTING_SET_SETTINGS, - source: 'json', - json: '{ "key": "value" }', - form: {}, - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('source', 'json'); - expect(state).to.have.deep.property('json', '{ "key": "value" }'); - expect(state).to.have.deep.property('form', {}); - }); - - it('return next state for SETTING_SHOW_ERROR', () => { - let action = { - type: actions.SETTING_SHOW_ERROR, - error: 'bad value', - json: '{}', - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('error', 'bad value'); - expect(state).to.have.deep.property('json', '{}'); - }); - - it('return next state for SETTING_SWITCH_TO_FORM', () => { - let action = { - type: actions.SETTING_SWITCH_TO_FORM, - form: {}, - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('form', {}); - expect(state).to.have.deep.property('source', 'form'); - }); - - it('return next state for SETTING_SWITCH_TO_JSON', () => { - let action = { - type: actions.SETTING_SWITCH_TO_JSON, - json: '{}', - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('json', '{}'); - expect(state).to.have.deep.property('source', 'json'); - }); -}); diff --git a/test/settings/reducers/setting.test.ts b/test/settings/reducers/setting.test.ts new file mode 100644 index 0000000..c1a1648 --- /dev/null +++ b/test/settings/reducers/setting.test.ts @@ -0,0 +1,55 @@ +import actions from 'settings/actions'; +import settingReducer from 'settings/reducers/setting'; + +describe("settings setting reducer", () => { + it('return the initial state', () => { + let state = settingReducer(undefined, {}); + expect(state).to.have.deep.property('json', ''); + expect(state).to.have.deep.property('form', null); + expect(state).to.have.deep.property('error', ''); + }); + + it('return next state for SETTING_SET_SETTINGS', () => { + let action = { + type: actions.SETTING_SET_SETTINGS, + source: 'json', + json: '{ "key": "value" }', + form: {}, + }; + let state = settingReducer(undefined, action); + expect(state).to.have.deep.property('source', 'json'); + expect(state).to.have.deep.property('json', '{ "key": "value" }'); + expect(state).to.have.deep.property('form', {}); + }); + + it('return next state for SETTING_SHOW_ERROR', () => { + let action = { + type: actions.SETTING_SHOW_ERROR, + error: 'bad value', + json: '{}', + }; + let state = settingReducer(undefined, action); + expect(state).to.have.deep.property('error', 'bad value'); + expect(state).to.have.deep.property('json', '{}'); + }); + + it('return next state for SETTING_SWITCH_TO_FORM', () => { + let action = { + type: actions.SETTING_SWITCH_TO_FORM, + form: {}, + }; + let state = settingReducer(undefined, action); + expect(state).to.have.deep.property('form', {}); + expect(state).to.have.deep.property('source', 'form'); + }); + + it('return next state for SETTING_SWITCH_TO_JSON', () => { + let action = { + type: actions.SETTING_SWITCH_TO_JSON, + json: '{}', + }; + let state = settingReducer(undefined, action); + expect(state).to.have.deep.property('json', '{}'); + expect(state).to.have.deep.property('source', 'json'); + }); +}); 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