okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
1697fee
main
1// The sessions search is a plain substring match on every word, in the order 2// the sessions are listed, so a scattered run of letters never matches. No e2e 3// scenario types a query and reads the list back. 4package tui 5 6import ( 7"slices" 8"testing" 9) 10 11func filteredIDs (m PickerModel ) []string { 12var ids []string 13for _ ,item := range m .Filtered { 14ids = append (ids ,item .ID ) 15 } 16return ids 17} 18 19func TestPickerFilterIsSubstringPerWordInListedOrder (t * testing.T ) { 20items := []PickerItem { 21 {ID :"scattered" ,Label :"yellow elephant hat" }, 22 {ID :"literal" ,Label :"yeh" }, 23 {ID :"detail" ,Label :"other" ,Detail :"/work/yeh-notes" }, 24 } 25m := NewPickerModel ("" ,items ,true ,"" ) 26m .SearchInput .SetValue ("yeh" ) 27m .applyFilter () 28if got := filteredIDs (m );! slices .Equal (got , []string {"literal" ,"detail" }) { 29t .Fatalf ("search = %v, want only the literal matches, in listed order" ,got ) 30 } 31m .SearchInput .SetValue ("OTHER yeh" ) 32m .applyFilter () 33if got := filteredIDs (m );! slices .Equal (got , []string {"detail" }) { 34t .Fatalf ("two words = %v, want only the item containing both" ,got ) 35 } 36m .SearchInput .SetValue ("" ) 37m .applyFilter () 38if got := filteredIDs (m );len (got )!= 3 { 39t .Fatalf ("empty search = %v, want everything" ,got ) 40 } 41}