forked from pterm/pterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_select_printer_test.go
79 lines (66 loc) · 2.58 KB
/
interactive_select_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
package pterm_test
import (
"reflect"
"testing"
"atomicgo.dev/keyboard"
"atomicgo.dev/keyboard/keys"
"github.com/MarvinJWendt/testza"
"github.com/overmindtech/pterm"
)
func TestInteractiveSelectPrinter_Show(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(keys.Down)
keyboard.SimulateKeyPress(keys.Down)
keyboard.SimulateKeyPress(keys.Enter)
}()
result, _ := pterm.DefaultInteractiveSelect.WithOptions([]string{"a", "b", "c", "d", "e"}).WithDefaultOption("b").Show()
testza.AssertEqual(t, "d", result)
}
func TestInteractiveSelectPrinter_Show_MaxHeightSlidingWindow(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(keys.Up)
keyboard.SimulateKeyPress(keys.Up)
keyboard.SimulateKeyPress(keys.Enter)
}()
result, _ := pterm.DefaultInteractiveSelect.WithOptions([]string{"a", "b", "c", "d", "e", "f"}).WithDefaultOption("e").Show()
testza.AssertEqual(t, "c", result)
}
func TestInteractiveSelectPrinter_Show_AlternateNavigationKeys(t *testing.T) {
go func() {
keyboard.SimulateKeyPress(keys.CtrlN)
keyboard.SimulateKeyPress(keys.CtrlN)
keyboard.SimulateKeyPress(keys.CtrlP)
keyboard.SimulateKeyPress(keys.Enter)
}()
result, _ := pterm.DefaultInteractiveSelect.WithOptions([]string{"a", "b", "c", "d", "e"}).WithDefaultOption("b").Show()
testza.AssertEqual(t, "c", result)
}
func TestInteractiveSelectPrinter_WithDefaultText(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithDefaultText("default")
testza.AssertEqual(t, p.DefaultText, "default")
}
func TestInteractiveSelectPrinter_WithDefaultOption(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithDefaultOption("default")
testza.AssertEqual(t, p.DefaultOption, "default")
}
func TestInteractiveSelectPrinter_WithOptions(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithOptions([]string{"a", "b", "c"})
testza.AssertEqual(t, p.Options, []string{"a", "b", "c"})
}
func TestInteractiveSelectPrinter_WithMaxHeight(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithMaxHeight(1337)
testza.AssertEqual(t, p.MaxHeight, 1337)
}
func TestInteractiveSelectPrinter_WithOnInterruptFunc(t *testing.T) {
// OnInterrupt function defaults to nil
pd := pterm.InteractiveSelectPrinter{}
testza.AssertNil(t, pd.OnInterruptFunc)
// Verify OnInterrupt is set
exitfunc := func() {}
p := pterm.DefaultInteractiveSelect.WithOnInterruptFunc(exitfunc)
testza.AssertEqual(t, reflect.ValueOf(p.OnInterruptFunc).Pointer(), reflect.ValueOf(exitfunc).Pointer())
}
func TestInteractiveSelectPrinter_WithFilter(t *testing.T) {
p := pterm.DefaultInteractiveSelect.WithFilter(false)
testza.AssertEqual(t, p.Filter, false)
}