2014-08-22 08:32:42 -05:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-03-11 17:13:06 -06:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2018-03-27 13:24:11 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2014-08-22 08:32:42 -05:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDashboardModel(t *testing.T) {
|
|
|
|
|
2018-03-27 13:24:11 -05:00
|
|
|
Convey("Generate full dashboard url", t, func() {
|
|
|
|
setting.AppUrl = "http://grafana.local/"
|
|
|
|
fullUrl := GetFullDashboardUrl("uid", "my-dashboard")
|
|
|
|
So(fullUrl, ShouldEqual, "http://grafana.local/d/uid/my-dashboard")
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Generate relative dashboard url", t, func() {
|
|
|
|
setting.AppUrl = ""
|
|
|
|
fullUrl := GetDashboardUrl("uid", "my-dashboard")
|
|
|
|
So(fullUrl, ShouldEqual, "/d/uid/my-dashboard")
|
|
|
|
})
|
|
|
|
|
2014-08-22 08:32:42 -05:00
|
|
|
Convey("When generating slug", t, func() {
|
|
|
|
dashboard := NewDashboard("Grafana Play Home")
|
|
|
|
dashboard.UpdateSlug()
|
|
|
|
|
|
|
|
So(dashboard.Slug, ShouldEqual, "grafana-play-home")
|
|
|
|
})
|
|
|
|
|
2017-12-27 09:32:39 -06:00
|
|
|
Convey("Can slugify title", t, func() {
|
|
|
|
slug := SlugifyTitle("Grafana Play Home")
|
|
|
|
|
|
|
|
So(slug, ShouldEqual, "grafana-play-home")
|
|
|
|
})
|
|
|
|
|
2015-06-12 02:04:10 -05:00
|
|
|
Convey("Given a dashboard json", t, func() {
|
2016-03-11 17:13:06 -06:00
|
|
|
json := simplejson.New()
|
|
|
|
json.Set("title", "test dash")
|
2015-06-12 02:04:10 -05:00
|
|
|
|
|
|
|
Convey("With tags as string value", func() {
|
2016-03-11 17:13:06 -06:00
|
|
|
json.Set("tags", "")
|
2015-06-12 02:04:10 -05:00
|
|
|
dash := NewDashboardFromJson(json)
|
|
|
|
|
|
|
|
So(len(dash.GetTags()), ShouldEqual, 0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-06-02 04:49:27 -05:00
|
|
|
Convey("Given a new dashboard folder", t, func() {
|
|
|
|
json := simplejson.New()
|
|
|
|
json.Set("title", "test dash")
|
|
|
|
|
|
|
|
cmd := &SaveDashboardCommand{Dashboard: json, IsFolder: true}
|
|
|
|
dash := cmd.GetDashboardModel()
|
|
|
|
|
|
|
|
Convey("Should set IsFolder to true", func() {
|
|
|
|
So(dash.IsFolder, ShouldBeTrue)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Given a child dashboard", t, func() {
|
|
|
|
json := simplejson.New()
|
|
|
|
json.Set("title", "test dash")
|
|
|
|
|
2017-06-23 15:00:26 -05:00
|
|
|
cmd := &SaveDashboardCommand{Dashboard: json, FolderId: 1}
|
2017-06-02 04:49:27 -05:00
|
|
|
dash := cmd.GetDashboardModel()
|
|
|
|
|
2017-06-23 15:00:26 -05:00
|
|
|
Convey("Should set FolderId", func() {
|
|
|
|
So(dash.FolderId, ShouldEqual, 1)
|
2017-06-02 04:49:27 -05:00
|
|
|
})
|
|
|
|
})
|
2014-08-22 08:32:42 -05:00
|
|
|
}
|