dash_import_ctrl_specs.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
  2. import {DashImportCtrl} from 'app/features/dashboard/import/dash_import';
  3. import config from 'app/core/config';
  4. describe('DashImportCtrl', function() {
  5. var ctx: any = {};
  6. var backendSrv = {
  7. search: sinon.stub().returns(Promise.resolve([])),
  8. get: sinon.stub()
  9. };
  10. beforeEach(angularMocks.module('grafana.core'));
  11. beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
  12. ctx.$q = $q;
  13. ctx.scope = $rootScope.$new();
  14. ctx.ctrl = $controller(DashImportCtrl, {
  15. $scope: ctx.scope,
  16. backendSrv: backendSrv,
  17. });
  18. }));
  19. describe('when uploading json', function() {
  20. beforeEach(function() {
  21. config.datasources = {
  22. ds: {
  23. type: 'test-db',
  24. }
  25. };
  26. ctx.ctrl.onUpload({
  27. '__inputs': [
  28. {name: 'ds', pluginId: 'test-db', type: 'datasource', pluginName: 'Test DB'}
  29. ]
  30. });
  31. });
  32. it('should build input model', function() {
  33. expect(ctx.ctrl.inputs.length).to.eql(1);
  34. expect(ctx.ctrl.inputs[0].name).to.eql('ds');
  35. expect(ctx.ctrl.inputs[0].info).to.eql('Select a Test DB data source');
  36. });
  37. it('should set inputValid to false', function() {
  38. expect(ctx.ctrl.inputsValid).to.eql(false);
  39. });
  40. });
  41. describe('when specifing grafana.net url', function() {
  42. beforeEach(function() {
  43. ctx.ctrl.gnetUrl = 'http://grafana.net/dashboards/123';
  44. // setup api mock
  45. backendSrv.get = sinon.spy(() => {
  46. return Promise.resolve({
  47. });
  48. });
  49. ctx.ctrl.checkGnetDashboard();
  50. });
  51. it('should call gnet api with correct dashboard id', function() {
  52. expect(backendSrv.get.getCall(0).args[0]).to.eql('api/gnet/dashboards/123');
  53. });
  54. });
  55. describe('when specifing dashbord id', function() {
  56. beforeEach(function() {
  57. ctx.ctrl.gnetUrl = '2342';
  58. // setup api mock
  59. backendSrv.get = sinon.spy(() => {
  60. return Promise.resolve({
  61. });
  62. });
  63. ctx.ctrl.checkGnetDashboard();
  64. });
  65. it('should call gnet api with correct dashboard id', function() {
  66. expect(backendSrv.get.getCall(0).args[0]).to.eql('api/gnet/dashboards/2342');
  67. });
  68. });
  69. });