Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115package ui
import ( "image" "testing"
"gioui.org/f32" "gioui.org/io/pointer"
"100gex/internal/rex" "100gex/internal/rex/rextest" "100gex/internal/rexsession" "100gex/internal/theme")
// TestPaneHeaderButtons clicks the buttons in a pane's header: split// beside, split below, float, and, on the floating pane, dock.func TestPaneHeaderButtons(t *testing.T) { srv := rextest.Start(t) other := srv.Dial(t, "other-device") sid, b1 := rextest.NewSession(t, other, rextest.RawCat...)
c := srv.Dial(t, "100gex-test") h := startUI(t, srv, c, sid) h.until("the pane", func(f rexsession.Frame) bool { return len(f.Visible) == 1 && f.Ready() })
// button is the centre of a header's button, counting from the right. // The header row is inset 8 on the right, and each button is its side // and shadow wide, 4 apart. button := func(block string, fromRight int) image.Point { t.Helper() for _, s := range h.u.paneSlots { if s.block == block { side, shadow := int(theme.IconButtonSize), int(theme.Shadow)/2 x := s.rect.Max.X - int(theme.Border) - 8 - shadow - side/2 - fromRight*(side+shadow+4) return image.Pt(x, s.rect.Min.Y+int(theme.Border)+14) } } t.Fatalf("no pane drawn for %s", block) return image.Point{} } click := func(p image.Point) { for _, kind := range []pointer.Kind{pointer.Press, pointer.Release} { h.router.Queue(pointer.Event{Kind: kind, Source: pointer.Mouse, Position: f32.Pt(float32(p.X), float32(p.Y)), Buttons: pointer.ButtonPrimary}) } h.frame() } // tiled is the active window's layout: its split's direction, if any, // and its blocks in order; floating lists the floating layers' blocks. tiled := func(f rexsession.Frame) (dir string, ids, floating []string) { w := f.View.ActiveWindow() if w == nil { return } for _, l := range w.Layers { if l.Kind != "tiled" { for _, b := range l.Blocks { floating = append(floating, b.BlockID) } continue } for _, n := range leaves(l.Layout, nil) { ids = append(ids, n.BlockID) } if l.Layout != nil && l.Layout.Split != nil { dir = l.Layout.Split.Direction } } return }
// Split beside: a new pane to the right, focused. click(button(b1, 2)) f := h.until("a split beside", func(f rexsession.Frame) bool { dir, ids, _ := tiled(f) return dir == "horizontal" && len(ids) == 2 && ids[0] == b1 && f.Ready() }) _, ids, _ := tiled(f) b2 := ids[1] if got := f.Window.FocusedBlockID; got != b2 { t.Errorf("focused %s after splitting, want the new pane %s", got, b2) }
// Split below, on the pane that isn't focused: it splits that one. click(button(b1, 1)) h.until("a split below b1", func(f rexsession.Frame) bool { _, ids, _ := tiled(f) w := f.View.ActiveWindow() if len(ids) != 3 || ids[0] != b1 || ids[2] != b2 || w == nil { return false } before := w.Layers[0].Layout.Split.Before return before.Split != nil && before.Split.Direction == "vertical" && f.Ready() })
// Float b1, then dock it again with the same button. click(button(b1, 0)) h.until("b1 floating", func(f rexsession.Frame) bool { _, ids, floating := tiled(f) return len(ids) == 2 && len(floating) == 1 && floating[0] == b1 && f.Ready() }) click(button(b1, 0)) h.until("b1 docked", func(f rexsession.Frame) bool { _, ids, floating := tiled(f) return len(ids) == 3 && len(floating) == 0 && f.Ready() })
// The server agrees. var v rex.View rextest.Call(t, other, "session.view", map[string]any{"session_id": sid}, &v) if w := v.ActiveWindow(); w == nil || len(w.Layers) != 1 { t.Errorf("the server's window has layers %+v, want only the layout", w) }}