From 0485737cd9fe964ef22a1fd3ee22a7a594098c1f Mon Sep 17 00:00:00 2001 From: Haydar Metin Date: Wed, 26 Mar 2025 15:37:01 +0100 Subject: [PATCH] Fix edge routing handle page object --- .../reconnect/reconnect.capability.ts | 21 +++++++++++++----- .../glsp/features/routing/routing-point.po.ts | 22 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/glsp-playwright/src/glsp/features/reconnect/reconnect.capability.ts b/packages/glsp-playwright/src/glsp/features/reconnect/reconnect.capability.ts index bb7c64b..bcd8d0d 100644 --- a/packages/glsp-playwright/src/glsp/features/reconnect/reconnect.capability.ts +++ b/packages/glsp-playwright/src/glsp/features/reconnect/reconnect.capability.ts @@ -17,7 +17,8 @@ import type { Capability, Clickable } from '~/extension'; import { SVGMetadata, type PEdge, type PNode } from '~/glsp/graph'; import type { ConstructorA } from '~/types'; import { expect } from '../../../test'; -import { RoutingPointCapability } from '../routing'; +import { assertIsDefined } from '../../../utils'; +import { RoutingPointCapability, type RoutingPoint, type RoutingPointKind } from '../routing'; /** * Elements can be resized by using the resize handles. @@ -39,20 +40,28 @@ export function useReconnectCapability { abstract class Mixin extends Base implements ReconnectCapability { async reconnectSource(node: PNode & Clickable): Promise { - await this.reconnect(node, 0); + await this.reconnect(node, 'source'); await expect(this.locate()).toHaveAttribute(SVGMetadata.Edge.sourceId, await node.idAttr()); } async reconnectTarget(node: PNode & Clickable): Promise { - await this.reconnect(node, -1); + await this.reconnect(node, 'target'); await expect(this.locate()).toHaveAttribute(SVGMetadata.Edge.targetId, await node.idAttr()); } - private async reconnect(node: PNode & Clickable, index: number): Promise { + protected async reconnect(node: PNode & Clickable, dataKind: RoutingPointKind): Promise { const routingPoints = this.routingPoints(); await routingPoints.enable(); - const points = await routingPoints.points(); - await points.at(index)!.dragTo(node.locate(), { force: true }); + let point: RoutingPoint | undefined; + if (dataKind === 'source') { + point = await routingPoints.sourceHandle(); + } else if (dataKind === 'target') { + point = await routingPoints.targetHandle(); + } + + assertIsDefined(point, `Routing point of kind ${dataKind} not found`); + + await point.dragTo(node.locate(), { force: true }); await node.click(); await expect(node).toBeSelected(); } diff --git a/packages/glsp-playwright/src/glsp/features/routing/routing-point.po.ts b/packages/glsp-playwright/src/glsp/features/routing/routing-point.po.ts index e0b02ff..405c827 100644 --- a/packages/glsp-playwright/src/glsp/features/routing/routing-point.po.ts +++ b/packages/glsp-playwright/src/glsp/features/routing/routing-point.po.ts @@ -80,6 +80,28 @@ export class RoutingPoints { return elements; } + + async sourceHandle(options?: AutoWaitOptions): Promise { + const routingPoints = await this.points(options); + for (const point of routingPoints) { + if ((await point.dataKindAttr()) === 'source') { + return point; + } + } + + return undefined; + } + + async targetHandle(options?: AutoWaitOptions): Promise { + const routingPoints = await this.points(options); + for (const point of routingPoints) { + if ((await point.dataKindAttr()) === 'target') { + return point; + } + } + + return undefined; + } } export interface RoutingPointSnapshot extends PModelElementSnapshot {