aboutsummaryrefslogtreecommitdiff
path: root/test/shared/settings
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-25 22:14:28 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-11-26 11:45:05 +0900
commitd15de42a75ee0f722e8779af1ecff8b51e59c56d (patch)
treee5df392c8a1f1bf0007ab2095e8b8c2ca779f097 /test/shared/settings
parentf27d21908a2b402e3274288d4411a48160f38e4c (diff)
settings helpers
Diffstat (limited to 'test/shared/settings')
-rw-r--r--test/shared/settings/values.test.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/test/shared/settings/values.test.js b/test/shared/settings/values.test.js
new file mode 100644
index 0000000..2c222b6
--- /dev/null
+++ b/test/shared/settings/values.test.js
@@ -0,0 +1,112 @@
+import { expect } from 'chai';
+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"]
+ }`;
+ 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"]);
+ });
+ });
+
+ 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'],
+ };
+ 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"]);
+ });
+
+ 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');
+ });
+
+ 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']
+ };
+ let form = values.formFromValue(value);
+
+ expect(form.keymaps).to.have.property('scroll.vertically?{"count":1}', 'j');
+ 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');
+ });
+ });
+});