n8n/packages/testing/playwright/pages/components/ActionToggle.ts
n8n-cat-bot[bot] 37bc8230d8
chore: Adopt ActionToggle component across page objects (#32933)
Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 08:10:22 +00:00

34 lines
1.1 KiB
TypeScript

import type { Locator, Page } from '@playwright/test';
/**
* Wraps the Element Plus row/resource action menu
* (`[data-testid="action-toggle-dropdown"]`). Multiple toggles can be present
* on a page, so use the menu-item accessor to scope to the currently open one.
*/
export class ActionToggle {
constructor(private readonly page: Page) {}
/** Root of the action menu dropdown. */
get root(): Locator {
return this.page.getByTestId('action-toggle-dropdown');
}
/**
* Opens the action toggle nested inside the given row/resource trigger
* (the card, table row, or cell that hosts the `action-toggle` button).
*/
async open(trigger: Locator): Promise<void> {
await trigger.getByTestId('action-toggle').getByRole('button').click();
}
/** Action item scoped inside the toggle, e.g. `action-delete`. */
getAction(name: string): Locator {
return this.root.getByTestId(`action-${name}`);
}
/** Menu item by index from the currently open (visible) toggle. */
getMenuItem(index: number): Locator {
return this.root.filter({ visible: true }).getByRole('menuitem').nth(index);
}
}