@@ -341,3 +341,50 @@ func TestScrollClamp_CannotScrollPastContent(t *testing.T) {
341341 view := m .View ()
342342 assert .Contains (t , view , "b1" , "content should still be visible after excessive scrolling" )
343343}
344+
345+ func TestUpdate_CursorSkipsMergedBranches (t * testing.T ) {
346+ nodes := makeNodes ("b1" , "b2" , "b3" )
347+ nodes [1 ].Ref .PullRequest = & stack.PullRequestRef {Number : 2 , Merged : true }
348+ m := New (nodes , testTrunk , "0.0.1" )
349+ assert .Equal (t , 0 , m .cursor , "cursor should start on first non-merged branch" )
350+
351+ // Down should skip b2 (merged) and land on b3
352+ updated , _ := m .Update (keyMsg ("down" ))
353+ m = updated .(Model )
354+ assert .Equal (t , 2 , m .cursor , "down should skip merged b2 and land on b3" )
355+
356+ // Up should skip b2 (merged) and land back on b1
357+ updated , _ = m .Update (keyMsg ("up" ))
358+ m = updated .(Model )
359+ assert .Equal (t , 0 , m .cursor , "up should skip merged b2 and land on b1" )
360+ }
361+
362+ func TestNew_CursorSkipsMergedBranch (t * testing.T ) {
363+ nodes := makeNodes ("b1" , "b2" , "b3" )
364+ nodes [0 ].Ref .PullRequest = & stack.PullRequestRef {Number : 1 , Merged : true }
365+ m := New (nodes , testTrunk , "0.0.1" )
366+ assert .Equal (t , 1 , m .cursor , "cursor should skip merged b1 and start on b2" )
367+ }
368+
369+ func TestNew_CursorSkipsMergedCurrentBranch (t * testing.T ) {
370+ nodes := makeNodes ("b1" , "b2" , "b3" )
371+ nodes [0 ].IsCurrent = true
372+ nodes [0 ].Ref .PullRequest = & stack.PullRequestRef {Number : 1 , Merged : true }
373+ m := New (nodes , testTrunk , "0.0.1" )
374+ assert .Equal (t , 1 , m .cursor , "cursor should not start on merged current branch" )
375+ }
376+
377+ func TestUpdate_EnterOnMergedDoesNothing (t * testing.T ) {
378+ // All non-merged so we can navigate, but force cursor onto a merged node
379+ // by having b1 active and b2 merged and b3 active.
380+ nodes := makeNodes ("b1" , "b2" )
381+ nodes [0 ].Ref .PullRequest = & stack.PullRequestRef {Number : 1 , Merged : true }
382+ m := New (nodes , testTrunk , "0.0.1" )
383+ // Cursor is on b2 (first non-merged). Manually set to b1 to test guard.
384+ m .cursor = 0
385+
386+ updated , cmd := m .Update (keyMsg ("enter" ))
387+ m = updated .(Model )
388+ assert .Equal (t , "" , m .CheckoutBranch (), "enter on merged branch should not set checkout" )
389+ assert .Nil (t , cmd , "enter on merged branch should not quit" )
390+ }
0 commit comments