From 540def2c39eaaf9add12822413f829423f60a328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 27 May 2016 13:52:19 +0200 Subject: [PATCH] feat(import): working on unit tests for import ctrl --- conf/defaults.ini | 3 ++ pkg/api/gnetproxy.go | 3 +- pkg/setting/setting.go | 5 ++ .../import/{import.html => dash_import.html} | 16 +++++- .../import/{import.ts => dash_import.ts} | 2 +- .../dashboard/specs/dash_import_ctrl_specs.ts | 50 +++++++++++++++++++ .../dashboard/specs/exporter_specs.ts | 2 +- 7 files changed, 77 insertions(+), 4 deletions(-) rename public/app/features/dashboard/import/{import.html => dash_import.html} (84%) rename public/app/features/dashboard/import/{import.ts => dash_import.ts} (97%) create mode 100644 public/app/features/dashboard/specs/dash_import_ctrl_specs.ts diff --git a/conf/defaults.ini b/conf/defaults.ini index 0a4b61fbe78..64dc7c4f344 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -335,3 +335,6 @@ global_api_key = -1 # global limit on number of logged in users. global_session = -1 + +[grafana_net] +url = https://grafana.net diff --git a/pkg/api/gnetproxy.go b/pkg/api/gnetproxy.go index 6511afd39b7..344cd3fe926 100644 --- a/pkg/api/gnetproxy.go +++ b/pkg/api/gnetproxy.go @@ -8,6 +8,7 @@ import ( "time" "github.com/grafana/grafana/pkg/middleware" + "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" ) @@ -27,7 +28,7 @@ func ReverseProxyGnetReq(proxyPath string) *httputil.ReverseProxy { req.URL.Host = "grafana.net" req.Host = "grafana.net" - req.URL.Path = util.JoinUrlFragments("https://grafana.net/api", proxyPath) + req.URL.Path = util.JoinUrlFragments(setting.GrafanaNetUrl+"/api", proxyPath) // clear cookie headers req.Header.Del("Cookie") diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 413fb2fc9a0..5291ef748b8 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -138,6 +138,9 @@ var ( // QUOTA Quota QuotaSettings + + // Grafana.NET URL + GrafanaNetUrl string ) type CommandLineArgs struct { @@ -494,6 +497,8 @@ func NewConfigContext(args *CommandLineArgs) error { log.Warn("require_email_validation is enabled but smpt is disabled") } + GrafanaNetUrl = Cfg.Section("grafana.net").Key("url").MustString("https://grafana.net") + return nil } diff --git a/public/app/features/dashboard/import/import.html b/public/app/features/dashboard/import/dash_import.html similarity index 84% rename from public/app/features/dashboard/import/import.html rename to public/app/features/dashboard/import/dash_import.html index 5227569fcd8..65333a24ffa 100644 --- a/public/app/features/dashboard/import/import.html +++ b/public/app/features/dashboard/import/dash_import.html @@ -18,7 +18,21 @@ -
Or paste JSON:
+
Grafana.net Dashboard
+ +
+
+ +
+
+ +
+
+ +
Or paste JSON
diff --git a/public/app/features/dashboard/import/import.ts b/public/app/features/dashboard/import/dash_import.ts similarity index 97% rename from public/app/features/dashboard/import/import.ts rename to public/app/features/dashboard/import/dash_import.ts index 873b6d5d956..2bb6508ff01 100644 --- a/public/app/features/dashboard/import/import.ts +++ b/public/app/features/dashboard/import/dash_import.ts @@ -126,7 +126,7 @@ export class DashImportCtrl { export function dashImportDirective() { return { restrict: 'E', - templateUrl: 'public/app/features/dashboard/import/import.html', + templateUrl: 'public/app/features/dashboard/import/dash_import.html', controller: DashImportCtrl, bindToController: true, controllerAs: 'ctrl', diff --git a/public/app/features/dashboard/specs/dash_import_ctrl_specs.ts b/public/app/features/dashboard/specs/dash_import_ctrl_specs.ts new file mode 100644 index 00000000000..77fb3b30978 --- /dev/null +++ b/public/app/features/dashboard/specs/dash_import_ctrl_specs.ts @@ -0,0 +1,50 @@ +import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common'; + +import {DashImportCtrl} from 'app/features/dashboard/import/dash_import'; +import config from 'app/core/config'; + +describe('DashImportCtrl', function() { + var ctx: any = {}; + var backendSrv = { + search: sinon.stub().returns(Promise.resolve([])), + }; + + beforeEach(angularMocks.module('grafana.core')); + + beforeEach(angularMocks.inject(($rootScope, $controller, $q) => { + ctx.$q = $q; + ctx.scope = $rootScope.$new(); + ctx.ctrl = $controller(DashImportCtrl, { + $scope: ctx.scope, + backendSrv: backendSrv, + }); + })); + + describe('when upload json', function() { + beforeEach(function() { + config.datasources = { + ds: { + type: 'test-db', + } + }; + + ctx.ctrl.onUpload({ + '__inputs': [ + {name: 'ds', pluginId: 'test-db', type: 'datasource', pluginName: 'Test DB'} + ] + }); + }); + + it('should build input model', function() { + expect(ctx.ctrl.inputs.length).to.eql(1); + expect(ctx.ctrl.inputs[0].label).to.eql(1); + }); + + it('should set inputValid to false', function() { + expect(ctx.ctrl.inputsValid).to.eql(false); + }); + + }); +}); + + diff --git a/public/app/features/dashboard/specs/exporter_specs.ts b/public/app/features/dashboard/specs/exporter_specs.ts index 811ca0f563d..da2faec962c 100644 --- a/public/app/features/dashboard/specs/exporter_specs.ts +++ b/public/app/features/dashboard/specs/exporter_specs.ts @@ -4,7 +4,7 @@ import _ from 'lodash'; import config from 'app/core/config'; import {DashboardExporter} from '../export/exporter'; -describe.only('given dashboard with repeated panels', function() { +describe('given dashboard with repeated panels', function() { var dash, exported; beforeEach(done => {