mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
test: address CodeRabbit review feedback
- Resolve seed widget index by name instead of hardcoding [0] - Capture workflow count before reload for relative comparison
This commit is contained in:
@@ -32,46 +32,50 @@ test.describe('Workflow reopen overwrites unsaved changes', () => {
|
||||
}, modifiedSeed)
|
||||
await comfyPage.nextFrame()
|
||||
|
||||
// Capture workflow count before reload for relative comparison
|
||||
const countBeforeReload = await comfyPage.workflow.getOpenWorkflowCount()
|
||||
|
||||
// Step 4: Re-load the SAME workflow via loadGraphData with the same
|
||||
// filename. This mirrors what handleFile() does when the user drags
|
||||
// the same file onto the canvas a second time.
|
||||
const seedAfterReload = await comfyPage.page.evaluate(async () => {
|
||||
const seedAfterReload = await comfyPage.page.evaluate(async (seed) => {
|
||||
const app = window.app!
|
||||
const workflow = JSON.parse(JSON.stringify(app.graph.serialize()))
|
||||
|
||||
// Reset the seed back to its original serialized value to simulate
|
||||
// re-reading the unmodified file from disk.
|
||||
// Find seed widget index by name rather than hardcoding position
|
||||
const liveNode = app.graph.nodes.find((n) => n.type === 'KSampler')
|
||||
const seedIndex =
|
||||
liveNode?.widgets?.findIndex((w) => w.name === 'seed') ?? 0
|
||||
const ksNode = workflow.nodes.find(
|
||||
(n: { type: string }) => n.type === 'KSampler'
|
||||
)
|
||||
if (ksNode?.widgets_values) {
|
||||
ksNode.widgets_values[0] = 0
|
||||
ksNode.widgets_values[seedIndex] = seed
|
||||
}
|
||||
|
||||
// This is the exact call handleFile makes — same filename triggers
|
||||
// isSameActiveWorkflowLoad in afterLoadNewGraph.
|
||||
await app.loadGraphData(workflow, true, true, 'single_ksampler', {})
|
||||
|
||||
// Return the seed value after reload
|
||||
const reloadedNode = app.graph.nodes.find((n) => n.type === 'KSampler')
|
||||
return reloadedNode?.widgets?.find((w) => w.name === 'seed')
|
||||
?.value as number
|
||||
})
|
||||
}, originalSeed)
|
||||
|
||||
const workflowCount = await comfyPage.workflow.getOpenWorkflowCount()
|
||||
const countAfterReload = await comfyPage.workflow.getOpenWorkflowCount()
|
||||
|
||||
// The unsaved edits must not be silently discarded.
|
||||
// Acceptable outcomes:
|
||||
// a) The modified seed value is preserved (user stays on modified tab)
|
||||
// b) A new tab was opened for the re-loaded file
|
||||
const changesPreserved = seedAfterReload === modifiedSeed
|
||||
const newTabOpened = workflowCount > 2
|
||||
const newTabOpened = countAfterReload === countBeforeReload + 1
|
||||
|
||||
expect(
|
||||
changesPreserved || newTabOpened,
|
||||
`Unsaved changes were silently discarded. ` +
|
||||
`Seed was ${modifiedSeed} before reload, became ${seedAfterReload} after. ` +
|
||||
`Workflow count: ${workflowCount} (expected > 2 if new tab opened).`
|
||||
`Tabs before: ${countBeforeReload}, after: ${countAfterReload}.`
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user