mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-05 21:54:50 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user