2018-11-01 07:45:52 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2019-01-17 11:51:07 -06:00
|
|
|
import { DataSourceSettingsPage, Props } from './DataSourceSettingsPage';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { DataSourceSettings, DataSourcePlugin, DataSourceConstructor, NavModel } from '@grafana/data';
|
2018-11-01 07:45:52 -05:00
|
|
|
import { getMockDataSource } from '../__mocks__/dataSourcesMocks';
|
|
|
|
import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks';
|
2019-09-02 13:45:42 -05:00
|
|
|
import { setDataSourceName, setIsDefault, dataSourceLoaded } from '../state/actions';
|
2018-11-01 07:45:52 -05:00
|
|
|
|
2019-04-24 16:18:51 -05:00
|
|
|
const pluginMock = new DataSourcePlugin({} as DataSourceConstructor<any>);
|
|
|
|
|
2019-05-20 04:41:22 -05:00
|
|
|
jest.mock('app/features/plugins/plugin_loader', () => {
|
|
|
|
return {
|
|
|
|
importDataSourcePlugin: () => Promise.resolve(pluginMock),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-11-01 07:45:52 -05:00
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
const props: Props = {
|
|
|
|
navModel: {} as NavModel,
|
|
|
|
dataSource: getMockDataSource(),
|
|
|
|
dataSourceMeta: getMockPlugin(),
|
|
|
|
pageId: 1,
|
|
|
|
deleteDataSource: jest.fn(),
|
|
|
|
loadDataSource: jest.fn(),
|
2019-01-30 13:07:14 -06:00
|
|
|
setDataSourceName,
|
2018-11-01 07:45:52 -05:00
|
|
|
updateDataSource: jest.fn(),
|
2019-01-30 13:07:14 -06:00
|
|
|
setIsDefault,
|
2019-09-02 13:45:42 -05:00
|
|
|
dataSourceLoaded,
|
2019-05-14 00:55:49 -05:00
|
|
|
query: {},
|
2019-04-24 16:18:51 -05:00
|
|
|
...propOverrides,
|
2018-11-01 07:45:52 -05:00
|
|
|
};
|
|
|
|
|
2019-01-17 11:51:07 -06:00
|
|
|
return shallow(<DataSourceSettingsPage {...props} />);
|
2018-11-01 07:45:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('Render', () => {
|
|
|
|
it('should render component', () => {
|
|
|
|
const wrapper = setup();
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render loader', () => {
|
|
|
|
const wrapper = setup({
|
2019-01-17 11:51:07 -06:00
|
|
|
dataSource: {} as DataSourceSettings,
|
2019-04-24 16:18:51 -05:00
|
|
|
plugin: pluginMock,
|
2018-11-01 07:45:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render beta info text', () => {
|
|
|
|
const wrapper = setup({
|
|
|
|
dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render alpha info text', () => {
|
|
|
|
const wrapper = setup({
|
|
|
|
dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
|
2019-04-24 16:18:51 -05:00
|
|
|
plugin: pluginMock,
|
2018-11-01 07:45:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render is ready only message', () => {
|
|
|
|
const wrapper = setup({
|
|
|
|
dataSource: { ...getMockDataSource(), readOnly: true },
|
2019-04-24 16:18:51 -05:00
|
|
|
plugin: pluginMock,
|
2018-11-01 07:45:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|