datasource_srv_specs.ts 1.9 KB

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