@@ -337,7 +337,7 @@ func TestAgentPickerWindowing(t *testing.T) {
337337 assert .NotContains (t , out , "agent-0" )
338338
339339 // Hit-testing maps points to absolute indices within the window.
340- x , y := firstCardPoint (t , m , 4 )
340+ x , y := renderedCardRefPoint (t , m , 4 )
341341 i , ok := m .cardAt (x , y )
342342 assert .True (t , ok )
343343 assert .Equal (t , 4 , i )
@@ -433,7 +433,7 @@ func TestAgentPickerMouseHoverSelects(t *testing.T) {
433433 m .width = 120
434434 m .height = 40
435435
436- x , y := firstCardPoint (t , m , 1 )
436+ x , y := renderedCardRefPoint (t , m , 1 )
437437 _ , _ = m .Update (tea.MouseMotionMsg {X : x , Y : y })
438438 assert .Equal (t , 1 , m .cursor , "hover should move the cursor to the hovered card" )
439439}
@@ -448,7 +448,7 @@ func TestAgentPickerDoubleClickSelects(t *testing.T) {
448448 m .width = 120
449449 m .height = 40
450450
451- x , y := firstCardPoint (t , m , 1 )
451+ x , y := renderedCardRefPoint (t , m , 1 )
452452 click := tea.MouseClickMsg {X : x , Y : y , Button : tea .MouseLeft }
453453
454454 // First click selects (moves cursor) but does not quit.
@@ -469,7 +469,7 @@ func TestAgentPickerDoubleClickResetsAfterTimeout(t *testing.T) {
469469 m .width = 120
470470 m .height = 40
471471
472- x , y := firstCardPoint (t , m , 0 )
472+ x , y := renderedCardRefPoint (t , m , 0 )
473473 click := tea.MouseClickMsg {X : x , Y : y , Button : tea .MouseLeft }
474474
475475 _ , cmd := m .Update (click )
@@ -577,7 +577,7 @@ func TestAgentPickerDetailsResetsClickTracking(t *testing.T) {
577577 m .width = 120
578578 m .height = 40
579579
580- x , y := firstCardPoint (t , m , 0 )
580+ x , y := renderedCardRefPoint (t , m , 0 )
581581 click := tea.MouseClickMsg {X : x , Y : y , Button : tea .MouseLeft }
582582
583583 // First click primes double-click tracking.
@@ -811,16 +811,25 @@ func TestAgentPickerPanelSizeMatchesRenderNarrow(t *testing.T) {
811811 }
812812}
813813
814- // firstCardPoint scans the grid for a coordinate that maps to card index want .
815- func firstCardPoint (t * testing.T , m * agentPickerModel , want int ) (int , int ) {
814+ // renderedCardRefPoint locates fixture text on the rendered screen, independently of hit testing .
815+ func renderedCardRefPoint (t * testing.T , m * agentPickerModel , want int ) (int , int ) {
816816 t .Helper ()
817- for y := range m .height {
818- for x := range m .width {
819- if i , ok := m .cardAt (x , y ); ok && i == want {
820- return x , y
821- }
817+ require .GreaterOrEqual (t , want , 0 )
818+ require .Less (t , want , len (m .choices ))
819+ ref := displayRef (m .choices [want ].ref )
820+ require .NotEmpty (t , ref )
821+ screen := ansi .Strip (lipgloss .Place (m .width , m .height , lipgloss .Center , lipgloss .Center , m .render ()))
822+ for y , line := range strings .Split (screen , "\n " ) {
823+ offset := strings .Index (line , ref )
824+ if offset < 0 {
825+ continue
822826 }
827+ x := lipgloss .Width (line [:offset ])
828+ index , ok := m .cardAt (x , y )
829+ require .True (t , ok , "rendered card %d must be clickable" , want )
830+ require .Equal (t , want , index )
831+ return x , y
823832 }
824- t .Fatalf ("no coordinate maps to card %d " , want )
833+ t .Fatalf ("card %d (%q) is not visible " , want , ref )
825834 return 0 , 0
826835}
0 commit comments