Search queries when enter is pressed (#6043)

* Search queries when enter is pressed

* Add unit test

* Remove line

* Improve test
This commit is contained in:
Beto Dealmeida
2018-10-07 12:48:06 -07:00
committed by GitHub
parent 06e029f9d3
commit 96952d0daf
2 changed files with 18 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import sinon from 'sinon';
import QuerySearch from '../../../src/SqlLab/components/QuerySearch';
describe('QuerySearch', () => {
const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');
const mockedProps = {
actions: {},
height: 0,
@@ -53,15 +54,21 @@ describe('QuerySearch', () => {
expect(wrapper.state().searchText).to.equal('text');
});
it('refreshes queries when enter (only) is pressed on the input', () => {
const callCount = search.callCount;
wrapper.find('input').simulate('keyDown', { keyCode: 'a'.charCodeAt(0) });
expect(search.callCount).to.equal(callCount);
wrapper.find('input').simulate('keyDown', { keyCode: '\r'.charCodeAt(0) });
expect(search.callCount).to.equal(callCount + 1);
});
it('should have one Button', () => {
expect(wrapper.find(Button)).to.have.length(1);
});
it('refreshes queries when clicked', () => {
const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');
wrapper = shallow(<QuerySearch {...mockedProps} />);
const callCount = search.callCount;
wrapper.find(Button).simulate('click');
/* eslint-disable no-unused-expressions */
expect(search.called).to.equal(true);
expect(search.callCount).to.equal(callCount + 1);
});
});