-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_handler_test.go
More file actions
90 lines (75 loc) · 2.22 KB
/
remote_handler_test.go
File metadata and controls
90 lines (75 loc) · 2.22 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
//go:build !wasm
package devtui
import (
"testing"
"github.com/tinywasm/mcp"
)
// TestRemoteField_RegistersShortcuts verifies shortcuts from StateEntry are registered
func TestRemoteField_RegistersShortcuts(t *testing.T) {
tui := &DevTUI{
shortcutRegistry: newShortcutRegistry(),
TabSections: []*tabSection{{Index: 0, Title: "BUILD"}},
}
entry := StateEntry{
TabTitle: "BUILD",
HandlerName: "WASM",
HandlerType: HandlerTypeEdit,
Shortcut: "WASM",
Shortcuts: []map[string]string{
{"L": "Large"},
{"M": "Medium"},
{"S": "Small"},
},
}
section := tui.TabSections[0]
client := &mcp.Client{}
f := newRemoteField(entry, client, section, tui)
if f == nil {
t.Fatal("newRemoteField returned nil")
}
// Verify shortcuts were registered
for _, m := range entry.Shortcuts {
for key := range m {
shortcut, exists := tui.shortcutRegistry.Get(key)
if !exists {
t.Errorf("shortcut %q was not registered", key)
continue
}
if shortcut.HandlerName != "WASM" {
t.Errorf("shortcut %q: expected HandlerName='WASM', got %q", key, shortcut.HandlerName)
}
if shortcut.Value != key {
t.Errorf("shortcut %q: expected Value=%q, got %q", key, key, shortcut.Value)
}
}
}
}
// TestRemoteField_DispatchesWithHandlerName verifies field created from StateEntry uses handler name as key
func TestRemoteField_DispatchesWithHandlerName(t *testing.T) {
entry := StateEntry{
TabTitle: "BUILD",
HandlerName: "WasmClient",
HandlerType: HandlerTypeEdit,
Shortcut: "WasmClient",
Label: "WASM Mode",
Value: "M",
}
section := &tabSection{Index: 0, Title: "BUILD"}
// Pass nil client to avoid dispatch calls; we just verify field construction
f := newRemoteField(entry, nil, section, nil)
if f == nil {
t.Fatal("newRemoteField returned nil")
}
// Verify field was created with correct handler type
if f.handler.handlerType != handlerTypeEdit {
t.Errorf("expected handlerTypeEdit, got %d", f.handler.handlerType)
}
// Verify isRemote flag is set
if !f.isRemote {
t.Error("expected isRemote=true")
}
// Verify handler name is accessible
if f.handler.Name() != "WasmClient" {
t.Errorf("expected handler.Name()='WasmClient', got %q", f.handler.Name())
}
}