aboutsummaryrefslogtreecommitdiff
path: root/test/shared
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-05 01:08:07 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:58:59 +0000
commit2116ac90a6dfdb0910d7ad2896f70a052aa635cc (patch)
treee3ed16ac3fb126e06e97b18a742e074fbeed079a /test/shared
parent410ffbb0376b9399928ef8d4dd13079bfb120e14 (diff)
Make Search class
Diffstat (limited to 'test/shared')
-rw-r--r--test/shared/SettingData.test.ts19
-rw-r--r--test/shared/Settings.test.ts66
-rw-r--r--test/shared/settings/Search.test.ts68
-rw-r--r--test/shared/urls.test.ts8
4 files changed, 86 insertions, 75 deletions
diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts
index 9567f76..f8995d9 100644
--- a/test/shared/SettingData.test.ts
+++ b/test/shared/SettingData.test.ts
@@ -4,6 +4,7 @@ import SettingData, {
import Settings from '../../src/shared/Settings';
import { expect } from 'chai';
import Keymaps from '../../src/shared/settings/Keymaps';
+import Search from '../../src/shared/settings/Search';
describe('shared/SettingData', () => {
describe('FormKeymaps', () => {
@@ -60,7 +61,7 @@ describe('shared/SettingData', () => {
let settings = JSONTextSettings.fromText(o).toSettings();
expect({
keymaps: settings.keymaps.toJSON(),
- search: settings.search,
+ search: settings.search.toJSON(),
properties: settings.properties,
blacklist: settings.blacklist,
}).to.deep.equal(JSON.parse(o));
@@ -71,12 +72,12 @@ describe('shared/SettingData', () => {
it('create from a Settings and create a JSON string', () => {
let o = {
keymaps: Keymaps.fromJSON({}),
- search: {
+ search: Search.fromJSON({
default: "google",
engines: {
google: "https://google.com/search?q={}",
},
- },
+ }),
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
@@ -88,7 +89,7 @@ describe('shared/SettingData', () => {
let json = JSONTextSettings.fromSettings(o).toJSONText();
expect(JSON.parse(json)).to.deep.equal({
keymaps: o.keymaps.toJSON(),
- search: o.search,
+ search: o.search.toJSON(),
properties: o.properties,
blacklist: o.blacklist,
});
@@ -121,7 +122,7 @@ describe('shared/SettingData', () => {
let settings = FormSettings.valueOf(data).toSettings();
expect({
keymaps: settings.keymaps.toJSON(),
- search: settings.search,
+ search: settings.search.toJSON(),
properties: settings.properties,
blacklist: settings.blacklist,
}).to.deep.equal({
@@ -152,12 +153,12 @@ describe('shared/SettingData', () => {
'j': { type: 'scroll.vertically', count: 1 },
'0': { type: 'scroll.home' },
}),
- search: {
+ search: Search.fromJSON({
default: "google",
engines: {
"google": "https://google.com/search?q={}"
}
- },
+ }),
properties: {
hintchars: "abcdefghijklmnopqrstuvwxyz",
smoothscroll: false,
@@ -278,7 +279,7 @@ describe('shared/SettingData', () => {
};
let settings = SettingData.valueOf(data).toSettings();
- expect(settings.search.default).to.equal('google');
+ expect(settings.search.defaultEngine).to.equal('google');
});
it('parse object from form source', () => {
@@ -302,7 +303,7 @@ describe('shared/SettingData', () => {
};
let settings = SettingData.valueOf(data).toSettings();
- expect(settings.search.default).to.equal('yahoo');
+ expect(settings.search.defaultEngine).to.equal('yahoo');
});
});
});
diff --git a/test/shared/Settings.test.ts b/test/shared/Settings.test.ts
index 9faf9d1..ed791a1 100644
--- a/test/shared/Settings.test.ts
+++ b/test/shared/Settings.test.ts
@@ -1,67 +1,7 @@
import * as settings from '../../src/shared/Settings';
-import {expect} from 'chai';
+import { expect } from 'chai';
describe('Settings', () => {
- 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', () => {
@@ -129,7 +69,7 @@ describe('Settings', () => {
expect({
keymaps: x.keymaps.toJSON(),
- search: x.search,
+ search: x.search.toJSON(),
properties: x.properties,
blacklist: x.blacklist,
}).to.deep.equal({
@@ -153,7 +93,7 @@ describe('Settings', () => {
let value = settings.valueOf({});
expect(value.keymaps.toJSON()).to.not.be.empty;
expect(value.properties).to.not.be.empty;
- expect(value.search.default).to.be.a('string');
+ expect(value.search.defaultEngine).to.be.a('string');
expect(value.search.engines).to.be.an('object');
expect(value.blacklist).to.be.empty;
});
diff --git a/test/shared/settings/Search.test.ts b/test/shared/settings/Search.test.ts
new file mode 100644
index 0000000..7c9134d
--- /dev/null
+++ b/test/shared/settings/Search.test.ts
@@ -0,0 +1,68 @@
+import Search from '../../../src/shared/settings/Search';
+import { expect } from 'chai';
+
+describe('Search', () => {
+ it('returns search settings by valid settings', () => {
+ let search = Search.fromJSON({
+ default: 'google',
+ engines: {
+ 'google': 'https://google.com/search?q={}',
+ 'yahoo': 'https://search.yahoo.com/search?p={}',
+ }
+ });
+
+ expect(search.defaultEngine).to.equal('google')
+ expect(search.engines).to.deep.equals({
+ 'google': 'https://google.com/search?q={}',
+ 'yahoo': 'https://search.yahoo.com/search?p={}',
+ });
+ expect(search.toJSON()).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(() => Search.fromJSON(null)).to.throw(TypeError);
+ expect(() => Search.fromJSON({})).to.throw(TypeError);
+ expect(() => Search.fromJSON([])).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 123,
+ engines: {}
+ })).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 'google',
+ engines: {
+ 'google': 123456,
+ }
+ })).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 'wikipedia',
+ engines: {
+ 'google': 'https://google.com/search?q={}',
+ 'yahoo': 'https://search.yahoo.com/search?p={}',
+ }
+ })).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 'g o o g l e',
+ engines: {
+ 'g o o g l e': 'https://google.com/search?q={}',
+ }
+ })).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 'google',
+ engines: {
+ 'google': 'https://google.com/search',
+ }
+ })).to.throw(TypeError);
+ expect(() => Search.fromJSON({
+ default: 'google',
+ engines: {
+ 'google': 'https://google.com/search?q={}&r={}',
+ }
+ })).to.throw(TypeError);
+ });
+});
diff --git a/test/shared/urls.test.ts b/test/shared/urls.test.ts
index f2950b6..3a3eea6 100644
--- a/test/shared/urls.test.ts
+++ b/test/shared/urls.test.ts
@@ -1,14 +1,16 @@
-import * as parsers from 'shared/urls';
+import * as parsers from '../../src/shared/urls';
+import { expect } from 'chai';
+import Search from '../../src/shared/settings/Search';
describe("shared/commands/parsers", () => {
describe('#searchUrl', () => {
- const config = {
+ const config = Search.fromJSON({
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))