Skip to content

Conversation

@seanmcguire12
Copy link
Member

@seanmcguire12 seanmcguire12 commented Dec 19, 2025

why

  • to add more coverage for the functions that captureHybridSnapshot() depends on

what changed

added unit tests for:

  • parseXPathToSteps()
    • checks that descendant (//) and child (/) axes are stored and names get normalized correctly
    • checks that blank or empty segments are ignored
  • buildXPathFromSteps()
    • checks that a sequence of step objects gets converted into the expected xpath
    • checks that an empty sequence returns /
  • listChildrenOf()
    • checks that only direct children of the given parent ID are returned (in insertion order)
    • checks that parents without entries yield an empty array

test plan

  • this is it

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.

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

⚠️ No Changeset found

Latest commit: 119ce4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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"]
Loading

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 19, 2025

Greptile Summary

Added unit tests for three focus selector utility functions: parseXPathToSteps(), buildXPathFromSteps(), and listChildrenOf().

  • Tests for parseXPathToSteps() verify that descendant (//) and child (/) axes are correctly identified and stored, tag names are normalized to lowercase, and empty/blank segments are properly ignored
  • Tests for buildXPathFromSteps() confirm that step objects are reconstructed into valid XPath strings and empty sequences return "/"
  • Tests for listChildrenOf() verify that only direct children of a given parent ID are returned in insertion order, and parents without children return empty arrays

These tests increase coverage for functions that captureHybridSnapshot() depends on, improving reliability of the snapshot focus selector system.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The PR adds well-structured unit tests for pure utility functions with clear test cases covering normal behavior and edge cases. The tests correctly validate the implementation logic and follow the project's testing patterns established in similar test files.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/tests/snapshot-focus-selectors-utils.test.ts Added comprehensive unit tests for parseXPathToSteps(), buildXPathFromSteps(), and listChildrenOf() utility functions

Sequence Diagram

sequenceDiagram
    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: []
Loading

@seanmcguire12 seanmcguire12 merged commit 7666ce0 into main Dec 20, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants