45 lines
1.9 KiB
Go
45 lines
1.9 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package interaction_test
|
|
|
|
import (
|
|
flat "git.stormux.org/storm/screenreader-common/interaction"
|
|
"git.stormux.org/storm/screenreader-common/interaction/tabbed"
|
|
"testing"
|
|
)
|
|
|
|
// Exercise both public form APIs, so an update to grid movement or speech must
|
|
// reach both readers even though their surrounding focus/presentation differs.
|
|
func TestGridBehaviorAcrossFormLayouts(t *testing.T) {
|
|
items := []flat.Item{{ID: "a", Label: "Alpha"}, {ID: "b", Label: "Beta"}, {ID: "c", Label: "Charlie"}, {ID: "d", Label: "Delta"}, {ID: "e", Label: "Echo"}}
|
|
choices := make([]tabbed.Choice, len(items))
|
|
for i, item := range items {
|
|
choices[i] = tabbed.Choice{ID: item.ID, Label: item.Label}
|
|
}
|
|
first, err := flat.NewGridSession("Picker", []flat.GridTab{{ID: "items", Label: "Items", Items: items}}, 3, flat.Element{ID: "copy", Label: "Copy", Kind: flat.CheckBox})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := tabbed.New_session(tabbed.Form{Type: tabbed.TabForm, Title: "Picker", Tabs: []tabbed.Tab{{ID: "items", Label: "Items", Controls: []tabbed.Control{{ID: "grid", Label: "Grid", Kind: tabbed.Grid, Choices: choices, Columns: 3}}}}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
first.Handle(flat.Event{Key: flat.Tab})
|
|
second.Handle(tabbed.Key{Name: "tab"})
|
|
for _, step := range []struct {
|
|
key flat.Key
|
|
name string
|
|
}{{flat.Right, "right"}, {flat.Down, "down"}, {flat.Down, "down"}, {flat.Up, "up"}, {flat.End, "end"}, {flat.Left, "left"}, {flat.Home, "home"}} {
|
|
a := first.Handle(flat.Event{Key: step.key})
|
|
b := second.Handle(tabbed.Key{Name: step.name})
|
|
if a.Speech != b.Speech {
|
|
t.Fatalf("%s speech: %q != %q", step.name, a.Speech, b.Speech)
|
|
}
|
|
selected := second.Values()["items.grid"]
|
|
if first.Values()["grid"].Selected != selected.Choices[selected.Selected].ID {
|
|
t.Fatalf("%s selection mismatch", step.name)
|
|
}
|
|
}
|
|
}
|