-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[test]: add tests for ax tree post-processing #1446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[test]: add tests for ax tree post-processing #1446
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 1 file
Architecture diagram
sequenceDiagram
participant Test as Vitest Runner
participant Utils as a11yTree Utils
participant Helper as Helper Functions
Note over Test,Helper: NEW: Unit Test Coverage for Hybrid Snapshot Processing
%% decorateRoles Tests
rect rgb(23,37,84)
Note right of Test: Test Suite: decorateRoles()
Test->>Utils: decorateRoles(nodes, options)
loop For each node
Utils->>Utils: Lookup backendID in tagNameMap
alt Node mapped as Scrollable
Utils->>Utils: NEW TEST: Prepend "scrollable" to role
else Standard Node
Utils->>Utils: Keep original role
end
opt Encoding Error
Utils->>Utils: NEW TEST: Handle encoding fallback
end
end
Utils-->>Test: Decorated Nodes
Test->>Test: Assert roles & labels
end
%% buildHierarchicalTree Tests
rect rgb(23,37,84)
Note right of Test: Test Suite: buildHierarchicalTree()
Test->>Utils: buildHierarchicalTree(nodes)
loop Tree Construction
Utils->>Helper: isStructural(role)
Helper-->>Utils: true/false
alt NEW TEST: Negative Node ID
Utils->>Utils: Skip Node
else NEW TEST: Structural Node (generic/none)
alt No Name & No Children
Utils->>Utils: Prune from tree
else Only Structural Children
Utils->>Utils: Prune & promote descendants
else Valid Content
Utils->>Utils: Remap tag name (e.g. section)
end
else NEW TEST: Role is Combobox/Select
Utils->>Utils: Force role to HTML tag name
end
Utils->>Helper: removeRedundantStaticTextChildren()
alt NEW TEST: Child text == Parent Name
Helper-->>Utils: Remove child
else Text differs
Helper-->>Utils: Keep child
end
end
Utils-->>Test: Final Hierarchical Tree
Test->>Test: Assert structure & pruning
end
%% URL Extraction Tests
rect rgb(23,37,84)
Note right of Test: Test Suite: extractUrlFromAXNode()
Test->>Utils: extractUrlFromAXNode(node)
alt NEW TEST: Valid String Property
Utils-->>Test: Return trimmed URL
else Invalid/Missing
Utils-->>Test: Return undefined
end
end
Greptile SummaryAdded comprehensive unit tests for AX tree post-processing utilities to increase test coverage for the hybrid snapshot flow. The tests cover:
All test data is well-structured using helper functions like Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Decorate as decorateRoles()
participant Build as buildHierarchicalTree()
participant Prune as pruneStructuralSafe()
participant Static as removeRedundantStaticTextChildren()
Note over Test: Test Flow for AX Tree Post-Processing
Test->>Decorate: Pass AXNode[] + options
Decorate->>Decorate: Encode backendDOMNodeId
Decorate->>Decorate: Check scrollable/html tags
Decorate->>Decorate: Apply role labels
Decorate-->>Test: Return A11yNode[]
Test->>Build: Pass decorated nodes
Build->>Build: Filter structural nodes without content
Build->>Build: Build parent-child relationships
Build->>Prune: Process each root node
Prune->>Prune: Skip negative nodeIds
Prune->>Prune: Recursively clean children
Prune->>Static: Remove redundant StaticText
Static->>Static: Compare concatenated text to parent
Static-->>Prune: Return filtered children
Prune->>Prune: Apply tag name remapping
Prune-->>Build: Return cleaned node
Build-->>Test: Return hierarchical tree
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 3 comments
why
what changed
added
tests/snapshot-a11y-tree-utils.test.tswhich tests:decorateRoles()#documentnodes get left as 'generic'htmlnodes always get the scrollable labelbuildHierarchicalTree()combobox&selectroles are remapped to their HTML tag namesisStructural()removeRedundantStaticTextChildren()StaticTextchildren when their combined text exactly matches the parent label, keeps them when the text differs, and returns the original array when the parent has no nameextractUrlFromAXNode()test plan
Summary by cubic
Add unit tests for AX tree post-processing helpers to increase coverage of the hybrid snapshot flow (STG-1095). Covers role decoration (scrollable labels, encoding fallback), hierarchical tree building (structural pruning, tag remapping, negative ID skip), structural role detection, redundant StaticText pruning, and URL extraction.
Written for commit 310fd75. Summary will update automatically on new commits.