datasource_srv_specs.js 1.8 KB

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