DerivedField.test.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { DataSourceInstanceSettings } from '@grafana/data';
  4. import { DataSourcePicker } from '@grafana/runtime';
  5. import { DerivedField } from './DerivedField';
  6. jest.mock('app/features/plugins/datasource_srv', () => ({
  7. getDatasourceSrv() {
  8. return {
  9. getExternal(): DataSourceInstanceSettings[] {
  10. return [
  11. {
  12. id: 1,
  13. uid: 'metrics',
  14. name: 'metrics_ds',
  15. meta: {
  16. tracing: false,
  17. } as any,
  18. } as any,
  19. {
  20. id: 2,
  21. uid: 'tracing',
  22. name: 'tracing_ds',
  23. meta: {
  24. tracing: true,
  25. } as any,
  26. } as any,
  27. ];
  28. },
  29. };
  30. },
  31. }));
  32. describe('DerivedField', () => {
  33. it('shows internal link if uid is set', () => {
  34. const value = {
  35. matcherRegex: '',
  36. name: '',
  37. datasourceUid: 'test',
  38. };
  39. const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
  40. expect(wrapper.find(DataSourcePicker).length).toBe(1);
  41. });
  42. it('shows url link if uid is not set', () => {
  43. const value = {
  44. matcherRegex: '',
  45. name: '',
  46. url: 'test',
  47. };
  48. const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
  49. expect(wrapper.find(DataSourcePicker).length).toBe(0);
  50. });
  51. it('shows only tracing datasources for internal link', () => {
  52. const value = {
  53. matcherRegex: '',
  54. name: '',
  55. datasourceUid: 'test',
  56. };
  57. const wrapper = shallow(<DerivedField value={value} onChange={() => {}} onDelete={() => {}} suggestions={[]} />);
  58. expect(wrapper.find(DataSourcePicker).props().tracing).toEqual(true);
  59. });
  60. });