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.
|
|
|
|
*/
|
2018-08-06 18:30:13 -04:00
|
|
|
import React from 'react';
|
|
|
|
import { Tabs } from 'react-bootstrap';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import configureStore from 'redux-mock-store';
|
2018-10-19 14:41:11 -04:00
|
|
|
import fetchMock from 'fetch-mock';
|
|
|
|
import thunk from 'redux-thunk';
|
2018-08-06 18:30:13 -04:00
|
|
|
|
2020-05-07 17:18:10 -04:00
|
|
|
import DatasourceEditor from 'src/datasource/DatasourceEditor';
|
|
|
|
import Field from 'src/CRUD/Field';
|
2018-08-06 18:30:13 -04:00
|
|
|
import mockDatasource from '../../fixtures/mockDatasource';
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
datasource: mockDatasource['7__table'],
|
|
|
|
addSuccessToast: () => {},
|
|
|
|
addDangerToast: () => {},
|
2018-10-19 14:41:11 -04:00
|
|
|
onChange: () => {},
|
2018-08-06 18:30:13 -04:00
|
|
|
};
|
2018-10-19 14:41:11 -04:00
|
|
|
|
2018-08-06 18:30:13 -04:00
|
|
|
const extraColumn = {
|
|
|
|
column_name: 'new_column',
|
|
|
|
type: 'VARCHAR(10)',
|
|
|
|
description: null,
|
|
|
|
filterable: true,
|
|
|
|
verbose_name: null,
|
|
|
|
is_dttm: false,
|
|
|
|
expression: '',
|
|
|
|
groupby: true,
|
|
|
|
};
|
|
|
|
|
2018-10-19 14:41:11 -04:00
|
|
|
const DATASOURCE_ENDPOINT = 'glob:*/datasource/external_metadata/*';
|
|
|
|
|
2018-08-06 18:30:13 -04:00
|
|
|
describe('DatasourceEditor', () => {
|
2018-10-19 14:41:11 -04:00
|
|
|
const mockStore = configureStore([thunk]);
|
2018-08-06 18:30:13 -04:00
|
|
|
const store = mockStore({});
|
2018-10-19 14:41:11 -04:00
|
|
|
fetchMock.get(DATASOURCE_ENDPOINT, []);
|
2018-08-06 18:30:13 -04:00
|
|
|
|
|
|
|
let wrapper;
|
|
|
|
let el;
|
|
|
|
let inst;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
el = <DatasourceEditor {...props} />;
|
|
|
|
wrapper = shallow(el, { context: { store } }).dive();
|
|
|
|
inst = wrapper.instance();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is valid', () => {
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(React.isValidElement(el)).toBe(true);
|
2018-08-06 18:30:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Tabs', () => {
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.find(Tabs)).toHaveLength(1);
|
2018-08-06 18:30:13 -04:00
|
|
|
});
|
|
|
|
|
2020-06-29 00:37:04 -04:00
|
|
|
it('makes an async request', () => {
|
|
|
|
return new Promise(done => {
|
|
|
|
wrapper.setState({ activeTabKey: 2 });
|
|
|
|
const syncButton = wrapper.find('.sync-from-source');
|
|
|
|
expect(syncButton).toHaveLength(1);
|
|
|
|
syncButton.simulate('click');
|
2018-10-19 14:41:11 -04:00
|
|
|
|
2020-06-29 00:37:04 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(fetchMock.calls(DATASOURCE_ENDPOINT)).toHaveLength(1);
|
|
|
|
fetchMock.reset();
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
2018-08-06 18:30:13 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('merges columns', () => {
|
|
|
|
const numCols = props.datasource.columns.length;
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(inst.state.databaseColumns).toHaveLength(numCols);
|
2018-08-06 18:30:13 -04:00
|
|
|
inst.mergeColumns([extraColumn]);
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(inst.state.databaseColumns).toHaveLength(numCols + 1);
|
2018-08-06 18:30:13 -04:00
|
|
|
});
|
2018-10-29 13:33:03 -04:00
|
|
|
|
|
|
|
it('renders isSqla fields', () => {
|
2019-10-29 18:26:11 -04:00
|
|
|
wrapper.setState({ activeTabKey: 4 });
|
2018-10-29 13:33:03 -04:00
|
|
|
expect(wrapper.state('isSqla')).toBe(true);
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
2020-05-07 17:18:10 -04:00
|
|
|
wrapper.find(Field).find({ fieldKey: 'fetch_values_predicate' }).exists(),
|
2019-11-27 17:02:48 -05:00
|
|
|
).toBe(true);
|
2018-10-29 13:33:03 -04:00
|
|
|
});
|
2018-08-06 18:30:13 -04:00
|
|
|
});
|