mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-21 04:46:29 +03:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8aba9b7086
commit
1c65e78b37
5 files changed
+40
-2
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user