Repository navigation
Expand file tree
/
Copy pathactions_test.go
More file actions
160 lines (144 loc) · 4.83 KB
/
Copy pathactions_test.go
File metadata and controls
160 lines (144 loc) · 4.83 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"reflect"
"strings"
"testing"
"time"
)
func fixedClock() time.Time { return time.Date(2026, 7, 23, 9, 5, 0, 0, time.UTC) }
func TestSaludarReply(t *testing.T) {
a := buildActions(fixedClock)["saludar"]
reply, err := a.Run(&fakeRunner{})
if err != nil || reply == "" {
t.Fatalf("esperaba saludo sin error; reply=%q err=%v", reply, err)
}
}
func TestHoraUsaElReloj(t *testing.T) {
a := buildActions(fixedClock)["hora"]
reply, err := a.Run(&fakeRunner{})
if err != nil {
t.Fatalf("no debería fallar: %v", err)
}
if !strings.Contains(reply, "09:05") {
t.Fatalf("esperaba que incluyera 09:05, fue %q", reply)
}
}
func TestSubirVolumenLlamaWpctl(t *testing.T) {
fake := &fakeRunner{}
if _, err := buildActions(fixedClock)["subir_volumen"].Run(fake); err != nil {
t.Fatalf("no debería fallar: %v", err)
}
want := []string{"wpctl", "set-volume", "@DEFAULT_AUDIO_SINK@", "5%+"}
if got := fake.lastCall(); !reflect.DeepEqual(got, want) {
t.Fatalf("esperaba %v, fue %v", want, got)
}
}
func TestAbrirUsaHyprctl(t *testing.T) {
fake := &fakeRunner{}
if _, err := openAppAction("firefox").Run(fake); err != nil {
t.Fatalf("no debería fallar: %v", err)
}
want := []string{"hyprctl", "dispatch", "exec", "firefox"}
if got := fake.lastCall(); !reflect.DeepEqual(got, want) {
t.Fatalf("esperaba %v, fue %v", want, got)
}
}
func TestAccionesTienenDescripcion(t *testing.T) {
for name, a := range buildActions(time.Now) {
if a.Desc == "" {
t.Errorf("acción %q sin Desc (la necesita el menú del LLM)", name)
}
}
}
func TestQueSuenaDiceLaCancion(t *testing.T) {
acts := buildActions(time.Now)
fake := &fakeRunner{output: "Nate Gentile - Mi PC Linux"}
reply, err := acts["que_suena"].Run(fake)
if err != nil {
t.Fatal(err)
}
if reply != "Está sonando: Nate Gentile - Mi PC Linux." {
t.Fatalf("fue %q", reply)
}
if got := fake.lastCall(); got[0] != "playerctl" || got[1] != "metadata" {
t.Fatalf("esperaba playerctl metadata, fue %v", got)
}
}
func TestBateriaParseaPorcentaje(t *testing.T) {
acts := buildActions(time.Now)
// upower -e → device; upower -i <dev> → info con "percentage:"
fake := &fakeRunner{output: "/org/freedesktop/UPower/devices/battery_BAT0\n percentage: 87%\n"}
reply, err := acts["bateria"].Run(fake)
if err != nil {
t.Fatal(err)
}
if reply != "Batería al 87%." {
t.Fatalf("fue %q", reply)
}
// N1: ata que la 1ª llamada enumera y la 2ª pide info del device encontrado
if len(fake.calls) != 2 || !reflect.DeepEqual(fake.calls[0], []string{"upower", "-e"}) {
t.Fatalf("esperaba upower -e primero, fue %v", fake.calls)
}
if len(fake.calls[1]) < 3 || !strings.Contains(fake.calls[1][2], "battery_BAT0") {
t.Fatalf("esperaba upower -i <dev battery>, fue %v", fake.calls[1])
}
}
func TestFechaEnEspanol(t *testing.T) {
fija := func() time.Time { return time.Date(2026, 7, 24, 10, 0, 0, 0, time.UTC) } // viernes 24 de julio
acts := buildActions(fija)
reply, _ := acts["fecha"].Run(&fakeRunner{})
if reply != "Hoy es viernes 24 de julio." {
t.Fatalf("fue %q", reply)
}
}
func TestClimaVacioAmable(t *testing.T) {
acts := buildActions(time.Now)
reply, err := acts["clima"].Run(&fakeRunner{output: ""})
if err != nil || reply != "No pude ver el clima." {
t.Fatalf("reply=%q err=%v", reply, err)
}
}
func TestAgendaPrimerEventoNoVacio(t *testing.T) {
acts := buildActions(time.Now)
// khal puede meter una línea vacía/encabezado; tomamos la 1ª NO vacía
fake := &fakeRunner{output: "\n10:00 Reunión con el equipo\n12:00 Almuerzo\n"}
reply, _ := acts["agenda"].Run(fake)
if reply != "Próximo: 10:00 Reunión con el equipo." {
t.Fatalf("fue %q", reply)
}
}
func TestArgBrilloSubir(t *testing.T) {
fake := &fakeRunner{}
if _, err := buildArgActions()["brillo"].Build("subir").Run(fake); err != nil {
t.Fatal(err)
}
want := []string{"brightnessctl", "set", "+10%"}
if got := fake.lastCall(); !reflect.DeepEqual(got, want) {
t.Fatalf("esperaba %v, fue %v", want, got)
}
}
func TestArgAbrirUrlAgregaHttps(t *testing.T) {
fake := &fakeRunner{}
if _, err := buildArgActions()["abrir_url"].Build("youtube.com").Run(fake); err != nil {
t.Fatal(err)
}
want := []string{"xdg-open", "https://youtube.com"}
if got := fake.lastCall(); !reflect.DeepEqual(got, want) {
t.Fatalf("esperaba %v, fue %v", want, got)
}
}
func TestArgBuscarUrlEncode(t *testing.T) {
fake := &fakeRunner{}
if _, err := buildArgActions()["buscar"].Build("gatos monos").Run(fake); err != nil {
t.Fatal(err)
}
want := []string{"xdg-open", "https://duckduckgo.com/?q=gatos+monos"}
if got := fake.lastCall(); !reflect.DeepEqual(got, want) {
t.Fatalf("esperaba %v, fue %v", want, got)
}
}
func TestArgWorkspaceInvalido(t *testing.T) {
if _, err := buildArgActions()["ir_a_workspace"].Build("catorce").Run(&fakeRunner{}); err == nil {
t.Fatal("workspace no numérico debía dar error")
}
}