forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
interactive_confirm_printer_test.go
89 lines (74 loc) · 2.56 KB
/
interactive_confirm_printer_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
package pterm_test
import (
"testing"
"atomicgo.dev/keyboard"
"atomicgo.dev/keyboard/keys"
"github.com/MarvinJWendt/testza"
"github.com/forvitinn/pterm"
)
func TestInteractiveConfirmPrinter_Show_yes(t *testing.T) {
go func() {
keyboard.SimulateKeyPress('y')
}()
result, _ := pterm.DefaultInteractiveConfirm.Show()
testza.AssertTrue(t, result)
}
func TestInteractiveConfirmPrinter_Show_no(t *testing.T) {
go func() {
keyboard.SimulateKeyPress('n')
}()
result, _ := pterm.DefaultInteractiveConfirm.Show()
testza.AssertFalse(t, result)
}
func TestInteractiveConfirmPrinter_WithDefaultValue(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithDefaultValue(true)
testza.AssertTrue(t, p.DefaultValue)
}
func TestInteractiveConfirmPrinter_WithDefaultValue_false(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(keys.Enter)
}()
p := pterm.DefaultInteractiveConfirm.WithDefaultValue(false)
result, _ := p.Show()
testza.AssertFalse(t, result)
}
func TestInteractiveConfirmPrinter_WithDefaultValue_true(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(keys.Enter)
}()
p := pterm.DefaultInteractiveConfirm.WithDefaultValue(true)
result, _ := p.Show()
testza.AssertTrue(t, result)
}
func TestInteractiveConfirmPrinter_WithConfirmStyle(t *testing.T) {
style := pterm.NewStyle(pterm.FgRed)
p := pterm.DefaultInteractiveConfirm.WithConfirmStyle(style)
testza.AssertEqual(t, p.ConfirmStyle, style)
}
func TestInteractiveConfirmPrinter_WithConfirmText(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithConfirmText("confirm")
testza.AssertEqual(t, p.ConfirmText, "confirm")
}
func TestInteractiveConfirmPrinter_WithDefaultText(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithDefaultText("default")
testza.AssertEqual(t, p.DefaultText, "default")
}
func TestInteractiveConfirmPrinter_WithRejectStyle(t *testing.T) {
style := pterm.NewStyle(pterm.FgRed)
p := pterm.DefaultInteractiveConfirm.WithRejectStyle(style)
testza.AssertEqual(t, p.RejectStyle, style)
}
func TestInteractiveConfirmPrinter_WithRejectText(t *testing.T) {
p := pterm.DefaultInteractiveConfirm.WithRejectText("reject")
testza.AssertEqual(t, p.RejectText, "reject")
}
func TestInteractiveConfirmPrinter_WithSuffixStyle(t *testing.T) {
style := pterm.NewStyle(pterm.FgRed)
p := pterm.DefaultInteractiveConfirm.WithSuffixStyle(style)
testza.AssertEqual(t, p.SuffixStyle, style)
}
func TestInteractiveConfirmPrinter_WithTextStyle(t *testing.T) {
style := pterm.NewStyle(pterm.FgRed)
p := pterm.DefaultInteractiveConfirm.WithTextStyle(style)
testza.AssertEqual(t, p.TextStyle, style)
}