-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
76 lines (63 loc) · 1.95 KB
/
integration_test.go
File metadata and controls
76 lines (63 loc) · 1.95 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
package devtui
import (
"sync"
"testing"
"time"
)
// TestRealWorldScenario simula el escenario exacto que causaba el error original
func TestRealWorldScenario(t *testing.T) {
// Exactamente la misma configuración que en main.go
tui := NewTUI(&TuiConfig{
AppName: "Ejemplo DevTUI",
ExitChan: make(chan bool),
Color: &ColorPalette{
Foreground: "#F4F4F4",
Background: "#000000",
Primary: "#FF6600",
Secondary: "#666666",
},
Logger: func(messages ...any) {
t.Logf("Log: %v", messages)
},
})
// Configurar la sección y los campos exactamente como en main.go
nombreHandler := NewTestEditableHandler("Nombre", "")
edadHandler := NewTestEditableHandler("Edad", "")
emailHandler := NewTestEditableHandler("Email", "")
tab := tui.NewTabSection("Datos personales", "Información básica")
tui.AddHandler(nombreHandler, "", tab)
tui.AddHandler(edadHandler, "", tab)
tui.AddHandler(emailHandler, "", tab)
// Asegurarnos de que no hay panic durante la inicialización
defer func() {
if r := recover(); r != nil {
t.Errorf("No se esperaba ningún panic, pero se obtuvo: %v", r)
}
}()
// Usar un WaitGroup como en el ejemplo original
var wg sync.WaitGroup
wg.Add(1)
// Simular la inicialización de la TUI en una goroutine separada
go func() {
defer wg.Done()
// En lugar de inicializar la TUI completa (que bloquearía el test),
// simplemente simulamos las operaciones que causaban el problema
// Simular que se presiona Enter en un campo
section := tui.TabSections[0] // Primera sección
// Esto era lo que causaba el panic original
section.addNewContent(0, "Test content from real scenario")
t.Log("Operación completada sin panic")
}()
// Esperar un momento para que la goroutine termine
done := make(chan bool)
go func() {
wg.Wait()
done <- true
}()
select {
case <-done:
t.Log("Test completado exitosamente")
case <-time.After(2 * time.Second):
t.Error("El test tardó demasiado en completarse")
}
}