forked from Comfy-Org/ComfyUI_frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewportVirtualization.spec.ts
More file actions
293 lines (267 loc) · 10 KB
/
Copy pathviewportVirtualization.spec.ts
File metadata and controls
293 lines (267 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import {
comfyExpect as expect,
comfyPageFixture as test
} from '@e2e/fixtures/ComfyPage'
import { toNodeId } from '@/types/nodeId'
test.describe(
'Vue node viewport virtualization',
{ tag: ['@vue-nodes', '@canvas'] },
() => {
test.afterEach(async ({ comfyPage }) => {
await comfyPage.settings.setSetting(
'Comfy.VueNodes.ViewportVirtualization',
false
)
await comfyPage.settings.setSetting('Comfy.VueNodes.LowZoomLOD', true)
await comfyPage.settings.setSetting('Comfy.VueNodes.FullDetailZoom', 95)
await comfyPage.canvasOps.resetView()
})
test('hydrates all nodes, then swaps to the settled viewport', async ({
comfyPage
}) => {
const graphNodeIds =
await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(
(_nodeId, index) => [
index < 2 ? 100 + index * 500 : 1800 + (index - 2) * 1800,
100
]
)
const firstViewportIds = graphNodeIds.slice(0, 2)
await expect
.poll(() => comfyPage.vueNodes.getNodeIds())
.toEqual(firstViewportIds)
await comfyPage.page.evaluate(() => {
const canvas = window.app!.canvas
canvas.ds.offset[0] = -1800
canvas.setDirty(true, true)
})
await comfyPage.nextFrame()
await expect
.poll(() => comfyPage.vueNodes.getNodeIds())
.toEqual([graphNodeIds[2]])
expect(
await comfyPage.page.evaluate(() => window.app!.graph.nodes.length)
).toBe(graphNodeIds.length)
})
test('keeps a multi-node drag mount set frozen during edge auto-pan', async ({
comfyPage
}) => {
const graphNodeIds =
await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(
(_nodeId, index) => [
index < 2 ? 100 + index * 500 : 1800 + (index - 2) * 1800,
100
]
)
const initialIds = graphNodeIds.slice(0, 2)
await expect
.poll(() => comfyPage.vueNodes.getNodeIds())
.toEqual(initialIds)
await comfyPage.vueNodes.selectNodes(initialIds)
const dragNode = comfyPage.vueNodes.getNodeLocator(initialIds[0])
const header = dragNode.locator('.lg-node-header')
const headerBox = await header.boundingBox()
const canvasBox = await comfyPage.canvas.boundingBox()
if (!headerBox || !canvasBox) throw new Error('Drag geometry unavailable')
const initialOffset = await comfyPage.canvasOps.getOffset()
await comfyPage.page.mouse.move(
headerBox.x + headerBox.width / 2,
headerBox.y + headerBox.height / 2
)
await comfyPage.page.mouse.down()
try {
await comfyPage.page.mouse.move(
canvasBox.x + canvasBox.width - 2,
canvasBox.y + canvasBox.height / 2,
{ steps: 10 }
)
await expect
.poll(() => comfyPage.canvasOps.getOffset())
.not.toEqual(initialOffset)
expect(await comfyPage.vueNodes.getNodeIds()).toEqual(initialIds)
} finally {
await comfyPage.page.mouse.up()
}
})
test('keeps a group drag mounted until the interaction ends', async ({
comfyPage
}) => {
await comfyPage.workflow.loadWorkflow('groups/oversized_group')
await comfyPage.page.evaluate(() => {
const group = window.app!.graph.groups[0]
group.pos = [50, 50]
group.size = [900, 825]
})
const [nodeId] =
await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(() => [
100, 100
])
if (!nodeId) throw new Error('Expected a node in the group workflow')
await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([nodeId])
await comfyPage.page.evaluate(() => {
const canvas = window.app!.canvas
const node = window.app!.graph.nodes[0]
canvas.isDragging = true
canvas.ds.offset[0] -= 1
node.setPos(3100, 100)
node.updateArea()
canvas.setDirty(true, true)
})
const settleDeadline = Date.now() + 200
await expect
.poll(async () => {
if (Date.now() < settleDeadline) return []
return await comfyPage.vueNodes.getNodeIds()
})
.toEqual([nodeId])
await comfyPage.page.evaluate(() => {
window.app!.canvas.isDragging = false
window.dispatchEvent(new PointerEvent('pointerup'))
})
await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([])
})
test('hydrates a node pasted into a distant settled viewport', async ({
comfyPage
}) => {
const [sourceId] =
await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(
(_nodeId, index) => [
index === 0 ? 100 : 4000 + (index - 1) * 1800,
100
]
)
if (!sourceId) throw new Error('Expected a source node')
await expect
.poll(() => comfyPage.vueNodes.getNodeIds())
.toEqual([sourceId])
await comfyPage.vueNodes.getNodeLocator(sourceId).click()
await comfyPage.clipboard.copy()
await comfyPage.page.evaluate(() => {
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
})
await comfyPage.page.evaluate(() => {
const canvas = window.app!.canvas
canvas.ds.offset[0] = -1800
canvas.setDirty(true, true)
})
const canvasBox = await comfyPage.canvas.boundingBox()
if (!canvasBox) throw new Error('Canvas geometry unavailable')
await comfyPage.page.mouse.move(
canvasBox.x + canvasBox.width / 2,
canvasBox.y + canvasBox.height / 2
)
await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toEqual([])
const graphNodeCount = await comfyPage.page.evaluate(
() => window.app!.graph.nodes.length
)
await comfyPage.clipboard.paste()
await expect
.poll(() =>
comfyPage.page.evaluate(() => window.app!.graph.nodes.length)
)
.toBe(graphNodeCount + 1)
await expect.poll(() => comfyPage.vueNodes.getNodeIds()).toHaveLength(1)
})
test('mounts a distant link target after auto-pan pauses', async ({
comfyPage
}) => {
const ids = await comfyPage.page.evaluate(() => {
const graph = window.app!.graph
const source = graph.nodes.find(
(node) => node.getTitle() === 'Load Diffusion Model'
)!
const target = graph.nodes.find(
(node) => node.getTitle() === 'KSampler'
)!
const targetSlot = target.findInputSlot('model')
if (targetSlot >= 0) target.disconnectInput(targetSlot)
return { source: String(source.id), target: String(target.id) }
})
await comfyPage.vueNodes.layoutNodesAndEnableVirtualization(
(nodeId, index) => {
if (nodeId === ids.source) return [100, 100]
if (nodeId === ids.target) return [1800, 100]
return [4000 + index * 1800, 100]
}
)
await expect(comfyPage.vueNodes.getNodeLocator(ids.source)).toBeVisible()
await expect(comfyPage.vueNodes.getNodeLocator(ids.target)).toHaveCount(0)
const source = await comfyPage.vueNodes.getFixtureByTitle(
'Load Diffusion Model'
)
const sourceSlot = source.getSlot('MODEL')
const sourceBox = await sourceSlot.boundingBox()
const canvasBox = await comfyPage.canvas.boundingBox()
if (!sourceBox || !canvasBox) throw new Error('Link geometry unavailable')
await comfyPage.page.mouse.move(
sourceBox.x + sourceBox.width / 2,
sourceBox.y + sourceBox.height / 2
)
await comfyPage.page.mouse.down()
try {
await comfyPage.page.mouse.move(
canvasBox.x + canvasBox.width - 2,
canvasBox.y + canvasBox.height / 2
)
await expect
.poll(async () => (await comfyPage.canvasOps.getOffset())[0])
.toBeLessThan(-1000)
await comfyPage.page.mouse.move(
canvasBox.x + canvasBox.width / 2,
canvasBox.y + canvasBox.height / 2
)
await expect(
comfyPage.vueNodes.getNodeLocator(ids.target)
).toBeVisible()
const target = await comfyPage.vueNodes.getFixtureByTitle('KSampler')
const targetSlot = target.getSlot('model')
const targetBox = await targetSlot.boundingBox()
if (!targetBox) throw new Error('Target slot geometry unavailable')
await comfyPage.page.mouse.move(
targetBox.x + targetBox.width / 2,
targetBox.y + targetBox.height / 2
)
} finally {
await comfyPage.page.mouse.up()
}
await expect
.poll(() =>
comfyPage.page.evaluate((targetId) => {
const target = window.app!.graph.getNodeById(targetId)
const slot = target?.findInputSlot('model') ?? -1
return slot >= 0 ? target?.inputs[slot].link : null
}, toNodeId(ids.target))
)
.not.toBeNull()
})
test('switches paint detail strictly below the configured zoom', async ({
comfyPage
}) => {
await comfyPage.settings.setSetting('Comfy.VueNodes.LowZoomLOD', true)
await comfyPage.settings.setSetting('Comfy.VueNodes.FullDetailZoom', 95)
const widget = comfyPage.vueNodes.nodes.locator('.lg-node-widget').first()
await comfyPage.page.evaluate(() => {
window.app!.canvas.ds.scale = 0.949
window.app!.canvas.setDirty(true, true)
})
await expect
.poll(() => comfyPage.page.locator('html').getAttribute('class'))
.toContain('vue-nodes-low-detail')
await expect
.poll(() => widget.evaluate((el) => getComputedStyle(el).visibility))
.toBe('hidden')
await comfyPage.page.evaluate(() => {
window.app!.canvas.ds.scale = 0.95
window.app!.canvas.setDirty(true, true)
})
await expect
.poll(() => comfyPage.page.locator('html').getAttribute('class'))
.not.toContain('vue-nodes-low-detail')
await expect
.poll(() => widget.evaluate((el) => getComputedStyle(el).visibility))
.toBe('visible')
})
}
)