Add shared internal UI toolkit for both readers
This commit is contained in:
1 parent
672caca854
commit
e49ba198d7
34 files changed
+3471
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// Fenrir console screen reader.
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package tabbed
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestListPrefixSearch(t *testing.T) {
|
||||
session, err := New_session(Form{Type: TabForm, Title: "Picker", Tabs: []Tab{{ID: "items", Label: "Items", Controls: []Control{
|
||||
{ID: "list", Label: "Item", Kind: List, Items: []string{"Default", "NetworkManager", "Ninjam", "Éclair"}, Action: "choose"},
|
||||
{ID: "cancel", Label: "Cancel", Kind: Button, Action: "cancel"},
|
||||
}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
session.Handle(Key{Name: "tab"})
|
||||
for _, step := range []struct {
|
||||
key Key
|
||||
want, prefix string
|
||||
selected int
|
||||
}{
|
||||
{Key{Text: "N"}, "NetworkManager", "N", 1},
|
||||
{Key{Text: "i"}, "Ninjam", "Ni", 2},
|
||||
{Key{Text: "z"}, "No matches", "Ni", 2},
|
||||
{Key{Text: "n"}, "Ninjam", "Nin", 2},
|
||||
{Key{Name: "backspace"}, "Ninjam", "Ni", 2},
|
||||
{Key{Name: "backspace"}, "NetworkManager", "N", 1},
|
||||
{Key{Name: "backspace", Ctrl: true}, "Default", "", 0},
|
||||
{Key{Text: "é"}, "Éclair", "é", 3},
|
||||
{Key{Name: "down"}, "Éclair", "", 3},
|
||||
{Key{Text: "ni"}, "Ninjam", "ni", 2},
|
||||
{Key{Name: "up"}, "NetworkManager", "", 1},
|
||||
{Key{Text: "d"}, "Default", "d", 0},
|
||||
{Key{Text: "n", Ctrl: true}, "", "d", 0},
|
||||
{Key{Text: "n", Alt: true}, "", "d", 0},
|
||||
{Key{Text: "\n"}, "", "d", 0},
|
||||
} {
|
||||
got := session.Handle(step.key)
|
||||
control := session.Values()["items.list"]
|
||||
if got.Speech != step.want || got.Action != "" || control.Text != step.prefix || control.Selected != step.selected {
|
||||
t.Fatalf("key %+v: result %+v, prefix %q, selection %d; want %q, %q, %d", step.key, got, control.Text, control.Selected, step.want, step.prefix, step.selected)
|
||||
}
|
||||
}
|
||||
session.Handle(Key{Name: "tab"})
|
||||
session.Handle(Key{Name: "tab", Shift: true})
|
||||
if got := session.Handle(Key{Text: "ni"}).Speech; got != "Ninjam" {
|
||||
t.Fatal("focus change did not clear search", got)
|
||||
}
|
||||
if got := session.Handle(Key{Name: "enter"}).Action; got != "choose" {
|
||||
t.Fatal("search prevented activation", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user