From 45b787ac4a6474520fbb19a42264cb7fe5bb31c6 Mon Sep 17 00:00:00 2001 From: Navid Yaghoobi Date: Wed, 20 Dec 2023 20:40:02 +1100 Subject: [PATCH] unit tests Signed-off-by: Navid Yaghoobi --- sparkline_test.go | 26 ++++++++++++++++++++++++++ spinner_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/sparkline_test.go b/sparkline_test.go index 1c78fe5..b595c98 100644 --- a/sparkline_test.go +++ b/sparkline_test.go @@ -63,4 +63,30 @@ var _ = Describe("Sparkline", Ordered, func() { Expect(heigth).To(Equal(50)) }) }) + + Describe("DataTitle and Color", func() { + It("checks data title text and color", func() { + tests := []struct { + title string + color tcell.Color + }{ + {title: "test01", color: tcell.ColorDarkOrange}, + {title: "abc123", color: tcell.ColorBlue}, + } + + for _, test := range tests { + sparkline.SetDataTitle(test.title) + sparkline.SetDataTitleColor(test.color) + app.Draw() + + for x := 0; x < len(test.title); x++ { + prune, _, style, _ := screen.GetContent(x, 1) + fg, _, _ := style.Decompose() + + Expect(fg).To(Equal(test.color)) + Expect(string(prune)).To(Equal(string(test.title[x]))) + } + } + }) + }) }) diff --git a/spinner_test.go b/spinner_test.go index 91df0e6..e11c517 100644 --- a/spinner_test.go +++ b/spinner_test.go @@ -63,4 +63,42 @@ var _ = Describe("Spinner", Ordered, func() { Expect(heigth).To(Equal(50)) }) }) + + Describe("Style", func() { + It("checks style", func() { + spinner.SetStyle(tvxwidgets.SpinnerGrowHorizontal) + spinner.Reset() + app.Draw() + + prune, _, _, _ := screen.GetContent(0, 1) + Expect(prune).To(Equal('▉')) + + spinner.Pulse() + app.Draw() + prune, _, _, _ = screen.GetContent(0, 1) + Expect(prune).To(Equal('▊')) + }) + }) + + Describe("CustomStyle", func() { + It("checks custom style", func() { + customStyle := []rune{'\u2705', '\u274C'} + spinner.SetCustomStyle(customStyle) + spinner.Reset() + + app.Draw() + prune, _, _, _ := screen.GetContent(0, 1) + Expect(prune).To(Equal(customStyle[0])) + + spinner.Pulse() + app.Draw() + prune, _, _, _ = screen.GetContent(0, 1) + Expect(prune).To(Equal(customStyle[1])) + + spinner.Pulse() + app.Draw() + prune, _, _, _ = screen.GetContent(0, 1) + Expect(prune).To(Equal(customStyle[0])) + }) + }) })