Skip to content

Commit

Permalink
board_visual: add TextPanel tests (grafana-tools#172)
Browse files Browse the repository at this point in the history
Add TextPanel tests that test whether it actually works on Grafana.
  • Loading branch information
GiedriusS authored and wurbanski committed Mar 30, 2022
1 parent c86aa68 commit b02c34d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions board_visual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sdk_test
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -62,6 +63,11 @@ func TestSinglestatPanel(t *testing.T) {
panel.SinglestatPanel.ValueName = "avg"

r.Add(panel)

textPanel := sdk.NewText("text")
textPanel.TextPanel.Content = "content"
textPanel.TextPanel.Mode = "markdown"
r.Add(textPanel)
cl := getClient(t)

db, err := cl.SetDashboard(context.TODO(), *b, sdk.SetDashboardParams{
Expand All @@ -71,6 +77,12 @@ func TestSinglestatPanel(t *testing.T) {
if err != nil {
t.Fatalf("failed setting dashboard: %v", err)
}
t.Cleanup(func() {
_, err := cl.DeleteDashboardByUID(context.TODO(), *db.UID)
if err != nil {
t.Fatal("failed cleaning up due to", err.Error())
}
})

durl := getDebugURL(t)

Expand Down Expand Up @@ -105,4 +117,17 @@ func TestSinglestatPanel(t *testing.T) {
if res == "" {
t.Fatalf("expected single-stat panel to have some value")
}

err = chromedp.Run(ctx,
chromedp.Navigate(fullAddr),
chromedp.WaitReady(`grafana-app`),
chromedp.TextContent(`p.markdown-html`, &res, chromedp.NodeVisible, chromedp.ByQuery),
)
if err != nil {
t.Fatalf("running chromedp has failed: %v", err)
}

if strings.TrimSpace(res) != `content` {
t.Fatalf("expected text panel to have the correct value, got: %s", res)
}
}

0 comments on commit b02c34d

Please sign in to comment.