mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
refactor: extract loadWithPositions and setCollapsed to shared helpers
- Add NodeOperationsHelper.loadWithPositions for reloading workflow with modified node positions - Add NodeReference.setCollapsed using node.collapse() API with current state check for deterministic set (not toggle) - Remove local helper duplicates from test file
This commit is contained in:
@@ -4,7 +4,10 @@ import type {
|
||||
LGraph,
|
||||
LGraphNode
|
||||
} from '../../../src/lib/litegraph/src/litegraph'
|
||||
import type { NodeId } from '../../../src/platform/workflow/validation/schemas/workflowSchema'
|
||||
import type {
|
||||
ComfyWorkflowJSON,
|
||||
NodeId
|
||||
} from '../../../src/platform/workflow/validation/schemas/workflowSchema'
|
||||
import type { ComfyPage } from '../ComfyPage'
|
||||
import { DefaultGraphPositions } from '../constants/defaultGraphPositions'
|
||||
import type { Position, Size } from '../types'
|
||||
@@ -111,6 +114,27 @@ export class NodeOperationsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
async loadWithPositions(
|
||||
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 }
|
||||
)
|
||||
}
|
||||
|
||||
async resizeNode(
|
||||
nodePos: Position,
|
||||
nodeSize: Size,
|
||||
|
||||
@@ -332,6 +332,16 @@ export class NodeReference {
|
||||
async isCollapsed() {
|
||||
return !!(await this.getFlags()).collapsed
|
||||
}
|
||||
async setCollapsed(collapsed: boolean) {
|
||||
await this.comfyPage.page.evaluate(
|
||||
([id, collapsed]) => {
|
||||
const node = window.app!.canvas.graph!.getNodeById(id)
|
||||
if (!node) throw new Error('Node not found')
|
||||
if (node.collapsed !== collapsed) node.collapse(true)
|
||||
},
|
||||
[this.id, collapsed] as const
|
||||
)
|
||||
}
|
||||
async isBypassed() {
|
||||
return (await this.getProperty<number | null | undefined>('mode')) === 4
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { expect } from '@playwright/test'
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema'
|
||||
|
||||
import { comfyPageFixture as test } from '../fixtures/ComfyPage'
|
||||
import type { ComfyPage } from '../fixtures/ComfyPage'
|
||||
|
||||
interface CanvasRect {
|
||||
x: number
|
||||
@@ -85,49 +82,6 @@ async function measureBounds(
|
||||
) as Promise<MeasureResult>
|
||||
}
|
||||
|
||||
async function loadWithPositions(
|
||||
page: Page,
|
||||
positions: Record<string, [number, number]>
|
||||
) {
|
||||
await 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 }
|
||||
)
|
||||
}
|
||||
|
||||
async function setNodeCollapsed(
|
||||
comfyPage: ComfyPage,
|
||||
nodeId: string,
|
||||
collapsed: boolean
|
||||
) {
|
||||
await comfyPage.page.evaluate(
|
||||
({ id, collapsed }) => {
|
||||
const node = window.app!.graph._nodes.find(
|
||||
(n: { id: number | string }) => String(n.id) === id
|
||||
)
|
||||
if (node) {
|
||||
node.flags = node.flags || {}
|
||||
node.flags.collapsed = collapsed
|
||||
window.app!.canvas.setDirty(true, true)
|
||||
}
|
||||
},
|
||||
{ id: nodeId, collapsed }
|
||||
)
|
||||
await comfyPage.vueNodes.getNodeLocator(nodeId).waitFor()
|
||||
}
|
||||
|
||||
const SUBGRAPH_ID = '2'
|
||||
const REGULAR_ID = '3'
|
||||
const WORKFLOW = 'selection/subgraph-with-regular-node'
|
||||
@@ -175,7 +129,7 @@ test.describe('Selection bounding box', { tag: ['@canvas', '@node'] }, () => {
|
||||
const targetId = getTargetId(type)
|
||||
const refId = getRefId(type)
|
||||
|
||||
await loadWithPositions(page, {
|
||||
await comfyPage.nodeOps.loadWithPositions({
|
||||
[refId]: REF_POS,
|
||||
[targetId]: TARGET_POSITIONS[pos]
|
||||
})
|
||||
@@ -184,7 +138,8 @@ test.describe('Selection bounding box', { tag: ['@canvas', '@node'] }, () => {
|
||||
await comfyPage.vueNodes.getNodeLocator(refId).waitFor()
|
||||
|
||||
if (state === 'collapsed') {
|
||||
await setNodeCollapsed(comfyPage, targetId, true)
|
||||
const nodeRef = await comfyPage.nodeOps.getNodeRefById(targetId)
|
||||
await nodeRef.setCollapsed(true)
|
||||
}
|
||||
|
||||
await comfyPage.canvas.press('Control+a')
|
||||
|
||||
Reference in New Issue
Block a user