aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-10-07 12:54:32 +0000
committerGitHub <noreply@github.com>2019-10-07 12:54:32 +0000
commit8eddcc1785a85bbe74be254d1055ebe5125dad10 (patch)
treef3f51320d12a90a1b421ed8b1f811c576996ea8e /test
parent7fc2bb615f530fc6adfade54b9553568f5d50ceb (diff)
parentb77a4734985722e96066e713f3b1b9e81a6e1811 (diff)
Merge pull request #654 from ueokande/settings-as-a-class
Refactor settings on shared logics
Diffstat (limited to 'test')
-rw-r--r--test/content/InputDriver.test.ts69
-rw-r--r--test/content/domains/Key.test.ts137
-rw-r--r--test/content/domains/KeySequence.test.ts72
-rw-r--r--test/content/repositories/KeymapRepository.test.ts24
-rw-r--r--test/content/repositories/SettingRepository.test.ts8
-rw-r--r--test/content/usecases/SettingUseCaase.test.ts2
-rw-r--r--test/settings/components/form/KeymapsForm.test.tsx4
-rw-r--r--test/settings/components/form/PropertiesForm.test.tsx4
-rw-r--r--test/settings/components/form/SearchEngineForm.test.tsx8
-rw-r--r--test/shared/SettingData.test.ts51
-rw-r--r--test/shared/Settings.test.ts194
-rw-r--r--test/shared/blacklists.test.ts49
-rw-r--r--test/shared/properties.test.js18
-rw-r--r--test/shared/property-defs.test.js18
-rw-r--r--test/shared/settings/Blacklist.test.ts77
-rw-r--r--test/shared/settings/Key.test.ts92
-rw-r--r--test/shared/settings/KeySequence.test.ts72
-rw-r--r--test/shared/settings/Keymaps.test.ts66
-rw-r--r--test/shared/settings/Properties.test.ts30
-rw-r--r--test/shared/settings/Search.test.ts68
-rw-r--r--test/shared/settings/Settings.test.ts54
-rw-r--r--test/shared/urls.test.ts8
-rw-r--r--test/shared/utils/re.test.ts19
23 files changed, 574 insertions, 570 deletions
diff --git a/test/content/InputDriver.test.ts b/test/content/InputDriver.test.ts
index b9f2c28..441d107 100644
--- a/test/content/InputDriver.test.ts
+++ b/test/content/InputDriver.test.ts
@@ -1,6 +1,6 @@
-import InputDriver from '../../src/content/InputDriver';
+import InputDriver, {keyFromKeyboardEvent} from '../../src/content/InputDriver';
import { expect } from 'chai';
-import Key from '../../src/content/domains/Key';
+import Key from '../../src/shared/settings/Key';
describe('InputDriver', () => {
let target: HTMLElement;
@@ -21,10 +21,10 @@ describe('InputDriver', () => {
it('register callbacks', (done) => {
driver.onKey((key: Key): boolean => {
expect(key.key).to.equal('a');
- expect(key.ctrlKey).to.be.true;
- expect(key.shiftKey).to.be.false;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.shift).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
done();
return true;
});
@@ -68,15 +68,15 @@ describe('InputDriver', () => {
it('propagates and stop handler chain', () => {
let a = 0, b = 0, c = 0;
- driver.onKey((key: Key): boolean => {
+ driver.onKey((_key: Key): boolean => {
a++;
return false;
});
- driver.onKey((key: Key): boolean => {
+ driver.onKey((_key: Key): boolean => {
b++;
return true;
});
- driver.onKey((key: Key): boolean => {
+ driver.onKey((_key: Key): boolean => {
c++;
return true;
});
@@ -89,7 +89,7 @@ describe('InputDriver', () => {
})
it('does not invoke only meta keys', () => {
- driver.onKey((key: Key): boolean=> {
+ driver.onKey((_key: Key): boolean=> {
expect.fail();
return false;
});
@@ -115,7 +115,7 @@ describe('InputDriver', () => {
it('ignores events from contenteditable elements', () => {
let div = window.document.createElement('div');
let driver = new InputDriver(div);
- driver.onKey((key: Key): boolean => {
+ driver.onKey((_key: Key): boolean => {
expect.fail();
return false;
});
@@ -127,3 +127,50 @@ describe('InputDriver', () => {
div.dispatchEvent(new KeyboardEvent('keydown', { key: 'x' }));
});
});
+
+describe("#keyFromKeyboardEvent", () => {
+ it('returns from keyboard input Ctrl+X', () => {
+ let k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
+ key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true,
+ }));
+ expect(k.key).to.equal('x');
+ expect(k.shift).to.be.false;
+ expect(k.ctrl).to.be.true;
+ expect(k.alt).to.be.false;
+ expect(k.meta).to.be.true;
+ });
+
+ it('returns from keyboard input Shift+Esc', () => {
+ let k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
+ key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true
+ }));
+ expect(k.key).to.equal('Esc');
+ expect(k.shift).to.be.true;
+ expect(k.ctrl).to.be.false;
+ expect(k.alt).to.be.false;
+ expect(k.meta).to.be.true;
+ });
+
+ it('returns from keyboard input Ctrl+$', () => {
+ // $ required shift pressing on most keyboards
+ let k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
+ key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
+ }));
+ expect(k.key).to.equal('$');
+ expect(k.shift).to.be.false;
+ expect(k.ctrl).to.be.true;
+ expect(k.alt).to.be.false;
+ expect(k.meta).to.be.false;
+ });
+
+ it('returns from keyboard input Crtl+Space', () => {
+ let k = keyFromKeyboardEvent(new KeyboardEvent('keydown', {
+ key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false
+ }));
+ expect(k.key).to.equal('Space');
+ expect(k.shift).to.be.false;
+ expect(k.ctrl).to.be.true;
+ expect(k.alt).to.be.false;
+ expect(k.meta).to.be.false;
+ });
+});
diff --git a/test/content/domains/Key.test.ts b/test/content/domains/Key.test.ts
deleted file mode 100644
index b3f9fb6..0000000
--- a/test/content/domains/Key.test.ts
+++ /dev/null
@@ -1,137 +0,0 @@
-import Key, * as keys from '../../../src/content/domains/Key';
-import { expect } from 'chai'
-
-describe("Key", () => {
- describe('fromKeyboardEvent', () => {
- it('returns from keyboard input Ctrl+X', () => {
- let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'x', shiftKey: false, ctrlKey: true, altKey: false, metaKey: true,
- }));
- expect(k.key).to.equal('x');
- expect(k.shiftKey).to.be.false;
- expect(k.ctrlKey).to.be.true;
- expect(k.altKey).to.be.false;
- expect(k.metaKey).to.be.true;
- });
-
- it('returns from keyboard input Shift+Esc', () => {
- let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
- key: 'Escape', shiftKey: true, ctrlKey: false, altKey: false, metaKey: true
- }));
- expect(k.key).to.equal('Esc');
- expect(k.shiftKey).to.be.true;
- expect(k.ctrlKey).to.be.false;
- expect(k.altKey).to.be.false;
- expect(k.metaKey).to.be.true;
- });
-
- it('returns from keyboard input Ctrl+$', () => {
- // $ required shift pressing on most keyboards
- let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
- key: '$', shiftKey: true, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('$');
- expect(k.shiftKey).to.be.false;
- expect(k.ctrlKey).to.be.true;
- expect(k.altKey).to.be.false;
- expect(k.metaKey).to.be.false;
- });
-
- it('returns from keyboard input Crtl+Space', () => {
- let k = keys.fromKeyboardEvent(new KeyboardEvent('keydown', {
- key: ' ', shiftKey: false, ctrlKey: true, altKey: false, metaKey: false
- }));
- expect(k.key).to.equal('Space');
- expect(k.shiftKey).to.be.false;
- expect(k.ctrlKey).to.be.true;
- expect(k.altKey).to.be.false;
- expect(k.metaKey).to.be.false;
- });
- });
-
- describe('fromMapKey', () => {
- it('return for X', () => {
- let key = keys.fromMapKey('x');
- expect(key.key).to.equal('x');
- expect(key.shiftKey).to.be.false;
- expect(key.ctrlKey).to.be.false;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('return for Shift+X', () => {
- let key = keys.fromMapKey('X');
- expect(key.key).to.equal('X');
- expect(key.shiftKey).to.be.true;
- expect(key.ctrlKey).to.be.false;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('return for Ctrl+X', () => {
- let key = keys.fromMapKey('<C-X>');
- expect(key.key).to.equal('x');
- expect(key.shiftKey).to.be.false;
- expect(key.ctrlKey).to.be.true;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('returns for Ctrl+Meta+X', () => {
- let key = keys.fromMapKey('<C-M-X>');
- expect(key.key).to.equal('x');
- expect(key.shiftKey).to.be.false;
- expect(key.ctrlKey).to.be.true;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.true;
- });
-
- it('returns for Ctrl+Shift+x', () => {
- let key = keys.fromMapKey('<C-S-x>');
- expect(key.key).to.equal('X');
- expect(key.shiftKey).to.be.true;
- expect(key.ctrlKey).to.be.true;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('returns for Shift+Esc', () => {
- let key = keys.fromMapKey('<S-Esc>');
- expect(key.key).to.equal('Esc');
- expect(key.shiftKey).to.be.true;
- expect(key.ctrlKey).to.be.false;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('returns for Ctrl+Esc', () => {
- let key = keys.fromMapKey('<C-Esc>');
- expect(key.key).to.equal('Esc');
- expect(key.shiftKey).to.be.false;
- expect(key.ctrlKey).to.be.true;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
-
- it('returns for Ctrl+Esc', () => {
- let key = keys.fromMapKey('<C-Space>');
- expect(key.key).to.equal('Space');
- expect(key.shiftKey).to.be.false;
- expect(key.ctrlKey).to.be.true;
- expect(key.altKey).to.be.false;
- expect(key.metaKey).to.be.false;
- });
- });
-
- describe('equals', () => {
- expect(keys.equals(
- { key: 'x', ctrlKey: true, },
- { key: 'x', ctrlKey: true, },
- )).to.be.true;
-
- expect(keys.equals(
- { key: 'X', shiftKey: true, },
- { key: 'x', ctrlKey: true, },
- )).to.be.false;
- });
-});
diff --git a/test/content/domains/KeySequence.test.ts b/test/content/domains/KeySequence.test.ts
deleted file mode 100644
index 7387c06..0000000
--- a/test/content/domains/KeySequence.test.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import KeySequence, * as utils from '../../../src/content/domains/KeySequence';
-import { expect } from 'chai'
-
-describe("KeySequence", () => {
- describe('#push', () => {
- it('append a key to the sequence', () => {
- let seq = KeySequence.from([]);
- seq.push({ key: 'g' });
- seq.push({ key: 'u', shiftKey: true });
-
- let array = seq.getKeyArray();
- expect(array[0]).to.deep.equal({ key: 'g' });
- expect(array[1]).to.deep.equal({ key: 'u', shiftKey: true });
- })
- });
-
- describe('#startsWith', () => {
- it('returns true if the key sequence starts with param', () => {
- let seq = KeySequence.from([
- { key: 'g' },
- { key: 'u', shiftKey: true },
- ]);
-
- expect(seq.startsWith(KeySequence.from([
- ]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
- { key: 'g' },
- ]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
- { key: 'g' }, { key: 'u', shiftKey: true },
- ]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
- { key: 'g' }, { key: 'u', shiftKey: true }, { key: 'x' },
- ]))).to.be.false;
- expect(seq.startsWith(KeySequence.from([
- { key: 'h' },
- ]))).to.be.false;
- })
-
- it('returns true if the empty sequence starts with an empty sequence', () => {
- let seq = KeySequence.from([]);
-
- expect(seq.startsWith(KeySequence.from([]))).to.be.true;
- expect(seq.startsWith(KeySequence.from([
- { key: 'h' },
- ]))).to.be.false;
- })
- });
-
- describe('#fromMapKeys', () => {
- it('returns mapped keys for Shift+Esc', () => {
- let keyArray = utils.fromMapKeys('<S-Esc>').getKeyArray();
- expect(keyArray).to.have.lengthOf(1);
- expect(keyArray[0].key).to.equal('Esc');
- expect(keyArray[0].shiftKey).to.be.true;
- });
-
- it('returns mapped keys for a<C-B><A-C>d<M-e>', () => {
- let keyArray = utils.fromMapKeys('a<C-B><A-C>d<M-e>').getKeyArray();
- expect(keyArray).to.have.lengthOf(5);
- expect(keyArray[0].key).to.equal('a');
- expect(keyArray[1].ctrlKey).to.be.true;
- expect(keyArray[1].key).to.equal('b');
- expect(keyArray[2].altKey).to.be.true;
- expect(keyArray[2].key).to.equal('c');
- expect(keyArray[3].key).to.equal('d');
- expect(keyArray[4].metaKey).to.be.true;
- expect(keyArray[4].key).to.equal('e');
- });
- })
-
-});
diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts
index 34704d9..df013df 100644
--- a/test/content/repositories/KeymapRepository.test.ts
+++ b/test/content/repositories/KeymapRepository.test.ts
@@ -1,6 +1,7 @@
import KeymapRepository, { KeymapRepositoryImpl }
from '../../../src/content/repositories/KeymapRepository';
import { expect } from 'chai';
+import Key from "../../../src/shared/settings/Key";
describe('KeymapRepositoryImpl', () => {
let sut: KeymapRepository;
@@ -11,24 +12,25 @@ describe('KeymapRepositoryImpl', () => {
describe('#enqueueKey()', () => {
it('enqueues keys', () => {
- sut.enqueueKey({ key: 'a' });
- sut.enqueueKey({ key: 'b' });
- let sequence = sut.enqueueKey({ key: 'c' });
-
- expect(sequence.getKeyArray()).deep.equals([
- { key: 'a' }, { key: 'b' }, { key: 'c' },
- ]);
+ sut.enqueueKey(Key.fromMapKey('a');
+ sut.enqueueKey(Key.fromMapKey('b');
+ let sequence = sut.enqueueKey(Key.fromMapKey('c'));
+
+ let keys = sequence.keys;
+ expect(keys[0].equals(Key.fromMapKey('a'))).to.be.true;
+ expect(keys[1].equals(Key.fromMapKey('b'))).to.be.true;
+ expect(keys[2].equals(Key.fromMapKey('c'))).to.be.true;
});
});
describe('#clear()', () => {
it('clears keys', () => {
- sut.enqueueKey({ key: 'a' });
- sut.enqueueKey({ key: 'b' });
- sut.enqueueKey({ key: 'c' });
+ sut.enqueueKey(Key.fromMapKey('a'));
+ sut.enqueueKey(Key.fromMapKey('b'));
+ sut.enqueueKey(Key.fromMapKey('c'));
sut.clear();
- let sequence = sut.enqueueKey({ key: 'a' });
+ let sequence = sut.enqueueKey(Key.fromMapKey('a'));
expect(sequence.length()).to.equal(1);
});
});
diff --git a/test/content/repositories/SettingRepository.test.ts b/test/content/repositories/SettingRepository.test.ts
index fea70b7..db4c528 100644
--- a/test/content/repositories/SettingRepository.test.ts
+++ b/test/content/repositories/SettingRepository.test.ts
@@ -1,13 +1,14 @@
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
import { expect } from 'chai';
+import Settings from '../../../src/shared/settings/Settings';
describe('SettingRepositoryImpl', () => {
it('updates and gets current value', () => {
let sut = new SettingRepositoryImpl();
- let settings = {
+ let settings = Settings.fromJSON({
keymaps: {},
- search: {
+ search:{
default: 'google',
engines: {
google: 'https://google.com/?q={}',
@@ -19,7 +20,7 @@ describe('SettingRepositoryImpl', () => {
complete: 'sbh',
},
blacklist: [],
- }
+ });
sut.set(settings);
@@ -27,4 +28,3 @@ describe('SettingRepositoryImpl', () => {
expect(actual.properties.hintchars).to.equal('abcd1234');
});
});
-
diff --git a/test/content/usecases/SettingUseCaase.test.ts b/test/content/usecases/SettingUseCaase.test.ts
index e9633f4..136c5af 100644
--- a/test/content/usecases/SettingUseCaase.test.ts
+++ b/test/content/usecases/SettingUseCaase.test.ts
@@ -1,7 +1,7 @@
import SettingRepository from '../../../src/content/repositories/SettingRepository';
import SettingClient from '../../../src/content/client/SettingClient';
import SettingUseCase from '../../../src/content/usecases/SettingUseCase';
-import Settings, { DefaultSetting } from '../../../src/shared/Settings';
+import Settings, { DefaultSetting } from '../../../src/shared/settings/Settings';
import { expect } from 'chai';
class MockSettingRepository implements SettingRepository {
diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx
index dc2322b..1d1e77c 100644
--- a/test/settings/components/form/KeymapsForm.test.tsx
+++ b/test/settings/components/form/KeymapsForm.test.tsx
@@ -9,7 +9,7 @@ import { expect } from 'chai';
describe("settings/form/KeymapsForm", () => {
describe('render', () => {
it('renders keymap fields', () => {
- let root = ReactTestRenderer.create(<KeymapsForm value={FormKeymaps.valueOf({
+ let root = ReactTestRenderer.create(<KeymapsForm value={FormKeymaps.fromJSON({
'scroll.vertically?{"count":1}': 'j',
'scroll.vertically?{"count":-1}': 'k',
})} />).root
@@ -48,7 +48,7 @@ describe("settings/form/KeymapsForm", () => {
it('invokes onChange event on edit', (done) => {
ReactTestUtils.act(() => {
ReactDOM.render(<KeymapsForm
- value={FormKeymaps.valueOf({
+ value={FormKeymaps.fromJSON({
'scroll.vertically?{"count":1}': 'j',
'scroll.vertically?{"count":-1}': 'k',
})}
diff --git a/test/settings/components/form/PropertiesForm.test.tsx b/test/settings/components/form/PropertiesForm.test.tsx
index 80f60d2..0e33cc8 100644
--- a/test/settings/components/form/PropertiesForm.test.tsx
+++ b/test/settings/components/form/PropertiesForm.test.tsx
@@ -13,14 +13,14 @@ describe("settings/form/PropertiesForm", () => {
mybool: 'boolean',
empty: 'string',
}
- let value = {
+ let values = {
mystr: 'abc',
mynum: 123,
mybool: true,
};
let root = ReactTestRenderer.create(
- <PropertiesForm types={types} value={value} />,
+ <PropertiesForm types={types} value={values} />,
).root
let input = root.findByProps({ name: 'mystr' });
diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx
index 0e6b17d..1f0420d 100644
--- a/test/settings/components/form/SearchEngineForm.test.tsx
+++ b/test/settings/components/form/SearchEngineForm.test.tsx
@@ -8,7 +8,7 @@ import { FormSearch } from 'shared/SettingData';
describe("settings/form/SearchForm", () => {
describe('render', () => {
it('renders SearchForm', () => {
- let root = ReactTestRenderer.create(<SearchForm value={FormSearch.valueOf({
+ let root = ReactTestRenderer.create(<SearchForm value={FormSearch.fromJSON({
default: 'google',
engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']],
})} />).root;
@@ -41,7 +41,7 @@ describe("settings/form/SearchForm", () => {
it('invokes onChange event on edit', (done) => {
ReactTestUtils.act(() => {
ReactDOM.render(<SearchForm
- value={FormSearch.valueOf({
+ value={FormSearch.fromJSON({
default: 'google',
engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']]
})}
@@ -67,7 +67,7 @@ describe("settings/form/SearchForm", () => {
it('invokes onChange event on delete', (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<SearchForm value={FormSearch.valueOf({
+ ReactDOM.render(<SearchForm value={FormSearch.fromJSON({
default: 'yahoo',
engines: [['louvre', 'google.com'], ['yahoo', 'yahoo.com']]
})}
@@ -88,7 +88,7 @@ describe("settings/form/SearchForm", () => {
it('invokes onChange event on add', (done) => {
ReactTestUtils.act(() => {
- ReactDOM.render(<SearchForm value={FormSearch.valueOf({
+ ReactDOM.render(<SearchForm value={FormSearch.fromJSON({
default: 'yahoo',
engines: [['google', 'google.com']]
})}
diff --git a/test/shared/SettingData.test.ts b/test/shared/SettingData.test.ts
index 8736ecb..5de7770 100644
--- a/test/shared/SettingData.test.ts
+++ b/test/shared/SettingData.test.ts
@@ -1,8 +1,9 @@
import SettingData, {
- FormKeymaps, JSONSettings, FormSettings,
+ FormKeymaps, JSONTextSettings, FormSettings,
} from '../../src/shared/SettingData';
-import Settings, { Keymaps } from '../../src/shared/Settings';
+import Settings from '../../src/shared/settings/Settings';
import { expect } from 'chai';
+import Keymaps from '../../src/shared/settings/Keymaps';
describe('shared/SettingData', () => {
describe('FormKeymaps', () => {
@@ -11,9 +12,9 @@ describe('shared/SettingData', () => {
let data = {
'scroll.vertically?{"count":1}': 'j',
'scroll.home': '0',
- }
+ };
- let keymaps = FormKeymaps.valueOf(data).toKeymaps();
+ let keymaps = FormKeymaps.fromJSON(data).toKeymaps().toJSON();
expect(keymaps).to.deep.equal({
'j': { type: 'scroll.vertically', count: 1 },
'0': { type: 'scroll.home' },
@@ -23,13 +24,13 @@ describe('shared/SettingData', () => {
describe('#fromKeymaps to #toJSON', () => {
it('create from a Keymaps and create a JSON object', () => {
- let data: Keymaps = {
+ let keymaps: Keymaps = Keymaps.fromJSON({
'j': { type: 'scroll.vertically', count: 1 },
'0': { type: 'scroll.home' },
- }
+ });
- let keymaps = FormKeymaps.fromKeymaps(data).toJSON();
- expect(keymaps).to.deep.equal({
+ let form = FormKeymaps.fromKeymaps(keymaps).toJSON();
+ expect(form).to.deep.equal({
'scroll.vertically?{"count":1}': 'j',
'scroll.home': '0',
});
@@ -56,14 +57,14 @@ describe('shared/SettingData', () => {
"blacklist": []
}`;
- let settings = JSONSettings.valueOf(o).toSettings();
- expect(settings).to.deep.equal(JSON.parse(o));
+ let settings = JSONTextSettings.fromText(o).toSettings();
+ expect(settings.toJSON()).to.deep.equal(JSON.parse(o));
});
});
describe('#fromSettings to #toJSON', () => {
it('create from a Settings and create a JSON string', () => {
- let o = {
+ let o = Settings.fromJSON({
keymaps: {},
search: {
default: "google",
@@ -77,10 +78,10 @@ describe('shared/SettingData', () => {
complete: "sbh"
},
blacklist: [],
- };
+ });
- let json = JSONSettings.fromSettings(o).toJSON();
- expect(JSON.parse(json)).to.deep.equal(o);
+ let json = JSONTextSettings.fromSettings(o).toJSONText();
+ expect(JSON.parse(json)).to.deep.equal(o.toJSON());
});
});
});
@@ -107,8 +108,8 @@ describe('shared/SettingData', () => {
blacklist: []
};
- let settings = FormSettings.valueOf(data).toSettings();
- expect(settings).to.deep.equal({
+ let settings = FormSettings.fromJSON(data).toSettings();
+ expect(settings.toJSON()).to.deep.equal({
keymaps: {
'j': { type: 'scroll.vertically', count: 1 },
'0': { type: 'scroll.home' },
@@ -131,7 +132,7 @@ describe('shared/SettingData', () => {
describe('#fromSettings to #toJSON', () => {
it('create from a Settings and create a JSON string', () => {
- let data: Settings = {
+ let data: Settings = Settings.fromJSON({
keymaps: {
'j': { type: 'scroll.vertically', count: 1 },
'0': { type: 'scroll.home' },
@@ -147,8 +148,8 @@ describe('shared/SettingData', () => {
smoothscroll: false,
complete: "sbh"
},
- blacklist: []
- };
+ blacklist: [],
+ });
let json = FormSettings.fromSettings(data).toJSON();
expect(json).to.deep.equal({
@@ -195,7 +196,7 @@ describe('shared/SettingData', () => {
}`,
};
- let j = SettingData.valueOf(data).toJSON();
+ let j = SettingData.fromJSON(data).toJSON();
expect(j.source).to.equal('json');
expect(j.json).to.be.a('string');
});
@@ -220,7 +221,7 @@ describe('shared/SettingData', () => {
},
};
- let j = SettingData.valueOf(data).toJSON();
+ let j = SettingData.fromJSON(data).toJSON();
expect(j.source).to.equal('form');
expect(j.form).to.deep.equal({
keymaps: {},
@@ -261,8 +262,8 @@ describe('shared/SettingData', () => {
}`,
};
- let settings = SettingData.valueOf(data).toSettings();
- expect(settings.search.default).to.equal('google');
+ let settings = SettingData.fromJSON(data).toSettings();
+ expect(settings.search.defaultEngine).to.equal('google');
});
it('parse object from form source', () => {
@@ -285,8 +286,8 @@ describe('shared/SettingData', () => {
},
};
- let settings = SettingData.valueOf(data).toSettings();
- expect(settings.search.default).to.equal('yahoo');
+ let settings = SettingData.fromJSON(data).toSettings();
+ expect(settings.search.defaultEngine).to.equal('yahoo');
});
});
});
diff --git a/test/shared/Settings.test.ts b/test/shared/Settings.test.ts
deleted file mode 100644
index 04b28c4..0000000
--- a/test/shared/Settings.test.ts
+++ /dev/null
@@ -1,194 +0,0 @@
-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;
- });
-
- it('throws a TypeError with an unknown field', () => {
- expect(() => settings.valueOf({ name: 'alice' })).to.throw(TypeError)
- });
- });
-});
diff --git a/test/shared/blacklists.test.ts b/test/shared/blacklists.test.ts
deleted file mode 100644
index 289ea0f..0000000
--- a/test/shared/blacklists.test.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { includes } from 'shared/blacklists';
-
-describe("shared/blacklist", () => {
- it('matches by *', () => {
- let blacklist = ['*'];
-
- expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
- })
-
- it('matches by hostname', () => {
- let blacklist = ['github.com'];
-
- expect(includes(blacklist, 'https://github.com')).to.be.true;
- expect(includes(blacklist, 'https://gist.github.com')).to.be.false;
- expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true;
- expect(includes(blacklist, 'https://github.org')).to.be.false;
- expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false;
- })
-
- it('matches by hostname with wildcard', () => {
- let blacklist = ['*.github.com'];
-
- expect(includes(blacklist, 'https://github.com')).to.be.false;
- expect(includes(blacklist, 'https://gist.github.com')).to.be.true;
- })
-
- it('matches by path', () => {
- let blacklist = ['github.com/abc'];
-
- expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
- expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false;
- expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
- })
-
- it('matches by path with wildcard', () => {
- let blacklist = ['github.com/abc*'];
-
- expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
- expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true;
- expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
- })
-
- it('matches address and port', () => {
- let blacklist = ['127.0.0.1:8888'];
-
- expect(includes(blacklist, 'http://127.0.0.1:8888/')).to.be.true;
- expect(includes(blacklist, 'http://127.0.0.1:8888/hello')).to.be.true;
- })
-});
diff --git a/test/shared/properties.test.js b/test/shared/properties.test.js
deleted file mode 100644
index 37903d8..0000000
--- a/test/shared/properties.test.js
+++ /dev/null
@@ -1,18 +0,0 @@
-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
deleted file mode 100644
index 37903d8..0000000
--- a/test/shared/property-defs.test.js
+++ /dev/null
@@ -1,18 +0,0 @@
-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/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts
new file mode 100644
index 0000000..fbacf5d
--- /dev/null
+++ b/test/shared/settings/Blacklist.test.ts
@@ -0,0 +1,77 @@
+import Blacklist from '../../../src/shared/settings/Blacklist';
+import { expect } from 'chai';
+
+describe('Blacklist', () => {
+ describe('fromJSON', () => {
+ it('returns empty array by empty settings', () => {
+ let blacklist = Blacklist.fromJSON([]);
+ expect(blacklist.toJSON()).to.be.empty;
+ });
+
+ it('returns blacklist by valid settings', () => {
+ let blacklist = Blacklist.fromJSON([
+ 'github.com',
+ 'circleci.com',
+ ]);
+
+ expect(blacklist.toJSON()).to.deep.equal([
+ 'github.com',
+ 'circleci.com',
+ ]);
+ });
+
+ it('throws a TypeError by invalid settings', () => {
+ expect(() => Blacklist.fromJSON(null)).to.throw(TypeError);
+ expect(() => Blacklist.fromJSON({})).to.throw(TypeError);
+ expect(() => Blacklist.fromJSON([1,2,3])).to.throw(TypeError);
+ });
+ });
+
+ describe('#includes', () => {
+ it('matches by *', () => {
+ let blacklist = new Blacklist(['*']);
+
+ expect(blacklist.includes('https://github.com/abc')).to.be.true;
+ });
+
+ it('matches by hostname', () => {
+ let blacklist = new Blacklist(['github.com']);
+
+ expect(blacklist.includes('https://github.com')).to.be.true;
+ expect(blacklist.includes('https://gist.github.com')).to.be.false;
+ expect(blacklist.includes('https://github.com/ueokande')).to.be.true;
+ expect(blacklist.includes('https://github.org')).to.be.false;
+ expect(blacklist.includes('https://google.com/search?q=github.org')).to.be.false;
+ });
+
+ it('matches by hostname with wildcard', () => {
+ let blacklist = new Blacklist(['*.github.com']);
+
+ expect(blacklist.includes('https://github.com')).to.be.false;
+ expect(blacklist.includes('https://gist.github.com')).to.be.true;
+ })
+
+ it('matches by path', () => {
+ let blacklist = new Blacklist(['github.com/abc']);
+
+ expect(blacklist.includes('https://github.com/abc')).to.be.true;
+ expect(blacklist.includes('https://github.com/abcdef')).to.be.false;
+ expect(blacklist.includes('https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches by path with wildcard', () => {
+ let blacklist = new Blacklist(['github.com/abc*']);
+
+ expect(blacklist.includes('https://github.com/abc')).to.be.true;
+ expect(blacklist.includes('https://github.com/abcdef')).to.be.true;
+ expect(blacklist.includes('https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches address and port', () => {
+ let blacklist = new Blacklist(['127.0.0.1:8888']);
+
+ expect(blacklist.includes('http://127.0.0.1:8888/')).to.be.true;
+ expect(blacklist.includes('http://127.0.0.1:8888/hello')).to.be.true;
+ })
+ })
+});
diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts
new file mode 100644
index 0000000..8222d5a
--- /dev/null
+++ b/test/shared/settings/Key.test.ts
@@ -0,0 +1,92 @@
+import { expect } from 'chai'
+import Key from '../../../src/shared/settings/Key';
+
+describe("Key", () => {
+ describe('fromMapKey', () => {
+ it('return for X', () => {
+ let key = Key.fromMapKey('x');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('return for Shift+X', () => {
+ let key = Key.fromMapKey('X');
+ expect(key.key).to.equal('X');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('return for Ctrl+X', () => {
+ let key = Key.fromMapKey('<C-X>');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Meta+X', () => {
+ let key = Key.fromMapKey('<C-M-X>');
+ expect(key.key).to.equal('x');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.true;
+ });
+
+ it('returns for Ctrl+Shift+x', () => {
+ let key = Key.fromMapKey('<C-S-x>');
+ expect(key.key).to.equal('X');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Shift+Esc', () => {
+ let key = Key.fromMapKey('<S-Esc>');
+ expect(key.key).to.equal('Esc');
+ expect(key.shift).to.be.true;
+ expect(key.ctrl).to.be.false;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Esc', () => {
+ let key = Key.fromMapKey('<C-Esc>');
+ expect(key.key).to.equal('Esc');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+
+ it('returns for Ctrl+Esc', () => {
+ let key = Key.fromMapKey('<C-Space>');
+ expect(key.key).to.equal('Space');
+ expect(key.shift).to.be.false;
+ expect(key.ctrl).to.be.true;
+ expect(key.alt).to.be.false;
+ expect(key.meta).to.be.false;
+ });
+ });
+
+ describe('equals', () => {
+ expect(new Key({
+ key: 'x', shift: false, ctrl: true, alt: false, meta: false,
+ }).equals(new Key({
+ key: 'x', shift: false, ctrl: true, alt: false, meta: false,
+ }))).to.be.true;
+
+ expect(new Key({
+ key: 'x', shift: false, ctrl: false, alt: false, meta: false,
+ }).equals(new Key({
+ key: 'X', shift: true, ctrl: false, alt: false, meta: false,
+ }))).to.be.false;
+ });
+});
diff --git a/test/shared/settings/KeySequence.test.ts b/test/shared/settings/KeySequence.test.ts
new file mode 100644
index 0000000..361cbd1
--- /dev/null
+++ b/test/shared/settings/KeySequence.test.ts
@@ -0,0 +1,72 @@
+import KeySequence from '../../../src/shared/settings/KeySequence';
+import { expect } from 'chai'
+import Key from "../../../src/shared/settings/Key";
+
+describe("KeySequence", () => {
+ describe('#push', () => {
+ it('append a key to the sequence', () => {
+ let seq = new KeySequence([]);
+ seq.push(Key.fromMapKey('g'));
+ seq.push(Key.fromMapKey('<S-U>'));
+
+ expect(seq.keys[0].key).to.equal('g');
+ expect(seq.keys[1].key).to.equal('U');
+ expect(seq.keys[1].shift).to.be.true;
+ })
+ });
+
+ describe('#startsWith', () => {
+ it('returns true if the key sequence starts with param', () => {
+ let seq = new KeySequence([
+ Key.fromMapKey('g'),
+ Key.fromMapKey('<S-U>'),
+ ]);
+
+ expect(seq.startsWith(new KeySequence([
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'),
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'), Key.fromMapKey('<S-U>'),
+ ]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('g'), Key.fromMapKey('<S-U>'), Key.fromMapKey('x'),
+ ]))).to.be.false;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('h'),
+ ]))).to.be.false;
+ });
+
+ it('returns true if the empty sequence starts with an empty sequence', () => {
+ let seq = new KeySequence([]);
+
+ expect(seq.startsWith(new KeySequence([]))).to.be.true;
+ expect(seq.startsWith(new KeySequence([
+ Key.fromMapKey('h'),
+ ]))).to.be.false;
+ })
+ });
+
+ describe('#fromMapKeys', () => {
+ it('returns mapped keys for Shift+Esc', () => {
+ let keys = KeySequence.fromMapKeys('<S-Esc>').keys;
+ expect(keys).to.have.lengthOf(1);
+ expect(keys[0].key).to.equal('Esc');
+ expect(keys[0].shift).to.be.true;
+ });
+
+ it('returns mapped keys for a<C-B><A-C>d<M-e>', () => {
+ let keys = KeySequence.fromMapKeys('a<C-B><A-C>d<M-e>').keys;
+ expect(keys).to.have.lengthOf(5);
+ expect(keys[0].key).to.equal('a');
+ expect(keys[1].ctrl).to.be.true;
+ expect(keys[1].key).to.equal('b');
+ expect(keys[2].alt).to.be.true;
+ expect(keys[2].key).to.equal('c');
+ expect(keys[3].key).to.equal('d');
+ expect(keys[4].meta).to.be.true;
+ expect(keys[4].key).to.equal('e');
+ });
+ })
+});
diff --git a/test/shared/settings/Keymaps.test.ts b/test/shared/settings/Keymaps.test.ts
new file mode 100644
index 0000000..7896a63
--- /dev/null
+++ b/test/shared/settings/Keymaps.test.ts
@@ -0,0 +1,66 @@
+import Keymaps from '../../../src/shared/settings/Keymaps';
+import { expect } from 'chai';
+
+describe('Keymaps', () => {
+ describe('#valueOf', () => {
+ it('returns empty object by empty settings', () => {
+ let keymaps = Keymaps.fromJSON({}).toJSON();
+ expect(keymaps).to.be.empty;
+ });
+
+ it('returns keymaps by valid settings', () => {
+ let keymaps = Keymaps.fromJSON({
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ }).toJSON();
+
+ 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(() => Keymaps.fromJSON(null)).to.throw(TypeError);
+ expect(() => Keymaps.fromJSON({
+ k: { type: "invalid.operation" },
+ })).to.throw(TypeError);
+ });
+ });
+
+ describe('#combine', () => {
+ it('returns combined keymaps', () => {
+ let keymaps = Keymaps.fromJSON({
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ }).combine(Keymaps.fromJSON({
+ n: { type: "find.next" },
+ N: { type: "find.prev" },
+ }));
+
+ let entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ expect(entries).deep.equals([
+ ['j', { type: "scroll.vertically", count: 1 }],
+ ['k', { type: "scroll.vertically", count: -1 }],
+ ['n', { type: "find.next" }],
+ ['N', { type: "find.prev" }],
+ ]);
+ });
+
+ it('overrides current keymaps', () => {
+ let keymaps = Keymaps.fromJSON({
+ k: { type: "scroll.vertically", count: -1 },
+ j: { type: "scroll.vertically", count: 1 },
+ }).combine(Keymaps.fromJSON({
+ n: { type: "find.next" },
+ j: { type: "find.prev" },
+ }));
+
+ let entries = keymaps.entries().sort(([name1], [name2]) => name1.localeCompare(name2));
+ expect(entries).deep.equals([
+ ['j', { type: "find.prev" }],
+ ['k', { type: "scroll.vertically", count: -1 }],
+ ['n', { type: "find.next" }],
+ ]);
+ });
+ });
+});
+
diff --git a/test/shared/settings/Properties.test.ts b/test/shared/settings/Properties.test.ts
new file mode 100644
index 0000000..609a565
--- /dev/null
+++ b/test/shared/settings/Properties.test.ts
@@ -0,0 +1,30 @@
+import Properties from '../../../src/shared/settings/Properties';
+import { expect } from 'chai';
+
+describe('Properties', () => {
+ describe('#propertiesValueOf', () => {
+ it('returns with default properties by empty settings', () => {
+ let props = Properties.fromJSON({});
+ expect(props).to.deep.equal({
+ hintchars: "abcdefghijklmnopqrstuvwxyz",
+ smoothscroll: false,
+ complete: "sbh"
+ })
+ });
+
+ it('returns properties by valid settings', () => {
+ let props = Properties.fromJSON({
+ hintchars: "abcdefgh",
+ smoothscroll: false,
+ complete: "sbh"
+ });
+
+ expect(props).to.deep.equal({
+ hintchars: "abcdefgh",
+ smoothscroll: false,
+ complete: "sbh"
+ });
+ });
+ });
+});
+
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/settings/Settings.test.ts b/test/shared/settings/Settings.test.ts
new file mode 100644
index 0000000..ab6af04
--- /dev/null
+++ b/test/shared/settings/Settings.test.ts
@@ -0,0 +1,54 @@
+import Settings from '../../../src/shared/settings/Settings';
+import { expect } from 'chai';
+
+describe('Settings', () => {
+ describe('#valueOf', () => {
+ it('returns settings by valid settings', () => {
+ let x = Settings.fromJSON({
+ keymaps: {},
+ "search": {
+ "default": "google",
+ "engines": {
+ "google": "https://google.com/search?q={}",
+ }
+ },
+ "properties": {},
+ "blacklist": []
+ });
+
+ expect({
+ keymaps: x.keymaps.toJSON(),
+ search: x.search.toJSON(),
+ properties: x.properties.toJSON(),
+ blacklist: x.blacklist.toJSON(),
+ }).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.fromJSON({});
+ expect(value.keymaps.toJSON()).to.not.be.empty;
+ expect(value.properties.toJSON()).to.not.be.empty;
+ expect(value.search.defaultEngine).to.be.a('string');
+ expect(value.search.engines).to.be.an('object');
+ expect(value.blacklist.toJSON()).to.be.empty;
+ });
+
+ it('throws a TypeError with an unknown field', () => {
+ expect(() => Settings.fromJSON({ name: 'alice' })).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))
diff --git a/test/shared/utils/re.test.ts b/test/shared/utils/re.test.ts
deleted file mode 100644
index d12ceb7..0000000
--- a/test/shared/utils/re.test.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import * as re from 'shared/utils/re';
-
-describe("re util", () => {
- it('matches by pattern', () => {
- let regex = re.fromWildcard('*.example.com/*');
- expect('foo.example.com/bar').to.match(regex);
- expect('foo.example.com').not.to.match(regex);
- expect('example.com/bar').not.to.match(regex);
-
- regex = re.fromWildcard('example.com/*')
- expect('example.com/foo').to.match(regex);
- expect('example.com/').to.match(regex);
-
- regex = re.fromWildcard('example.com/*bar')
- expect('example.com/foobar').to.match(regex);
- expect('example.com/bar').to.match(regex);
- expect('example.com/foobarfoo').not.to.match(regex);
- })
-});