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/shared/SettingData.test.ts | |
parent | 457d954e08923b4accd28a919c72d0b61db1bb98 (diff) | |
parent | 27d0a7f37d24a0ad68a8ccb7dee18fc1d00eea58 (diff) |
Merge pull request #578 from ueokande/move-to-typescript
Move to TypeScript
Diffstat (limited to 'test/shared/SettingData.test.ts')
-rw-r--r-- | test/shared/SettingData.test.ts | 293 |
1 files changed, 293 insertions, 0 deletions
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'); + }); + }); + }); +}); |