datasource_srv.jest.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import config from 'app/core/config';
  2. import 'app/features/plugins/datasource_srv';
  3. import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
  4. describe('datasource_srv', function() {
  5. let _datasourceSrv = new DatasourceSrv({}, {}, {}, {});
  6. let metricSources;
  7. describe('when loading metric sources', () => {
  8. let unsortedDatasources = {
  9. mmm: {
  10. type: 'test-db',
  11. meta: { metrics: { m: 1 } },
  12. },
  13. '--Grafana--': {
  14. type: 'grafana',
  15. meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
  16. },
  17. '--Mixed--': {
  18. type: 'test-db',
  19. meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
  20. },
  21. ZZZ: {
  22. type: 'test-db',
  23. meta: { metrics: { m: 1 } },
  24. },
  25. aaa: {
  26. type: 'test-db',
  27. meta: { metrics: { m: 1 } },
  28. },
  29. BBB: {
  30. type: 'test-db',
  31. meta: { metrics: { m: 1 } },
  32. },
  33. };
  34. beforeEach(() => {
  35. config.datasources = unsortedDatasources;
  36. metricSources = _datasourceSrv.getMetricSources({ skipVariables: true });
  37. });
  38. it('should return a list of sources sorted case insensitively with builtin sources last', () => {
  39. expect(metricSources[0].name).toBe('aaa');
  40. expect(metricSources[1].name).toBe('BBB');
  41. expect(metricSources[2].name).toBe('mmm');
  42. expect(metricSources[3].name).toBe('ZZZ');
  43. expect(metricSources[4].name).toBe('--Grafana--');
  44. expect(metricSources[5].name).toBe('--Mixed--');
  45. });
  46. beforeEach(() => {
  47. config.defaultDatasource = 'BBB';
  48. });
  49. it('should set default data source', () => {
  50. expect(metricSources[2].name).toBe('default');
  51. expect(metricSources[2].sort).toBe('BBB');
  52. });
  53. });
  54. });