-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor_behavior_test.go
More file actions
54 lines (43 loc) · 1.38 KB
/
cursor_behavior_test.go
File metadata and controls
54 lines (43 loc) · 1.38 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
package devtui
import (
"testing"
tea "github.com/charmbracelet/bubbletea"
)
// TestCursorBehaviorInEditMode verifica el comportamiento del cursor durante la edición
func TestCursorBehaviorInEditMode(t *testing.T) {
t.Run("Cursor position affects character insertion correctly", func(t *testing.T) {
// Setup
h := DefaultTUIForTest(func(messages ...any) {})
portHandler := &PortTestHandler{currentPort: "8080"}
tab := h.NewTabSection("Server", "Config")
h.AddHandler(portHandler, "", tab)
// Set viewport size properly for calculation
h.viewport.Width = 80
h.viewport.Height = 24
serverTabIndex := len(h.TabSections) - 1
h.activeTab = serverTabIndex
tabSection := tab.(*tabSection)
field := tabSection.FieldHandlers[0]
// Enter edit mode
h.handleKeyboard(tea.KeyMsg{Type: tea.KeyEnter})
// Test insertion at beginning
field.cursor = 0
h.handleKeyboard(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{'9'},
})
if field.tempEditValue != "98080" {
t.Errorf("Expected '98080' when typing at beginning, got '%s'", field.tempEditValue)
}
// Test insertion at end
field.tempEditValue = "8080"
field.cursor = len([]rune(field.tempEditValue))
h.handleKeyboard(tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{'9'},
})
if field.tempEditValue != "80809" {
t.Errorf("Expected '80809' when typing at end, got '%s'", field.tempEditValue)
}
})
}