2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-08-01 15:08:00 -04:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2018-07-12 14:50:25 -04:00
|
|
|
import configureStore from 'redux-mock-store';
|
2017-08-01 15:08:00 -04:00
|
|
|
import { shallow } from 'enzyme';
|
2020-10-23 12:08:35 -04:00
|
|
|
import { Menu } from 'src/common/components';
|
2020-05-07 17:18:10 -04:00
|
|
|
import DatasourceModal from 'src/datasource/DatasourceModal';
|
|
|
|
import ChangeDatasourceModal from 'src/datasource/ChangeDatasourceModal';
|
|
|
|
import DatasourceControl from 'src/explore/components/controls/DatasourceControl';
|
2017-08-01 15:08:00 -04:00
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
name: 'datasource',
|
2020-08-29 21:09:47 -04:00
|
|
|
label: 'Dataset',
|
2017-08-01 15:08:00 -04:00
|
|
|
value: '1__table',
|
|
|
|
datasource: {
|
|
|
|
name: 'birth_names',
|
|
|
|
type: 'table',
|
|
|
|
uid: '1__table',
|
|
|
|
id: 1,
|
2018-01-02 11:41:27 -05:00
|
|
|
columns: [],
|
|
|
|
metrics: [],
|
|
|
|
database: {
|
|
|
|
backend: 'mysql',
|
|
|
|
name: 'main',
|
|
|
|
},
|
2017-08-01 15:08:00 -04:00
|
|
|
},
|
2020-07-10 15:46:25 -04:00
|
|
|
actions: {
|
|
|
|
setDatasource: sinon.spy(),
|
|
|
|
},
|
2017-08-01 15:08:00 -04:00
|
|
|
onChange: sinon.spy(),
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('DatasourceControl', () => {
|
2020-04-30 20:32:01 -04:00
|
|
|
function setup(overrideProps) {
|
2018-07-12 14:50:25 -04:00
|
|
|
const mockStore = configureStore([]);
|
|
|
|
const store = mockStore({});
|
2020-04-30 20:32:01 -04:00
|
|
|
const props = {
|
|
|
|
...defaultProps,
|
|
|
|
...overrideProps,
|
|
|
|
};
|
|
|
|
return shallow(<DatasourceControl {...props} />, {
|
2019-11-27 17:02:48 -05:00
|
|
|
context: { store },
|
|
|
|
});
|
2018-07-12 14:50:25 -04:00
|
|
|
}
|
2017-08-01 15:08:00 -04:00
|
|
|
|
2020-10-02 15:15:06 -04:00
|
|
|
it('should not render Modal', () => {
|
2018-07-12 14:50:25 -04:00
|
|
|
const wrapper = setup();
|
2020-10-02 15:15:06 -04:00
|
|
|
expect(wrapper.find(DatasourceModal)).toHaveLength(0);
|
2017-08-01 15:08:00 -04:00
|
|
|
});
|
2019-02-20 17:32:33 -05:00
|
|
|
|
2020-10-02 15:15:06 -04:00
|
|
|
it('should not render ChangeDatasourceModal', () => {
|
2019-02-20 17:32:33 -05:00
|
|
|
const wrapper = setup();
|
2020-10-02 15:15:06 -04:00
|
|
|
expect(wrapper.find(ChangeDatasourceModal)).toHaveLength(0);
|
2019-02-20 17:32:33 -05:00
|
|
|
});
|
2020-04-30 20:32:01 -04:00
|
|
|
|
|
|
|
it('show or hide Edit Datasource option', () => {
|
|
|
|
let wrapper = setup();
|
2020-10-23 12:08:35 -04:00
|
|
|
expect(wrapper.find('[data-test="datasource-menu"]')).toExist();
|
|
|
|
let menuWrapper = shallow(
|
|
|
|
<div>
|
|
|
|
{wrapper.find('[data-test="datasource-menu"]').prop('overlay')}
|
|
|
|
</div>,
|
2020-05-07 17:18:10 -04:00
|
|
|
);
|
2020-10-23 12:08:35 -04:00
|
|
|
expect(menuWrapper.find(Menu.Item)).toHaveLength(3);
|
2020-04-30 20:32:01 -04:00
|
|
|
|
|
|
|
wrapper = setup({
|
2020-07-10 15:46:25 -04:00
|
|
|
isEditable: false,
|
2020-04-30 20:32:01 -04:00
|
|
|
});
|
2020-10-23 12:08:35 -04:00
|
|
|
expect(wrapper.find('[data-test="datasource-menu"]')).toExist();
|
|
|
|
menuWrapper = shallow(
|
|
|
|
<div>
|
|
|
|
{wrapper.find('[data-test="datasource-menu"]').prop('overlay')}
|
|
|
|
</div>,
|
2020-05-07 17:18:10 -04:00
|
|
|
);
|
2020-10-23 12:08:35 -04:00
|
|
|
expect(menuWrapper.find(Menu.Item)).toHaveLength(2);
|
2020-04-30 20:32:01 -04:00
|
|
|
});
|
2017-08-01 15:08:00 -04:00
|
|
|
});
|