mirror of
https://github.com/grafana/grafana.git
synced 2025-09-25 16:54:15 +08:00

* moved the datasource picker to grafana-runtime. * fixed imports. * added e2e selectors as an external package. * adding react as external package. * exposing dependent types for DataSourcePicker. * added docs for ui components. * moving component to components.
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
import { shallow } from 'enzyme';
|
|
import { DerivedField } from './DerivedField';
|
|
import { DataSourcePicker } from '@grafana/runtime';
|
|
import { DataSourceInstanceSettings } from '@grafana/data';
|
|
|
|
jest.mock('app/features/plugins/datasource_srv', () => ({
|
|
getDatasourceSrv() {
|
|
return {
|
|
getExternal(): DataSourceInstanceSettings[] {
|
|
return [
|
|
{
|
|
id: 1,
|
|
uid: 'metrics',
|
|
name: 'metrics_ds',
|
|
meta: {
|
|
tracing: false,
|
|
} as any,
|
|
} as any,
|
|
|
|
{
|
|
id: 2,
|
|
uid: 'tracing',
|
|
name: 'tracing_ds',
|
|
meta: {
|
|
tracing: true,
|
|
} as any,
|
|
} as any,
|
|
];
|
|
},
|
|
};
|
|
},
|
|
}));
|
|
|
|
describe('DerivedField', () => {
|
|
it('shows internal link if uid is set', () => {
|
|
const value = {
|
|
matcherRegex: '',
|
|
name: '',
|
|
datasourceUid: 'test',
|
|
};
|
|
const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
|
|
|
|
expect(wrapper.find(DataSourcePicker).length).toBe(1);
|
|
});
|
|
|
|
it('shows url link if uid is not set', () => {
|
|
const value = {
|
|
matcherRegex: '',
|
|
name: '',
|
|
url: 'test',
|
|
};
|
|
const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
|
|
expect(wrapper.find(DataSourcePicker).length).toBe(0);
|
|
});
|
|
|
|
it('shows only tracing datasources for internal link', () => {
|
|
const value = {
|
|
matcherRegex: '',
|
|
name: '',
|
|
datasourceUid: 'test',
|
|
};
|
|
const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
|
|
expect(wrapper.find(DataSourcePicker).props().tracing).toEqual(true);
|
|
});
|
|
});
|