зеркало из https://github.com/mozilla/normandy.git
Replace SwitchBox tests for LabeledInput tests
This commit is contained in:
Родитель
9a0abbf140
Коммит
47db43e114
|
@ -10,19 +10,13 @@ export default class LabeledCheckbox extends LabeledInput {
|
|||
}
|
||||
|
||||
getElementProps() {
|
||||
const { value } = this.props;
|
||||
|
||||
return {
|
||||
checked: value,
|
||||
};
|
||||
return { checked: this.props.value };
|
||||
}
|
||||
|
||||
getLabelProps() {
|
||||
const { value } = this.props;
|
||||
|
||||
return {
|
||||
role: 'checkbox',
|
||||
'aria-checked': value,
|
||||
'aria-checked': this.props.value,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,11 @@ import React from 'react';
|
|||
export default class LabeledInput extends React.Component {
|
||||
static propTypes = {
|
||||
children: PropTypes.node,
|
||||
element: PropTypes.node,
|
||||
onChange: PropTypes.func,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
children: null,
|
||||
element: undefined,
|
||||
onChange: () => {},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
import { Switch } from 'antd';
|
||||
import autobind from 'autobind-decorator';
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
import SwitchBox from 'control/components/forms/SwitchBox';
|
||||
import LabeledInput from 'control/components/forms/LabeledInput';
|
||||
|
||||
describe('<SwitchBox>', () => {
|
||||
@autobind
|
||||
class TestInput extends LabeledInput {
|
||||
getElement() { return Switch; }
|
||||
getElementProps() { return { checked: this.props.value, testProp: 123 }; }
|
||||
handleLabelClick() { this.props.onChange(); }
|
||||
}
|
||||
|
||||
describe('<LabeledInput>', () => {
|
||||
const props = {
|
||||
children: null,
|
||||
onChange: () => {},
|
||||
value: null,
|
||||
};
|
||||
|
||||
const factory = (customProps = {}) => mount(<SwitchBox {...props} {...customProps} />);
|
||||
const factory = (customProps = {}) => mount(<TestInput {...props} {...customProps} />);
|
||||
|
||||
it('should work', () => {
|
||||
expect(factory).not.toThrow();
|
||||
|
@ -43,8 +51,14 @@ describe('<SwitchBox>', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('the Switch', () => {
|
||||
it('should inherit the `value` as a `checked` prop', () => {
|
||||
describe('getElementProps', () => {
|
||||
it('should pass properties into the internal component', () => {
|
||||
const wrapper = factory();
|
||||
expect(wrapper.find(Switch).length).toBe(1);
|
||||
expect(wrapper.find(Switch).props().testProp).toBe(123);
|
||||
});
|
||||
|
||||
it('should pass dynamic props (`value` as a `checked` prop)', () => {
|
||||
const wrapper = factory({ value: true });
|
||||
expect(wrapper.find(Switch).length).toBe(1);
|
||||
expect(wrapper.find(Switch).props().checked).toBe(true);
|
Загрузка…
Ссылка в новой задаче