-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[test]: add tests for focus selector utils #1447
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 focus selector utils #1447
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 Suite
participant Utils as Focus Selector Utils
Note over Test,Utils: NEW: Unit Test Coverage for Hybrid Snapshot Logic
%% Group 1: Parsing Logic
Test->>Utils: parseXPathToSteps(" //iframe[1]/div[2]//SPAN ")
Note right of Utils: Logic verified:<br/>- Handles // (descendant) vs / (child)<br/>- Normalizes tag names (SPAN -> span)<br/>- Ignores whitespace
Utils-->>Test: Returns parsed Step[] array
%% Group 2: XPath Construction
Test->>Utils: buildXPathFromSteps([Step objects...])
Note right of Utils: Logic verified:<br/>- Reconstructs valid XPath string<br/>- Handles empty inputs -> "/"
Utils-->>Test: Returns "/iframe[1]//div[@id='main']/span"
%% Group 3: Tree Traversal
Test->>Utils: listChildrenOf(parentByFrameMap, "frame-1")
Note right of Utils: Logic verified:<br/>- Filters for direct children only<br/>- Preserves insertion order
Utils-->>Test: Returns ["frame-2", "frame-3"]
Greptile SummaryAdded unit tests for three focus selector utility functions:
These tests increase coverage for functions that Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Parse as parseXPathToSteps()
participant Build as buildXPathFromSteps()
participant List as listChildrenOf()
Note over Test,List: Unit Tests for Focus Selector Utils
Test->>Parse: " //iframe[1]/div[2]//SPAN "
Parse->>Parse: Trim and parse axes
Parse->>Parse: Extract raw segments
Parse->>Parse: Normalize names to lowercase
Parse-->>Test: [{axis:"desc",raw:"iframe[1]",name:"iframe"}...]
Test->>Parse: " " (blank input)
Parse->>Parse: Trim and check empty
Parse-->>Test: [] (empty array)
Test->>Build: [{axis:"child",raw:"iframe[1]",name:"iframe"}...]
Build->>Build: Iterate steps
Build->>Build: Append "/" or "//" based on axis
Build->>Build: Append raw segment
Build-->>Test: "/iframe[1]//div[@id='main']/span"
Test->>Build: [] (empty array)
Build-->>Test: "/"
Test->>List: (parentByFrame Map, "frame-1")
List->>List: Iterate map entries
List->>List: Filter by parent ID
List-->>Test: ["frame-2", "frame-3"]
Test->>List: (parentByFrame Map, "frame-4")
List->>List: No children found
List-->>Test: []
|
why
captureHybridSnapshot()depends onwhat changed
added unit tests for:
parseXPathToSteps()//) and child (/) axes are stored and names get normalized correctlybuildXPathFromSteps()/listChildrenOf()test plan
Summary by cubic
Add unit tests for focus selector utils to improve coverage for captureHybridSnapshot(). Tests cover axis handling and name normalization in parseXPathToSteps, XPath reconstruction and empty input in buildXPathFromSteps, and direct-child filtering and order in listChildrenOf.
Written for commit 119ce4a. Summary will update automatically on new commits.