dashboards_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package models
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/components/simplejson"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDashboardModel(t *testing.T) {
  8. Convey("When generating slug", t, func() {
  9. dashboard := NewDashboard("Grafana Play Home")
  10. dashboard.UpdateSlug()
  11. So(dashboard.Slug, ShouldEqual, "grafana-play-home")
  12. })
  13. Convey("Can slugify title", t, func() {
  14. slug := SlugifyTitle("Grafana Play Home")
  15. So(slug, ShouldEqual, "grafana-play-home")
  16. })
  17. Convey("Given a dashboard json", t, func() {
  18. json := simplejson.New()
  19. json.Set("title", "test dash")
  20. Convey("With tags as string value", func() {
  21. json.Set("tags", "")
  22. dash := NewDashboardFromJson(json)
  23. So(len(dash.GetTags()), ShouldEqual, 0)
  24. })
  25. })
  26. Convey("Given a new dashboard folder", t, func() {
  27. json := simplejson.New()
  28. json.Set("title", "test dash")
  29. cmd := &SaveDashboardCommand{Dashboard: json, IsFolder: true}
  30. dash := cmd.GetDashboardModel()
  31. Convey("Should set IsFolder to true", func() {
  32. So(dash.IsFolder, ShouldBeTrue)
  33. })
  34. })
  35. Convey("Given a child dashboard", t, func() {
  36. json := simplejson.New()
  37. json.Set("title", "test dash")
  38. cmd := &SaveDashboardCommand{Dashboard: json, FolderId: 1}
  39. dash := cmd.GetDashboardModel()
  40. Convey("Should set FolderId", func() {
  41. So(dash.FolderId, ShouldEqual, 1)
  42. })
  43. })
  44. }