|
| 1 | +import { expect } from '@playwright/test' |
| 2 | + |
| 3 | +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' |
| 4 | +import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' |
| 5 | + |
| 6 | +/** |
| 7 | + * Regression coverage for FE-853: promoting/demoting a widget on a subgraph |
| 8 | + * node — or merely opening the right-side properties panel for one — used to |
| 9 | + * collapse the node back to its computed minimum size, discarding whatever |
| 10 | + * size the user had explicitly set. |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * These fixture workflows carry a saved pan/zoom that was not authored |
| 15 | + * against the default 1280x720 Playwright viewport, so nodes can load |
| 16 | + * partially below the fold. Panning the nodes into view keeps resize |
| 17 | + * handles and the subgraph-enter footer button on-screen for subsequent |
| 18 | + * screen-space clicks and drags. |
| 19 | + * |
| 20 | + * This deliberately pans rather than using the app's zoom-to-fit command: |
| 21 | + * these tests compute drag targets and pixel-space size deltas directly |
| 22 | + * from node.pos/node.size, which only line up with on-screen pixels when |
| 23 | + * the canvas scale is 1. Panning leaves scale untouched, so it also avoids |
| 24 | + * the 'Top' menu bar's workflow tab strip, which renders above the canvas |
| 25 | + * and would intercept a click at a fixed coordinate. |
| 26 | + */ |
| 27 | +async function fitViewToNodes(comfyPage: ComfyPage): Promise<void> { |
| 28 | + await comfyPage.page.evaluate(() => { |
| 29 | + const canvas = window.app!.canvas |
| 30 | + const nodes = canvas.graph?.nodes ?? [] |
| 31 | + if (nodes.length === 0) return |
| 32 | + |
| 33 | + const margin = 100 |
| 34 | + const left = Math.min(...nodes.map((node) => node.pos[0])) |
| 35 | + const top = Math.min(...nodes.map((node) => node.pos[1])) |
| 36 | + |
| 37 | + canvas.ds.scale = 1 |
| 38 | + canvas.ds.offset = [margin - left, margin - top] |
| 39 | + canvas.setDirty(true, true) |
| 40 | + }) |
| 41 | + await comfyPage.nextFrame() |
| 42 | +} |
| 43 | + |
| 44 | +test.describe( |
| 45 | + 'Subgraph node resize preservation', |
| 46 | + { tag: ['@subgraph', '@widget', '@vue-nodes'] }, |
| 47 | + () => { |
| 48 | + test.beforeEach(async ({ comfyPage }) => { |
| 49 | + await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Top') |
| 50 | + }) |
| 51 | + |
| 52 | + test('Promoting a widget preserves a user-resized subgraph node', async ({ |
| 53 | + comfyPage |
| 54 | + }) => { |
| 55 | + await comfyPage.workflow.loadWorkflow('subgraphs/basic-subgraph') |
| 56 | + await fitViewToNodes(comfyPage) |
| 57 | + |
| 58 | + const subgraphNode = |
| 59 | + await comfyPage.vueNodes.getFixtureByTitle('New Subgraph') |
| 60 | + await subgraphNode.resizeFromCorner('SE', 250, 200) |
| 61 | + await comfyPage.nextFrame() |
| 62 | + const resizedBox = (await subgraphNode.boundingBox())! |
| 63 | + |
| 64 | + const ksampler = comfyPage.vueNodes.getNodeLocator('1') |
| 65 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 66 | + await comfyPage.subgraph.promoteWidget(ksampler, 'steps') |
| 67 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 68 | + |
| 69 | + const box = await subgraphNode.boundingBox() |
| 70 | + expect(box?.width).toBeCloseTo(resizedBox.width, 0) |
| 71 | + expect(box?.height).toBeGreaterThanOrEqual(resizedBox.height - 1) |
| 72 | + }) |
| 73 | + |
| 74 | + test('Un-promoting a widget preserves a user-resized subgraph node', async ({ |
| 75 | + comfyPage |
| 76 | + }) => { |
| 77 | + await comfyPage.workflow.loadWorkflow('subgraphs/basic-subgraph') |
| 78 | + await fitViewToNodes(comfyPage) |
| 79 | + |
| 80 | + const subgraphNode = |
| 81 | + await comfyPage.vueNodes.getFixtureByTitle('New Subgraph') |
| 82 | + const ksampler = comfyPage.vueNodes.getNodeLocator('1') |
| 83 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 84 | + await comfyPage.subgraph.promoteWidget(ksampler, 'steps') |
| 85 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 86 | + |
| 87 | + await subgraphNode.resizeFromCorner('SE', 250, 200) |
| 88 | + await comfyPage.nextFrame() |
| 89 | + const resizedBox = (await subgraphNode.boundingBox())! |
| 90 | + |
| 91 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 92 | + await comfyPage.subgraph.unpromoteWidget(ksampler, 'steps') |
| 93 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 94 | + |
| 95 | + const box = await subgraphNode.boundingBox() |
| 96 | + expect(box?.width).toBeCloseTo(resizedBox.width, 0) |
| 97 | + expect(box?.height).toBeCloseTo(resizedBox.height, 0) |
| 98 | + }) |
| 99 | + |
| 100 | + test('Opening the properties panel does not shrink a user-resized subgraph node', async ({ |
| 101 | + comfyPage |
| 102 | + }) => { |
| 103 | + await comfyPage.workflow.loadWorkflow('subgraphs/basic-subgraph') |
| 104 | + await fitViewToNodes(comfyPage) |
| 105 | + |
| 106 | + const subgraphNode = |
| 107 | + await comfyPage.vueNodes.getFixtureByTitle('New Subgraph') |
| 108 | + await subgraphNode.resizeFromCorner('SE', 250, 200) |
| 109 | + await comfyPage.nextFrame() |
| 110 | + const resizedBox = (await subgraphNode.boundingBox())! |
| 111 | + |
| 112 | + await subgraphNode.select() |
| 113 | + await comfyPage.actionbar.propertiesButton.click() |
| 114 | + await expect(comfyPage.menu.propertiesPanel.root).toBeVisible() |
| 115 | + |
| 116 | + const box = await subgraphNode.boundingBox() |
| 117 | + expect(box?.width).toBeCloseTo(resizedBox.width, 0) |
| 118 | + expect(box?.height).toBeCloseTo(resizedBox.height, 0) |
| 119 | + }) |
| 120 | + |
| 121 | + test('Promoting and demoting multiple widgets in sequence preserves the resized size', async ({ |
| 122 | + comfyPage |
| 123 | + }) => { |
| 124 | + await comfyPage.workflow.loadWorkflow('subgraphs/basic-subgraph') |
| 125 | + await fitViewToNodes(comfyPage) |
| 126 | + |
| 127 | + const subgraphNode = |
| 128 | + await comfyPage.vueNodes.getFixtureByTitle('New Subgraph') |
| 129 | + await subgraphNode.resizeFromCorner('SE', 300, 250) |
| 130 | + await comfyPage.nextFrame() |
| 131 | + const resizedBox = (await subgraphNode.boundingBox())! |
| 132 | + const ksampler = comfyPage.vueNodes.getNodeLocator('1') |
| 133 | + |
| 134 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 135 | + await comfyPage.subgraph.promoteWidget(ksampler, 'steps') |
| 136 | + await comfyPage.subgraph.promoteWidget(ksampler, 'cfg') |
| 137 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 138 | + |
| 139 | + await expect |
| 140 | + .poll(async () => (await subgraphNode.boundingBox())?.width) |
| 141 | + .toBeCloseTo(resizedBox.width, 0) |
| 142 | + |
| 143 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 144 | + await comfyPage.subgraph.unpromoteWidget(ksampler, 'steps') |
| 145 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 146 | + |
| 147 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 148 | + await comfyPage.subgraph.unpromoteWidget(ksampler, 'cfg') |
| 149 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 150 | + |
| 151 | + const box = await subgraphNode.boundingBox() |
| 152 | + expect(box?.width).toBeCloseTo(resizedBox.width, 0) |
| 153 | + expect(box?.height).toBeCloseTo(resizedBox.height, 0) |
| 154 | + }) |
| 155 | + |
| 156 | + test('Manually resizing still works normally after a promotion', async ({ |
| 157 | + comfyPage |
| 158 | + }) => { |
| 159 | + await comfyPage.workflow.loadWorkflow('subgraphs/basic-subgraph') |
| 160 | + await fitViewToNodes(comfyPage) |
| 161 | + |
| 162 | + const subgraphNode = |
| 163 | + await comfyPage.vueNodes.getFixtureByTitle('New Subgraph') |
| 164 | + const ksampler = comfyPage.vueNodes.getNodeLocator('1') |
| 165 | + await comfyPage.vueNodes.enterSubgraph('2') |
| 166 | + await comfyPage.subgraph.promoteWidget(ksampler, 'steps') |
| 167 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 168 | + |
| 169 | + const boxBeforeResize = (await subgraphNode.boundingBox())! |
| 170 | + await subgraphNode.resizeFromCorner('SE', 200, 150) |
| 171 | + await comfyPage.nextFrame() |
| 172 | + |
| 173 | + const box = await subgraphNode.boundingBox() |
| 174 | + expect(box?.width).toBeGreaterThan(boxBeforeResize.width) |
| 175 | + expect(box?.height).toBeGreaterThan(boxBeforeResize.height) |
| 176 | + }) |
| 177 | + } |
| 178 | +) |
| 179 | + |
| 180 | +test.describe( |
| 181 | + 'Subgraph node resize preservation — nested subgraphs', |
| 182 | + { tag: ['@subgraph', '@widget', '@vue-nodes'] }, |
| 183 | + () => { |
| 184 | + test.beforeEach(async ({ comfyPage }) => { |
| 185 | + await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Top') |
| 186 | + }) |
| 187 | + |
| 188 | + test('Demoting a nested promotion does not shrink a user-resized outer host', async ({ |
| 189 | + comfyPage |
| 190 | + }) => { |
| 191 | + await comfyPage.workflow.loadWorkflow( |
| 192 | + 'subgraphs/subgraph-nested-promotion' |
| 193 | + ) |
| 194 | + await fitViewToNodes(comfyPage) |
| 195 | + |
| 196 | + const [outerHost] = await comfyPage.nodeOps.getNodeRefsByTitle('Sub 0') |
| 197 | + expect(outerHost).toBeDefined() |
| 198 | + |
| 199 | + const nodePos = await outerHost.getPosition() |
| 200 | + const nodeSize = await outerHost.getSize() |
| 201 | + // Keep the ratio modest: resizeNode scales the existing size (not an |
| 202 | + // additive delta), and a larger ratio would push the resized node's |
| 203 | + // bottom edge — and the subgraph-enter footer button below it — off |
| 204 | + // the bottom of the viewport, since the top-left corner stays fixed |
| 205 | + // during a resize-from-corner drag. |
| 206 | + await comfyPage.nodeOps.resizeNode(nodePos, nodeSize, 1.4, 1.4) |
| 207 | + const resizedSize = await outerHost.getSize() |
| 208 | + expect(resizedSize.width).toBeGreaterThan(nodeSize.width) |
| 209 | + expect(resizedSize.height).toBeGreaterThan(nodeSize.height) |
| 210 | + |
| 211 | + // Node 6 ('Sub 1' instance) exposes a 'value_1' widget that is itself a |
| 212 | + // promotion chain three subgraphs deep (Inner 3 -> Sub 2 -> Sub 1), |
| 213 | + // which Sub 0 re-promotes onto `outerHost`. The per-row toggle in the |
| 214 | + // properties panel is disabled for widgets promoted this way, so |
| 215 | + // demoting has to go through the same context-menu action a user would |
| 216 | + // use: entering the host and un-promoting from the widget's own node. |
| 217 | + await comfyPage.vueNodes.enterSubgraph(String(outerHost.id)) |
| 218 | + const sub1Instance = comfyPage.vueNodes.getNodeLocator('6') |
| 219 | + await comfyPage.subgraph.unpromoteWidget(sub1Instance, 'value_1') |
| 220 | + await comfyPage.subgraph.exitViaBreadcrumb() |
| 221 | + |
| 222 | + await expect |
| 223 | + .poll(async () => (await outerHost.getSize()).width) |
| 224 | + .toBeCloseTo(resizedSize.width, 0) |
| 225 | + const finalSize = await outerHost.getSize() |
| 226 | + expect(finalSize.height).toBeCloseTo(resizedSize.height, 0) |
| 227 | + }) |
| 228 | + } |
| 229 | +) |
0 commit comments