superset/superset-frontend/spec/javascripts/sqllab/QuerySearch_spec.jsx
Jesse Yang 81ab8dd8b4
feat: upgrade react-select and make multi-select sortable (#9628)
* feat: upgrade react-select v1.3.0 to v3.1.0

Upgrade `react-select`, replace `react-virtualized-select` with a custom
solution implemented with `react-window`.

Future plans include deprecate `react-virtualized` used in other places, too.

Migrate all react-select related components to `src/Components/Select`.

* Fix new list view

* Fix tests

* Address PR comments

* Fix a flacky Cypress test

* Adjust styles for Select in CRUD ListView

* Fix loadOptions for owners select in chart PropertiesModal

TODO: add typing support for AsyncSelect props.

* Address PR comments; allow isMulti in SelectControl, too

* Clean up NaN in table filter values

* Fix flacky test
2020-05-19 16:59:49 -07:00

89 lines
3.0 KiB
JavaScript

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { Button } from 'react-bootstrap';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import Select from 'src/components/Select';
import QuerySearch from 'src/SqlLab/components/QuerySearch';
describe('QuerySearch', () => {
const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');
const mockedProps = {
actions: {},
height: 0,
};
it('is valid', () => {
expect(React.isValidElement(<QuerySearch {...mockedProps} />)).toBe(true);
});
let wrapper;
beforeEach(() => {
wrapper = shallow(<QuerySearch {...mockedProps} />);
});
it('should have three Select', () => {
expect(wrapper.findWhere(x => x.type() === Select)).toHaveLength(3);
});
it('updates fromTime on user selects from time', () => {
wrapper.find('[name="select-from"]').simulate('change', { value: 0 });
expect(wrapper.state().from).toBe(0);
});
it('updates toTime on user selects to time', () => {
wrapper.find('[name="select-to"]').simulate('change', { value: 0 });
expect(wrapper.state().to).toBe(0);
});
it('updates status on user selects status', () => {
wrapper
.find('[name="select-status"]')
.simulate('change', { value: 'success' });
expect(wrapper.state().status).toBe('success');
});
it('should have one input for searchText', () => {
expect(wrapper.find('input')).toHaveLength(1);
});
it('updates search text on user inputs search text', () => {
wrapper.find('input').simulate('change', { target: { value: 'text' } });
expect(wrapper.state().searchText).toBe('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).toBe(callCount);
wrapper.find('input').simulate('keyDown', { keyCode: '\r'.charCodeAt(0) });
expect(search.callCount).toBe(callCount + 1);
});
it('should have one Button', () => {
expect(wrapper.find(Button)).toHaveLength(1);
});
it('refreshes queries when clicked', () => {
const callCount = search.callCount;
wrapper.find(Button).simulate('click');
expect(search.callCount).toBe(callCount + 1);
});
});