|
| 1 | +import type { Locator } from '@playwright/test' |
| 2 | + |
| 3 | +import { getSlotKey } from '../../../src/renderer/core/layout/slots/slotIdentifier' |
| 4 | +import { |
| 5 | + comfyExpect as expect, |
| 6 | + comfyPageFixture as test |
| 7 | +} from '../../fixtures/ComfyPage' |
| 8 | +import { fitToViewInstant } from '../../helpers/fitToView' |
| 9 | + |
| 10 | +async function getCenter(locator: Locator): Promise<{ x: number; y: number }> { |
| 11 | + const box = await locator.boundingBox() |
| 12 | + if (!box) throw new Error('Slot bounding box not available') |
| 13 | + return { |
| 14 | + x: box.x + box.width / 2, |
| 15 | + y: box.y + box.height / 2 |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +test.describe('Vue Node Link Interaction', () => { |
| 20 | + test.beforeEach(async ({ comfyPage }) => { |
| 21 | + await comfyPage.setSetting('Comfy.UseNewMenu', 'Top') |
| 22 | + await comfyPage.setSetting('Comfy.VueNodes.Enabled', true) |
| 23 | + await comfyPage.setup() |
| 24 | + await comfyPage.loadWorkflow('vueNodes/simple-triple') |
| 25 | + await comfyPage.vueNodes.waitForNodes() |
| 26 | + await fitToViewInstant(comfyPage) |
| 27 | + }) |
| 28 | + |
| 29 | + test('should show a link dragging out from a slot when dragging on a slot', async ({ |
| 30 | + comfyPage, |
| 31 | + comfyMouse |
| 32 | + }) => { |
| 33 | + const samplerNodes = await comfyPage.getNodeRefsByType('KSampler') |
| 34 | + expect(samplerNodes.length).toBeGreaterThan(0) |
| 35 | + |
| 36 | + const samplerNode = samplerNodes[0] |
| 37 | + const outputSlot = await samplerNode.getOutput(0) |
| 38 | + await outputSlot.removeLinks() |
| 39 | + await comfyPage.nextFrame() |
| 40 | + |
| 41 | + const slotKey = getSlotKey(String(samplerNode.id), 0, false) |
| 42 | + const slotLocator = comfyPage.page.locator(`[data-slot-key="${slotKey}"]`) |
| 43 | + await expect(slotLocator).toBeVisible() |
| 44 | + |
| 45 | + const start = await getCenter(slotLocator) |
| 46 | + const canvasBox = await comfyPage.canvas.boundingBox() |
| 47 | + if (!canvasBox) throw new Error('Canvas bounding box not available') |
| 48 | + |
| 49 | + // Arbitrary value |
| 50 | + const dragTarget = { |
| 51 | + x: start.x + 180, |
| 52 | + y: start.y - 140 |
| 53 | + } |
| 54 | + |
| 55 | + await comfyMouse.move(start) |
| 56 | + await comfyMouse.drag(dragTarget) |
| 57 | + await comfyPage.nextFrame() |
| 58 | + |
| 59 | + try { |
| 60 | + await expect(comfyPage.canvas).toHaveScreenshot( |
| 61 | + 'vue-node-dragging-link.png' |
| 62 | + ) |
| 63 | + } finally { |
| 64 | + await comfyMouse.drop() |
| 65 | + } |
| 66 | + }) |
| 67 | + |
| 68 | + test('should create a link when dropping on a compatible slot', async ({ |
| 69 | + comfyPage |
| 70 | + }) => { |
| 71 | + const samplerNodes = await comfyPage.getNodeRefsByType('KSampler') |
| 72 | + expect(samplerNodes.length).toBeGreaterThan(0) |
| 73 | + const samplerNode = samplerNodes[0] |
| 74 | + |
| 75 | + const vaeNodes = await comfyPage.getNodeRefsByType('VAEDecode') |
| 76 | + expect(vaeNodes.length).toBeGreaterThan(0) |
| 77 | + const vaeNode = vaeNodes[0] |
| 78 | + |
| 79 | + const samplerOutput = await samplerNode.getOutput(0) |
| 80 | + const vaeInput = await vaeNode.getInput(0) |
| 81 | + |
| 82 | + const outputSlotKey = getSlotKey(String(samplerNode.id), 0, false) |
| 83 | + const inputSlotKey = getSlotKey(String(vaeNode.id), 0, true) |
| 84 | + |
| 85 | + const outputSlot = comfyPage.page.locator( |
| 86 | + `[data-slot-key="${outputSlotKey}"]` |
| 87 | + ) |
| 88 | + const inputSlot = comfyPage.page.locator( |
| 89 | + `[data-slot-key="${inputSlotKey}"]` |
| 90 | + ) |
| 91 | + |
| 92 | + await expect(outputSlot).toBeVisible() |
| 93 | + await expect(inputSlot).toBeVisible() |
| 94 | + |
| 95 | + await outputSlot.dragTo(inputSlot) |
| 96 | + await comfyPage.nextFrame() |
| 97 | + |
| 98 | + expect(await samplerOutput.getLinkCount()).toBe(1) |
| 99 | + expect(await vaeInput.getLinkCount()).toBe(1) |
| 100 | + |
| 101 | + const linkDetails = await comfyPage.page.evaluate((sourceId) => { |
| 102 | + const app = window['app'] |
| 103 | + const graph = app?.canvas?.graph ?? app?.graph |
| 104 | + if (!graph) return null |
| 105 | + |
| 106 | + const source = graph.getNodeById(sourceId) |
| 107 | + if (!source) return null |
| 108 | + |
| 109 | + const linkId = source.outputs[0]?.links?.[0] |
| 110 | + if (linkId == null) return null |
| 111 | + |
| 112 | + const link = graph.links[linkId] |
| 113 | + if (!link) return null |
| 114 | + |
| 115 | + return { |
| 116 | + originId: link.origin_id, |
| 117 | + originSlot: link.origin_slot, |
| 118 | + targetId: link.target_id, |
| 119 | + targetSlot: link.target_slot |
| 120 | + } |
| 121 | + }, samplerNode.id) |
| 122 | + |
| 123 | + expect(linkDetails).not.toBeNull() |
| 124 | + expect(linkDetails).toMatchObject({ |
| 125 | + originId: samplerNode.id, |
| 126 | + originSlot: 0, |
| 127 | + targetId: vaeNode.id, |
| 128 | + targetSlot: 0 |
| 129 | + }) |
| 130 | + }) |
| 131 | + |
| 132 | + test('should not create a link when slot types are incompatible', async ({ |
| 133 | + comfyPage |
| 134 | + }) => { |
| 135 | + const samplerNodes = await comfyPage.getNodeRefsByType('KSampler') |
| 136 | + expect(samplerNodes.length).toBeGreaterThan(0) |
| 137 | + const samplerNode = samplerNodes[0] |
| 138 | + |
| 139 | + const clipNodes = await comfyPage.getNodeRefsByType('CLIPTextEncode') |
| 140 | + expect(clipNodes.length).toBeGreaterThan(0) |
| 141 | + const clipNode = clipNodes[0] |
| 142 | + |
| 143 | + const samplerOutput = await samplerNode.getOutput(0) |
| 144 | + const clipInput = await clipNode.getInput(0) |
| 145 | + |
| 146 | + const outputSlotKey = getSlotKey(String(samplerNode.id), 0, false) |
| 147 | + const inputSlotKey = getSlotKey(String(clipNode.id), 0, true) |
| 148 | + |
| 149 | + const outputSlot = comfyPage.page.locator( |
| 150 | + `[data-slot-key="${outputSlotKey}"]` |
| 151 | + ) |
| 152 | + const inputSlot = comfyPage.page.locator( |
| 153 | + `[data-slot-key="${inputSlotKey}"]` |
| 154 | + ) |
| 155 | + |
| 156 | + await expect(outputSlot).toBeVisible() |
| 157 | + await expect(inputSlot).toBeVisible() |
| 158 | + |
| 159 | + await outputSlot.dragTo(inputSlot) |
| 160 | + await comfyPage.nextFrame() |
| 161 | + |
| 162 | + expect(await samplerOutput.getLinkCount()).toBe(0) |
| 163 | + expect(await clipInput.getLinkCount()).toBe(0) |
| 164 | + |
| 165 | + const graphLinkCount = await comfyPage.page.evaluate((sourceId) => { |
| 166 | + const app = window['app'] |
| 167 | + const graph = app?.canvas?.graph ?? app?.graph |
| 168 | + if (!graph) return 0 |
| 169 | + |
| 170 | + const source = graph.getNodeById(sourceId) |
| 171 | + if (!source) return 0 |
| 172 | + |
| 173 | + return source.outputs[0]?.links?.length ?? 0 |
| 174 | + }, samplerNode.id) |
| 175 | + |
| 176 | + expect(graphLinkCount).toBe(0) |
| 177 | + }) |
| 178 | + |
| 179 | + test('should not create a link when dropping onto a slot on the same node', async ({ |
| 180 | + comfyPage |
| 181 | + }) => { |
| 182 | + const samplerNodes = await comfyPage.getNodeRefsByType('KSampler') |
| 183 | + expect(samplerNodes.length).toBeGreaterThan(0) |
| 184 | + const samplerNode = samplerNodes[0] |
| 185 | + |
| 186 | + const samplerOutput = await samplerNode.getOutput(0) |
| 187 | + const samplerInput = await samplerNode.getInput(3) |
| 188 | + |
| 189 | + const outputSlotKey = getSlotKey(String(samplerNode.id), 0, false) |
| 190 | + const inputSlotKey = getSlotKey(String(samplerNode.id), 3, true) |
| 191 | + |
| 192 | + const outputSlot = comfyPage.page.locator( |
| 193 | + `[data-slot-key="${outputSlotKey}"]` |
| 194 | + ) |
| 195 | + const inputSlot = comfyPage.page.locator( |
| 196 | + `[data-slot-key="${inputSlotKey}"]` |
| 197 | + ) |
| 198 | + |
| 199 | + await expect(outputSlot).toBeVisible() |
| 200 | + await expect(inputSlot).toBeVisible() |
| 201 | + |
| 202 | + await outputSlot.dragTo(inputSlot) |
| 203 | + await comfyPage.nextFrame() |
| 204 | + |
| 205 | + expect(await samplerOutput.getLinkCount()).toBe(0) |
| 206 | + expect(await samplerInput.getLinkCount()).toBe(0) |
| 207 | + |
| 208 | + const graphLinkCount = await comfyPage.page.evaluate((sourceId) => { |
| 209 | + const app = window['app'] |
| 210 | + const graph = app?.canvas?.graph ?? app?.graph |
| 211 | + if (!graph) return 0 |
| 212 | + |
| 213 | + const source = graph.getNodeById(sourceId) |
| 214 | + if (!source) return 0 |
| 215 | + |
| 216 | + return source.outputs[0]?.links?.length ?? 0 |
| 217 | + }, samplerNode.id) |
| 218 | + |
| 219 | + expect(graphLinkCount).toBe(0) |
| 220 | + }) |
| 221 | +}) |
0 commit comments