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

Commit 0b8e2d2

Browse files
committed
Update tests to reflect removal of value from state
1 parent 92d818e commit 0b8e2d2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/__tests__/Autocomplete-test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ chai.use(chaiEnzyme());
1515
function AutocompleteComponentJSX (extraProps) {
1616
return (
1717
<Autocomplete
18-
initialValue=''
1918
labelText="Choose a state from the US"
2019
inputProps={{name: "US state"}}
2120
getItemValue={(item) => item.name}
@@ -49,11 +48,11 @@ describe('Autocomplete acceptance tests', () => {
4948
expect(autocompleteWrapper.instance().refs.menu).to.exist;
5049
});
5150

52-
it('should show results when partial match is typed in', () => {
51+
it('should show results when value is a partial match', () => {
5352

5453
// Render autocomplete results upon partial input match
5554
expect(autocompleteWrapper.ref('menu').children()).to.have.length(50);
56-
autocompleteInputWrapper.simulate('change', { target: { value: 'Ar' } });
55+
autocompleteWrapper.setProps({ value: 'Ar' });
5756
expect(autocompleteWrapper.ref('menu').children()).to.have.length(6);
5857

5958
});
@@ -173,32 +172,34 @@ describe('Autocomplete kewDown->Enter event handlers', () => {
173172
});
174173

175174
it('should close menu if input has focus but no item has been selected and then the Enter key is hit', () => {
175+
let value = '';
176176
autocompleteWrapper.setState({'isOpen': true});
177177
autocompleteInputWrapper.simulate('focus');
178-
autocompleteInputWrapper.simulate('change', { target: { value: '' } });
178+
autocompleteWrapper.setProps({ value, onSelect(v) { value = v; } });
179179

180180
// simulate keyUp of backspace, triggering autocomplete suggestion on an empty string, which should result in nothing highlighted
181181
autocompleteInputWrapper.simulate('keyUp', { key : 'Backspace', keyCode: 8, which: 8 });
182182
expect(autocompleteWrapper.state('highlightedIndex')).to.be.null;
183183

184184
autocompleteInputWrapper.simulate('keyDown', { key : 'Enter', keyCode: 13, which: 13 });
185185

186-
expect(autocompleteWrapper.state('value')).to.equal('');
186+
expect(value).to.equal('');
187187
expect(autocompleteWrapper.state('isOpen')).to.be.false;
188188

189189
});
190190

191-
it('should update input value from selected menu item and close the menu', () => {
191+
it('should invoke `onSelect` with the selected menu item and close the menu', () => {
192+
let value = 'Ar';
192193
autocompleteWrapper.setState({'isOpen': true});
193194
autocompleteInputWrapper.simulate('focus');
194-
autocompleteInputWrapper.simulate('change', { target: { value: 'Ar' } });
195+
autocompleteWrapper.setProps({ value, onSelect(v) { value = v; } });
195196

196197
// simulate keyUp of last key, triggering autocomplete suggestion + selection of the suggestion in the menu
197198
autocompleteInputWrapper.simulate('keyUp', { key : 'r', keyCode: 82, which: 82 });
198199

199200
// Hit enter, updating state.value with the selected Autocomplete suggestion
200201
autocompleteInputWrapper.simulate('keyDown', { key : 'Enter', keyCode: 13, which: 13 });
201-
expect(autocompleteWrapper.state('value')).to.equal('Arizona');
202+
expect(value).to.equal('Arizona');
202203
expect(autocompleteWrapper.state('isOpen')).to.be.false;
203204

204205
});
@@ -238,7 +239,7 @@ describe('Autocomplete#renderMenu', () => {
238239

239240
it('should return a menu ReactComponent with a subset of children when partial match text has been entered', () => {
240241
// Input 'Ar' should result in 6 items in the menu, populated from autocomplete.
241-
autocompleteInputWrapper.simulate('change', { target: { value: 'Ar' } });
242+
autocompleteWrapper.setProps({ value: 'Ar' });
242243

243244
var autocompleteMenu = autocompleteWrapper.instance().renderMenu();
244245
expect(autocompleteMenu.props.children.length).to.be.equal(6);

0 commit comments

Comments
 (0)