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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
package tui
import (
"bytes"
"testing"
"github.com/dundee/gdu/v5/internal/testanalyze"
"github.com/dundee/gdu/v5/internal/testapp"
"github.com/dundee/gdu/v5/internal/testdir"
"github.com/dundee/gdu/v5/pkg/fs"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/stretchr/testify/assert"
)
func TestDoubleClick(t *testing.T) {
fin := testdir.CreateTestDir()
defer fin()
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
app := testapp.CreateMockedApp(false)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
ui.done = make(chan struct{})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
<-ui.done // wait for analyzer
for _, f := range ui.app.(*testapp.MockedApp).GetUpdateDraws() {
f()
}
ui.table.Select(0, 0)
assert.Equal(t, "test_dir", ui.currentDir.GetName())
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseLeftDoubleClick)
assert.Equal(t, "nested", ui.currentDir.GetName())
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseLeftDoubleClick)
assert.Equal(t, "test_dir", ui.currentDir.GetName())
// show file content
ui.keyPressed(tcell.NewEventKey(tcell.KeyRight, 'l', 0))
ui.table.Select(2, 0)
selectedFile := ui.table.GetCell(2, 0).GetReference().(fs.Item)
assert.Equal(t, selectedFile.GetName(), "file2")
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseLeftDoubleClick)
assert.True(t, ui.pages.HasPage("file"))
}
func TestScroll(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
ui.Analyzer = &testanalyze.MockedAnalyzer{}
ui.done = make(chan struct{})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
<-ui.done // wait for analyzer
for _, f := range ui.app.(*testapp.MockedApp).GetUpdateDraws() {
f()
}
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseScrollDown)
row, _ := ui.table.GetSelection()
assert.Equal(t, row, 1)
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseScrollUp)
row, _ = ui.table.GetSelection()
assert.Equal(t, row, 0)
}
func TestScrollWhenPageOpened(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
ui.Analyzer = &testanalyze.MockedAnalyzer{}
ui.done = make(chan struct{})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
<-ui.done // wait for analyzer
for _, f := range ui.app.(*testapp.MockedApp).GetUpdateDraws() {
f()
}
// open confirm dialog
ui.keyPressed(tcell.NewEventKey(tcell.KeyRune, 'd', 0))
ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseScrollDown)
row, _ := ui.table.GetSelection()
// scrolling does nothing
assert.Equal(t, 0, row)
}
func TestEmptyEvent(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
event, action := ui.onMouse(nil, tview.MouseMove)
assert.True(t, event == nil)
assert.Equal(t, action, tview.MouseMove)
}
func TestMouseMove(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, true, true, false, false, false)
event, action := ui.onMouse(tcell.NewEventMouse(0, 0, 0, 0), tview.MouseMove)
assert.True(t, event != nil)
assert.Equal(t, action, tview.MouseMove)
}
|