datasource_srv_specs.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
  2. import config from 'app/core/config';
  3. import 'app/features/plugins/datasource_srv';
  4. describe('datasource_srv', function() {
  5. var _datasourceSrv;
  6. var metricSources;
  7. var templateSrv = {};
  8. beforeEach(angularMocks.module('grafana.core'));
  9. beforeEach(
  10. angularMocks.module(function($provide) {
  11. $provide.value('templateSrv', templateSrv);
  12. })
  13. );
  14. beforeEach(angularMocks.module('grafana.services'));
  15. beforeEach(
  16. angularMocks.inject(function(datasourceSrv) {
  17. _datasourceSrv = datasourceSrv;
  18. })
  19. );
  20. describe('when loading metric sources', function() {
  21. var unsortedDatasources = {
  22. mmm: {
  23. type: 'test-db',
  24. meta: { metrics: { m: 1 } },
  25. },
  26. '--Grafana--': {
  27. type: 'grafana',
  28. meta: { builtIn: true, metrics: { m: 1 }, id: 'grafana' },
  29. },
  30. '--Mixed--': {
  31. type: 'test-db',
  32. meta: { builtIn: true, metrics: { m: 1 }, id: 'mixed' },
  33. },
  34. ZZZ: {
  35. type: 'test-db',
  36. meta: { metrics: { m: 1 } },
  37. },
  38. aaa: {
  39. type: 'test-db',
  40. meta: { metrics: { m: 1 } },
  41. },
  42. BBB: {
  43. type: 'test-db',
  44. meta: { metrics: { m: 1 } },
  45. },
  46. };
  47. beforeEach(function() {
  48. config.datasources = unsortedDatasources;
  49. metricSources = _datasourceSrv.getMetricSources({ skipVariables: true });
  50. });
  51. it('should return a list of sources sorted case insensitively with builtin sources last', function() {
  52. expect(metricSources[0].name).to.be('aaa');
  53. expect(metricSources[1].name).to.be('BBB');
  54. expect(metricSources[2].name).to.be('mmm');
  55. expect(metricSources[3].name).to.be('ZZZ');
  56. expect(metricSources[4].name).to.be('--Grafana--');
  57. expect(metricSources[5].name).to.be('--Mixed--');
  58. });
  59. });
  60. });