Files
openchamber-android-native/third_party/mygo/ui/list_menukey_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

89 lines
2.5 KiB
Go

package ui
import (
"slices"
"testing"
)
// The menu key opens the context menu of the row chosen in the focused
// list, below the row, as a right-click on it opens it at the pointer.
func TestMenuKeyOpensChosenRowsMenu(t *testing.T) {
for _, multi := range []bool{false, true} {
var s ListState
sel := -1
var set Selection[int]
if multi {
s.Selection = &set
} else {
s.Selected = &sel
}
menuRow := -1
tt := NewTester(func(c *Context) {
List(c, &s, 6, func(i int) {
Textf(c, "Row %d", i).ContextMenu(func(m *Menu) {
menuRow = i
m.Item("Delete")
})
}).Grow(1).ContextMenu(func(m *Menu) {
menuRow = -2
m.Item("New")
})
}, 300, 300)
tt.Frame()
tt.Click("Row 2")
tt.Key(0, KeyDown)
tt.Key(0, KeyContextMenu)
if got := tt.Menu(); !slices.Equal(got, []string{"Delete"}) || menuRow != 3 {
t.Fatalf("multi %v: the menu key opened %q for row %d, want Row 3's", multi, got, menuRow)
}
r, _ := tt.Find("Row 3")
if at := tt.h.menuAt; at[0] < r.X-1 || at[0] > r.X+1 || at[1] < r.Y+r.H-1 || at[1] > r.Y+r.H+8 {
t.Errorf("multi %v: the menu at %v, not below Row 3 at %+v", multi, at, r)
}
tt.CloseMenu()
tt.Key(Shift, KeyF10)
if err := tt.ChooseMenuItem("Delete"); err != nil || menuRow != 3 {
t.Fatalf("multi %v: Shift+F10: %v, row %d", multi, err, menuRow)
}
}
}
// Without a row chosen, the menu key opens the list's own menu.
func TestMenuKeyWithoutChosenRow(t *testing.T) {
sel := -1
s := ListState{Selected: &sel}
tt := NewTester(func(c *Context) {
List(c, &s, 6, func(i int) {
Textf(c, "Row %d", i).ContextMenu(func(m *Menu) { m.Item("Delete") })
}).Grow(1).ContextMenu(func(m *Menu) { m.Item("New") })
}, 300, 300)
tt.Frame()
tt.Key(0, KeyTab)
tt.Key(0, KeyContextMenu)
if got := tt.Menu(); !slices.Equal(got, []string{"New"}) {
t.Fatalf("the menu key opened %q, want the list's", got)
}
}
// In a Table, the menu key opens the menu of the chosen row's cells.
func TestMenuKeyOpensChosenTableRowsMenu(t *testing.T) {
sel := -1
s := ListState{Selected: &sel}
cols := []TableColumn{{ID: "name", Title: "Name"}, {ID: "size", Title: "Size"}}
menuRow := -1
tt := NewTester(func(c *Context) {
Table(c, &s, cols, 4, func(row, col int) {
Textf(c, "r%dc%d", row, col).ContextMenu(func(m *Menu) {
menuRow = row
m.Item("Open")
})
}).Grow(1)
}, 400, 300)
tt.Frame()
tt.Click("r1c0")
tt.Key(0, KeyContextMenu)
if got := tt.Menu(); !slices.Equal(got, []string{"Open"}) || menuRow != 1 {
t.Fatalf("the menu key opened %q for row %d, want r1's", got, menuRow)
}
}