mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
fix(verifier): label editable fields by hint, not the typed value
an editable field's own text is its transient content; prefer the hint so the field is named by purpose and the label stays stable.
This commit is contained in:
1 parent
9845b89173
commit
b65b8373e6
2 files changed
+26
No files matched your search
@@ -581,6 +581,13 @@ func buildNodeIndex(tree *hierarchy.Tree) map[*hierarchy.Element]*hierarchy.Node
|
|||||||
// case that fixes empty-text Compose buttons whose word lives on a child), then
|
// case that fixes empty-text Compose buttons whose word lives on a child), then
|
||||||
// its class as a last resort.
|
// its class as a last resort.
|
||||||
func visibleLabel(element *hierarchy.Element, nodeIndex map[*hierarchy.Element]*hierarchy.Node) string {
|
func visibleLabel(element *hierarchy.Element, nodeIndex map[*hierarchy.Element]*hierarchy.Node) string {
|
||||||
|
// An editable field's own text is the transient typed value ("1"); its hint
|
||||||
|
// names its purpose ("Amount") and stays stable, so prefer the hint there.
|
||||||
|
if element.Editable {
|
||||||
|
if hint := element.Attributes["hintText"]; hint != "" {
|
||||||
|
return truncateLabel(hint)
|
||||||
|
}
|
||||||
|
}
|
||||||
if element.Text != "" {
|
if element.Text != "" {
|
||||||
return truncateLabel(element.Text)
|
return truncateLabel(element.Text)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,25 @@ func TestCandidatesTypingExposesInputType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCandidatesLabelsEditableFieldByHintNotTypedValue(t *testing.T) {
|
||||||
|
// A field already showing "99" must still be labeled by its purpose (the
|
||||||
|
// hint), not by its transient content, so the description stays stable.
|
||||||
|
tree := `{
|
||||||
|
"attributes": {"bounds": "[0,0,400,800]"},
|
||||||
|
"children": [
|
||||||
|
{"attributes": {"resource-id": "Amt", "class": "EditText", "hintText": "Amount", "text": "99", "bounds": "[0,0,400,100]"}, "enabled": true, "children": []}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
v := enumVerifier(t, "{kind:'builtin', verb:'typing'}", tree)
|
||||||
|
candidates := v.Candidates()
|
||||||
|
if hasCandidate(candidates, `Type into "99" (number)`) || hasCandidate(candidates, `Type into "99"`) {
|
||||||
|
t.Errorf("editable field labeled by its typed value: %v", descriptions(candidates))
|
||||||
|
}
|
||||||
|
if !hasCandidate(candidates, `Type into "Amount" (number)`) {
|
||||||
|
t.Errorf("want the field labeled by its hint, got %v", descriptions(candidates))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCandidatesFoldsGesturesIntoDirectionalScrolls(t *testing.T) {
|
func TestCandidatesFoldsGesturesIntoDirectionalScrolls(t *testing.T) {
|
||||||
v := enumVerifier(t,
|
v := enumVerifier(t,
|
||||||
"{kind:'weighted', branches:[[1,{kind:'builtin',verb:'scrolls'}],[1,{kind:'builtin',verb:'swipes'}]]}",
|
"{kind:'weighted', branches:[[1,{kind:'builtin',verb:'scrolls'}],[1,{kind:'builtin',verb:'swipes'}]]}",
|
||||||
|
|||||||
Reference in new issue
Block a user