Test for bool TypedInput

This commit is contained in:
Jaco Greeff 2016-12-12 10:55:20 +01:00
parent f9b5a056cf
commit 28be8d6f6c
3 changed files with 43 additions and 17 deletions

View File

@ -46,26 +46,26 @@ export default class Select extends Component {
} }
render () { render () {
const { disabled, error, label, hint, value, children, className, onBlur, onChange, onKeyDown } = this.props; const { children, className, disabled, error, hint, label, onBlur, onChange, onKeyDown, value } = this.props;
return ( return (
<SelectField <SelectField
className={ className }
autoComplete='off' autoComplete='off'
className={ className }
disabled={ disabled } disabled={ disabled }
errorText={ error } errorText={ error }
floatingLabelFixed floatingLabelFixed
floatingLabelText={ label } floatingLabelText={ label }
fullWidth fullWidth
hintText={ hint } hintText={ hint }
name={ NAME_ID }
id={ NAME_ID } id={ NAME_ID }
underlineDisabledStyle={ UNDERLINE_DISABLED } name={ NAME_ID }
underlineStyle={ UNDERLINE_NORMAL }
value={ value }
onBlur={ onBlur } onBlur={ onBlur }
onChange={ onChange } onChange={ onChange }
onKeyDown={ onKeyDown }> onKeyDown={ onKeyDown }
underlineDisabledStyle={ UNDERLINE_DISABLED }
underlineStyle={ UNDERLINE_NORMAL }
value={ value }>
{ children } { children }
</SelectField> </SelectField>
); );

View File

@ -289,9 +289,8 @@ export default class TypedInput extends Component {
return ( return (
<MenuItem <MenuItem
key={ bool } key={ bool }
value={ bool }
label={ bool } label={ bool }
> value={ bool }>
{ bool } { bool }
</MenuItem> </MenuItem>
); );
@ -299,19 +298,23 @@ export default class TypedInput extends Component {
return ( return (
<Select <Select
label={ label }
hint={ hint }
value={ value ? 'true' : 'false' }
error={ error } error={ error }
hint={ hint }
label={ label }
onChange={ this.onChangeBool } onChange={ this.onChangeBool }
> value={
value
? 'true'
: 'false'
}>
{ boolitems } { boolitems }
</Select> </Select>
); );
} }
onChangeBool = (event, _index, value) => { onChangeBool = (event, _index, value) => {
this.props.onChange(value === 'true'); // NOTE: event.target.value added for enzyme simulated event testing
this.props.onChange((value || event.target.value) === 'true');
} }
onEthTypeChange = () => { onEthTypeChange = () => {

View File

@ -36,12 +36,35 @@ function render (props) {
</ContextProvider> </ContextProvider>
); );
console.log(component.debug());
return component; return component;
} }
describe.only('ui/Form/TypedInput', () => { describe.only('ui/Form/TypedInput', () => {
it('renders defaults', () => { describe('bool selection', () => {
expect(render({ param: { type: ABI_TYPES.BOOL } })).to.be.ok; beforeEach(() => {
render({ param: { type: ABI_TYPES.BOOL } });
});
it('renders', () => {
expect(component).to.be.ok;
});
it('calls onChange when value changes', () => {
component.find('DropDownMenu').simulate('change', { target: { value: 'true' } });
expect(onChange).to.have.been.called;
});
it("calls onChange(true) when value changes to 'true'", () => {
component.find('DropDownMenu').simulate('change', { target: { value: 'true' } });
expect(onChange).to.have.been.calledWith(true);
});
it("calls onChange(false) when value changes to 'false'", () => {
component.find('DropDownMenu').simulate('change', { target: { value: 'false' } });
expect(onChange).to.have.been.calledWith(false);
});
}); });
}); });