-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[test]: add tests for synchronous DOM node helpers #1443
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 synchronous DOM node helpers #1443
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 2 files
Greptile SummaryAdds unit test coverage for four synchronous DOM node helper functions used when parsing Test Coverage:
Minor Observation: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Helper as DOM Helper Functions
participant Node as Protocol.DOM.Node
Note over Test,Node: shouldExpandNode Testing
Test->>Helper: shouldExpandNode(node)
Helper->>Node: Check childNodeCount
Helper->>Node: Check children.length
Helper-->>Test: true/false (needs expansion?)
Note over Test,Node: mergeDomNodes Testing
Test->>Helper: mergeDomNodes(target, source)
Helper->>Node: Update childNodeCount
Helper->>Node: Update children array
Helper->>Node: Update shadowRoots
Helper->>Node: Update contentDocument
Helper-->>Test: void (target mutated)
Note over Test,Node: collectDomTraversalTargets Testing
Test->>Helper: collectDomTraversalTargets(node)
Helper->>Node: Collect children
Helper->>Node: Collect shadowRoots
Helper->>Node: Collect contentDocument
Helper-->>Test: Array of target nodes
Note over Test,Node: findNodeByBackendId Testing
Test->>Helper: findNodeByBackendId(root, backendId)
Helper->>Node: Stack-based traversal
Helper->>Node: Check children
Helper->>Node: Check shadowRoots
Helper-->>Test: Found node or undefined
|
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.
2 files reviewed, 1 comment
| describe("shouldExpandNode", () => { | ||
| it("returns true when declared children exceed realized children", () => { | ||
| const node = makeNode({ | ||
| childNodeCount: 2, | ||
| children: [makeNode()], | ||
| }); | ||
| expect(shouldExpandNode(node)).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false when all declared children are realized", () => { | ||
| const child = makeNode(); | ||
| const node = makeNode({ | ||
| childNodeCount: 1, | ||
| children: [child], | ||
| }); | ||
| expect(shouldExpandNode(node)).toBe(false); | ||
| }); | ||
| }); |
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.
style: Consider edge case: node with childNodeCount: 0 and no children array (should return false)
| describe("shouldExpandNode", () => { | |
| it("returns true when declared children exceed realized children", () => { | |
| const node = makeNode({ | |
| childNodeCount: 2, | |
| children: [makeNode()], | |
| }); | |
| expect(shouldExpandNode(node)).toBe(true); | |
| }); | |
| it("returns false when all declared children are realized", () => { | |
| const child = makeNode(); | |
| const node = makeNode({ | |
| childNodeCount: 1, | |
| children: [child], | |
| }); | |
| expect(shouldExpandNode(node)).toBe(false); | |
| }); | |
| }); | |
| describe("shouldExpandNode", () => { | |
| it("returns true when declared children exceed realized children", () => { | |
| const node = makeNode({ | |
| childNodeCount: 2, | |
| children: [makeNode()], | |
| }); | |
| expect(shouldExpandNode(node)).toBe(true); | |
| }); | |
| it("returns false when all declared children are realized", () => { | |
| const child = makeNode(); | |
| const node = makeNode({ | |
| childNodeCount: 1, | |
| children: [child], | |
| }); | |
| expect(shouldExpandNode(node)).toBe(false); | |
| }); | |
| it("returns false when node has no children", () => { | |
| const node = makeNode({ | |
| childNodeCount: 0, | |
| }); | |
| expect(shouldExpandNode(node)).toBe(false); | |
| }); | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/tests/snapshot-dom-tree-utils.test.ts
Line: 28:45
Comment:
**style:** Consider edge case: node with `childNodeCount: 0` and no `children` array (should return false)
```suggestion
describe("shouldExpandNode", () => {
it("returns true when declared children exceed realized children", () => {
const node = makeNode({
childNodeCount: 2,
children: [makeNode()],
});
expect(shouldExpandNode(node)).toBe(true);
});
it("returns false when all declared children are realized", () => {
const child = makeNode();
const node = makeNode({
childNodeCount: 1,
children: [child],
});
expect(shouldExpandNode(node)).toBe(false);
});
it("returns false when node has no children", () => {
const node = makeNode({
childNodeCount: 0,
});
expect(shouldExpandNode(node)).toBe(false);
});
});
```
How can I resolve this? If you propose a fix, please make it concise.
why
DOM.getDocumentwhat changed
domTree.tsfor testingshouldExpandNode(),mergeDomNodes(),collectDomTraversalTargets(), andfindNodeByBackendId()test plan
Summary by cubic
Add unit tests for synchronous DOM tree helpers used when parsing DOM.getDocument. Supports STG-1094 by exporting helpers and adding tests for shouldExpandNode, mergeDomNodes, collectDomTraversalTargets, and findNodeByBackendId.
Written for commit 078e98c. Summary will update automatically on new commits.