mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,6 +41,7 @@ class QuerySearch extends React.PureComponent {
|
||||
this.dbMutator = this.dbMutator.bind(this);
|
||||
this.onChange = this.onChange.bind(this);
|
||||
this.changeSearch = this.changeSearch.bind(this);
|
||||
this.onKeyDown = this.onKeyDown.bind(this);
|
||||
this.changeFrom = this.changeFrom.bind(this);
|
||||
this.changeTo = this.changeTo.bind(this);
|
||||
this.changeStatus = this.changeStatus.bind(this);
|
||||
@@ -65,6 +66,11 @@ class QuerySearch extends React.PureComponent {
|
||||
const val = db ? db.value : null;
|
||||
this.setState({ databaseId: val });
|
||||
}
|
||||
onKeyDown(event) {
|
||||
if (event.keyCode === 13) {
|
||||
this.refreshQueries();
|
||||
}
|
||||
}
|
||||
getTimeFromSelection(selection) {
|
||||
switch (selection) {
|
||||
case 'now':
|
||||
@@ -173,6 +179,7 @@ class QuerySearch extends React.PureComponent {
|
||||
<input
|
||||
type="text"
|
||||
onChange={this.changeSearch}
|
||||
onKeyDown={this.onKeyDown}
|
||||
className="form-control input-sm"
|
||||
placeholder={t('Search Results')}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user