Add test for loader widget

This commit is contained in:
Ivan Danyliuk 2018-09-06 15:48:19 +03:00
parent 9d0ec2d0f1
commit 62f807b6fe
No known key found for this signature in database
GPG Key ID: 97ED33CE024E1DBF
1 changed files with 33 additions and 0 deletions

33
widgets/loader_test.go Normal file
View File

@ -0,0 +1,33 @@
package widgets
import (
"fmt"
"testing"
)
func TestLoader(t *testing.T) {
l := NewLoader(100)
for i := 1; i < 100; i++ {
l.Inc()
got := l.Progress()
if int(got) != i {
t.Fatalf("Expect progress to be %d%%, but got %.f%%", i, got)
}
gotText := l.text()
expectedText := fmt.Sprintf("Loading %d%%...", i)
if gotText != expectedText {
t.Fatalf("Expect text to be %s, but got %s", expectedText, gotText)
}
}
// 100%
l.Inc()
if l.Progress() != 100.0 {
t.Fatalf("Expect progress to be 100%%, but got %.f%%", l.Progress())
}
if l.text() != "Completed" {
t.Fatalf("Expect text to be \"Completed\", but got %s", l.text())
}
}