Skip to content

Commit

Permalink
fix(Search): only call onBlur & onFocus event handler once (#1963)
Browse files Browse the repository at this point in the history
* fix(Search): only call onBlur & onFocus event handler once

* test(Search): add onBlur & onFocus tests

* test(Search): fix onBlur & onFocus test titles

* test(Search): test onBlur & onFocus called with arguments
  • Loading branch information
chopstikk authored and levithomason committed Aug 20, 2017
1 parent 86bd8b5 commit a655123
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/modules/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,8 @@ export default class Search extends Component {
...rest,
icon,
input: { className: 'prompt', tabIndex: '0', autoComplete: 'off' },
onBlur: this.handleBlur,
onChange: this.handleSearchChange,
onClick: this.handleInputClick,
onFocus: this.handleFocus,
value,
} })
}
Expand Down
22 changes: 22 additions & 0 deletions test/specs/modules/Search/Search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,28 @@ describe('Search', () => {
})
})

describe('onBlur', () => {
it('is called with (event, data) on search input blur', () => {
const onBlur = sandbox.spy()
wrapperMount(<Search results={options} onBlur={onBlur} />)
.simulate('blur', nativeEvent)

onBlur.should.have.been.calledOnce()
onBlur.should.have.been.calledWithMatch(nativeEvent, { onBlur, results: options })
})
})

describe('onFocus', () => {
it('is called with (event, data) on search input focus', () => {
const onFocus = sandbox.spy()
wrapperMount(<Search results={options} onFocus={onFocus} />)
.simulate('focus', nativeEvent)

onFocus.should.have.been.calledOnce()
onFocus.should.have.been.calledWithMatch(nativeEvent, { onFocus, results: options })
})
})

describe('onResultSelect', () => {
let spy
beforeEach(() => {
Expand Down

0 comments on commit a655123

Please sign in to comment.