diff options
| author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-07 21:16:47 +0900 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-07 21:16:47 +0900 | 
| commit | 05ef6a8ca35aaa801c11eb6b4896caa3690058af (patch) | |
| tree | 2c7708ca91ac2b462cc86aa28612e3d3943496f3 /test | |
| parent | 457d954e08923b4accd28a919c72d0b61db1bb98 (diff) | |
| parent | 27d0a7f37d24a0ad68a8ccb7dee18fc1d00eea58 (diff) | |
Merge pull request #578 from ueokande/move-to-typescript
Move to TypeScript
Diffstat (limited to 'test')
| -rw-r--r-- | test/background/domains/GlobalMark.test.js | 11 | ||||
| -rw-r--r-- | test/background/infrastructures/MemoryStorage.test.ts (renamed from test/background/infrastructures/MemoryStorage.test.js) | 0 | ||||
| -rw-r--r-- | test/background/repositories/Mark.test.ts (renamed from test/background/repositories/Mark.test.js) | 3 | ||||
| -rw-r--r-- | test/background/repositories/Version.js | 34 | ||||
| -rw-r--r-- | test/background/usecases/filters.test.ts (renamed from test/background/usecases/filters.test.js) | 0 | ||||
| -rw-r--r-- | test/background/usecases/parsers.test.js | 47 | ||||
| -rw-r--r-- | test/background/usecases/parsers.test.ts | 34 | ||||
| -rw-r--r-- | test/console/actions/console.test.ts (renamed from test/console/actions/console.test.js) | 2 | ||||
| -rw-r--r-- | test/console/components/console/Completion.test.tsx (renamed from test/console/components/console/Completion.test.jsx) | 0 | ||||
| -rw-r--r-- | test/console/reducers/console.test.ts (renamed from test/console/reducers/console.test.js) | 2 | ||||
| -rw-r--r-- | test/content/actions/follow-controller.test.ts (renamed from test/content/actions/follow-controller.test.js) | 2 | ||||
| -rw-r--r-- | test/content/actions/input.test.ts (renamed from test/content/actions/input.test.js) | 2 | ||||
| -rw-r--r-- | test/content/actions/mark.test.ts (renamed from test/content/actions/mark.test.js) | 2 | ||||
| -rw-r--r-- | test/content/actions/setting.test.js | 35 | ||||
| -rw-r--r-- | test/content/actions/setting.test.ts | 43 | ||||
| -rw-r--r-- | test/content/components/common/follow.test.ts (renamed from test/content/components/common/follow.test.js) | 0 | ||||
| -rw-r--r-- | test/content/components/common/hint.test.ts (renamed from test/content/components/common/hint.test.js) | 0 | ||||
| -rw-r--r-- | test/content/components/common/input.test.ts (renamed from test/content/components/common/input.test.js) | 14 | ||||
| -rw-r--r-- | test/content/hint-key-producer.test.ts (renamed from test/content/hint-key-producer.test.js) | 0 | ||||
| -rw-r--r-- | test/content/navigates.test.ts (renamed from test/content/navigates.test.js) | 0 | ||||
| -rw-r--r-- | test/content/reducers/addon.test.ts (renamed from test/content/reducers/addon.test.js) | 2 | ||||
| -rw-r--r-- | test/content/reducers/find.test.ts (renamed from test/content/reducers/find.test.js) | 2 | ||||
| -rw-r--r-- | test/content/reducers/follow-controller.test.ts (renamed from test/content/reducers/follow-controller.test.js) | 2 | ||||
| -rw-r--r-- | test/content/reducers/input.test.ts (renamed from test/content/reducers/input.test.js) | 2 | ||||
| -rw-r--r-- | test/content/reducers/mark.test.ts (renamed from test/content/reducers/mark.test.js) | 2 | ||||
| -rw-r--r-- | test/content/reducers/setting.test.js | 17 | ||||
| -rw-r--r-- | test/content/reducers/setting.test.ts | 31 | ||||
| -rw-r--r-- | test/main.ts (renamed from test/main.js) | 0 | ||||
| -rw-r--r-- | test/settings/components/form/BlacklistForm.test.tsx (renamed from test/settings/components/form/BlacklistForm.test.jsx) | 0 | ||||
| -rw-r--r-- | test/settings/components/form/KeymapsForm.test.tsx (renamed from test/settings/components/form/KeymapsForm.test.jsx) | 14 | ||||
| -rw-r--r-- | test/settings/components/form/PropertiesForm.test.tsx (renamed from test/settings/components/form/PropertiesForm.test.jsx) | 0 | ||||
| -rw-r--r-- | test/settings/components/form/SearchEngineForm.test.tsx (renamed from test/settings/components/form/SearchEngineForm.test.jsx) | 60 | ||||
| -rw-r--r-- | test/settings/components/ui/input.test.tsx (renamed from test/settings/components/ui/input.test.jsx) | 0 | ||||
| -rw-r--r-- | test/settings/reducers/setting.test.ts (renamed from test/settings/reducers/setting.test.js) | 5 | ||||
| -rw-r--r-- | test/shared/SettingData.test.ts | 293 | ||||
| -rw-r--r-- | test/shared/Settings.test.ts | 190 | ||||
| -rw-r--r-- | test/shared/blacklists.test.ts (renamed from test/shared/blacklists.test.js) | 0 | ||||
| -rw-r--r-- | test/shared/operations.test.ts | 41 | ||||
| -rw-r--r-- | test/shared/properties.test.js | 18 | ||||
| -rw-r--r-- | test/shared/property-defs.test.js | 18 | ||||
| -rw-r--r-- | test/shared/settings/validator.test.js | 81 | ||||
| -rw-r--r-- | test/shared/settings/values.test.js | 138 | ||||
| -rw-r--r-- | test/shared/urls.test.ts (renamed from test/shared/urls.test.js) | 0 | ||||
| -rw-r--r-- | test/shared/utils/keys.test.ts (renamed from test/shared/utils/keys.test.js) | 0 | ||||
| -rw-r--r-- | test/shared/utils/re.test.ts (renamed from test/shared/utils/re.test.js) | 0 | 
45 files changed, 718 insertions, 429 deletions
| 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/infrastructures/MemoryStorage.test.js b/test/background/infrastructures/MemoryStorage.test.ts index 95d3780..95d3780 100644 --- a/test/background/infrastructures/MemoryStorage.test.js +++ b/test/background/infrastructures/MemoryStorage.test.ts diff --git a/test/background/repositories/Mark.test.js b/test/background/repositories/Mark.test.ts index 2a5b099..167e512 100644 --- a/test/background/repositories/Mark.test.js +++ b/test/background/repositories/Mark.test.ts @@ -9,12 +9,11 @@ describe('background/repositories/mark', () => {    });    it('get and set', async() => { -    let mark = new GlobalMark(1, 'http://example.com', 10, 30); +    let mark = { tabId: 1, url: 'http://example.com', x: 10, y: 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); 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/usecases/filters.test.js b/test/background/usecases/filters.test.ts index bdfb0be..bdfb0be 100644 --- a/test/background/usecases/filters.test.js +++ b/test/background/usecases/filters.test.ts 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..f3a64eb --- /dev/null +++ b/test/background/usecases/parsers.test.ts @@ -0,0 +1,34 @@ +import * as parsers from 'background/usecases/parsers'; + +describe("shared/commands/parsers", () => { +  describe("#parsers.parseSetOption", () => { +    it('parse set string', () => { +      let [key, value] = parsers.parseSetOption('hintchars=abcdefgh'); +      expect(key).to.equal('hintchars'); +      expect(value).to.equal('abcdefgh'); +    }); + +    it('parse set empty string', () => { +      let [key, value] = parsers.parseSetOption('hintchars='); +      expect(key).to.equal('hintchars'); +      expect(value).to.equal(''); +    }); + +    it('parse set boolean', () => { +      let [key, value] = parsers.parseSetOption('smoothscroll'); +      expect(key).to.equal('smoothscroll'); +      expect(value).to.be.true; + +      [key, value] = parsers.parseSetOption('nosmoothscroll'); +      expect(key).to.equal('smoothscroll'); +      expect(value).to.be.false; +    }); + +    it('throws error on unknown property', () => { +      expect(() => parsers.parseSetOption('encoding=utf-8')).to.throw(Error, 'Unknown'); +      expect(() => parsers.parseSetOption('paste')).to.throw(Error, 'Unknown'); +      expect(() => parsers.parseSetOption('nopaste')).to.throw(Error, 'Unknown'); +      expect(() => parsers.parseSetOption('smoothscroll=yes')).to.throw(Error, 'Invalid argument'); +    }); +  }); +}); diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.ts index 10cd9fe..e45d008 100644 --- a/test/console/actions/console.test.js +++ b/test/console/actions/console.test.ts @@ -1,4 +1,4 @@ -import actions from 'console/actions'; +import * as actions from 'console/actions';  import * as consoleActions from 'console/actions/console';  describe("console actions", () => { diff --git a/test/console/components/console/Completion.test.jsx b/test/console/components/console/Completion.test.tsx index 16bf11a..16bf11a 100644 --- a/test/console/components/console/Completion.test.jsx +++ b/test/console/components/console/Completion.test.tsx diff --git a/test/console/reducers/console.test.js b/test/console/reducers/console.test.ts index d5a38cf..47e7daf 100644 --- a/test/console/reducers/console.test.js +++ b/test/console/reducers/console.test.ts @@ -1,4 +1,4 @@ -import actions from 'console/actions'; +import * as actions from 'console/actions';  import reducer from 'console/reducers';  describe("console reducer", () => { diff --git a/test/content/actions/follow-controller.test.js b/test/content/actions/follow-controller.test.ts index 718a90a..a4b1710 100644 --- a/test/content/actions/follow-controller.test.js +++ b/test/content/actions/follow-controller.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import * as followControllerActions from 'content/actions/follow-controller';  describe('follow-controller actions', () => { diff --git a/test/content/actions/input.test.js b/test/content/actions/input.test.ts index fe9db5f..33238a5 100644 --- a/test/content/actions/input.test.js +++ b/test/content/actions/input.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import * as inputActions from 'content/actions/input';  describe("input actions", () => { diff --git a/test/content/actions/mark.test.js b/test/content/actions/mark.test.ts index adbf06b..6c6d59e 100644 --- a/test/content/actions/mark.test.js +++ b/test/content/actions/mark.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import * as markActions from 'content/actions/mark';  describe('mark actions', () => { 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<C-A>': '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..c831433 --- /dev/null +++ b/test/content/actions/setting.test.ts @@ -0,0 +1,43 @@ +import * as 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({ +        keymaps: { +          'dd': 'remove current tab', +          'z<C-A>': 'increment', +        }, +        search: { +          default: "google", +          engines: { +            google: 'https://google.com/search?q={}', +          } +        }, +        properties: { +          hintchars: 'abcd1234', +        }, +        blacklist: [], +      }); +      expect(action.type).to.equal(actions.SETTING_SET); +      expect(action.settings.properties.hintchars).to.equal('abcd1234'); +    }); + +    it('overrides cancel keys', () => { +      let action = settingActions.set({ +        keymaps: { +          "k": { "type": "scroll.vertically", "count": -1 }, +          "j": { "type": "scroll.vertically", "count": 1 }, +        } +      }); +      let keymaps = action.settings.keymaps; +      expect(action.settings.keymaps).to.deep.equals({ +        "k": { type: "scroll.vertically", count: -1 }, +        "j": { type: "scroll.vertically", count: 1 }, +        '<Esc>': { type: 'cancel' }, +        '<C-[>': { type: 'cancel' }, +      }); +    }); +  }); +}); diff --git a/test/content/components/common/follow.test.js b/test/content/components/common/follow.test.ts index 90d6cf5..90d6cf5 100644 --- a/test/content/components/common/follow.test.js +++ b/test/content/components/common/follow.test.ts diff --git a/test/content/components/common/hint.test.js b/test/content/components/common/hint.test.ts index 42d571f..42d571f 100644 --- a/test/content/components/common/hint.test.js +++ b/test/content/components/common/hint.test.ts diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.ts index 2ba5507..f3a943c 100644 --- a/test/content/components/common/input.test.js +++ b/test/content/components/common/input.test.ts @@ -21,12 +21,14 @@ describe('InputComponent', () => {          ++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' }); + +    let elem = document.body; +    component.onKeyDown({ key: 'a', target: elem }); +    component.onKeyDown({ key: 'b', target: elem }); +    component.onKeyPress({ key: 'a', target: elem }); +    component.onKeyUp({ key: 'a', target: elem }); +    component.onKeyPress({ key: 'b', target: elem }); +    component.onKeyUp({ key: 'b', target: elem });      expect(a).is.equals(1);      expect(b).is.equals(1); diff --git a/test/content/hint-key-producer.test.js b/test/content/hint-key-producer.test.ts index dcf477d..dcf477d 100644 --- a/test/content/hint-key-producer.test.js +++ b/test/content/hint-key-producer.test.ts diff --git a/test/content/navigates.test.js b/test/content/navigates.test.ts index 1d73344..1d73344 100644 --- a/test/content/navigates.test.js +++ b/test/content/navigates.test.ts diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.ts index d4eb845..fb05244 100644 --- a/test/content/reducers/addon.test.js +++ b/test/content/reducers/addon.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import addonReducer from 'content/reducers/addon';  describe("addon reducer", () => { diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.ts index a8c30d7..66a2c67 100644 --- a/test/content/reducers/find.test.js +++ b/test/content/reducers/find.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import findReducer from 'content/reducers/find';  describe("find reducer", () => { diff --git a/test/content/reducers/follow-controller.test.js b/test/content/reducers/follow-controller.test.ts index 8a4c2d4..39f326c 100644 --- a/test/content/reducers/follow-controller.test.js +++ b/test/content/reducers/follow-controller.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import followControllerReducer from 'content/reducers/follow-controller';  describe('follow-controller reducer', () => { diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.ts index 0011943..f892201 100644 --- a/test/content/reducers/input.test.js +++ b/test/content/reducers/input.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import inputReducer from 'content/reducers/input';  describe("input reducer", () => { diff --git a/test/content/reducers/mark.test.js b/test/content/reducers/mark.test.ts index 76efbf7..1a51c3e 100644 --- a/test/content/reducers/mark.test.js +++ b/test/content/reducers/mark.test.ts @@ -1,4 +1,4 @@ -import actions from 'content/actions'; +import * as actions from 'content/actions';  import reducer from 'content/reducers/mark';  describe("mark reducer", () => { 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..9b332aa --- /dev/null +++ b/test/content/reducers/setting.test.ts @@ -0,0 +1,31 @@ +import * as 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, +      settings: { +        keymaps: { +          "zz": { type: "zoom.neutral" }, +          "<S-Esc>": { "type": "addon.toggle.enabled" } +        }, +        "blacklist": [] +      } +    } +    let state = settingReducer(undefined, action); +    expect(state.keymaps).to.have.deep.all.members([ +      { key: [{ key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, +              { key: 'z', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], +        op: { type: 'zoom.neutral' }}, +      { key: [{ key: 'Esc', shiftKey: true, ctrlKey: false, altKey: false, metaKey: false }], +        op: { type: 'addon.toggle.enabled' }}, +    ]); +  }); +}); diff --git a/test/main.js b/test/main.ts index 3aeae69..3aeae69 100644 --- a/test/main.js +++ b/test/main.ts diff --git a/test/settings/components/form/BlacklistForm.test.jsx b/test/settings/components/form/BlacklistForm.test.tsx index 2be5d96..2be5d96 100644 --- a/test/settings/components/form/BlacklistForm.test.jsx +++ b/test/settings/components/form/BlacklistForm.test.tsx diff --git a/test/settings/components/form/KeymapsForm.test.jsx b/test/settings/components/form/KeymapsForm.test.tsx index 6ac57c9..dc2322b 100644 --- a/test/settings/components/form/KeymapsForm.test.jsx +++ b/test/settings/components/form/KeymapsForm.test.tsx @@ -2,15 +2,17 @@ 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' +import KeymapsForm from '../../../../src/settings/components/form/KeymapsForm' +import { FormKeymaps } from 'shared/SettingData'; +import { expect } from 'chai';  describe("settings/form/KeymapsForm", () => {    describe('render', () => {      it('renders keymap fields', () => { -      let root = ReactTestRenderer.create(<KeymapsForm value={{ +      let root = ReactTestRenderer.create(<KeymapsForm value={FormKeymaps.valueOf({          'scroll.vertically?{"count":1}': 'j',          'scroll.vertically?{"count":-1}': 'k', -      }} />).root +      })} />).root        let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' });        let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); @@ -46,12 +48,12 @@ describe("settings/form/KeymapsForm", () => {      it('invokes onChange event on edit', (done) => {        ReactTestUtils.act(() => {          ReactDOM.render(<KeymapsForm -          value={{ +          value={FormKeymaps.valueOf({              'scroll.vertically?{"count":1}': 'j',              'scroll.vertically?{"count":-1}': 'k', -          }} +          })}            onChange={value => { -            expect(value['scroll.vertically?{"count":1}']).to.equal('jjj'); +            expect(value.toJSON()['scroll.vertically?{"count":1}']).to.equal('jjj');              done();            }} />, container);        }); diff --git a/test/settings/components/form/PropertiesForm.test.jsx b/test/settings/components/form/PropertiesForm.test.tsx index 80f60d2..80f60d2 100644 --- a/test/settings/components/form/PropertiesForm.test.jsx +++ b/test/settings/components/form/PropertiesForm.test.tsx diff --git a/test/settings/components/form/SearchEngineForm.test.jsx b/test/settings/components/form/SearchEngineForm.test.tsx index 06822f2..0e6b17d 100644 --- a/test/settings/components/form/SearchEngineForm.test.jsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -3,14 +3,15 @@ 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' +import { FormSearch } from 'shared/SettingData';  describe("settings/form/SearchForm", () => {    describe('render', () => {      it('renders SearchForm', () => { -      let root = ReactTestRenderer.create(<SearchForm value={{ +      let root = ReactTestRenderer.create(<SearchForm value={FormSearch.valueOf({          default: 'google',          engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']], -      }} />).root; +      })} />).root;        let names = root.findAllByProps({ name: 'name' });        expect(names).to.have.lengthOf(2); @@ -22,28 +23,6 @@ describe("settings/form/SearchForm", () => {        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(<SearchForm />).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( -        <SearchForm value={{ default: 'google' }} />, -      ).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', () => { @@ -62,14 +41,15 @@ describe("settings/form/SearchForm", () => {      it('invokes onChange event on edit', (done) => {        ReactTestUtils.act(() => {          ReactDOM.render(<SearchForm -          value={{ +          value={FormSearch.valueOf({              default: 'google',                engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']] -          }} +          })}            onChange={value => { -            expect(value.default).to.equal('louvre'); -            expect(value.engines).to.have.lengthOf(2) -            expect(value.engines).to.have.deep.members( +            let json = value.toJSON(); +            expect(json.default).to.equal('louvre'); +            expect(json.engines).to.have.lengthOf(2) +            expect(json.engines).to.have.deep.members(                [['louvre', 'google.com'], ['yahoo', 'yahoo.com']]              );              done(); @@ -87,14 +67,15 @@ describe("settings/form/SearchForm", () => {      it('invokes onChange event on delete', (done) => {        ReactTestUtils.act(() => { -        ReactDOM.render(<SearchForm value={{ +        ReactDOM.render(<SearchForm value={FormSearch.valueOf({              default: 'yahoo',              engines: [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] -          }} +          })}            onChange={value => { -            expect(value.default).to.equal('yahoo'); -            expect(value.engines).to.have.lengthOf(1) -            expect(value.engines).to.have.deep.members( +            let json = value.toJSON(); +            expect(json.default).to.equal('yahoo'); +            expect(json.engines).to.have.lengthOf(1) +            expect(json.engines).to.have.deep.members(                [['yahoo', 'yahoo.com']]              );              done(); @@ -107,14 +88,15 @@ describe("settings/form/SearchForm", () => {      it('invokes onChange event on add', (done) => {        ReactTestUtils.act(() => { -        ReactDOM.render(<SearchForm value={{ +        ReactDOM.render(<SearchForm value={FormSearch.valueOf({            default: 'yahoo',              engines: [['google', 'google.com']] -          }} +          })}            onChange={value => { -            expect(value.default).to.equal('yahoo'); -            expect(value.engines).to.have.lengthOf(2) -            expect(value.engines).to.have.deep.members( +            let json = value.toJSON(); +            expect(json.default).to.equal('yahoo'); +            expect(json.engines).to.have.lengthOf(2) +            expect(json.engines).to.have.deep.members(                [['google', 'google.com'], ['', '']],              );              done(); diff --git a/test/settings/components/ui/input.test.jsx b/test/settings/components/ui/input.test.tsx index 432efcb..432efcb 100644 --- a/test/settings/components/ui/input.test.jsx +++ b/test/settings/components/ui/input.test.tsx diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.ts index c1a1648..376d66e 100644 --- a/test/settings/reducers/setting.test.js +++ b/test/settings/reducers/setting.test.ts @@ -1,11 +1,10 @@ -import actions from 'settings/actions'; +import * as 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('source', 'json');      expect(state).to.have.deep.property('error', '');    }); diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts new file mode 100644 index 0000000..8736ecb --- /dev/null +++ b/test/shared/SettingData.test.ts @@ -0,0 +1,293 @@ +import SettingData, { +  FormKeymaps, JSONSettings, FormSettings, +} from '../../src/shared/SettingData'; +import Settings, { Keymaps } from '../../src/shared/Settings'; +import { expect } from 'chai'; + +describe('shared/SettingData', () => { +  describe('FormKeymaps', () => { +    describe('#valueOF to #toKeymaps', () => { +      it('parses form keymaps and convert to operations', () => { +        let data = { +          'scroll.vertically?{"count":1}': 'j', +          'scroll.home': '0', +        } + +        let keymaps = FormKeymaps.valueOf(data).toKeymaps(); +        expect(keymaps).to.deep.equal({ +          'j': { type: 'scroll.vertically', count: 1 }, +          '0': { type: 'scroll.home' }, +        }); +      }); +    }); + +    describe('#fromKeymaps to #toJSON', () => { +      it('create from a Keymaps and create a JSON object', () => { +        let data: Keymaps = { +          'j': { type: 'scroll.vertically', count: 1 }, +          '0': { type: 'scroll.home' }, +        } + +        let keymaps = FormKeymaps.fromKeymaps(data).toJSON(); +        expect(keymaps).to.deep.equal({ +          'scroll.vertically?{"count":1}': 'j', +          'scroll.home': '0', +        }); +      }); +    }); +  }); + +  describe('JSONSettings', () => { +    describe('#valueOf to #toSettings', () => { +      it('parse object and create a Settings', () => { +        let o = `{ +          "keymaps": {}, +          "search": { +            "default": "google", +            "engines": { +              "google": "https://google.com/search?q={}" +            } +          }, +          "properties": { +            "hintchars": "abcdefghijklmnopqrstuvwxyz", +            "smoothscroll": false, +            "complete": "sbh" +          }, +          "blacklist": [] +        }`; + +        let settings = JSONSettings.valueOf(o).toSettings(); +        expect(settings).to.deep.equal(JSON.parse(o)); +      }); +    }); + +    describe('#fromSettings to #toJSON', () => { +      it('create from a Settings and create a JSON string', () => { +        let o = { +          keymaps: {}, +          search: { +            default: "google", +            engines: { +              google: "https://google.com/search?q={}", +            }, +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [], +        }; + +        let json = JSONSettings.fromSettings(o).toJSON(); +        expect(JSON.parse(json)).to.deep.equal(o); +      }); +    }); +  }); + +  describe('FormSettings', () => { +    describe('#valueOf to #toSettings', () => { +      it('parse object and create a Settings', () => { +        let data = { +          keymaps: { +            'scroll.vertically?{"count":1}': 'j', +            'scroll.home': '0', +          }, +          search: { +            default: "google", +            engines: [ +              ["google", "https://google.com/search?q={}"], +            ] +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [] +        }; + +        let settings = FormSettings.valueOf(data).toSettings(); +        expect(settings).to.deep.equal({ +          keymaps: { +            'j': { type: 'scroll.vertically', count: 1 }, +            '0': { type: 'scroll.home' }, +          }, +          search: { +            default: "google", +            engines: { +              "google": "https://google.com/search?q={}" +            } +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [] +        }); +      }); +    }); + +    describe('#fromSettings to #toJSON', () => { +      it('create from a Settings and create a JSON string', () => { +        let data: Settings = { +          keymaps: { +            'j': { type: 'scroll.vertically', count: 1 }, +            '0': { type: 'scroll.home' }, +          }, +          search: { +            default: "google", +            engines: { +              "google": "https://google.com/search?q={}" +            } +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [] +        }; + +        let json = FormSettings.fromSettings(data).toJSON(); +        expect(json).to.deep.equal({ +          keymaps: { +            'scroll.vertically?{"count":1}': 'j', +            'scroll.home': '0', +          }, +          search: { +            default: "google", +            engines: [ +              ["google", "https://google.com/search?q={}"], +            ] +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [], +        }); +      }); +    }); +  }); + +  describe('SettingData', () => { +    describe('#valueOf to #toJSON', () => { +      it('parse object from json source', () => { +        let data = { +          source: 'json', +          json: `{ +            "keymaps": {}, +            "search": { +              "default": "google", +              "engines": { +                "google": "https://google.com/search?q={}" +              } +            }, +            "properties": { +              "hintchars": "abcdefghijklmnopqrstuvwxyz", +              "smoothscroll": false, +              "complete": "sbh" +            }, +            "blacklist": [] +          }`, +        }; + +        let j = SettingData.valueOf(data).toJSON(); +        expect(j.source).to.equal('json'); +        expect(j.json).to.be.a('string'); +      }); + +      it('parse object from form source', () => { +        let data = { +          source: 'form', +          form: { +            keymaps: {}, +            search: { +              default: "yahoo", +              engines: [ +                ['yahoo', 'https://yahoo.com/search?q={}'], +              ], +            }, +            properties: { +              hintchars: "abcdefghijklmnopqrstuvwxyz", +              smoothscroll: false, +              complete: "sbh" +            }, +            blacklist: [], +          }, +        }; + +        let j = SettingData.valueOf(data).toJSON(); +        expect(j.source).to.equal('form'); +        expect(j.form).to.deep.equal({ +          keymaps: {}, +          search: { +            default: "yahoo", +            engines: [ +              ['yahoo', 'https://yahoo.com/search?q={}'], +            ], +          }, +          properties: { +            hintchars: "abcdefghijklmnopqrstuvwxyz", +            smoothscroll: false, +            complete: "sbh" +          }, +          blacklist: [], +        }); +      }); +    }); + +    describe('#toSettings', () => { +      it('parse object from json source', () => { +        let data = { +          source: 'json', +          json: `{ +            "keymaps": {}, +            "search": { +              "default": "google", +              "engines": { +                "google": "https://google.com/search?q={}" +              } +            }, +            "properties": { +              "hintchars": "abcdefghijklmnopqrstuvwxyz", +              "smoothscroll": false, +              "complete": "sbh" +            }, +            "blacklist": [] +          }`, +        }; + +        let settings = SettingData.valueOf(data).toSettings(); +        expect(settings.search.default).to.equal('google'); +      }); + +      it('parse object from form source', () => { +        let data = { +          source: 'form', +          form: { +            keymaps: {}, +            search: { +              default: "yahoo", +              engines: [ +                ['yahoo', 'https://yahoo.com/search?q={}'], +              ], +            }, +            properties: { +              hintchars: "abcdefghijklmnopqrstuvwxyz", +              smoothscroll: false, +              complete: "sbh" +            }, +            blacklist: [], +          }, +        }; + +        let settings = SettingData.valueOf(data).toSettings(); +        expect(settings.search.default).to.equal('yahoo'); +      }); +    }); +  }); +}); diff --git a/test/shared/Settings.test.ts b/test/shared/Settings.test.ts new file mode 100644 index 0000000..02cd022 --- /dev/null +++ b/test/shared/Settings.test.ts @@ -0,0 +1,190 @@ +import * as settings from '../../src/shared/Settings'; +import { expect } from 'chai'; + +describe('Settings', () => { +  describe('#keymapsValueOf', () => { +    it('returns empty object by empty settings', () => { +      let keymaps = settings.keymapsValueOf({}); +      expect(keymaps).to.be.empty; +    }); + +    it('returns keymaps by valid settings', () => { +      let keymaps = settings.keymapsValueOf({ +        k: { type: "scroll.vertically", count: -1 }, +        j: { type: "scroll.vertically", count: 1 }, +      }); + +      expect(keymaps['k']).to.deep.equal({ type: "scroll.vertically", count: -1 }); +      expect(keymaps['j']).to.deep.equal({ type: "scroll.vertically", count: 1 }); +    }); + +    it('throws a TypeError by invalid settings', () => { +      expect(() => settings.keymapsValueOf(null)).to.throw(TypeError); +      expect(() => settings.keymapsValueOf({ +        k: { type: "invalid.operation" }, +      })).to.throw(TypeError); +    }); +  }); + +  describe('#searchValueOf', () => { +    it('returns search settings by valid settings', () => { +      let search = settings.searchValueOf({ +        default: "google", +        engines: { +          "google": "https://google.com/search?q={}", +          "yahoo": "https://search.yahoo.com/search?p={}", +        } +      }); + +      expect(search).to.deep.equal({ +        default: "google", +        engines: { +          "google": "https://google.com/search?q={}", +          "yahoo": "https://search.yahoo.com/search?p={}", +        } +      }); +    }); + +    it('throws a TypeError by invalid settings', () => { +      expect(() => settings.searchValueOf(null)).to.throw(TypeError); +      expect(() => settings.searchValueOf({})).to.throw(TypeError); +      expect(() => settings.searchValueOf([])).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: 123, +        engines: {} +      })).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: "google", +        engines: { +          "google": 123456, +        } +      })).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: "wikipedia", +        engines: { +          "google": "https://google.com/search?q={}", +          "yahoo": "https://search.yahoo.com/search?p={}", +        } +      })).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: "g o o g l e", +        engines: { +          "g o o g l e": "https://google.com/search?q={}", +        } +      })).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: "google", +        engines: { +          "google": "https://google.com/search", +        } +      })).to.throw(TypeError); +      expect(() => settings.searchValueOf({ +        default: "google", +        engines: { +          "google": "https://google.com/search?q={}&r={}", +        } +      })).to.throw(TypeError); +    }); +  }); + +  describe('#propertiesValueOf', () => { +    it('returns with default properties by empty settings', () => { +      let props = settings.propertiesValueOf({}); +      expect(props).to.deep.equal({ +        hintchars: "abcdefghijklmnopqrstuvwxyz", +        smoothscroll: false, +        complete: "sbh" +      }) +    }); + +    it('returns properties by valid settings', () => { +      let props = settings.propertiesValueOf({ +        hintchars: "abcdefgh", +        smoothscroll: false, +        complete: "sbh" +      }); + +      expect(props).to.deep.equal({ +        hintchars: "abcdefgh", +        smoothscroll: false, +        complete: "sbh" +      }); +    }); + +    it('throws a TypeError by invalid settings', () => { +      expect(() => settings.keymapsValueOf(null)).to.throw(TypeError); +      expect(() => settings.keymapsValueOf({ +        smoothscroll: 'false', +      })).to.throw(TypeError); +      expect(() => settings.keymapsValueOf({ +        unknown: 'xyz' +      })).to.throw(TypeError); +    }); +  }); + +  describe('#blacklistValueOf', () => { +    it('returns empty array by empty settings', () => { +      let blacklist = settings.blacklistValueOf([]); +      expect(blacklist).to.be.empty; +    }); + +    it('returns blacklist by valid settings', () => { +      let blacklist = settings.blacklistValueOf([ +        "github.com", +        "circleci.com", +      ]); + +      expect(blacklist).to.deep.equal([ +        "github.com", +        "circleci.com", +      ]); +    }); + +    it('throws a TypeError by invalid settings', () => { +      expect(() => settings.blacklistValueOf(null)).to.throw(TypeError); +      expect(() => settings.blacklistValueOf({})).to.throw(TypeError); +      expect(() => settings.blacklistValueOf([1,2,3])).to.throw(TypeError); +    }); +  }); + +  describe('#valueOf', () => { +    it('returns settings by valid settings', () => { +      let x = settings.valueOf({ +        keymaps: {}, +        "search": { +          "default": "google", +          "engines": { +            "google": "https://google.com/search?q={}", +          } +        }, +        "properties": {}, +        "blacklist": [] +      }); + +      expect(x).to.deep.equal({ +        keymaps: {}, +        search: { +          default: "google", +          engines: { +            google: "https://google.com/search?q={}", +          } +        }, +        properties: { +          hintchars: "abcdefghijklmnopqrstuvwxyz", +          smoothscroll: false, +          complete: "sbh" +        }, +        blacklist: [] +      }); +    }); + +    it('sets default settings', () => { +      let value = settings.valueOf({}); +      expect(value.keymaps).to.not.be.empty; +      expect(value.properties).to.not.be.empty; +      expect(value.search.default).to.be.a('string'); +      expect(value.search.engines).to.be.an('object'); +      expect(value.blacklist).to.be.empty; +    }); +  }); +}); diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.ts index 289ea0f..289ea0f 100644 --- a/test/shared/blacklists.test.js +++ b/test/shared/blacklists.test.ts diff --git a/test/shared/operations.test.ts b/test/shared/operations.test.ts new file mode 100644 index 0000000..42a3eed --- /dev/null +++ b/test/shared/operations.test.ts @@ -0,0 +1,41 @@ +import * as operations from 'shared/operations'; + +describe('operations', () => { +  describe('#valueOf', () => { +    it('returns an Operation', () => { +      let op: operations.Operation = operations.valueOf({ +        type: operations.SCROLL_VERTICALLY, +        count: 10, +      }); +      expect(op.type).to.equal(operations.SCROLL_VERTICALLY); +      expect(op.count).to.equal(10); +    }); + +    it('throws an Error on missing required parameter', () => { +      expect(() => operations.valueOf({ +        type: operations.SCROLL_VERTICALLY, +      })).to.throw(TypeError); +    }); + +    it('fills default valus of optional parameter', () => { +      let op: operations.Operation = operations.valueOf({ +        type: operations.COMMAND_SHOW_OPEN, +      }); + +      expect(op.type).to.equal(operations.COMMAND_SHOW_OPEN) +      expect(op.alter).to.be.false; +    }); + +    it('throws an Error on mismatch of parameter', () => { +      expect(() => operations.valueOf({ +        type: operations.SCROLL_VERTICALLY, +        count: '10', +      })).to.throw(TypeError); + +      expect(() => valueOf({ +        type: operations.COMMAND_SHOW_OPEN, +        alter: 'true', +      })).to.throw(TypeError); +    }); +  }); +}) diff --git a/test/shared/properties.test.js b/test/shared/properties.test.js new file mode 100644 index 0000000..37903d8 --- /dev/null +++ b/test/shared/properties.test.js @@ -0,0 +1,18 @@ +import * as settings from 'shared/settings'; + +describe('properties', () => { +  describe('Def class', () => { +    it('returns property definitions', () => { +      let def = new proerties.Def( +        'smoothscroll', +        'smooth scroll', +        false); + +      expect(def.name).to.equal('smoothscroll'); +      expect(def.describe).to.equal('smooth scroll'); +      expect(def.defaultValue).to.equal(false); +      expect(def.type).to.equal('boolean'); +    }); +  }); +}); + diff --git a/test/shared/property-defs.test.js b/test/shared/property-defs.test.js new file mode 100644 index 0000000..37903d8 --- /dev/null +++ b/test/shared/property-defs.test.js @@ -0,0 +1,18 @@ +import * as settings from 'shared/settings'; + +describe('properties', () => { +  describe('Def class', () => { +    it('returns property definitions', () => { +      let def = new proerties.Def( +        'smoothscroll', +        'smooth scroll', +        false); + +      expect(def.name).to.equal('smoothscroll'); +      expect(def.describe).to.equal('smooth scroll'); +      expect(def.defaultValue).to.equal(false); +      expect(def.type).to.equal('boolean'); +    }); +  }); +}); + 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/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/urls.test.js b/test/shared/urls.test.ts index f2950b6..f2950b6 100644 --- a/test/shared/urls.test.js +++ b/test/shared/urls.test.ts diff --git a/test/shared/utils/keys.test.js b/test/shared/utils/keys.test.ts index b2ad3cb..b2ad3cb 100644 --- a/test/shared/utils/keys.test.js +++ b/test/shared/utils/keys.test.ts diff --git a/test/shared/utils/re.test.js b/test/shared/utils/re.test.ts index d12ceb7..d12ceb7 100644 --- a/test/shared/utils/re.test.js +++ b/test/shared/utils/re.test.ts | 
