datasource_srv_specs.ts 1.8 KB

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