test: Create addNode convenience method (#18750)

This commit is contained in:
shortstacked
2025-08-26 10:23:57 +01:00
committed by GitHub
parent 9bc4f07b79
commit ede6f5b739
6 changed files with 166 additions and 48 deletions

View File

@@ -57,36 +57,63 @@ export class CanvasPage extends BasePage {
await this.nodeCreatorItemByName(text).click();
}
async addNode(text: string): Promise<void> {
/**
* Add a node to the canvas with flexible options
* @param nodeName - The name of the node to search for and add
* @param options - Configuration options for node addition
* @param options.closeNDV - Whether to close the NDV after adding (default: false, keeps open)
* @param options.action - Specific action to select (Actions tab is default)
* @param options.trigger - Specific trigger to select (will switch to Triggers)
* @example
* // Basic node addition
* await canvas.addNode('Code');
*
* // Add with specific action
* await canvas.addNode('Linear', { action: 'Create an issue' });
*
* // Add with trigger
* await canvas.addNode('Jira', { trigger: 'On issue created' });
*
* // Add and explicitly close with back button
* await canvas.addNode('Code', { closeNDV: true });
*/
async addNode(
nodeName: string,
options?: {
closeNDV?: boolean;
action?: string;
trigger?: string;
},
): Promise<void> {
// Always start with canvas plus button
await this.clickNodeCreatorPlusButton();
await this.fillNodeCreatorSearchBar(text);
await this.clickNodeCreatorItemName(text);
}
async addNodeAndCloseNDV(text: string, subItemText?: string): Promise<void> {
if (subItemText) {
await this.addNodeWithSubItem(text, subItemText);
} else {
await this.addNode(text);
// Search for and select the node, works on exact name match only
await this.fillNodeCreatorSearchBar(nodeName);
await this.clickNodeCreatorItemName(nodeName);
if (options?.action) {
// Check if Actions category is collapsed and expand if needed
const actionsCategory = this.page
.getByTestId('node-creator-category-item')
.getByText('Actions');
if ((await actionsCategory.getAttribute('data-category-collapsed')) === 'true') {
await actionsCategory.click();
}
await this.nodeCreatorSubItem(options.action).click();
} else if (options?.trigger) {
// Check if Triggers category is collapsed and expand if needed
const triggersCategory = this.page
.getByTestId('node-creator-category-item')
.getByText('Triggers');
if ((await triggersCategory.getAttribute('data-category-collapsed')) === 'true') {
await triggersCategory.click();
}
await this.nodeCreatorSubItem(options.trigger).click();
}
if (options?.closeNDV) {
await this.page.getByTestId('back-to-canvas').click();
}
await this.page.keyboard.press('Escape');
}
async addNodeWithSubItem(searchText: string, subItemText: string): Promise<void> {
await this.addNode(searchText);
await this.nodeCreatorSubItem(subItemText).click();
}
async addActionNode(searchText: string, subItemText: string): Promise<void> {
await this.addNode(searchText);
await this.page.getByText('Actions').click();
await this.nodeCreatorSubItem(subItemText).click();
}
async addTriggerNode(searchText: string, subItemText: string): Promise<void> {
await this.addNode(searchText);
await this.page.getByText('Triggers').click();
await this.nodeCreatorSubItem(subItemText).click();
}
async deleteNodeByName(nodeName: string): Promise<void> {
@@ -301,7 +328,7 @@ export class CanvasPage extends BasePage {
}
nodeCreatorNodeItems(): Locator {
return this.page.getByTestId('node-creator-node-item');
return this.page.getByTestId('node-creator-item-name');
}
nodeCreatorActionItems(): Locator {