mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-17 19:09:29 +00:00
## Summary Add E2E tests for node templates ## Changes - **What**: - add tests for save, insert, delete, import export - vue and litegraph - add testid to dialog - update `clickLitegraphMenuItem` to enable clicking children with the same name as parent ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-11564-test-e2e-coverage-for-node-templates-34b6d73d365081a39ce5c713f05a2a92) by [Unito](https://www.unito.io)
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import { expect } from '@playwright/test'
|
|
import type { Locator, Page } from '@playwright/test'
|
|
|
|
export class ContextMenu {
|
|
public readonly primeVueMenu: Locator
|
|
public readonly litegraphMenu: Locator
|
|
public readonly menuItems: Locator
|
|
|
|
constructor(public readonly page: Page) {
|
|
this.primeVueMenu = page.locator('.p-contextmenu, .p-menu')
|
|
this.litegraphMenu = page.locator('.litemenu')
|
|
this.menuItems = page.locator('.p-menuitem, .litemenu-entry')
|
|
}
|
|
|
|
async clickMenuItem(name: string): Promise<void> {
|
|
await this.page.getByRole('menuitem', { name }).click()
|
|
}
|
|
|
|
async clickMenuItemExact(name: string): Promise<void> {
|
|
await this.page.getByRole('menuitem', { name, exact: true }).click()
|
|
}
|
|
|
|
/**
|
|
* Click a litegraph menu entry. Selects the most recently opened matching
|
|
* entry so nested submenu items can be reached without being shadowed by
|
|
* the parent menu still visible behind them.
|
|
*/
|
|
async clickLitegraphMenuItem(name: string): Promise<void> {
|
|
await this.page
|
|
.locator('.litemenu-entry:visible', { hasText: name })
|
|
.last()
|
|
.click()
|
|
}
|
|
|
|
async isVisible(): Promise<boolean> {
|
|
const primeVueVisible = await this.primeVueMenu
|
|
.isVisible()
|
|
.catch(() => false)
|
|
const litegraphVisible = await this.litegraphMenu
|
|
.isVisible()
|
|
.catch(() => false)
|
|
return primeVueVisible || litegraphVisible
|
|
}
|
|
|
|
async assertHasItems(items: string[]): Promise<void> {
|
|
for (const item of items) {
|
|
await expect
|
|
.soft(this.page.getByRole('menuitem', { name: item }))
|
|
.toBeVisible()
|
|
}
|
|
}
|
|
|
|
async openFor(locator: Locator): Promise<this> {
|
|
await locator.click({ button: 'right' })
|
|
await expect.poll(() => this.isVisible()).toBe(true)
|
|
return this
|
|
}
|
|
|
|
/**
|
|
* Select a Vue node by clicking its header, then right-click to open
|
|
* the context menu. Vue nodes require a selection click before the
|
|
* right-click so the correct per-node menu items appear.
|
|
*/
|
|
async openForVueNode(header: Locator): Promise<this> {
|
|
await header.click()
|
|
await header.click({ button: 'right' })
|
|
await this.primeVueMenu.waitFor({ state: 'visible' })
|
|
return this
|
|
}
|
|
|
|
async waitForHidden(): Promise<void> {
|
|
await Promise.all([
|
|
this.primeVueMenu.waitFor({ state: 'hidden' }),
|
|
this.litegraphMenu.waitFor({ state: 'hidden' })
|
|
])
|
|
}
|
|
}
|