Skip to content

Commit

Permalink
fix: updated function name and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo committed Jun 15, 2018
1 parent bf7f849 commit 7c2794d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
13 changes: 8 additions & 5 deletions packages/text-field/Input.js
Expand Up @@ -79,12 +79,15 @@ export default class Input extends React.Component {

handleValidationAttributeUpdate = (nextProps) => {
const {foundation} = nextProps;

VALIDATION_ATTR_WHITELIST.some((attr) => {
VALIDATION_ATTR_WHITELIST.some((attributeName) => {
let attr = attributeName;
if (attributeName === 'minlength') {
attr = 'minLength';
} else if (attributeName === 'maxlength') {
attr = 'maxLength';
}
if (this.props[attr] !== nextProps[attr]) {
foundation.handleValidationAttributeMutation([{
attributeName: attr,
}]);
foundation.handleValidationAttributeChange([attributeName]);
return true;
}
});
Expand Down
22 changes: 11 additions & 11 deletions test/unit/text-field/Input.test.js
Expand Up @@ -56,11 +56,6 @@ test('#componentDidMount does not throw errow if props.id is passed', () => {
shallow(<Input id='123-best-id' />);
});

test('#componentDidMount does not throw errow if validation attr is updated', () => {
const wrapper = shallow(<Input />);
wrapper.setProps({required: true});
});

test('#componentDidMount should not call any method if disabled and id do not exist', () => {
const setDisabled = td.func();
const setInputId = td.func();
Expand All @@ -73,14 +68,19 @@ test('#componentDidMount should not call any method if disabled and id do not ex
td.verify(setDisabled(td.matchers.isA(Boolean)), {times: 0});
});

test('#componentWillReceiveProps calls handleValidationAttributeMutation_ when ' +
test('change to minLength calls handleValidationAttributeChange', () => {
const handleValidationAttributeChange = td.func();
const wrapper = shallow(<Input foundation={{handleValidationAttributeChange}} />);
wrapper.setProps({minLength: 20});
td.verify(handleValidationAttributeChange(['minlength']), {times: 1});
});

test('#componentWillReceiveProps calls handleValidationAttributeChange when ' +
'a whitelisted attr updates', () => {
const foundation = {handleValidationAttributeMutation_: td.func()};
const wrapper = shallow(<Input foundation={foundation} />);
const handleValidationAttributeChange = td.func();
const wrapper = shallow(<Input foundation={{handleValidationAttributeChange}} />);
wrapper.setProps({required: true});
td.verify(foundation.handleValidationAttributeMutation_([{
attributeName: 'pattern',
}]), {times: 1});
td.verify(handleValidationAttributeChange(['required']), {times: 1});
});

test('#componentWillReceiveProps calls setDisabled and foundation.setDisabled when ' +
Expand Down

0 comments on commit 7c2794d

Please sign in to comment.