From 1b2bd85fc5adaaaa7fa3e071f670ade0ebb10a9e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 21 Aug 2026 13:18:36 +0200 Subject: [PATCH] Let a test assert how a view draws its selection The selected line of a view says nothing about whether a selection is drawn over it, or which of the two ways it is drawn in, and those are what the tests coming up are about. Co-authored-by: Claude Opus 5 (1M context) --- pkg/integration/components/view_driver.go | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/integration/components/view_driver.go b/pkg/integration/components/view_driver.go index 102a8562a..dfae58c4b 100644 --- a/pkg/integration/components/view_driver.go +++ b/pkg/integration/components/view_driver.go @@ -360,6 +360,42 @@ func (self *ViewDriver) Content(matcher *TextMatcher) *ViewDriver { return self } +// SelectionIsActive asserts that the view draws its selection as the one the user +// is working in. These three assertions read the highlight flags rather than the +// selected lines, which say nothing about whether the selection is drawn at all. +func (self *ViewDriver) SelectionIsActive() *ViewDriver { + self.t.assertWithRetries(func() (bool, string) { + view := self.getView() + ok := view.Highlight && !view.HighlightInactive + return ok, fmt.Sprintf("%s: expected an active selection to be shown, but it wasn't", self.context) + }) + + return self +} + +// SelectionIsInactive asserts that the view draws its selection dimmed, as a panel +// does while the focus is somewhere else. +func (self *ViewDriver) SelectionIsInactive() *ViewDriver { + self.t.assertWithRetries(func() (bool, string) { + view := self.getView() + ok := view.Highlight && view.HighlightInactive + return ok, fmt.Sprintf("%s: expected an inactive selection to be shown, but it wasn't", self.context) + }) + + return self +} + +// SelectionIsHidden asserts that the view draws no selection at all, e.g. a list +// with nothing in it, where there is nothing to select. +func (self *ViewDriver) SelectionIsHidden() *ViewDriver { + self.t.assertWithRetries(func() (bool, string) { + ok := !self.getView().Highlight + return ok, fmt.Sprintf("%s: expected no selection to be shown, but one was", self.context) + }) + + return self +} + // asserts on the selected line of the view. If you are selecting a range, // you should use the SelectedLines method instead. func (self *ViewDriver) SelectedLine(matcher *TextMatcher) *ViewDriver {