package terminalui import ( "strings" "testing" ) // The gap after an invalid setting used to pin its heading over the setting. func TestGroupWindowKeepsTheRowBelowItsHeading(t *testing.T) { var list ListIndex list.Heading("Web search") list.Heading("Exa") list.Item(false) list.Gap() list.Heading("Context") list.Heading("Rolling") for range 3 { list.Item(false) } list.Gap() list.Heading("Next section") for range 5 { list.Item(false) } rows := list.Window(2, 10, "…", func(i int, selected bool) string { if i == 0 { return "invalid endpoint" } if selected { return "selected" } return "setting" }) if !strings.Contains(strings.Join(rows, "\n"), "Exa\ninvalid endpoint") { t.Fatalf("group lost its only row: %q", rows) } } func TestSessionNoticeKeepsItsRecoveryLine(t *testing.T) { page := Page{Footer: "esc back", Notices: []string{"Could not load sessions: daemon refused the saved configuration.\nRestore the previous configuration and retry."}, List: func(_, h int) []string { return make([]string, h) }} frame := page.Render(70, 20, Chrome{Title: func(int, string, string) string { return "Sessions" }}) if !strings.Contains(frame, "\n Restore the previous configuration and retry.\n") || len(strings.Split(frame, "\n")) != 20 { t.Fatalf("notice did not fit:\n%s", frame) } }