Skip to content

Commit 56cdea6

Browse files
authored
board_visual: add TextPanel tests (#172)
Add TextPanel tests that test whether it actually works on Grafana.
1 parent 84e6baa commit 56cdea6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

board_visual_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sdk_test
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"testing"
78
"time"
89

@@ -63,6 +64,11 @@ func TestSinglestatPanel(t *testing.T) {
6364
panel.SinglestatPanel.ValueName = "avg"
6465

6566
r.Add(panel)
67+
68+
textPanel := sdk.NewText("text")
69+
textPanel.TextPanel.Content = "content"
70+
textPanel.TextPanel.Mode = "markdown"
71+
r.Add(textPanel)
6672
cl := getClient(t)
6773

6874
db, err := cl.SetDashboard(context.TODO(), *b, sdk.SetDashboardParams{
@@ -72,6 +78,12 @@ func TestSinglestatPanel(t *testing.T) {
7278
if err != nil {
7379
t.Fatalf("failed setting dashboard: %v", err)
7480
}
81+
t.Cleanup(func() {
82+
_, err := cl.DeleteDashboardByUID(context.TODO(), *db.UID)
83+
if err != nil {
84+
t.Fatal("failed cleaning up due to", err.Error())
85+
}
86+
})
7587

7688
durl := getDebugURL(t)
7789

@@ -106,4 +118,17 @@ func TestSinglestatPanel(t *testing.T) {
106118
if res == "" {
107119
t.Fatalf("expected single-stat panel to have some value")
108120
}
121+
122+
err = chromedp.Run(ctx,
123+
chromedp.Navigate(fullAddr),
124+
chromedp.WaitReady(`grafana-app`),
125+
chromedp.TextContent(`p.markdown-html`, &res, chromedp.NodeVisible, chromedp.ByQuery),
126+
)
127+
if err != nil {
128+
t.Fatalf("running chromedp has failed: %v", err)
129+
}
130+
131+
if strings.TrimSpace(res) != `content` {
132+
t.Fatalf("expected text panel to have the correct value, got: %s", res)
133+
}
109134
}

0 commit comments

Comments
 (0)