Add an IsActiveTab assertion for integration tests

Side panel tabs share a window, so which tab is shown is decided by view
z-order rather than the visibility flag (every tab in a window is
'visible'). Tests had no way to assert which tab is actually drawn in
front, which is distinct from which view has keyboard focus. Expose the
window's top view and add an IsActiveTab assertion built on it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-06-15 11:32:24 +02:00
parent 30559f1058
commit 2614156b2f
4 changed files with 34 additions and 0 deletions

View file

@ -153,6 +153,12 @@ func (self *GuiDriver) View(viewName string) *gocui.View {
return view
}
// TopViewInWindow returns the frontmost visible view in the given window, i.e.
// the tab that is currently shown when a window holds several tabbed views.
func (self *GuiDriver) TopViewInWindow(windowName string) *gocui.View {
return self.gui.helpers.Window.TopViewInWindow(windowName, false)
}
func (self *GuiDriver) SetCaption(caption string) {
self.gui.setCaption(caption)
self.waitTillIdle()

View file

@ -75,6 +75,10 @@ func (self *fakeGuiDriver) View(viewName string) *gocui.View {
return nil
}
func (self *fakeGuiDriver) TopViewInWindow(windowName string) *gocui.View {
return nil
}
func (self *fakeGuiDriver) SetCaption(string) {
}

View file

@ -408,6 +408,28 @@ func (self *ViewDriver) IsFocused() *ViewDriver {
return self
}
// asserts that the view is the one currently shown in its window, i.e. it's the
// active tab of its panel (drawn in front of the window's other tabs). Unlike
// IsFocused, this is about what's displayed rather than which view has keyboard
// focus; the two can disagree, e.g. if a config reload reshuffles the tabs.
func (self *ViewDriver) IsActiveTab() *ViewDriver {
self.t.assertWithRetries(func() (bool, string) {
expected := self.getView().Name()
context := self.t.gui.ContextForView(expected)
if context == nil {
return false, fmt.Sprintf("%s: Could not find context for view, so can't determine its window", expected)
}
topView := self.t.gui.TopViewInWindow(context.GetWindowName())
actual := ""
if topView != nil {
actual = topView.Name()
}
return actual == expected, fmt.Sprintf("%s: Expected view to be the active tab of its window, but it was %s", expected, actual)
})
return self
}
func (self *ViewDriver) Press(key config.Keybinding) *ViewDriver {
self.IsFocused()

View file

@ -44,6 +44,8 @@ type GuiDriver interface {
// e.g. when we're showing both staged and unstaged changes
SecondaryView() *gocui.View
View(viewName string) *gocui.View
// the frontmost visible view in the given window, i.e. the currently shown tab
TopViewInWindow(windowName string) *gocui.View
SetCaption(caption string)
SetCaptionPrefix(prefix string)
// Pop the next toast that was displayed; returns nil if there was none