mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
test(cmd): table-test hier-check parse and FindAll on fixture
This commit is contained in:
1 parent
3197e64562
commit
adcd10cd52
2 files changed
+61
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/priyanshujain/sanderling/internal/hierarchy"
|
||||
)
|
||||
|
||||
func TestHierCheck_ParseAndFind(t *testing.T) {
|
||||
content, err := os.ReadFile(filepath.Join("testdata", "dump.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tree, err := hierarchy.Parse(string(content))
|
||||
if err != nil {
|
||||
t.Fatalf("parse: %v", err)
|
||||
}
|
||||
if got := len(tree.Elements); got != 4 {
|
||||
t.Fatalf("element count: got %d, want 4", got)
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
selector string
|
||||
want int
|
||||
}{
|
||||
{"desc:row", 2},
|
||||
{"id:title", 1},
|
||||
{"text:Bob", 1},
|
||||
{"id:missing", 0},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := len(tree.FindAll(c.selector)); got != c.want {
|
||||
t.Errorf("%s: got %d matches, want %d", c.selector, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHierCheck_MalformedReturnsError(t *testing.T) {
|
||||
if _, err := hierarchy.Parse(`{"attributes": {`); err == nil {
|
||||
t.Fatal("expected error for malformed hierarchy, got nil")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"attributes": {"class": "android.widget.LinearLayout", "package": "app", "bounds": "[0,0,1080,2340]"},
|
||||
"children": [
|
||||
{
|
||||
"attributes": {"resource-id": "app:id/title", "text": "Hello", "bounds": "[10,20,200,60]"},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"attributes": {"resource-id": "app:id/row", "text": "Alice", "content-desc": "row", "bounds": "[0,100,1080,200]"},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"attributes": {"resource-id": "app:id/row", "text": "Bob", "content-desc": "row", "bounds": "[0,200,1080,300]"},
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user