// Copyright (c) 2026 Storm Dragon // SPDX-License-Identifier: GPL-3.0-or-later package interaction import ( "strings" "testing" ) func TestEmptyAndRefreshedGridKeepsFocusSearchAndLiteralWords(t *testing.T) { form := grid_form() form.Tabs[0].Controls[0].Choices = nil form.Tabs[0].Controls[0].DeleteAction = "remove" session, err := New_session(form) if err != nil { t.Fatal(err) } session.Handle(Key{Name: "tab"}) if got := session.Handle(Key{Name: "enter"}); got.Action != "" || got.Speech != "No matches" { t.Fatal(got) } session.Handle(Key{Text: "c"}) session.Set_choices("one", "grid", []Choice{{ID: "cat", Label: "cat", Literal: true}, {ID: "car", Label: "car", Literal: true}}) session.Handle(Key{Name: "right"}) session.Set_choices("one", "grid", []Choice{{ID: "car", Label: "car", Literal: true}, {ID: "cat", Label: "cat", Literal: true}}) control, _ := session.Focused_control() if control.Text != "c" || control.Choices[control.Selected].ID != "car" { t.Fatal(control) } if got := session.Handle(Key{Name: "delete", Repeat: true}); got.Action != "" { t.Fatal(got) } if got := session.Handle(Key{Name: "delete"}); got.Action != "remove" { t.Fatal(got) } session.Set_choices("one", "grid", nil) if !strings.Contains(session.Describe(), "No matches") { t.Fatal(session.Describe()) } // Updating a grid must own its choices, independently of worker buffers. choices := []Choice{{ID: "cat", Label: "cat", Literal: true}} session.Set_choices("one", "grid", choices) choices[0].Label = "wrong" if !strings.Contains(session.Describe(), "cat") { t.Fatal(session.Describe()) } }