From b02c34d79d39e1392220d35d5b2e0294bc31b657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Fri, 15 Oct 2021 14:55:18 +0300 Subject: [PATCH] board_visual: add TextPanel tests (#172) Add TextPanel tests that test whether it actually works on Grafana. --- board_visual_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/board_visual_test.go b/board_visual_test.go index 5675c278..47df15c7 100644 --- a/board_visual_test.go +++ b/board_visual_test.go @@ -3,6 +3,7 @@ package sdk_test import ( "context" "fmt" + "strings" "testing" "time" @@ -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{ @@ -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) @@ -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) + } }