/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["test/lib/common","lodash","app/core/config","../export/exporter"],function(a){var b,c,d,e;return{setters:[function(a){b=a},function(a){c=a},function(a){d=a},function(a){e=a}],execute:function(){b.describe("given dashboard with repeated panels",function(){var a,f;b.beforeEach(function(c){a={rows:[],templating:{list:[]},annotations:{list:[]}},d["default"].buildInfo={version:"3.0.2"},a.templating.list.push({name:"apps",type:"query",datasource:"gfdb",current:{value:"Asd",text:"Asd"},options:[{value:"Asd",text:"Asd"}]}),a.templating.list.push({name:"prefix",type:"constant",current:{value:"collectd",text:"collectd"},options:[]}),a.annotations.list.push({name:"logs",datasource:"gfdb"}),a.rows.push({repeat:"test",panels:[{id:2,repeat:"apps",datasource:"gfdb",type:"graph"},{id:2,repeat:null,repeatPanelId:2}]}),a.rows.push({repeat:null,repeatRowId:1});var g={get:b.sinon.stub().returns(Promise.resolve({name:"gfdb",meta:{id:"testdb",info:{version:"1.2.1"},name:"TestDB"}}))};d["default"].panels.graph={id:"graph",name:"Graph",info:{version:"1.1.0"}};var h=new e.DashboardExporter(g);h.makeExportable(a).then(function(a){f=a,c()})}),b.it("exported dashboard should not contain repeated panels",function(){b.expect(f.rows[0].panels.length).to.be(1)}),b.it("exported dashboard should not contain repeated rows",function(){b.expect(f.rows.length).to.be(1)}),b.it("should replace datasource refs",function(){var a=f.rows[0].panels[0];b.expect(a.datasource).to.be("${DS_GFDB}")}),b.it("should replace datasource in variable query",function(){b.expect(f.templating.list[0].datasource).to.be("${DS_GFDB}"),b.expect(f.templating.list[0].options.length).to.be(0),b.expect(f.templating.list[0].current.value).to.be(void 0),b.expect(f.templating.list[0].current.text).to.be(void 0)}),b.it("should replace datasource in annotation query",function(){b.expect(f.annotations.list[0].datasource).to.be("${DS_GFDB}")}),b.it("should add datasource as input",function(){b.expect(f.__inputs[0].name).to.be("DS_GFDB"),b.expect(f.__inputs[0].pluginId).to.be("testdb"),b.expect(f.__inputs[0].type).to.be("datasource")}),b.it("should add datasource to required",function(){var a=c["default"].findWhere(f.__requires,{name:"TestDB"});b.expect(a.name).to.be("TestDB"),b.expect(a.id).to.be("testdb"),b.expect(a.type).to.be("datasource"),b.expect(a.version).to.be("1.2.1")}),b.it("should add panel to required",function(){var a=c["default"].findWhere(f.__requires,{name:"Graph"});b.expect(a.name).to.be("Graph"),b.expect(a.id).to.be("graph"),b.expect(a.version).to.be("1.1.0")}),b.it("should add grafana version",function(){var a=c["default"].findWhere(f.__requires,{name:"Grafana"});b.expect(a.type).to.be("grafana"),b.expect(a.id).to.be("grafana"),b.expect(a.version).to.be("3.0.2")}),b.it("should add constant template variables as inputs",function(){var a=c["default"].findWhere(f.__inputs,{name:"VAR_PREFIX"});b.expect(a.type).to.be("constant"),b.expect(a.label).to.be("prefix"),b.expect(a.value).to.be("collectd")}),b.it("should templatize constant variables",function(){var a=c["default"].findWhere(f.templating.list,{name:"prefix"});b.expect(a.query).to.be("${VAR_PREFIX}"),b.expect(a.current.text).to.be("${VAR_PREFIX}"),b.expect(a.current.value).to.be("${VAR_PREFIX}"),b.expect(a.options[0].text).to.be("${VAR_PREFIX}"),b.expect(a.options[0].value).to.be("${VAR_PREFIX}")})})}}});