Skip to content

Commit 2eaa841

Browse files
committed
Fix edge routing handle page object
1 parent 57ca0f9 commit 2eaa841

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

packages/glsp-playwright/src/glsp/features/reconnect/reconnect.capability.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import type { Capability, Clickable } from '~/extension';
1717
import { SVGMetadata, type PEdge, type PNode } from '~/glsp/graph';
1818
import type { ConstructorA } from '~/types';
1919
import { expect } from '../../../test';
20-
import { RoutingPointCapability } from '../routing';
20+
import { assertIsDefined } from '../../../utils';
21+
import { RoutingPointCapability, type RoutingPoint, type RoutingPointKind } from '../routing';
2122

2223
/**
2324
* Elements can be resized by using the resize handles.
@@ -39,20 +40,30 @@ export function useReconnectCapability<TBase extends ConstructorA<PEdge & Clicka
3940
): Capability<TBase, ReconnectCapability> {
4041
abstract class Mixin extends Base implements ReconnectCapability {
4142
async reconnectSource(node: PNode & Clickable): Promise<void> {
42-
await this.reconnect(node, 0);
43+
await this.reconnect(node, 'source');
4344
await expect(this.locate()).toHaveAttribute(SVGMetadata.Edge.sourceId, await node.idAttr());
4445
}
4546

4647
async reconnectTarget(node: PNode & Clickable): Promise<void> {
47-
await this.reconnect(node, -1);
48+
await this.reconnect(node, 'target');
4849
await expect(this.locate()).toHaveAttribute(SVGMetadata.Edge.targetId, await node.idAttr());
4950
}
5051

51-
private async reconnect(node: PNode & Clickable, index: number): Promise<void> {
52+
protected async reconnect(node: PNode & Clickable, dataKind: RoutingPointKind): Promise<void> {
5253
const routingPoints = this.routingPoints();
5354
await routingPoints.enable();
54-
const points = await routingPoints.points();
55-
await points.at(index)!.dragTo(node.locate(), { force: true });
55+
let point: RoutingPoint | undefined;
56+
if (dataKind === 'source') {
57+
point = await routingPoints.sourceHandle();
58+
} else if (dataKind === 'target') {
59+
point = await routingPoints.targetHandle();
60+
}
61+
62+
assertIsDefined(point, `Routing point of kind ${dataKind} not found`);
63+
64+
await this.page.pause();
65+
await point.dragTo(node.locate(), { force: true });
66+
await this.page.pause();
5667
await node.click();
5768
await expect(node).toBeSelected();
5869
}

packages/glsp-playwright/src/glsp/features/routing/routing-point.po.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ export class RoutingPoints {
7878

7979
return elements;
8080
}
81+
82+
async sourceHandle(options?: AutoWaitOptions): Promise<RoutingPoint | undefined> {
83+
const routingPoints = await this.points(options);
84+
for (const point of routingPoints) {
85+
if ((await point.dataKindAttr()) === 'source') {
86+
return point;
87+
}
88+
}
89+
90+
return undefined;
91+
}
92+
93+
async targetHandle(options?: AutoWaitOptions): Promise<RoutingPoint | undefined> {
94+
const routingPoints = await this.points(options);
95+
for (const point of routingPoints) {
96+
if ((await point.dataKindAttr()) === 'target') {
97+
return point;
98+
}
99+
}
100+
101+
return undefined;
102+
}
81103
}
82104

83105
export interface RoutingPointSnapshot extends PModelElementSnapshot {

0 commit comments

Comments
 (0)