diff --git a/browser_tests/tests/ecsMigration/historyClipboard.spec.ts b/browser_tests/tests/ecsMigration/historyClipboard.spec.ts new file mode 100644 index 00000000000..fd1bc4d84bd --- /dev/null +++ b/browser_tests/tests/ecsMigration/historyClipboard.spec.ts @@ -0,0 +1,436 @@ +import { + comfyExpect as expect, + comfyPageFixture as test +} from '@e2e/fixtures/ComfyPage' + +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' + +type GraphSnapshot = { + nodes: Array<{ + id: string + type: string + position: [number, number] + widgets: unknown[] + }> + links: Array<{ + originId: string + originSlot: number + targetId: string + targetSlot: number + }> +} + +async function getGraphSnapshot(comfyPage: ComfyPage): Promise { + return comfyPage.page.evaluate(() => ({ + nodes: window + .app!.graph.nodes.map((node) => ({ + id: String(node.id), + type: node.type, + position: [node.pos[0], node.pos[1]] as [number, number], + widgets: (node.widgets ?? []).map((widget) => widget.value) + })) + .sort((left, right) => left.id.localeCompare(right.id)), + links: [...window.app!.graph.links.values()] + .map((link) => ({ + originId: String(link.origin_id), + originSlot: link.origin_slot, + targetId: String(link.target_id), + targetSlot: link.target_slot + })) + .sort((left, right) => + `${left.originId}:${left.originSlot}:${left.targetId}:${left.targetSlot}`.localeCompare( + `${right.originId}:${right.originSlot}:${right.targetId}:${right.targetSlot}` + ) + ) + })) +} + +async function getPairGroupSnapshot(comfyPage: ComfyPage) { + return comfyPage.page.evaluate(() => { + const group = window.app!.graph.groups.find(({ title }) => title === 'Pair') + if (!group) throw new Error('Expected Pair group') + return { + group: [...group.pos, ...group.size], + members: window + .app!.graph.nodes.filter((node) => ['2', '3'].includes(String(node.id))) + .map((node) => ({ + id: String(node.id), + bounds: [...node.getBounding()] + })) + .sort((left, right) => left.id.localeCompare(right.id)) + } + }) +} + +async function marqueeNodes(comfyPage: ComfyPage, nodeIds: string[]) { + const { from, to } = await comfyPage.page.evaluate((ids) => { + const bounds = ids.map((id) => { + const node = window.app!.graph.nodes.find( + (candidate) => String(candidate.id) === id + )! + const [x, y, width, height] = node.getBounding() + const start = window.app!.canvasPosToClientPos([x, y]) + const end = window.app!.canvasPosToClientPos([x + width, y + height]) + return { + left: Math.min(start[0], end[0]), + top: Math.min(start[1], end[1]), + right: Math.max(start[0], end[0]), + bottom: Math.max(start[1], end[1]) + } + }) + return { + from: { + x: Math.min(...bounds.map(({ left }) => left)) - 20, + y: Math.min(...bounds.map(({ top }) => top)) - 20 + }, + to: { + x: Math.max(...bounds.map(({ right }) => right)) + 20, + y: Math.max(...bounds.map(({ bottom }) => bottom)) + 20 + } + } + }, nodeIds) + await comfyPage.canvasOps.dragAndDrop(from, to) +} + +test.describe( + 'ECS migration: history and clipboard regression sanity', + { tag: ['@canvas', '@workflow'] }, + () => { + test.use({ + initialSettings: { + 'Comfy.UseNewMenu': 'Disabled', + 'Comfy.VueNodes.Enabled': false, + 'Comfy.Canvas.LeftMouseClickBehavior': 'select' + } + }) + + test.beforeEach(async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow('default') + }) + + test.afterEach(async ({ comfyPage }) => { + await comfyPage.canvasOps.resetView() + }) + + for (const vueNodesEnabled of [false, true]) { + test(`undo restores a dragged group and every member (${vueNodesEnabled ? 'Vue' : 'LiteGraph'})`, async ({ + comfyPage + }) => { + await comfyPage.settings.setSetting( + 'Comfy.VueNodes.Enabled', + vueNodesEnabled + ) + await comfyPage.workflow.loadWorkflow('selection/three-nodes-and-group') + if (vueNodesEnabled) { + await comfyPage.vueNodes.waitForNodes() + await expect(comfyPage.vueNodes.nodes).toHaveCount(3) + } + const initial = await getPairGroupSnapshot(comfyPage) + expect(initial.members).toHaveLength(2) + + await comfyPage.canvasOps.dragGroup({ + name: 'Pair', + deltaX: 120, + deltaY: 90 + }) + await expect + .poll(() => getPairGroupSnapshot(comfyPage)) + .not.toEqual(initial) + const moved = await getPairGroupSnapshot(comfyPage) + expect( + moved.group.map((value, index) => value - initial.group[index]) + ).toEqual([120, 90, 0, 0]) + expect( + moved.members.map((member, index) => + member.bounds.map( + (value, axis) => value - initial.members[index].bounds[axis] + ) + ) + ).toEqual([ + [120, 90, 0, 0], + [120, 90, 0, 0] + ]) + + await comfyPage.keyboard.undo() + await expect + .poll(() => getPairGroupSnapshot(comfyPage)) + .toEqual(initial) + }) + } + + test('undoes and redoes a move, then deletes only the pasted duplicate', async ({ + comfyPage + }) => { + const original = await comfyPage.nodeOps.getNodeRefById(3) + const initialPosition = + await original.getProperty<[number, number]>('pos') + + await original.dragBy({ x: 137, y: 83 }) + const movedPosition = await original.getProperty<[number, number]>('pos') + expect(movedPosition).not.toEqual(initialPosition) + + await comfyPage.keyboard.undo() + await expect + .poll(() => original.getProperty<[number, number]>('pos')) + .toEqual(initialPosition) + await comfyPage.keyboard.redo() + await expect + .poll(() => original.getProperty<[number, number]>('pos')) + .toEqual(movedPosition) + + await comfyPage.page.evaluate(() => { + const node = window.app!.graph.nodes.find( + (candidate) => String(candidate.id) === '3' + )! + window.app!.canvas.selectNodes([node]) + }) + await expect + .poll(() => comfyPage.nodeOps.getSelectedNodeIds()) + .toEqual(['3']) + await comfyPage.clipboard.copy() + await comfyPage.page.mouse.move(10, 10) + await comfyPage.clipboard.paste() + + const pastedIds = await comfyPage.page.evaluate(() => + window + .app!.graph.nodes.filter( + (node) => node.type === 'KSampler' && String(node.id) !== '3' + ) + .map((node) => String(node.id)) + ) + expect(pastedIds).toHaveLength(1) + expect(await comfyPage.nodeOps.getSelectedNodeIds()).toEqual(pastedIds) + + await comfyPage.keyboard.delete() + await expect.poll(() => comfyPage.nodeOps.getGraphNodesCount()).toBe(7) + await expect.poll(() => original.exists()).toBe(true) + await expect + .poll(() => + comfyPage.page.evaluate( + (id) => + window.app!.graph.nodes.some((node) => String(node.id) === id), + pastedIds[0] + ) + ) + .toBe(false) + }) + + test('copies two connected nodes with their internal link and widget values', async ({ + comfyPage + }) => { + const sourceIds = ['3', '8'] + const sourceSnapshot = await getGraphSnapshot(comfyPage) + const sourceNodes = sourceSnapshot.nodes.filter(({ id }) => + sourceIds.includes(id) + ) + const sourceLink = sourceSnapshot.links.find( + ({ originId, targetId }) => originId === '3' && targetId === '8' + ) + expect(sourceNodes.map(({ type }) => type)).toEqual([ + 'KSampler', + 'VAEDecode' + ]) + expect(sourceLink).toEqual({ + originId: '3', + originSlot: 0, + targetId: '8', + targetSlot: 0 + }) + + await marqueeNodes(comfyPage, sourceIds) + await expect + .poll(() => comfyPage.nodeOps.getSelectedNodeIds()) + .toEqual(sourceIds) + await comfyPage.clipboard.copy() + await comfyPage.page.mouse.move(350, 650) + await comfyPage.clipboard.paste() + + const pastedIds = (await comfyPage.nodeOps.getSelectedNodeIds()).map( + String + ) + expect(pastedIds).toHaveLength(2) + expect(pastedIds.every((id) => !sourceIds.includes(id))).toBe(true) + const pastedSnapshot = await getGraphSnapshot(comfyPage) + const pastedNodes = pastedSnapshot.nodes.filter(({ id }) => + pastedIds.includes(id) + ) + const pastedBySourceId = new Map( + sourceNodes.map((source) => [ + source.id, + pastedNodes.find(({ type }) => type === source.type) + ]) + ) + expect([...pastedBySourceId.values()]).toEqual( + sourceNodes.map(({ type, widgets }) => + expect.objectContaining({ type, widgets }) + ) + ) + expect( + pastedSnapshot.links.filter( + ({ originId, targetId }) => + pastedIds.includes(originId) && pastedIds.includes(targetId) + ) + ).toEqual([ + { + originId: pastedBySourceId.get(sourceLink!.originId)!.id, + originSlot: sourceLink!.originSlot, + targetId: pastedBySourceId.get(sourceLink!.targetId)!.id, + targetSlot: sourceLink!.targetSlot + } + ]) + }) + + test('partial-name search places the selected node on Enter', async ({ + comfyPage + }) => { + const initialIds = await comfyPage.page.evaluate(() => + window.app!.graph.nodes.map((node) => String(node.id)) + ) + const position = { x: 640, y: 420 } + + await comfyPage.page.mouse.move(position.x, position.y) + await comfyPage.searchBoxV2.open() + await comfyPage.searchBoxV2.input.fill('KSamp') + await expect(comfyPage.searchBoxV2.results.first()).toContainText( + 'KSampler' + ) + await comfyPage.page.keyboard.press('Enter') + await expect(comfyPage.searchBoxV2.dialog).toBeHidden() + + const added = await comfyPage.page.evaluate((ids) => { + const node = window.app!.graph.nodes.find( + (candidate) => !ids.includes(String(candidate.id)) + ) + return node + ? { id: String(node.id), type: node.type, position: [...node.pos] } + : null + }, initialIds) + expect(added).not.toBeNull() + expect(added?.type).toBe('KSampler') + expect(added?.position).toEqual([position.x - 135, position.y + 10]) + }) + + test('pan, zoom and linked-node drag preserve exact link endpoints', async ({ + comfyPage + }) => { + const ids = ['3', '8'] + const before = await getGraphSnapshot(comfyPage) + const beforeView = await comfyPage.page.evaluate(() => ({ + scale: window.app!.canvas.ds.scale, + offset: [...window.app!.canvas.ds.offset] + })) + + await comfyPage.settings.setSetting( + 'Comfy.Canvas.LeftMouseClickBehavior', + 'panning' + ) + await comfyPage.canvasOps.pan({ x: 73, y: 41 }) + const pannedView = await comfyPage.page.evaluate(() => ({ + scale: window.app!.canvas.ds.scale, + offset: [...window.app!.canvas.ds.offset] + })) + expect(pannedView.offset).not.toEqual(beforeView.offset) + await comfyPage.canvasOps.zoom(100, 2) + const zoomedView = await comfyPage.page.evaluate(() => ({ + scale: window.app!.canvas.ds.scale, + offset: [...window.app!.canvas.ds.offset] + })) + expect(zoomedView.scale).not.toBe(pannedView.scale) + + await comfyPage.settings.setSetting( + 'Comfy.Canvas.LeftMouseClickBehavior', + 'select' + ) + await marqueeNodes(comfyPage, ids) + await expect + .poll(async () => + (await comfyPage.nodeOps.getSelectedNodeIds()).map(String).sort() + ) + .toEqual(ids) + await ( + await comfyPage.nodeOps.getNodeRefById('3') + ).dragBy({ x: 111, y: 69 }) + + const moved = await getGraphSnapshot(comfyPage) + const firstBefore = before.nodes.find(({ id }) => id === '3')! + const firstMoved = moved.nodes.find(({ id }) => id === '3')! + const delta = [ + firstMoved.position[0] - firstBefore.position[0], + firstMoved.position[1] - firstBefore.position[1] + ] + expect(delta[0]).not.toBe(0) + expect(delta[1]).not.toBe(0) + for (const id of ids) { + const nodeBefore = before.nodes.find((node) => node.id === id)! + const nodeMoved = moved.nodes.find((node) => node.id === id)! + expect(nodeMoved.position[0] - nodeBefore.position[0]).toBeCloseTo( + delta[0], + 8 + ) + expect(nodeMoved.position[1] - nodeBefore.position[1]).toBeCloseTo( + delta[1], + 8 + ) + } + expect(moved.links).toEqual(before.links) + expect(moved.links).toContainEqual({ + originId: '3', + originSlot: 0, + targetId: '8', + targetSlot: 0 + }) + }) + + for (const vueNodesEnabled of [false, true]) { + test(`box-select drag and delete undo restores three linked nodes (${vueNodesEnabled ? 'Vue' : 'LiteGraph'})`, async ({ + comfyPage + }) => { + await comfyPage.settings.setSetting( + 'Comfy.VueNodes.Enabled', + vueNodesEnabled + ) + if (vueNodesEnabled) await comfyPage.vueNodes.waitForNodes() + const ids = ['3', '8', '9'] + const before = await getGraphSnapshot(comfyPage) + await marqueeNodes(comfyPage, ids) + await expect + .poll(async () => + (await comfyPage.nodeOps.getSelectedNodeIds()).map(String).sort() + ) + .toEqual(ids) + + await ( + await comfyPage.nodeOps.getNodeRefById(3) + ).dragBy({ x: 91, y: 67 }) + const moved = await getGraphSnapshot(comfyPage) + const firstInitial = before.nodes.find((node) => node.id === ids[0])! + const firstTranslated = moved.nodes.find((node) => node.id === ids[0])! + const translation = [ + firstTranslated.position[0] - firstInitial.position[0], + firstTranslated.position[1] - firstInitial.position[1] + ] + expect(translation[0]).not.toBe(0) + expect(translation[1]).not.toBe(0) + for (const id of ids) { + const initial = before.nodes.find((node) => node.id === id)! + const translated = moved.nodes.find((node) => node.id === id)! + expect(translated.position[0] - initial.position[0]).toBeCloseTo( + translation[0], + 5 + ) + expect(translated.position[1] - initial.position[1]).toBeCloseTo( + translation[1], + 5 + ) + } + + await comfyPage.keyboard.delete() + await expect.poll(() => comfyPage.nodeOps.getGraphNodesCount()).toBe(4) + await comfyPage.keyboard.undo() + await expect.poll(() => getGraphSnapshot(comfyPage)).toEqual(moved) + await comfyPage.keyboard.undo() + await expect.poll(() => getGraphSnapshot(comfyPage)).toEqual(before) + }) + } + } +) diff --git a/browser_tests/tests/vueNodes/groups/groups.spec.ts b/browser_tests/tests/vueNodes/groups/groups.spec.ts index d25abdc1473..e6629ee7cef 100644 --- a/browser_tests/tests/vueNodes/groups/groups.spec.ts +++ b/browser_tests/tests/vueNodes/groups/groups.spec.ts @@ -5,6 +5,7 @@ import { import type { ComfyPage } from '@e2e/fixtures/ComfyPage' import { TestIds } from '@e2e/fixtures/selectors' import { getGroupTitlePosition } from '@e2e/fixtures/utils/groupHelpers' +import { openMoreOptions } from '@e2e/fixtures/utils/selectionToolbox' const CREATE_GROUP_HOTKEY = 'Control+g' @@ -42,6 +43,23 @@ function expectWithinBaseline( expect(Math.abs(actual - baseline)).toBeLessThan(tolerance) } +async function getPairSnapshot(comfyPage: ComfyPage) { + return comfyPage.page.evaluate(() => { + const group = window.app!.graph.groups.find(({ title }) => title === 'Pair') + if (!group) throw new Error('Expected Pair group') + return { + group: [...group.pos, ...group.size], + members: window + .app!.graph.nodes.filter((node) => ['2', '3'].includes(String(node.id))) + .map((node) => ({ + id: String(node.id), + bounds: [...node.getBounding()] + })) + .sort((left, right) => left.id.localeCompare(right.id)) + } + }) +} + async function getNodeGroupCenteringErrors( comfyPage: ComfyPage ): Promise { @@ -340,6 +358,85 @@ test.describe('Vue Node Groups', { tag: ['@screenshot', '@vue-nodes'] }, () => { await toggleBypass() await expect.poll(bypassCount, "won't toggle double selected node").toBe(7) }) + + test('visible controls update group title and color before both members drag', async ({ + comfyPage + }) => { + await comfyPage.settings.setSetting('Comfy.Canvas.SelectionToolbox', true) + await comfyPage.workflow.loadWorkflow('selection/three-nodes-and-group') + await comfyPage.vueNodes.waitForNodes() + await expect(comfyPage.vueNodes.nodes).toHaveCount(3) + const initial = await getPairSnapshot(comfyPage) + expect(initial.members).toHaveLength(2) + const groupTitle = await getGroupTitlePosition(comfyPage, 'Pair') + await comfyPage.page.mouse.click(groupTitle.x, groupTitle.y) + + const menu = await openMoreOptions(comfyPage) + await menu.getByText('Rename', { exact: true }).click() + await comfyPage.nodeOps.promptDialogInput.fill('Renamed Pair') + await comfyPage.nodeOps.promptDialogInput.press('Enter') + await expect + .poll(() => + comfyPage.page.evaluate(() => + window.app!.graph.groups.some(({ title }) => title === 'Renamed Pair') + ) + ) + .toBe(true) + + const renamedTitle = await getGroupTitlePosition(comfyPage, 'Renamed Pair') + await comfyPage.page.mouse.click(renamedTitle.x, renamedTitle.y, { + button: 'right' + }) + await expect(comfyPage.contextMenu.primeVueMenu).toBeVisible() + await comfyPage.page.getByText('Color', { exact: true }).click() + await comfyPage.page.getByTitle('Red').first().click() + await expect + .poll(() => + comfyPage.page.evaluate( + () => + window.app!.graph.groups.find( + ({ title }) => title === 'Renamed Pair' + )?.color + ) + ) + .toBe('#A88') + + await comfyPage.canvasOps.dragGroup({ + name: 'Renamed Pair', + deltaX: 110, + deltaY: 70 + }) + const moved = await comfyPage.page.evaluate(() => { + const group = window.app!.graph.groups.find( + ({ title }) => title === 'Renamed Pair' + )! + return { + group: [...group.pos, ...group.size], + members: window + .app!.graph.nodes.filter((node) => + ['2', '3'].includes(String(node.id)) + ) + .map((node) => ({ + id: String(node.id), + bounds: [...node.getBounding()] + })) + .sort((left, right) => left.id.localeCompare(right.id)) + } + }) + expect( + moved.group.map((value, index) => value - initial.group[index]) + ).toEqual([110, 70, 0, 0]) + expect( + moved.members.map((member, index) => + member.bounds.map( + (value, axis) => value - initial.members[index].bounds[axis] + ) + ) + ).toEqual([ + [110, 70, 0, 0], + [110, 70, 0, 0] + ]) + }) }) test.describe(