Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 7c2794d

Browse files
author
Matt Goo
committed
fix: updated function name and tests
1 parent bf7f849 commit 7c2794d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

packages/text-field/Input.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ export default class Input extends React.Component {
7979

8080
handleValidationAttributeUpdate = (nextProps) => {
8181
const {foundation} = nextProps;
82-
83-
VALIDATION_ATTR_WHITELIST.some((attr) => {
82+
VALIDATION_ATTR_WHITELIST.some((attributeName) => {
83+
let attr = attributeName;
84+
if (attributeName === 'minlength') {
85+
attr = 'minLength';
86+
} else if (attributeName === 'maxlength') {
87+
attr = 'maxLength';
88+
}
8489
if (this.props[attr] !== nextProps[attr]) {
85-
foundation.handleValidationAttributeMutation([{
86-
attributeName: attr,
87-
}]);
90+
foundation.handleValidationAttributeChange([attributeName]);
8891
return true;
8992
}
9093
});

test/unit/text-field/Input.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ test('#componentDidMount does not throw errow if props.id is passed', () => {
5656
shallow(<Input id='123-best-id' />);
5757
});
5858

59-
test('#componentDidMount does not throw errow if validation attr is updated', () => {
60-
const wrapper = shallow(<Input />);
61-
wrapper.setProps({required: true});
62-
});
63-
6459
test('#componentDidMount should not call any method if disabled and id do not exist', () => {
6560
const setDisabled = td.func();
6661
const setInputId = td.func();
@@ -73,14 +68,19 @@ test('#componentDidMount should not call any method if disabled and id do not ex
7368
td.verify(setDisabled(td.matchers.isA(Boolean)), {times: 0});
7469
});
7570

76-
test('#componentWillReceiveProps calls handleValidationAttributeMutation_ when ' +
71+
test('change to minLength calls handleValidationAttributeChange', () => {
72+
const handleValidationAttributeChange = td.func();
73+
const wrapper = shallow(<Input foundation={{handleValidationAttributeChange}} />);
74+
wrapper.setProps({minLength: 20});
75+
td.verify(handleValidationAttributeChange(['minlength']), {times: 1});
76+
});
77+
78+
test('#componentWillReceiveProps calls handleValidationAttributeChange when ' +
7779
'a whitelisted attr updates', () => {
78-
const foundation = {handleValidationAttributeMutation_: td.func()};
79-
const wrapper = shallow(<Input foundation={foundation} />);
80+
const handleValidationAttributeChange = td.func();
81+
const wrapper = shallow(<Input foundation={{handleValidationAttributeChange}} />);
8082
wrapper.setProps({required: true});
81-
td.verify(foundation.handleValidationAttributeMutation_([{
82-
attributeName: 'pattern',
83-
}]), {times: 1});
83+
td.verify(handleValidationAttributeChange(['required']), {times: 1});
8484
});
8585

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

0 commit comments

Comments
 (0)