n8n/packages/testing/playwright/pages/components/dialogLocators.ts
n8n-cat-bot[bot] 38bb77cd3a
chore: Dedupe modal close() through a shared helper (#33167)
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>
2026-06-29 14:00:30 +00:00

31 lines
1.1 KiB
TypeScript

import type { Locator, Page } from '@playwright/test';
/**
* Locator helpers for Element Plus `.el-dialog*` selectors.
*
* Element Plus teleports `.el-dialog` to `<body>` and exposes a class-only close
* icon (`.el-dialog__close`). Centralising the raw selectors here keeps them
* out of tests, page objects, and components that can't `extends BaseModal`
* (Locator-injected leaf components have no `Page` to pass to its constructor).
*/
export function dialogRootIn(scope: Page | Locator): Locator {
return scope.locator('.el-dialog');
}
export function dialogCloseIconIn(scope: Page | Locator): Locator {
return scope.locator('.el-dialog__close').first();
}
/**
* Click the dialog close (X) icon within `scope`, but only if it's currently visible.
*
* `scope` must be the modal's own root (not a page-wide `getByRole('dialog')`) so that,
* when modals are stacked, the close icon resolves to the intended dialog.
*/
export async function closeDialogIfOpen(scope: Page | Locator): Promise<void> {
const closeBtn = dialogCloseIconIn(scope);
if (!(await closeBtn.isVisible())) return;
await closeBtn.click();
}