From 1c65e78b374bc5656eb3f51ae1ee1a1d606d7c45 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 15 Nov 2026 16:46:44 +0100 Subject: [PATCH] Let integration tests hover the mouse and check the width of a view A test for resizing the side panels by dragging needs both. Co-Authored-By: Claude Opus 5.5 --- pkg/gui/gui_driver.go | 10 ++++++++-- pkg/integration/components/test_driver.go | 7 +++++++ pkg/integration/components/test_test.go | 3 +++ pkg/integration/components/view_driver.go | 20 ++++++++++++++++++++ pkg/integration/types/types.go | 2 ++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pkg/gui/gui_driver.go b/pkg/gui/gui_driver.go index a9d257072..fc782f557 100644 --- a/pkg/gui/gui_driver.go +++ b/pkg/gui/gui_driver.go @@ -78,12 +78,18 @@ func (self *GuiDriver) ClickAndHold(x, y int) { } // MouseMove reports the mouse at a new position with the left button still -// held down, i.e. a drag movement. (No test needs pointer motion without a -// button held, so that variant doesn't exist.) +// held down, i.e. a drag movement. func (self *GuiDriver) MouseMove(x, y int) { self.replayMouseEvent(x, y, tcell.ButtonPrimary, gocui.ModNone) } +// Hover reports the mouse at a new position with no button held down. It must +// not be used while a button is held, because the event would then be a +// release. +func (self *GuiDriver) Hover(x, y int) { + self.replayMouseEvent(x, y, tcell.ButtonNone, gocui.ModNone) +} + func (self *GuiDriver) ScrollWheelDown(x, y int) { self.replayMouseEvent(x, y, tcell.WheelDown, gocui.ModNone) } diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go index 375d37d61..6af622103 100644 --- a/pkg/integration/components/test_driver.go +++ b/pkg/integration/components/test_driver.go @@ -97,6 +97,13 @@ func (self *TestDriver) scrollWheelDown(x, y int) { self.Wait(self.inputDelay) } +func (self *TestDriver) hover(x, y int) { + self.SetCaption(fmt.Sprintf("Hovering at %d, %d", x, y)) + self.mouseX, self.mouseY = x, y + self.gui.Hover(x, y) + self.Wait(self.inputDelay) +} + func (self *TestDriver) mouseRelease() { self.SetCaption(fmt.Sprintf("Releasing mouse at %d, %d", self.mouseX, self.mouseY)) self.gui.MouseRelease(self.mouseX, self.mouseY) diff --git a/pkg/integration/components/test_test.go b/pkg/integration/components/test_test.go index 199f46af7..234994539 100644 --- a/pkg/integration/components/test_test.go +++ b/pkg/integration/components/test_test.go @@ -67,6 +67,9 @@ func (self *fakeGuiDriver) MouseRelease(x, y int) { self.releasedCoordinates = append(self.releasedCoordinates, coordinate{x: x, y: y}) } +func (self *fakeGuiDriver) Hover(x, y int) { +} + func (self *fakeGuiDriver) ScrollWheelDown(x, y int) { self.scrolledCoordinates = append(self.scrolledCoordinates, coordinate{x: x, y: y}) } diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go index 6fae04a86..1af8ee165 100644 --- a/pkg/integration/components/view_driver.go +++ b/pkg/integration/components/view_driver.go @@ -792,6 +792,13 @@ func (self *ViewDriver) MouseMove(x, y int) *ViewDriver { return self } +// moves the mouse to the given position with no button held down +func (self *ViewDriver) Hover(x, y int) *ViewDriver { + offsetX, offsetY, _ := self.viewGeometry() + self.t.hover(offsetX+1+x, offsetY+1+y) + return self +} + func (self *ViewDriver) MouseMoveToBottom(x int) *ViewDriver { offsetX, offsetY, innerHeight := self.viewGeometry() self.t.mouseMove(offsetX+1+x, offsetY+innerHeight) @@ -976,6 +983,19 @@ func (self *ViewDriver) getLineCount() int { return len(view.BufferLines()) } +// asserts on the width of the view, including its frame +func (self *ViewDriver) HasWidth(expected int) *ViewDriver { + self.t.assertWithRetries(func() (bool, string) { + var actual int + self.t.gui.OnUIThreadAndWait(func() { + actual = self.getView().Width() + }) + return actual == expected, fmt.Sprintf("%s: Expected width %d, got %d", self.context, expected, actual) + }) + + return self +} + func (self *ViewDriver) IsVisible() *ViewDriver { self.t.assertWithRetries(func() (bool, string) { return self.getView().Visible, fmt.Sprintf("%s: Expected view to be visible, but it was not", self.context) diff --git a/pkg/integration/types/types.go b/pkg/integration/types/types.go index 9a40192a1..f52ef28ee 100644 --- a/pkg/integration/types/types.go +++ b/pkg/integration/types/types.go @@ -38,6 +38,8 @@ type GuiDriver interface { ClickAndHold(int, int) MouseMove(int, int) MouseRelease(int, int) + // Move the mouse with no button held down + Hover(int, int) ScrollWheelDown(int, int) // Perform the refresh that a background routine would perform on a timer RefreshInBackground()