Files
openchamber-android-native/third_party/mygo/internal/e2e/menu_icons_linux_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

81 lines
2.9 KiB
Go

//go:build linux && !android && (amd64 || arm64) && !android
package e2e
import (
"image/color"
"testing"
"github.com/egoist/mygo"
"github.com/egoist/mygo/internal/linux"
"github.com/egoist/mygo/ui"
)
// Menu items show icons beside their labels, with their checks, and change
// them in place: replaced, removed, given one.
func TestMenuIconsLinux(t *testing.T) {
japan := menuIcon(t, 48, 32, color.NRGBA{255, 0, 0, 255}) // 3:2, as flags
square := menuIcon(t, 64, 64, color.NRGBA{0, 0, 255, 255})
var chosen string
click := func(it *mygo.MenuItem, _ *mygo.Window) { chosen = it.ID }
menu := mygo.NewMenu([]*mygo.MenuItem{
{Label: "Servers", Icon: japan, Submenu: []*mygo.MenuItem{
{ID: "tokyo", Label: "Tokyo", Type: mygo.MenuItemRadio, Checked: true, Icon: japan, Click: click},
{ID: "ny", Label: "New York", Type: mygo.MenuItemRadio, Icon: square, Click: click},
{ID: "direct", Label: "Direct", Type: mygo.MenuItemRadio, Click: click},
}},
})
w := newWindow(t, mygo.WindowOptions{Width: 300, Height: 200, Content: ui.View(func(c *ui.Context) { ui.Text(c, "menus") })})
w.SetMenu(menu)
type state struct {
w, h int
checked bool
}
at := func(path ...string) (s state) {
var err error
mygo.RunOnMain(func() { s.w, s.h, s.checked, err = linux.TestMenuItemIcon(w.NativeHandle(), path...) })
if err != nil {
t.Fatal(err)
}
return s
}
want := func(what string, got, want state) {
t.Helper()
if got != want {
t.Errorf("%s = %+v, want %+v", what, got, want)
}
}
want("Tokyo", at("Servers", "Tokyo"), state{16, 11, true})
want("New York", at("Servers", "New York"), state{16, 16, false})
want("Direct", at("Servers", "Direct"), state{0, 0, false})
want("the menu bar's item", at("Servers"), state{0, 0, false})
menu.ItemByID("direct").SetIcon(square)
eventually(t, "Direct to get an icon", func() bool { return at("Servers", "Direct") == state{16, 16, false} })
menu.ItemByID("tokyo").SetIcon(nil)
eventually(t, "Tokyo to lose its icon", func() bool { return at("Servers", "Tokyo") == state{0, 0, true} })
menu.ItemByID("tokyo").SetIcon(square)
eventually(t, "Tokyo to get an icon again", func() bool { return at("Servers", "Tokyo") == state{16, 16, true} })
menu.ItemByID("ny").SetIcon(japan)
menu.ItemByID("ny").SetLabel("Osaka")
eventually(t, "New York to become Osaka", func() bool {
var err error
mygo.RunOnMain(func() { _, _, _, err = linux.TestMenuItemIcon(w.NativeHandle(), "Servers", "Osaka") })
return err == nil
})
want("Osaka", at("Servers", "Osaka"), state{16, 11, false})
// The item with an icon is chosen as any other, its check following.
if err := activateMenu(w, "Servers", "Osaka"); err != nil {
t.Fatal(err)
}
eventually(t, "Osaka to be chosen", func() bool {
var c string
mygo.RunOnMain(func() { c = chosen })
return c == "ny"
})
eventually(t, "Osaka checked, Tokyo not", func() bool {
return at("Servers", "Osaka").checked && !at("Servers", "Tokyo").checked
})
}