-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirpicker_test.go
More file actions
96 lines (92 loc) · 2.7 KB
/
dirpicker_test.go
File metadata and controls
96 lines (92 loc) · 2.7 KB
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
package main
import (
"errors"
"fmt"
"io/fs"
"testing"
"testing/fstest"
"github.com/charmbracelet/lipgloss"
zone "github.com/lrstanley/bubblezone"
"github.com/muesli/termenv"
"github.com/samber/mo"
)
func TestDirPickerView(t *testing.T) {
lipgloss.SetColorProfile(termenv.Ascii)
zone.NewGlobal()
fs := fstest.MapFS{
".": {Mode: fs.ModeDir},
"foo/bar": {Mode: fs.ModeDir},
}
tests := []struct {
name string
directories []Directory
selectedIndex int
height int
displayIcons bool
hasChildDirectory mo.Option[bool]
err error
want string
}{
{
name: "When empty directory",
directories: []Directory{},
selectedIndex: 0,
height: 100,
displayIcons: false,
hasChildDirectory: mo.None[bool](),
err: nil,
want: " No directory found.",
},
{
name: "When only one directory",
directories: []Directory{{path: "foo", fsys: fs}},
selectedIndex: 0,
height: 100,
displayIcons: false,
hasChildDirectory: mo.None[bool](),
err: nil,
want: lipgloss.JoinVertical(
lipgloss.Top, zone.Mark("foo", "❯ foo")),
},
{
name: "When multiple directories",
directories: []Directory{{path: "foo", fsys: fs}, {path: "foo/bar", fsys: fs}},
selectedIndex: 0,
height: 100,
displayIcons: false,
hasChildDirectory: mo.None[bool](),
err: nil,
want: lipgloss.JoinVertical(
lipgloss.Top, zone.Mark("foo", "❯ foo"), zone.Mark("foo/bar", " bar")),
},
{
name: "When multiple directories and change the cursor position",
directories: []Directory{{path: "foo", fsys: fs}, {path: "foo/bar", fsys: fs}},
selectedIndex: 1,
height: 100,
displayIcons: false,
hasChildDirectory: mo.None[bool](),
err: nil,
want: lipgloss.JoinVertical(
lipgloss.Top, zone.Mark("foo", " foo"), zone.Mark("foo/bar", "❯ bar")),
},
{
name: "When has error",
directories: []Directory{{path: "foo", fsys: fs}, {path: "foo/bar", fsys: fs}},
selectedIndex: 0,
height: 100,
displayIcons: false,
hasChildDirectory: mo.None[bool](),
err: errors.New("Error"),
want: " Error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DirPickerView(tt.directories, tt.selectedIndex, tt.height, tt.displayIcons, tt.hasChildDirectory, tt.err); got != tt.want {
fmt.Println(got)
t.Errorf("DirPickerView = %v, want = %v", got, tt.want)
}
})
}
}