forked from chelnak/ysmrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinner_test.go
112 lines (92 loc) · 2.61 KB
/
spinner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package ysmrr_test
import (
"bytes"
"fmt"
"testing"
"github.com/zioc/ysmrr"
"github.com/zioc/ysmrr/pkg/animations"
"github.com/zioc/ysmrr/pkg/colors"
"github.com/stretchr/testify/assert"
)
var initialMessage = "test"
var initialOpts = ysmrr.SpinnerOptions{
Message: initialMessage,
SpinnerColor: colors.FgHiGreen,
CompleteColor: colors.FgHiGreen,
ErrorColor: colors.FgHiRed,
MessageColor: colors.NoColor,
HasUpdate: make(chan bool),
}
func TestNewSpinner(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
assert.NotNil(t, spinner)
}
func TestSpinnerGetMessage(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
assert.Equal(t, initialMessage, spinner.GetMessage())
}
func TestSpinnerIsError(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
assert.Equal(t, false, spinner.IsError())
}
func TestSpinnerIsComplete(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
assert.Equal(t, false, spinner.IsComplete())
}
func TestSpinnerUpdateMessage(t *testing.T) {
updatedMessage := "updated message"
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.UpdateMessage(updatedMessage)
assert.Equal(t, updatedMessage, spinner.GetMessage())
}
func TestSpinnerUpdateMessagef(t *testing.T) {
expectedMessage := "updated message test"
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.UpdateMessagef("updated message %s", "test")
assert.Equal(t, expectedMessage, spinner.GetMessage())
}
func TestSpinnerComplete(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.Complete()
assert.Equal(t, true, spinner.IsComplete())
}
func TestSpinnerError(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.Error()
assert.Equal(t, true, spinner.IsError())
}
func TestPrint(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
var buf bytes.Buffer
_, dots := animations.GetAnimation(animations.Dots)
spinner.Print(&buf, dots[0])
want := fmt.Sprintf("%s %s\r\n", dots[0], initialMessage)
assert.Equal(t, want, buf.String())
}
func TestPrintWithComplete(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.Complete()
var buf bytes.Buffer
spinner.Print(&buf, "✓")
want := fmt.Sprintf("%s %s\r\n", "✓", initialMessage)
assert.Equal(t, want, buf.String())
}
func TestPrintWithError(t *testing.T) {
opts := initialOpts
spinner := ysmrr.NewSpinner(opts)
spinner.Error()
var buf bytes.Buffer
spinner.Print(&buf, "✗")
want := fmt.Sprintf("%s %s\r\n", "✗", initialMessage)
assert.Equal(t, want, buf.String())
}