|
| 1 | +import { |
| 2 | + comfyExpect as expect, |
| 3 | + comfyPageFixture as test |
| 4 | +} from '@e2e/fixtures/ComfyPage' |
| 5 | +import type { Page } from '@playwright/test' |
| 6 | + |
| 7 | +async function setCanvasOffsetX(page: Page, offsetX: number): Promise<void> { |
| 8 | + await page.evaluate((x) => { |
| 9 | + const canvas = window.app!.canvas |
| 10 | + canvas.ds.offset[0] = x |
| 11 | + canvas.setDirty(true, true) |
| 12 | + }, offsetX) |
| 13 | +} |
| 14 | + |
| 15 | +test.describe( |
| 16 | + 'Vue node viewport KeepAlive', |
| 17 | + { tag: ['@canvas', '@node', '@vue-nodes', '@slow'] }, |
| 18 | + () => { |
| 19 | + test.beforeEach(async ({ comfyPage }) => { |
| 20 | + await comfyPage.settings.setSetting('Comfy.VueNodes.Enabled', true) |
| 21 | + await comfyPage.workflow.loadWorkflow('large-graph-workflow') |
| 22 | + await comfyPage.canvasOps.setScale(1) |
| 23 | + await comfyPage.page.evaluate(() => { |
| 24 | + const canvas = window.app!.canvas |
| 25 | + canvas.ds.offset[0] = 0 |
| 26 | + canvas.ds.offset[1] = 0 |
| 27 | + canvas.setDirty(true, true) |
| 28 | + }) |
| 29 | + await comfyPage.nextFrame() |
| 30 | + await comfyPage.vueNodes.waitForNodes() |
| 31 | + }) |
| 32 | + |
| 33 | + test.afterEach(async ({ comfyPage }) => { |
| 34 | + await comfyPage.canvasOps.resetView() |
| 35 | + }) |
| 36 | + |
| 37 | + test('detaches nodes and restores the same element without changing graph size', async ({ |
| 38 | + comfyPage |
| 39 | + }) => { |
| 40 | + test.slow() |
| 41 | + const initialNode = comfyPage.vueNodes.nodes.first() |
| 42 | + await expect(initialNode).toBeVisible() |
| 43 | + const nodeId = await initialNode.getAttribute('data-node-id') |
| 44 | + const initialElement = await initialNode.elementHandle() |
| 45 | + if (!nodeId || !initialElement) { |
| 46 | + throw new Error('Expected an active Vue node with an id') |
| 47 | + } |
| 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) |
| 55 | + |
| 56 | + await setCanvasOffsetX(comfyPage.page, -100_000) |
| 57 | + |
| 58 | + await expect |
| 59 | + .poll(() => initialElement.evaluate((element) => element.isConnected)) |
| 60 | + .toBe(false) |
| 61 | + await expect |
| 62 | + .poll(() => comfyPage.vueNodes.getNodeCount()) |
| 63 | + .toBeLessThan(245) |
| 64 | + |
| 65 | + await setCanvasOffsetX(comfyPage.page, 0) |
| 66 | + |
| 67 | + const returnedNode = comfyPage.vueNodes.getNodeLocator(nodeId) |
| 68 | + await expect(returnedNode).toBeVisible() |
| 69 | + const returnedElement = await returnedNode.elementHandle() |
| 70 | + if (!returnedElement) throw new Error('Expected the Vue node to return') |
| 71 | + |
| 72 | + expect( |
| 73 | + await initialElement.evaluate( |
| 74 | + (element, candidate) => element === candidate, |
| 75 | + returnedElement |
| 76 | + ) |
| 77 | + ).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) |
| 87 | + }) |
| 88 | + |
| 89 | + test('keeps the focused node connected while panning away', async ({ |
| 90 | + comfyPage |
| 91 | + }) => { |
| 92 | + test.slow() |
| 93 | + const focusedNode = comfyPage.vueNodes.nodes.first() |
| 94 | + const focusedElement = await focusedNode.elementHandle() |
| 95 | + if (!focusedElement) throw new Error('Expected an active Vue node') |
| 96 | + await focusedNode.focus() |
| 97 | + |
| 98 | + await setCanvasOffsetX(comfyPage.page, -100_000) |
| 99 | + |
| 100 | + await expect |
| 101 | + .poll(() => focusedElement.evaluate((element) => element.isConnected)) |
| 102 | + .toBe(true) |
| 103 | + expect( |
| 104 | + await focusedElement.evaluate((element) => |
| 105 | + element.contains(document.activeElement) |
| 106 | + ) |
| 107 | + ).toBe(true) |
| 108 | + }) |
| 109 | + |
| 110 | + test('keeps a link-drag source connected while panning away', async ({ |
| 111 | + comfyPage |
| 112 | + }) => { |
| 113 | + test.slow() |
| 114 | + const sourceNode = comfyPage.vueNodes.getNodeLocator('3') |
| 115 | + const outputSlot = sourceNode |
| 116 | + .locator('.lg-slot--output') |
| 117 | + .getByTestId('slot-connection-dot') |
| 118 | + await expect(outputSlot).toBeVisible() |
| 119 | + const sourceElement = await sourceNode.elementHandle() |
| 120 | + if (!sourceElement) throw new Error('Expected a link source node') |
| 121 | + |
| 122 | + await outputSlot.hover() |
| 123 | + await comfyPage.page.mouse.down() |
| 124 | + try { |
| 125 | + await comfyPage.page.evaluate(() => { |
| 126 | + window.app!.canvas.deselectAll() |
| 127 | + if (document.activeElement instanceof HTMLElement) { |
| 128 | + document.activeElement.blur() |
| 129 | + } |
| 130 | + }) |
| 131 | + await expect |
| 132 | + .poll(() => |
| 133 | + comfyPage.page.evaluate( |
| 134 | + () => window.app!.canvas.linkConnector.isConnecting |
| 135 | + ) |
| 136 | + ) |
| 137 | + .toBe(true) |
| 138 | + |
| 139 | + await setCanvasOffsetX(comfyPage.page, -100_000) |
| 140 | + |
| 141 | + await expect |
| 142 | + .poll(() => sourceElement.evaluate((element) => element.isConnected)) |
| 143 | + .toBe(true) |
| 144 | + } finally { |
| 145 | + await comfyPage.page.mouse.up() |
| 146 | + } |
| 147 | + |
| 148 | + await expect |
| 149 | + .poll(() => sourceElement.evaluate((element) => element.isConnected)) |
| 150 | + .toBe(false) |
| 151 | + }) |
| 152 | + } |
| 153 | +) |
0 commit comments