refactor: address test code review feedback

- Rename loadWithPositions to repositionNodes, decompose into
  getSerializedGraph + applyNodePositions (pure) + loadGraph
- Extract measureSelectionBounds to shared boundsUtils helper
- Add JSDoc to setCollapsed
- Move test helpers out of spec file into fixture utils
This commit is contained in:
jaeone94
2026-03-30 02:54:59 +09:00
parent 8b97cfb28d
commit 5b8d21bfa1
4 changed files with 114 additions and 99 deletions

View File

@@ -114,25 +114,25 @@ export class NodeOperationsHelper {
}
}
async loadWithPositions(
async getSerializedGraph(): Promise<ComfyWorkflowJSON> {
return this.page.evaluate(
() => window.app!.graph.serialize() as ComfyWorkflowJSON
)
}
async loadGraph(data: ComfyWorkflowJSON): Promise<void> {
await this.page.evaluate(
(d) => window.app!.loadGraphData(d, true, true, null),
data
)
}
async repositionNodes(
positions: Record<string, [number, number]>
): Promise<void> {
await this.page.evaluate(
async ({ positions }) => {
const data = window.app!.graph.serialize()
for (const node of data.nodes) {
const pos = positions[String(node.id)]
if (pos) node.pos = pos
}
await window.app!.loadGraphData(
data as ComfyWorkflowJSON,
true,
true,
null
)
},
{ positions }
)
const data = await this.getSerializedGraph()
applyNodePositions(data, positions)
await this.loadGraph(data)
}
async resizeNode(
@@ -209,3 +209,13 @@ export class NodeOperationsHelper {
await this.comfyPage.nextFrame()
}
}
function applyNodePositions(
data: ComfyWorkflowJSON,
positions: Record<string, [number, number]>
): void {
for (const node of data.nodes) {
const pos = positions[String(node.id)]
if (pos) node.pos = pos
}
}