Files

30 lines
1.2 KiB
Go

// Copyright (c) 2026 Storm Dragon
// SPDX-License-Identifier: GPL-3.0-or-later
package interaction
import "testing"
func TestGridRowsBoundsAndDisabledItems(t *testing.T) {
items := []Item{{ID: "1", Label: "One"}, {ID: "2", Label: "Two"}, {ID: "3", Label: "Three"}, {ID: "4", Label: "Four"}, {ID: "5", Label: "Five", Disabled: true}, {ID: "6", Label: "Six"}}
session, err := NewGridSession("Picker", []GridTab{{ID: "all", Label: "All", Items: items}}, 3, Element{ID: "copy", Label: "Copy", Kind: CheckBox})
if err != nil {
t.Fatal(err)
}
session.Handle(Event{Key: Tab})
for _, step := range []struct {
key Key
want string
}{{Right, "2"}, {Right, "3"}, {Down, "6"}, {Down, "6"}, {Up, "2"}, {Home, "1"}, {Left, "1"}, {End, "6"}, {Right, "6"}, {PageUp, "1"}, {PageDown, "6"}} {
session.Handle(Event{Key: step.key})
if got := session.Values()["grid"].Selected; got != step.want {
t.Fatalf("%v selected %q want %q", step.key, got, step.want)
}
}
if result := session.Handle(Event{Key: Escape}); !result.Cancelled {
t.Fatal("escape not cancelled")
}
if session.Handle(Event{Key: Enter}).Activated != "" || session.Presentation().Speech != "" {
t.Fatal("closed grid responded")
}
}