Files
openchamber-android-native/third_party/mygo/ui/access_keyshortcuts_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

65 lines
1.9 KiB
Go

package ui_test
import (
"runtime"
"testing"
"github.com/egoist/mygo/ui"
)
// TestAccessKeyShortcuts reads the keys that press elements
// (aria-keyshortcuts) as assistive technology gets them: as the
// platform's menus write them, several separated by spaces, each once,
// and none for a key with no name or an element not given one.
func TestAccessKeyShortcuts(t *testing.T) {
palette, shortcuts := false, true
tt := ui.NewTester(func(c *ui.Context) {
if c.Shortcut(ui.Cmd, ui.KeyK) {
palette = !palette
}
ui.Row(c).Role(ui.RoleToolbar).Label("Tools").Children(func() {
search := ui.Button(c, "Search")
if shortcuts {
search.KeyShortcuts(ui.Cmd, ui.KeyK)
}
if search.Clicked() {
palette = !palette
}
ui.Button(c, "Redo").KeyShortcuts(ui.Cmd|ui.Shift, ui.KeyZ).KeyShortcuts(ui.Cmd, ui.KeyY).KeyShortcuts(ui.Cmd, ui.KeyY)
ui.Button(c, "Help").KeyShortcuts(ui.Super|ui.Alt, ui.KeyF1).KeyShortcuts(0, ui.KeyBack)
ui.Button(c, "Close").Disabled(true).KeyShortcuts(0, ui.KeyEscape)
ui.Button(c, "Share")
})
}, 600, 200)
want := map[string]string{
"Search": "Ctrl+K",
"Redo": "Ctrl+Shift+Z Ctrl+Y",
"Help": "Super+Alt+F1",
"Close": "Escape",
"Share": "",
}
switch runtime.GOOS {
case "darwin":
want["Search"], want["Redo"], want["Help"], want["Close"] = "⌘K", "⇧⌘Z ⌘Y", "⌥⌘F1", "⎋"
case "windows":
want["Help"] = "Win+Alt+F1"
}
for name, keys := range want {
if a := accessOf(t, tt, ui.RoleButton, name); a.KeyShortcuts != keys {
t.Errorf("%s's key shortcuts %q, want %q", name, a.KeyShortcuts, keys)
}
}
// It only tells the key, which the view handles.
tt.Key(ui.Cmd, ui.KeyK)
if !palette {
t.Error("Cmd+K did not open the palette")
}
// An element tells the keys it is given in the frame.
shortcuts = false
tt.Frame()
if a := accessOf(t, tt, ui.RoleButton, "Search"); a.KeyShortcuts != "" {
t.Errorf("Search keeps the key shortcuts %q", a.KeyShortcuts)
}
}