diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-01-11 13:02:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-11 13:02:14 +0000 |
commit | f5dfdb0bd7ab850c77cae523928c876fe5e002fa (patch) | |
tree | 083a7c9dcd4e85daef7f8323067454b48730c6e6 /test/shared/settings | |
parent | c3d1535224231cd379cf503a4c4937342ef27383 (diff) | |
parent | fad8f96a663d83792138cc986474ec4228b6c6c9 (diff) |
Merge pull request #303 from ueokande/properties
Properties support
Diffstat (limited to 'test/shared/settings')
-rw-r--r-- | test/shared/settings/validator.test.js | 82 | ||||
-rw-r--r-- | test/shared/settings/values.test.js | 29 |
2 files changed, 109 insertions, 2 deletions
diff --git a/test/shared/settings/validator.test.js b/test/shared/settings/validator.test.js new file mode 100644 index 0000000..61d976a --- /dev/null +++ b/test/shared/settings/validator.test.js @@ -0,0 +1,82 @@ +import { expect } from "chai"; +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 index 2632cd7..62cfb5f 100644 --- a/test/shared/settings/values.test.js +++ b/test/shared/settings/values.test.js @@ -7,13 +7,21 @@ describe("settings values", () => { let json = `{ "keymaps": { "0": {"type": "scroll.home"}}, "search": { "default": "google", "engines": { "google": "https://google.com/search?q={}" }}, - "blacklist": [ "*.slack.com"] + "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); }); }); @@ -29,6 +37,11 @@ describe("settings values", () => { engines: [['google', 'https://google.com/search?q={}']], }, blacklist: ['*.slack.com'], + "properties": { + "mystr": "value", + "mynum": 123, + "mybool": true, + } }; let value = values.valueFromForm(form); @@ -37,6 +50,9 @@ describe("settings values", () => { 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', () => { @@ -45,6 +61,7 @@ describe("settings values", () => { 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', () => { @@ -96,7 +113,12 @@ describe("settings values", () => { 0: { type: 'scroll.home' }, }, search: { default: 'google', engines: { google: 'https://google.com/search?q={}' }}, - blacklist: [ '*.slack.com'] + blacklist: [ '*.slack.com'], + properties: { + "mystr": "value", + "mynum": 123, + "mybool": true, + } }; let allowed = ['scroll.vertically?{"count":1}', 'scroll.home' ]; let form = values.formFromValue(value, allowed); @@ -109,6 +131,9 @@ describe("settings values", () => { 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); }); }); }); |