internal/tui/view/filter_test.go

package view

import "testing"

func TestFilter_notifies(t *testing.T) {
	var got string
	f := NewFilter(func(q string) { got = q })
	f.onChange("/db")
	if got != "db" {
		t.Errorf("notify got %q, want %q", got, "db")
	}
	f.onChange("no-slash")
	if got != "no-slash" {
		t.Errorf("notify got %q, want %q", got, "no-slash")
	}
}

func TestFilter_nilCallback(t *testing.T) {
	f := NewFilter(nil)
	// Must not panic.
	f.onChange("/hi")
}

func TestFilter_value(t *testing.T) {
	var last string
	f := NewFilter(func(q string) { last = q })
	f.input.SetText("/core")
	// SetText triggers the changed func via tview; simulate directly.
	f.onChange("/core")
	if last != "core" || f.Value() != "core" {
		t.Errorf("last=%q value=%q", last, f.Value())
	}
}