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

72 lines
2.3 KiB
Go

package platform
import "testing"
func TestFitIcon(t *testing.T) {
for _, c := range []struct{ w, h, box, ww, wh int }{
{16, 16, 16, 16, 16},
{64, 64, 32, 32, 32},
{60, 40, 16, 16, 11}, // a 3:2 flag
{40, 60, 16, 11, 16},
{4, 3, 24, 24, 18},
{200, 1, 16, 16, 1}, // never thinner than a pixel
{0, 10, 16, 0, 0},
} {
if w, h := FitIcon(c.w, c.h, c.box); w != c.ww || h != c.wh {
t.Errorf("FitIcon(%d, %d, %d) = %d, %d, want %d, %d", c.w, c.h, c.box, w, h, c.ww, c.wh)
}
}
}
func TestMenuIconNativeOnce(t *testing.T) {
ic := &MenuIcon{PNG: []byte{1}}
n := 0
make := func() any { n++; return nil }
ic.Native(make)
ic.Native(make)
if n != 1 {
t.Errorf("made %d times, want once, a failure kept too", n)
}
}
// Apply keeps a snapshot a backend builds menus from later current.
func TestMenuApply(t *testing.T) {
icon := &MenuIcon{PNG: []byte{1}}
m := &Menu{Items: []*MenuItem{
{ID: 1, Label: "A"},
{ID: 2, Label: "Sub", Type: MenuItemSubmenu, Submenu: &Menu{Items: []*MenuItem{
{ID: 3, Label: "B", Type: MenuItemRadio},
}}},
}}
old := m.Items[1].Submenu.Items[0]
m.Apply(&MenuItem{ID: 3, Label: "B", Type: MenuItemRadio, Checked: true, Icon: icon})
got := m.Items[1].Submenu.Items[0]
if !got.Checked || got.Icon != icon {
t.Errorf("item 3 = %+v, want checked with the icon", got)
}
if old.Checked {
t.Error("Apply changed the item it replaced, which a menu being built may hold")
}
if m.Items[0].Label != "A" {
t.Error("Apply changed another item")
}
(*Menu)(nil).Apply(got) // no menu, nothing to do
}
// TestLabelWithSubtitleAndBadge checks the fallback of platforms that draw
// neither the subtitle nor the badge on its own.
func TestLabelWithSubtitleAndBadge(t *testing.T) {
if got := (&MenuItem{Label: "Node"}).LabelWithBadge(); got != "Node" {
t.Errorf("label without badge = %q", got)
}
if got := (&MenuItem{Label: "Node", Badge: "120 ms"}).LabelWithBadge(); got != "Node 120 ms" {
t.Errorf("label with badge = %q", got)
}
if got := (&MenuItem{Label: "Node", Subtitle: "Hong Kong"}).LabelWithSubtitleAndBadge(); got != "Node — Hong Kong" {
t.Errorf("label with subtitle = %q", got)
}
if got := (&MenuItem{Label: "Node", Subtitle: "Hong Kong", Badge: "120 ms"}).LabelWithSubtitleAndBadge(); got != "Node — Hong Kong 120 ms" {
t.Errorf("label with subtitle and badge = %q", got)
}
}