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 { await this.page.getByRole('menuitem', { name }).click() } async clickMenuItemExact(name: string): Promise { 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 { await this.page .locator('.litemenu-entry:visible', { hasText: name }) .last() .click() } async isVisible(): Promise { const primeVueVisible = await this.primeVueMenu .isVisible() .catch(() => false) const litegraphVisible = await this.litegraphMenu .isVisible() .catch(() => false) return primeVueVisible || litegraphVisible } async assertHasItems(items: string[]): Promise { for (const item of items) { await expect .soft(this.page.getByRole('menuitem', { name: item })) .toBeVisible() } } async openFor(locator: Locator): Promise { 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 { await header.click() await header.click({ button: 'right' }) await this.primeVueMenu.waitFor({ state: 'visible' }) return this } async waitForHidden(): Promise { await Promise.all([ this.primeVueMenu.waitFor({ state: 'hidden' }), this.litegraphMenu.waitFor({ state: 'hidden' }) ]) } }