mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 22:39:39 +00:00
## Summary Adds e2e Save As tests for #10679. Refactors tests to remove getByX and other locators in tests to instead be in fixtures. ## Changes - **What**: - extract app mode fixtures - add test ids where required - add new tests ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10680-test-refactor-App-mode-Refactor-Save-As-tests-3316d73d3650815b9d49ccfbb6d54416) by [Unito](https://www.unito.io)
140 lines
4.6 KiB
TypeScript
140 lines
4.6 KiB
TypeScript
import type { Locator, Page } from '@playwright/test'
|
|
|
|
import type { ComfyPage } from '../ComfyPage'
|
|
import type { NodeReference } from '../utils/litegraphUtils'
|
|
import { TestIds } from '../selectors'
|
|
|
|
export class BuilderSelectHelper {
|
|
constructor(private readonly comfyPage: ComfyPage) {}
|
|
|
|
private get page(): Page {
|
|
return this.comfyPage.page
|
|
}
|
|
|
|
/**
|
|
* Get the actions menu trigger for a builder IoItem (input-select sidebar).
|
|
* @param title The widget title shown in the IoItem.
|
|
*/
|
|
getInputItemMenu(title: string): Locator {
|
|
return this.page
|
|
.getByTestId(TestIds.builder.ioItem)
|
|
.filter({
|
|
has: this.page
|
|
.getByTestId(TestIds.builder.ioItemTitle)
|
|
.getByText(title, { exact: true })
|
|
})
|
|
.getByTestId(TestIds.builder.widgetActionsMenu)
|
|
}
|
|
|
|
/**
|
|
* Get the actions menu trigger for a widget in the preview/arrange sidebar.
|
|
* @param ariaLabel The aria-label on the widget row, e.g. "seed — KSampler".
|
|
*/
|
|
getPreviewWidgetMenu(ariaLabel: string): Locator {
|
|
return this.page
|
|
.getByLabel(ariaLabel, { exact: true })
|
|
.getByTestId(TestIds.builder.widgetActionsMenu)
|
|
}
|
|
|
|
/** Delete a builder input via its actions menu. */
|
|
async deleteInput(title: string) {
|
|
const menu = this.getInputItemMenu(title)
|
|
await menu.click()
|
|
await this.page.getByText('Delete', { exact: true }).click()
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
/**
|
|
* Rename a builder IoItem via the popover menu "Rename" action.
|
|
* @param title The current widget title shown in the IoItem.
|
|
* @param newName The new name to assign.
|
|
*/
|
|
async renameInputViaMenu(title: string, newName: string) {
|
|
const menu = this.getInputItemMenu(title)
|
|
await menu.click()
|
|
await this.page.getByText('Rename', { exact: true }).click()
|
|
|
|
const input = this.page
|
|
.getByTestId(TestIds.builder.ioItemTitle)
|
|
.getByRole('textbox')
|
|
await input.fill(newName)
|
|
await this.page.keyboard.press('Enter')
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
/**
|
|
* Rename a builder IoItem by double-clicking its title for inline editing.
|
|
* @param title The current widget title shown in the IoItem.
|
|
* @param newName The new name to assign.
|
|
*/
|
|
async renameInput(title: string, newName: string) {
|
|
const titleEl = this.page
|
|
.getByTestId(TestIds.builder.ioItemTitle)
|
|
.getByText(title, { exact: true })
|
|
await titleEl.dblclick()
|
|
|
|
const input = this.page
|
|
.getByTestId(TestIds.builder.ioItemTitle)
|
|
.getByRole('textbox')
|
|
await input.fill(newName)
|
|
await this.page.keyboard.press('Enter')
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
/**
|
|
* Rename a widget via its actions popover (works in preview and app mode).
|
|
* @param popoverTrigger The button that opens the widget's actions popover.
|
|
* @param newName The new name to assign.
|
|
*/
|
|
async renameWidget(popoverTrigger: Locator, newName: string) {
|
|
await popoverTrigger.click()
|
|
await this.page.getByText('Rename', { exact: true }).click()
|
|
|
|
const dialogInput = this.page.locator(
|
|
'.p-dialog-content input[type="text"]'
|
|
)
|
|
await dialogInput.fill(newName)
|
|
await this.page.keyboard.press('Enter')
|
|
await dialogInput.waitFor({ state: 'hidden' })
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
/** Center on a node and click its first widget to select it as input. */
|
|
async selectInputWidget(node: NodeReference) {
|
|
await this.comfyPage.canvasOps.setScale(1)
|
|
await node.centerOnNode()
|
|
|
|
const widgetRef = await node.getWidget(0)
|
|
const widgetPos = await widgetRef.getPosition()
|
|
const titleHeight = await this.page.evaluate(
|
|
() => window.LiteGraph!['NODE_TITLE_HEIGHT'] as number
|
|
)
|
|
await this.page.mouse.click(widgetPos.x, widgetPos.y + titleHeight)
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
|
|
/** Click the first SaveImage/PreviewImage node on the canvas. */
|
|
async selectOutputNode() {
|
|
const saveImageNodeId = await this.page.evaluate(() => {
|
|
const node = window.app!.rootGraph.nodes.find(
|
|
(n: { type?: string }) =>
|
|
n.type === 'SaveImage' || n.type === 'PreviewImage'
|
|
)
|
|
return node ? String(node.id) : null
|
|
})
|
|
if (!saveImageNodeId)
|
|
throw new Error('SaveImage/PreviewImage node not found')
|
|
const saveImageRef =
|
|
await this.comfyPage.nodeOps.getNodeRefById(saveImageNodeId)
|
|
await saveImageRef.centerOnNode()
|
|
|
|
const canvasBox = await this.page.locator('#graph-canvas').boundingBox()
|
|
if (!canvasBox) throw new Error('Canvas not found')
|
|
await this.page.mouse.click(
|
|
canvasBox.x + canvasBox.width / 2,
|
|
canvasBox.y + canvasBox.height / 2
|
|
)
|
|
await this.comfyPage.nextFrame()
|
|
}
|
|
}
|