Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -39,20 +40,28 @@ export function useReconnectCapability<TBase extends ConstructorA<PEdge & Clicka
): Capability<TBase, ReconnectCapability> {
abstract class Mixin extends Base implements ReconnectCapability {
async reconnectSource(node: PNode & Clickable): Promise<void> {
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<void> {
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<void> {
protected async reconnect(node: PNode & Clickable, dataKind: RoutingPointKind): Promise<void> {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ export class RoutingPoints {

return elements;
}

async sourceHandle(options?: AutoWaitOptions): Promise<RoutingPoint | undefined> {
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<RoutingPoint | undefined> {
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 {
Expand Down