mirror of
https://github.com/n8n-io/n8n.git
synced 2026-07-28 19:45:09 +02:00
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> Co-authored-by: Declan Carroll <declan@n8n.io>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { Locator, Page } from '@playwright/test';
|
|
|
|
import { closeDialogIfOpen } from './dialogLocators';
|
|
import { FloatingUiHelper } from './FloatingUiHelper';
|
|
|
|
/**
|
|
* Base modal component for handling modal dialogs.
|
|
*
|
|
* For modals that can extend this class (constructed with a `Page`). Leaf
|
|
* components injected with a `Locator` should import helpers from
|
|
* `./dialogLocators` directly instead.
|
|
*/
|
|
export class BaseModal extends FloatingUiHelper {
|
|
constructor(protected readonly page: Page) {
|
|
super(page);
|
|
}
|
|
|
|
get container() {
|
|
return this.page.getByRole('dialog');
|
|
}
|
|
|
|
getCloseButton() {
|
|
return this.container.getByRole('button', { name: /close/i });
|
|
}
|
|
|
|
async waitForModal() {
|
|
await this.container.waitFor({ state: 'visible' });
|
|
}
|
|
|
|
/** Close the modal via its Element Plus close (X) icon, if it's currently visible. */
|
|
async close(): Promise<void> {
|
|
await closeDialogIfOpen(this.container);
|
|
}
|
|
|
|
/** A text element visible inside this modal's container (e.g. a validation error). */
|
|
getText(text: string | RegExp, options?: { exact?: boolean }): Locator {
|
|
return this.container.getByText(text, options);
|
|
}
|
|
|
|
async fillInput(text: string) {
|
|
await this.container.getByRole('textbox').fill(text);
|
|
}
|
|
|
|
async clickButton(buttonText: string | RegExp) {
|
|
await this.container.getByRole('button', { name: buttonText }).click();
|
|
}
|
|
}
|