mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
## Summary
Add composite assertion and scoped opening methods to the `ContextMenu`
Playwright page object.
## Changes
- **What**: Added `assertHasItems(items: string[])` using
`expect.soft()` per item, and `openFor(locator: Locator)` which
right-clicks and waits for menu visibility. Fully backward-compatible.
## Review Focus
Both methods reuse existing locators (`primeVueMenu`, `litegraphMenu`,
`getByRole("menuitem")`). `openFor` uses `.or()` to handle both menu
types.
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-10659-feat-add-assertHasItems-and-openFor-to-ContextMenu-page-object-3316d73d36508193af45da7d3af4f50c)
by [Unito](https://www.unito.io)
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import { expect } from '@playwright/test'
|
|
import type { Locator, Page } from '@playwright/test'
|
|
|
|
export class ContextMenu {
|
|
constructor(public readonly page: Page) {}
|
|
|
|
get primeVueMenu() {
|
|
return this.page.locator('.p-contextmenu, .p-menu')
|
|
}
|
|
|
|
get litegraphMenu() {
|
|
return this.page.locator('.litemenu')
|
|
}
|
|
|
|
get menuItems() {
|
|
return this.page.locator('.p-menuitem, .litemenu-entry')
|
|
}
|
|
|
|
async clickMenuItem(name: string): Promise<void> {
|
|
await this.page.getByRole('menuitem', { name }).click()
|
|
}
|
|
|
|
async clickLitegraphMenuItem(name: string): Promise<void> {
|
|
await this.page.locator(`.litemenu-entry:has-text("${name}")`).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
|
|
}
|
|
|
|
async waitForHidden(): Promise<void> {
|
|
const waitIfExists = async (locator: Locator, menuName: string) => {
|
|
const count = await locator.count()
|
|
if (count > 0) {
|
|
await locator.waitFor({ state: 'hidden' }).catch((error: Error) => {
|
|
console.warn(
|
|
`[waitForHidden] ${menuName} waitFor failed:`,
|
|
error.message
|
|
)
|
|
})
|
|
}
|
|
}
|
|
|
|
await Promise.all([
|
|
waitIfExists(this.primeVueMenu, 'primeVueMenu'),
|
|
waitIfExists(this.litegraphMenu, 'litegraphMenu')
|
|
])
|
|
}
|
|
}
|