diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-05 08:03:29 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:18 +0900 |
commit | a0882bbceb7ed71d56bf8557620449fbc3f19749 (patch) | |
tree | f2087d44f21dd68fc3584f62cfb9b62ae58bab2b /test/settings | |
parent | d01db82c0dca352de2d7644c383d388fc3ec0366 (diff) |
Declare setting types
Diffstat (limited to 'test/settings')
-rw-r--r-- | test/settings/components/form/KeymapsForm.test.tsx | 14 | ||||
-rw-r--r-- | test/settings/components/form/SearchEngineForm.test.tsx | 60 | ||||
-rw-r--r-- | test/settings/reducers/setting.test.ts | 3 |
3 files changed, 30 insertions, 47 deletions
diff --git a/test/settings/components/form/KeymapsForm.test.tsx b/test/settings/components/form/KeymapsForm.test.tsx index 6ac57c9..dc2322b 100644 --- a/test/settings/components/form/KeymapsForm.test.tsx +++ b/test/settings/components/form/KeymapsForm.test.tsx @@ -2,15 +2,17 @@ import React from 'react'; import ReactDOM from 'react-dom'; import ReactTestRenderer from 'react-test-renderer'; import ReactTestUtils from 'react-dom/test-utils'; -import KeymapsForm from 'settings/components/form/KeymapsForm' +import KeymapsForm from '../../../../src/settings/components/form/KeymapsForm' +import { FormKeymaps } from 'shared/SettingData'; +import { expect } from 'chai'; describe("settings/form/KeymapsForm", () => { describe('render', () => { it('renders keymap fields', () => { - let root = ReactTestRenderer.create(<KeymapsForm value={{ + let root = ReactTestRenderer.create(<KeymapsForm value={FormKeymaps.valueOf({ 'scroll.vertically?{"count":1}': 'j', 'scroll.vertically?{"count":-1}': 'k', - }} />).root + })} />).root let inputj = root.findByProps({ id: 'scroll.vertically?{"count":1}' }); let inputk = root.findByProps({ id: 'scroll.vertically?{"count":-1}' }); @@ -46,12 +48,12 @@ describe("settings/form/KeymapsForm", () => { it('invokes onChange event on edit', (done) => { ReactTestUtils.act(() => { ReactDOM.render(<KeymapsForm - value={{ + value={FormKeymaps.valueOf({ 'scroll.vertically?{"count":1}': 'j', 'scroll.vertically?{"count":-1}': 'k', - }} + })} onChange={value => { - expect(value['scroll.vertically?{"count":1}']).to.equal('jjj'); + expect(value.toJSON()['scroll.vertically?{"count":1}']).to.equal('jjj'); done(); }} />, container); }); diff --git a/test/settings/components/form/SearchEngineForm.test.tsx b/test/settings/components/form/SearchEngineForm.test.tsx index 06822f2..0e6b17d 100644 --- a/test/settings/components/form/SearchEngineForm.test.tsx +++ b/test/settings/components/form/SearchEngineForm.test.tsx @@ -3,14 +3,15 @@ import ReactDOM from 'react-dom'; import ReactTestRenderer from 'react-test-renderer'; import ReactTestUtils from 'react-dom/test-utils'; import SearchForm from 'settings/components/form/SearchForm' +import { FormSearch } from 'shared/SettingData'; describe("settings/form/SearchForm", () => { describe('render', () => { it('renders SearchForm', () => { - let root = ReactTestRenderer.create(<SearchForm value={{ + let root = ReactTestRenderer.create(<SearchForm value={FormSearch.valueOf({ default: 'google', engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']], - }} />).root; + })} />).root; let names = root.findAllByProps({ name: 'name' }); expect(names).to.have.lengthOf(2); @@ -22,28 +23,6 @@ describe("settings/form/SearchForm", () => { expect(urls[0].props.value).to.equal('google.com'); expect(urls[1].props.value).to.equal('yahoo.com'); }); - - it('renders blank value', () => { - let root = ReactTestRenderer.create(<SearchForm />).root; - - let names = root.findAllByProps({ name: 'name' }); - expect(names).to.be.empty; - - let urls = root.findAllByProps({ name: 'url' }); - expect(urls).to.be.empty; - }); - - it('renders blank engines', () => { - let root = ReactTestRenderer.create( - <SearchForm value={{ default: 'google' }} />, - ).root; - - let names = root.findAllByProps({ name: 'name' }); - expect(names).to.be.empty; - - let urls = root.findAllByProps({ name: 'url' }); - expect(urls).to.be.empty; - }); }); describe('onChange event', () => { @@ -62,14 +41,15 @@ describe("settings/form/SearchForm", () => { it('invokes onChange event on edit', (done) => { ReactTestUtils.act(() => { ReactDOM.render(<SearchForm - value={{ + value={FormSearch.valueOf({ default: 'google', engines: [['google', 'google.com'], ['yahoo', 'yahoo.com']] - }} + })} onChange={value => { - expect(value.default).to.equal('louvre'); - expect(value.engines).to.have.lengthOf(2) - expect(value.engines).to.have.deep.members( + let json = value.toJSON(); + expect(json.default).to.equal('louvre'); + expect(json.engines).to.have.lengthOf(2) + expect(json.engines).to.have.deep.members( [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] ); done(); @@ -87,14 +67,15 @@ describe("settings/form/SearchForm", () => { it('invokes onChange event on delete', (done) => { ReactTestUtils.act(() => { - ReactDOM.render(<SearchForm value={{ + ReactDOM.render(<SearchForm value={FormSearch.valueOf({ default: 'yahoo', engines: [['louvre', 'google.com'], ['yahoo', 'yahoo.com']] - }} + })} onChange={value => { - expect(value.default).to.equal('yahoo'); - expect(value.engines).to.have.lengthOf(1) - expect(value.engines).to.have.deep.members( + let json = value.toJSON(); + expect(json.default).to.equal('yahoo'); + expect(json.engines).to.have.lengthOf(1) + expect(json.engines).to.have.deep.members( [['yahoo', 'yahoo.com']] ); done(); @@ -107,14 +88,15 @@ describe("settings/form/SearchForm", () => { it('invokes onChange event on add', (done) => { ReactTestUtils.act(() => { - ReactDOM.render(<SearchForm value={{ + ReactDOM.render(<SearchForm value={FormSearch.valueOf({ default: 'yahoo', engines: [['google', 'google.com']] - }} + })} onChange={value => { - expect(value.default).to.equal('yahoo'); - expect(value.engines).to.have.lengthOf(2) - expect(value.engines).to.have.deep.members( + let json = value.toJSON(); + expect(json.default).to.equal('yahoo'); + expect(json.engines).to.have.lengthOf(2) + expect(json.engines).to.have.deep.members( [['google', 'google.com'], ['', '']], ); done(); diff --git a/test/settings/reducers/setting.test.ts b/test/settings/reducers/setting.test.ts index 6a874e8..376d66e 100644 --- a/test/settings/reducers/setting.test.ts +++ b/test/settings/reducers/setting.test.ts @@ -4,8 +4,7 @@ import settingReducer from 'settings/reducers/setting'; describe("settings setting reducer", () => { it('return the initial state', () => { let state = settingReducer(undefined, {}); - expect(state).to.have.deep.property('json', ''); - expect(state).to.have.deep.property('form', null); + expect(state).to.have.deep.property('source', 'json'); expect(state).to.have.deep.property('error', ''); }); |