okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

dawntui: sessions search back to substring match per word, listed order1697fee

main
1.2 KiB41 linesraw
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 {
12	var ids []string
13	for _, item := range m.Filtered {
14		ids = append(ids, item.ID)
15	}
16	return ids
17}
18
19func TestPickerFilterIsSubstringPerWordInListedOrder(t *testing.T) {
20	items := []PickerItem{
21		{ID: "scattered", Label: "yellow elephant hat"},
22		{ID: "literal", Label: "yeh"},
23		{ID: "detail", Label: "other", Detail: "/work/yeh-notes"},
24	}
25	m := NewPickerModel("", items, true, "")
26	m.SearchInput.SetValue("yeh")
27	m.applyFilter()
28	if got := filteredIDs(m); !slices.Equal(got, []string{"literal", "detail"}) {
29		t.Fatalf("search = %v, want only the literal matches, in listed order", got)
30	}
31	m.SearchInput.SetValue("OTHER yeh")
32	m.applyFilter()
33	if got := filteredIDs(m); !slices.Equal(got, []string{"detail"}) {
34		t.Fatalf("two words = %v, want only the item containing both", got)
35	}
36	m.SearchInput.SetValue("")
37	m.applyFilter()
38	if got := filteredIDs(m); len(got) != 3 {
39		t.Fatalf("empty search = %v, want everything", got)
40	}
41}