add KeymapsForm test

jh-changes
Shin'ya Ueoka 7 years ago
parent 0967304ebe
commit 705c47bc63
  1. 6
      src/settings/components/form/keymaps-form.jsx
  2. 53
      test/settings/components/form/keymaps-form.test.jsx

@ -58,6 +58,10 @@ const KeyMapFields = [
class KeymapsForm extends Component { class KeymapsForm extends Component {
render() { render() {
let values = this.props.value;
if (!values) {
values = {};
}
return <div className='keymap-fields'> return <div className='keymap-fields'>
{ {
KeyMapFields.map((group, index) => { KeyMapFields.map((group, index) => {
@ -66,7 +70,7 @@ class KeymapsForm extends Component {
group.map((field) => { group.map((field) => {
let name = field[0]; let name = field[0];
let label = field[1]; let label = field[1];
let value = this.props.value[name]; let value = values[name];
return <Input return <Input
type='text' id={name} name={name} key={name} type='text' id={name} name={name} key={name}
label={label} value={value} label={label} value={value}

@ -0,0 +1,53 @@
import { expect } from 'chai';
import { h, render } from 'preact';
import KeymapsForm from 'settings/components/form/keymaps-form'
describe("settings/form/KeymapsForm", () => {
beforeEach(() => {
document.body.innerHTML = '';
});
describe('render', () => {
it('renders KeymapsForm', () => {
render(<KeymapsForm value={{
'scroll.vertically?{"count":1}': 'j',
'scroll.vertically?{"count":-1}': 'k',
}} />, document.body);
let inputj = document.getElementById('scroll.vertically?{"count":1}');
let inputk = document.getElementById('scroll.vertically?{"count":-1}');
expect(inputj.value).to.equal('j');
expect(inputk.value).to.equal('k');
});
it('renders blank value', () => {
render(<KeymapsForm />, document.body);
let inputj = document.getElementById('scroll.vertically?{"count":1}');
let inputk = document.getElementById('scroll.vertically?{"count":-1}');
expect(inputj.value).to.be.empty;
expect(inputk.value).to.be.empty;
});
});
describe('onChange event', () => {
it('invokes onChange event on edit', (done) => {
render(<KeymapsForm
value={{
'scroll.vertically?{"count":1}': 'j',
'scroll.vertically?{"count":-1}': 'k',
}}
onChange={value => {
expect(value['scroll.vertically?{"count":1}']).to.equal('jjj');
done();
}} />, document.body);
let input = document.getElementById('scroll.vertically?{"count":1}');
input.value = 'jjj';
input.dispatchEvent(new Event('change'))
});
});
});