-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Search): enter search always be called once each time, close #4049 (
- Loading branch information
Showing
3 changed files
with
52 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
import assert from 'power-assert'; | ||
import sinon from 'sinon'; | ||
import Search from '../../src/search/index'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
/* eslint-disable no-undef, react/jsx-filename-extension */ | ||
describe('Search issues', function() { | ||
// Fix https://github.com/alibaba-fusion/next/issues/4049 | ||
it('Enter search should be called once when autoHighlightFirstItem=false', function() { | ||
const onSearch = sinon.spy(); | ||
const wrapper = mount(<Search dataSource={['a']} onSearch={onSearch} autoHighlightFirstItem={false} />); | ||
// has matched item | ||
wrapper.find('input').simulate('change', { target: { value: 'a' } }); | ||
wrapper.find('input').simulate('keydown', { keyCode: 13 }); | ||
assert(onSearch.calledOnceWith('a')); | ||
// does not has matched item | ||
wrapper.find('input').simulate('change', { target: { value: 'b' } }); | ||
wrapper.find('input').simulate('keydown', { keyCode: 13 }); | ||
assert(onSearch.calledTwice); | ||
assert(onSearch.calledWith('b')); | ||
wrapper.unmount(); | ||
}); | ||
}); |