Make Settings class
This commit is contained in:
parent
b86b4680b6
commit
0dec6c641f
13 changed files with 120 additions and 99 deletions
|
@ -1,27 +1,26 @@
|
|||
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
|
||||
import { expect } from 'chai';
|
||||
import Keymaps from '../../../src/shared/settings/Keymaps';
|
||||
import Search from '../../../src/shared/settings/Search';
|
||||
import Settings from '../../../src/shared/settings/Settings';
|
||||
|
||||
describe('SettingRepositoryImpl', () => {
|
||||
it('updates and gets current value', () => {
|
||||
let sut = new SettingRepositoryImpl();
|
||||
|
||||
let settings = {
|
||||
keymaps: Keymaps.fromJSON({}),
|
||||
search: Search.fromJSON({
|
||||
let settings = Settings.fromJSON({
|
||||
keymaps: {},
|
||||
search:{
|
||||
default: 'google',
|
||||
engines: {
|
||||
google: 'https://google.com/?q={}',
|
||||
}
|
||||
}),
|
||||
},
|
||||
properties: {
|
||||
hintchars: 'abcd1234',
|
||||
smoothscroll: false,
|
||||
complete: 'sbh',
|
||||
},
|
||||
blacklist: [],
|
||||
};
|
||||
});
|
||||
|
||||
sut.set(settings);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import SettingData, {
|
||||
FormKeymaps, JSONTextSettings, FormSettings,
|
||||
} from '../../src/shared/SettingData';
|
||||
import Settings from '../../src/shared/Settings';
|
||||
import Settings from '../../src/shared/settings/Settings';
|
||||
import { expect } from 'chai';
|
||||
import Keymaps from '../../src/shared/settings/Keymaps';
|
||||
import Search from '../../src/shared/settings/Search';
|
||||
import Properties from '../../src/shared/settings/Properties';
|
||||
import Blacklist from '../../src/shared/settings/Blacklist'
|
||||
|
||||
describe('shared/SettingData', () => {
|
||||
describe('FormKeymaps', () => {
|
||||
|
@ -72,21 +69,21 @@ describe('shared/SettingData', () => {
|
|||
|
||||
describe('#fromSettings to #toJSON', () => {
|
||||
it('create from a Settings and create a JSON string', () => {
|
||||
let o = {
|
||||
keymaps: Keymaps.fromJSON({}),
|
||||
search: Search.fromJSON({
|
||||
let o = Settings.fromJSON({
|
||||
keymaps: {},
|
||||
search: {
|
||||
default: "google",
|
||||
engines: {
|
||||
google: "https://google.com/search?q={}",
|
||||
},
|
||||
}),
|
||||
properties: Properties.fromJSON({
|
||||
},
|
||||
properties: {
|
||||
hintchars: "abcdefghijklmnopqrstuvwxyz",
|
||||
smoothscroll: false,
|
||||
complete: "sbh"
|
||||
}),
|
||||
blacklist: Blacklist.fromJSON([]),
|
||||
};
|
||||
},
|
||||
blacklist: [],
|
||||
});
|
||||
|
||||
let json = JSONTextSettings.fromSettings(o).toJSONText();
|
||||
expect(JSON.parse(json)).to.deep.equal({
|
||||
|
@ -150,24 +147,24 @@ describe('shared/SettingData', () => {
|
|||
|
||||
describe('#fromSettings to #toJSON', () => {
|
||||
it('create from a Settings and create a JSON string', () => {
|
||||
let data: Settings = {
|
||||
keymaps: Keymaps.fromJSON({
|
||||
let data: Settings = Settings.fromJSON({
|
||||
keymaps: {
|
||||
'j': { type: 'scroll.vertically', count: 1 },
|
||||
'0': { type: 'scroll.home' },
|
||||
}),
|
||||
search: Search.fromJSON({
|
||||
},
|
||||
search: {
|
||||
default: "google",
|
||||
engines: {
|
||||
"google": "https://google.com/search?q={}"
|
||||
}
|
||||
}),
|
||||
properties: Properties.fromJSON({
|
||||
},
|
||||
properties: {
|
||||
hintchars: "abcdefghijklmnopqrstuvwxyz",
|
||||
smoothscroll: false,
|
||||
complete: "sbh"
|
||||
}),
|
||||
blacklist: Blacklist.fromJSON([]),
|
||||
};
|
||||
},
|
||||
blacklist: [],
|
||||
});
|
||||
|
||||
let json = FormSettings.fromSettings(data).toJSON();
|
||||
expect(json).to.deep.equal({
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import * as settings from '../../src/shared/Settings';
|
||||
import {expect} from 'chai';
|
||||
import Settings from '../../../src/shared/settings/Settings';
|
||||
import { expect } from 'chai';
|
||||
|
||||
describe('Settings', () => {
|
||||
describe('#valueOf', () => {
|
||||
it('returns settings by valid settings', () => {
|
||||
let x = settings.valueOf({
|
||||
let x = Settings.fromJSON({
|
||||
keymaps: {},
|
||||
"search": {
|
||||
"default": "google",
|
||||
|
@ -39,7 +39,7 @@ describe('Settings', () => {
|
|||
});
|
||||
|
||||
it('sets default settings', () => {
|
||||
let value = settings.valueOf({});
|
||||
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');
|
||||
|
@ -48,7 +48,7 @@ describe('Settings', () => {
|
|||
});
|
||||
|
||||
it('throws a TypeError with an unknown field', () => {
|
||||
expect(() => settings.valueOf({ name: 'alice' })).to.throw(TypeError)
|
||||
expect(() => Settings.fromJSON({ name: 'alice' })).to.throw(TypeError)
|
||||
});
|
||||
});
|
||||
});
|
Reference in a new issue