@@ -2,7 +2,12 @@ import {
22 comfyExpect as expect ,
33 comfyPageFixture as test
44} from '@e2e/fixtures/ComfyPage'
5+ import type { ComfyPage } from '@e2e/fixtures/ComfyPage'
6+ import largeGraphWorkflow from '@e2e/assets/large-graph-workflow.json' with { type : 'json' }
57import type { Page } from '@playwright/test'
8+ import { zComfyWorkflow } from '@/platform/workflow/validation/schemas/workflowSchema'
9+
10+ const LARGE_GRAPH_WORKFLOW = zComfyWorkflow . parse ( largeGraphWorkflow )
611
712async function setCanvasOffsetX ( page : Page , offsetX : number ) : Promise < void > {
813 await page . evaluate ( ( x ) => {
@@ -12,13 +17,28 @@ async function setCanvasOffsetX(page: Page, offsetX: number): Promise<void> {
1217 } , offsetX )
1318}
1419
20+ async function setCanvasScale ( comfyPage : ComfyPage , scale : number ) {
21+ await comfyPage . canvasOps . setScale ( scale )
22+ await comfyPage . nextFrame ( )
23+ }
24+
25+ async function getGraphNodeSize ( page : Page , nodeId : string ) {
26+ return await page . evaluate ( ( id ) => {
27+ const node = window . app ! . graph ! . nodes . find (
28+ ( candidate ) => String ( candidate . id ) === id
29+ )
30+ if ( ! node ) throw new Error ( `Node ${ id } is missing` )
31+ return Array . from ( node . size )
32+ } , nodeId )
33+ }
34+
1535test . describe (
1636 'Vue node viewport KeepAlive' ,
1737 { tag : [ '@canvas' , '@node' , '@vue-nodes' , '@slow' ] } ,
1838 ( ) => {
1939 test . beforeEach ( async ( { comfyPage } ) => {
2040 await comfyPage . settings . setSetting ( 'Comfy.VueNodes.Enabled' , true )
21- await comfyPage . workflow . loadWorkflow ( 'large-graph-workflow' )
41+ await comfyPage . workflow . loadGraphData ( LARGE_GRAPH_WORKFLOW )
2242 await comfyPage . canvasOps . setScale ( 1 )
2343 await comfyPage . page . evaluate ( ( ) => {
2444 const canvas = window . app ! . canvas
@@ -45,13 +65,7 @@ test.describe(
4565 if ( ! nodeId || ! initialElement ) {
4666 throw new Error ( 'Expected an active Vue node with an id' )
4767 }
48- const initialSize = await comfyPage . page . evaluate ( ( id ) => {
49- const node = window . app ! . graph ! . nodes . find (
50- ( candidate ) => String ( candidate . id ) === id
51- )
52- if ( ! node ) throw new Error ( `Node ${ id } is missing` )
53- return Array . from ( node . size )
54- } , nodeId )
68+ const initialSize = await getGraphNodeSize ( comfyPage . page , nodeId )
5569
5670 await setCanvasOffsetX ( comfyPage . page , - 100_000 )
5771
@@ -75,15 +89,9 @@ test.describe(
7589 returnedElement
7690 )
7791 ) . toBe ( true )
78- expect (
79- await comfyPage . page . evaluate ( ( id ) => {
80- const node = window . app ! . graph ! . nodes . find (
81- ( candidate ) => String ( candidate . id ) === id
82- )
83- if ( ! node ) throw new Error ( `Node ${ id } is missing` )
84- return Array . from ( node . size )
85- } , nodeId )
86- ) . toEqual ( initialSize )
92+ expect ( await getGraphNodeSize ( comfyPage . page , nodeId ) ) . toEqual (
93+ initialSize
94+ )
8795 } )
8896
8997 test ( 'keeps the focused node connected while panning away' , async ( {
@@ -149,5 +157,61 @@ test.describe(
149157 . poll ( ( ) => sourceElement . evaluate ( ( element ) => element . isConnected ) )
150158 . toBe ( false )
151159 } )
160+
161+ test ( 'uses boxes at low quality and restores the same node element' , async ( {
162+ comfyPage
163+ } ) => {
164+ test . slow ( )
165+ const initialNode = comfyPage . vueNodes . nodes . first ( )
166+ const nodeId = await initialNode . getAttribute ( 'data-node-id' )
167+ const initialElement = await initialNode . elementHandle ( )
168+ if ( ! nodeId || ! initialElement ) {
169+ throw new Error ( 'Expected an active Vue node with an id' )
170+ }
171+ const initialSize = await getGraphNodeSize ( comfyPage . page , nodeId )
172+
173+ await setCanvasScale ( comfyPage , 0.4 )
174+ await expect ( comfyPage . page . getByTestId ( 'node-box-overlay' ) ) . toBeVisible ( )
175+ await expect
176+ . poll ( ( ) => initialElement . evaluate ( ( element ) => element . isConnected ) )
177+ . toBe ( false )
178+
179+ await setCanvasScale ( comfyPage , 1 )
180+ const returnedNode = comfyPage . vueNodes . getNodeLocator ( nodeId )
181+ await expect ( returnedNode ) . toBeVisible ( )
182+ const returnedElement = await returnedNode . elementHandle ( )
183+ if ( ! returnedElement ) throw new Error ( 'Expected the Vue node to return' )
184+
185+ expect (
186+ await initialElement . evaluate (
187+ ( element , candidate ) => element === candidate ,
188+ returnedElement
189+ )
190+ ) . toBe ( true )
191+ expect ( await getGraphNodeSize ( comfyPage . page , nodeId ) ) . toEqual (
192+ initialSize
193+ )
194+ } )
195+
196+ test ( 'keeps the focused node connected in low-quality mode' , async ( {
197+ comfyPage
198+ } ) => {
199+ test . slow ( )
200+ const focusedNode = comfyPage . vueNodes . nodes . first ( )
201+ const focusedElement = await focusedNode . elementHandle ( )
202+ if ( ! focusedElement ) throw new Error ( 'Expected an active Vue node' )
203+ await focusedNode . focus ( )
204+
205+ await setCanvasScale ( comfyPage , 0.4 )
206+ await expect ( comfyPage . page . getByTestId ( 'node-box-overlay' ) ) . toBeVisible ( )
207+ await expect
208+ . poll ( ( ) => focusedElement . evaluate ( ( element ) => element . isConnected ) )
209+ . toBe ( true )
210+ expect (
211+ await focusedElement . evaluate ( ( element ) =>
212+ element . contains ( document . activeElement )
213+ )
214+ ) . toBe ( true )
215+ } )
152216 }
153217)
0 commit comments