dashboards_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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("Given a dashboard json", t, func() {
  14. json := simplejson.New()
  15. json.Set("title", "test dash")
  16. Convey("With tags as string value", func() {
  17. json.Set("tags", "")
  18. dash := NewDashboardFromJson(json)
  19. So(len(dash.GetTags()), ShouldEqual, 0)
  20. })
  21. })
  22. Convey("Given a new dashboard folder", t, func() {
  23. json := simplejson.New()
  24. json.Set("title", "test dash")
  25. cmd := &SaveDashboardCommand{Dashboard: json, IsFolder: true}
  26. dash := cmd.GetDashboardModel()
  27. Convey("Should set IsFolder to true", func() {
  28. So(dash.IsFolder, ShouldBeTrue)
  29. })
  30. })
  31. Convey("Given a child dashboard", t, func() {
  32. json := simplejson.New()
  33. json.Set("title", "test dash")
  34. cmd := &SaveDashboardCommand{Dashboard: json, ParentId: 1}
  35. dash := cmd.GetDashboardModel()
  36. Convey("Should set ParentId", func() {
  37. So(dash.ParentId, ShouldEqual, 1)
  38. })
  39. })
  40. }