From 93580e076dc594c36fdcb814e1d03666bf1fdfdb Mon Sep 17 00:00:00 2001 From: PJ Date: Tue, 18 Aug 2026 00:10:53 +0530 Subject: [PATCH] test(chrome): a hinted field is not named by its css class The fixture inputs carried no class at all, so the test could not fail the way the bug did. They now carry folio-web-shaped classes, and the test asserts the editable gate the hint is read behind. --- internal/driver/chrome/driver_test.go | 52 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/internal/driver/chrome/driver_test.go b/internal/driver/chrome/driver_test.go index 57d1e7c..f18f03e 100644 --- a/internal/driver/chrome/driver_test.go +++ b/internal/driver/chrome/driver_test.go @@ -317,14 +317,14 @@ func TestHierarchy_ScrollableAttribute(t *testing.T) { func TestHierarchy_HintTextNamesAnEditableField(t *testing.T) { const html = `` + `` + - `` + - `` + + `` + + `` + `` + - `` + - `` + - `` + - `` + - `` + + `` + + `` + + `` + + `` + + `` + `` server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.Header().Set("Content-Type", "text/html") @@ -346,17 +346,18 @@ func TestHierarchy_HintTextNamesAnEditableField(t *testing.T) { type node struct { Attributes map[string]string `json:"attributes"` + Editable bool `json:"editable"` Children []node `json:"children"` } var root node if err := json.Unmarshal([]byte(dump), &root); err != nil { t.Fatalf("unmarshal hierarchy: %v", err) } - hintByID := map[string]string{} + fieldByID := map[string]node{} var walk func(n node) walk = func(n node) { if id := n.Attributes["resource-id"]; id != "" { - hintByID[id] = n.Attributes["hintText"] + fieldByID[id] = n } for _, c := range n.Children { walk(c) @@ -365,19 +366,30 @@ func TestHierarchy_HintTextNamesAnEditableField(t *testing.T) { walk(root) for _, tc := range []struct { - id string - want string + id string + want string + editable bool }{ - {"search", "Search"}, - {"amount", "Amount"}, - {"note", "What's this for?"}, - {"reference", "reference-field"}, - {"unnamed", ""}, - {"agree", ""}, - {"go", ""}, + {"search", "Search", true}, + {"amount", "Amount", true}, + {"note", "What's this for?", true}, + {"reference", "reference-field", true}, + {"unnamed", "", true}, + {"agree", "", false}, + {"go", "", false}, } { - if hintByID[tc.id] != tc.want { - t.Errorf("%q: hintText = %q, want %q", tc.id, hintByID[tc.id], tc.want) + field := fieldByID[tc.id] + if field.Attributes["hintText"] != tc.want { + t.Errorf("%q: hintText = %q, want %q", tc.id, field.Attributes["hintText"], tc.want) + } + // visibleLabel reaches the hint only for an element the dump calls + // editable, so a field named right and marked wrong is still named by + // its class downstream. + if field.Editable != tc.editable { + t.Errorf("%q: editable = %v, want %v", tc.id, field.Editable, tc.editable) + } + if tc.want != "" && field.Attributes["hintText"] == field.Attributes["class"] { + t.Errorf("%q: named by its CSS class %q", tc.id, field.Attributes["class"]) } } }