n8n/packages/testing/playwright/pages/components/VariableModal.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

62 lines
1.6 KiB
TypeScript

import type { Locator } from '@playwright/test';
import { closeDialogIfOpen } from './dialogLocators';
/**
* Variable modal component for canvas and variables interactions.
* Used within VariablesPage as `n8n.variables.modal.*`
*
* @example
* // Access via canvas page or variables page
* await n8n.variables.modal.addVariable();
* await expect(n8n.variables.modal.getModal()).toBeVisible();
*/
export class VariableModal {
constructor(private root: Locator) {}
getKeyInput(): Locator {
return this.root.getByTestId('variable-modal-key-input').getByRole('textbox');
}
getValueInput(): Locator {
return this.root.getByTestId('variable-modal-value-input').getByRole('textbox');
}
async waitForModal(): Promise<void> {
await this.root.waitFor({ state: 'visible' });
}
getSaveButton(): Locator {
return this.root.getByTestId('variable-modal-save-button');
}
async save(): Promise<void> {
const saveBtn = this.getSaveButton();
await saveBtn.click();
}
async close(): Promise<void> {
await closeDialogIfOpen(this.root);
}
/**
* Add a variable to the modal
* @param key - The variable key
* @param value - The variable value
* @param options - The options to pass to the modal
* @param options.closeDialog - Whether to close the modal after saving
*/
async addVariable(
key: string,
value: string,
{ shouldSave }: { shouldSave: boolean } = { shouldSave: true },
): Promise<void> {
await this.getKeyInput().fill(key);
await this.getValueInput().fill(value);
if (shouldSave) {
console.log('Saving variable from modal');
await this.save();
}
}
}