mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
## Summary
Internalize `nextFrame()` calls into fixture/helper methods so spec
authors don't need to remember to call it after common operations.
`nextFrame()` waits for one `requestAnimationFrame` (~16ms) — an extra
call is always safe, making this a low-risk refactor.
## Changes
### Phase 1: `SettingsHelper.setSetting()`
`setSetting()` now calls `nextFrame()` internally. Removed 15 redundant
calls across 7 files.
### Phase 2: `CommandHelper.executeCommand()`
`executeCommand()` now calls `nextFrame()` internally. Removed 15
redundant calls across 7 files, including the now-redundant call in
`AppModeHelper.toggleAppMode()`.
### Phase 3: `WorkflowHelper.loadGraphData()`
New helper wraps `page.evaluate(loadGraphData)` + `nextFrame()`.
Migrated `SubgraphHelper.serializeAndReload()` and `groupNode.spec.ts`.
### Phase 4: `NodeReference` cleanup
Removed redundant `nextFrame()` from `copy()`, `convertToGroupNode()`,
`resizeNode()`, `dragTextEncodeNode2()`, and
`convertDefaultKSamplerToSubgraph()`. Removed 6 spec-level calls after
`node.click('title')`.
### Phase 5: `KeyboardHelper.press()` and `delete()`
New convenience methods that press a key and wait one frame. Converted
40 `canvas.press(key)` + `nextFrame()` pairs across 13 spec files.
### Phase 6: `ComfyPage.expectScreenshot()`
New helper combines `nextFrame()` + `toHaveScreenshot()`. Converted 45
pairs across 12 spec files.
## Total impact
- **~130 redundant `nextFrame()` calls eliminated** across ~35
spec/helper files
- **3 new helper methods** added (`loadGraphData`, `press`/`delete`,
`expectScreenshot`)
- **2 existing methods** enhanced (`setSetting`, `executeCommand`)
## What was NOT changed
- `performance.spec.ts` frame-counting loops (intentional)
- `ComfyMouse.ts` / `CanvasHelper.ts` (already internalized)
- `SubgraphHelper.packAllInteriorNodes()` (deliberate orchestration)
- Builder helpers (already internalized)
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-11166-refactor-internalize-nextFrame-into-fixture-helper-methods-33f6d73d3650817bb5f6fb46e396085e)
by [Unito](https://www.unito.io)
---------
Co-authored-by: Amp <amp@ampcode.com>
152 lines
4.5 KiB
TypeScript
152 lines
4.5 KiB
TypeScript
import { expect } from '@playwright/test'
|
|
|
|
import { assetPath } from '@e2e/fixtures/utils/paths'
|
|
import { load3dTest as test } from '@e2e/fixtures/helpers/Load3DFixtures'
|
|
|
|
test.describe('Load3D', () => {
|
|
test(
|
|
'Renders canvas with upload buttons and controls menu',
|
|
{ tag: ['@smoke', '@screenshot'] },
|
|
async ({ load3d }) => {
|
|
await expect(load3d.node).toBeVisible()
|
|
|
|
await expect(load3d.canvas).toBeVisible()
|
|
|
|
await expect
|
|
.poll(async () => {
|
|
const b = await load3d.canvas.boundingBox()
|
|
return b?.width ?? 0
|
|
})
|
|
.toBeGreaterThan(0)
|
|
await expect
|
|
.poll(async () => {
|
|
const b = await load3d.canvas.boundingBox()
|
|
return b?.height ?? 0
|
|
})
|
|
.toBeGreaterThan(0)
|
|
|
|
await expect(load3d.getUploadButton('upload 3d model')).toBeVisible()
|
|
await expect(
|
|
load3d.getUploadButton('upload extra resources')
|
|
).toBeVisible()
|
|
await expect(load3d.getUploadButton('clear')).toBeVisible()
|
|
|
|
await expect(load3d.menuButton).toBeVisible()
|
|
|
|
await expect(load3d.node).toHaveScreenshot('load3d-empty-node.png', {
|
|
maxDiffPixelRatio: 0.05
|
|
})
|
|
}
|
|
)
|
|
|
|
test(
|
|
'Controls menu opens and shows all categories',
|
|
{ tag: ['@smoke', '@screenshot'] },
|
|
async ({ load3d }) => {
|
|
await load3d.openMenu()
|
|
|
|
await expect(load3d.getMenuCategory('Scene')).toBeVisible()
|
|
await expect(load3d.getMenuCategory('Model')).toBeVisible()
|
|
await expect(load3d.getMenuCategory('Camera')).toBeVisible()
|
|
await expect(load3d.getMenuCategory('Light')).toBeVisible()
|
|
await expect(load3d.getMenuCategory('Export')).toBeVisible()
|
|
|
|
await expect(load3d.node).toHaveScreenshot(
|
|
'load3d-controls-menu-open.png',
|
|
{ maxDiffPixelRatio: 0.05 }
|
|
)
|
|
}
|
|
)
|
|
|
|
test(
|
|
'Changing background color updates the scene',
|
|
{ tag: ['@smoke', '@screenshot'] },
|
|
async ({ comfyPage, load3d }) => {
|
|
await load3d.setBackgroundColor('#cc3333')
|
|
await comfyPage.nextFrame()
|
|
|
|
await expect
|
|
.poll(() =>
|
|
comfyPage.page.evaluate(() => {
|
|
const n = window.app!.graph.getNodeById(1)
|
|
const config = n?.properties?.['Scene Config'] as
|
|
| Record<string, string>
|
|
| undefined
|
|
return config?.backgroundColor
|
|
})
|
|
)
|
|
.toBe('#cc3333')
|
|
|
|
await expect(load3d.node).toHaveScreenshot('load3d-red-background.png', {
|
|
maxDiffPixelRatio: 0.05
|
|
})
|
|
}
|
|
)
|
|
|
|
test(
|
|
'Recording controls are visible for Load3D',
|
|
{ tag: '@smoke' },
|
|
async ({ load3d }) => {
|
|
await expect(load3d.recordingButton).toBeVisible()
|
|
}
|
|
)
|
|
|
|
test(
|
|
'Uploads a 3D model via button and renders it',
|
|
{ tag: ['@screenshot'] },
|
|
async ({ comfyPage, load3d }) => {
|
|
const uploadResponsePromise = comfyPage.page.waitForResponse(
|
|
(resp) => resp.url().includes('/upload/') && resp.status() === 200,
|
|
{ timeout: 15000 }
|
|
)
|
|
|
|
const fileChooserPromise = comfyPage.page.waitForEvent('filechooser')
|
|
await load3d.getUploadButton('upload 3d model').click()
|
|
const fileChooser = await fileChooserPromise
|
|
await fileChooser.setFiles(assetPath('cube.obj'))
|
|
|
|
await uploadResponsePromise
|
|
|
|
const node = await comfyPage.nodeOps.getNodeRefById(1)
|
|
const modelFileWidget = await node.getWidget(0)
|
|
await expect.poll(() => modelFileWidget.getValue()).toContain('cube.obj')
|
|
|
|
await load3d.waitForModelLoaded()
|
|
await comfyPage.expectScreenshot(
|
|
load3d.node,
|
|
'load3d-uploaded-cube-obj.png',
|
|
{ maxDiffPixelRatio: 0.1 }
|
|
)
|
|
}
|
|
)
|
|
|
|
test(
|
|
'Drag-and-drops a 3D model onto the canvas',
|
|
{ tag: ['@screenshot'] },
|
|
async ({ comfyPage, load3d }) => {
|
|
const canvasBox = await load3d.canvas.boundingBox()
|
|
expect(canvasBox, 'Canvas bounding box should exist').not.toBeNull()
|
|
const dropPosition = {
|
|
x: canvasBox!.x + canvasBox!.width / 2,
|
|
y: canvasBox!.y + canvasBox!.height / 2
|
|
}
|
|
|
|
await comfyPage.dragDrop.dragAndDropFile('cube.obj', {
|
|
dropPosition,
|
|
waitForUpload: true
|
|
})
|
|
|
|
const node = await comfyPage.nodeOps.getNodeRefById(1)
|
|
const modelFileWidget = await node.getWidget(0)
|
|
await expect.poll(() => modelFileWidget.getValue()).toContain('cube.obj')
|
|
|
|
await load3d.waitForModelLoaded()
|
|
await comfyPage.expectScreenshot(
|
|
load3d.node,
|
|
'load3d-dropped-cube-obj.png',
|
|
{ maxDiffPixelRatio: 0.1 }
|
|
)
|
|
}
|
|
)
|
|
})
|