From 98cb233058ceca99c965d2bb07cc3fcdcb13cb64 Mon Sep 17 00:00:00 2001 From: Jozef Marko Date: Wed, 13 Mar 2024 16:54:05 +0100 Subject: [PATCH] introduce addWaypoint2 fixture --- .../tests/e2e/__fixtures__/diagram.ts | 7 +++++++ .../tests/e2e/__fixtures__/edges.ts | 21 +++++++++++++++++++ .../addAssociationWaypoint.spec.ts | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/dmn-editor/tests/e2e/__fixtures__/diagram.ts b/packages/dmn-editor/tests/e2e/__fixtures__/diagram.ts index 9b7ee773635..5922a3b24d1 100644 --- a/packages/dmn-editor/tests/e2e/__fixtures__/diagram.ts +++ b/packages/dmn-editor/tests/e2e/__fixtures__/diagram.ts @@ -29,6 +29,13 @@ export class Diagram { return this.page.getByTestId("kie-dmn-editor--diagram-container"); } + public async dblclick(position: { x: number; y: number }) { + const offsetX = 100; + const offsetY = 100; + + return this.get().dblclick({ position: { x: position.x + offsetX, y: position.y + offsetY } }); + } + public async resetFocus() { return this.get().click({ position: { x: 0, y: 0 } }); } diff --git a/packages/dmn-editor/tests/e2e/__fixtures__/edges.ts b/packages/dmn-editor/tests/e2e/__fixtures__/edges.ts index 3e80cac9215..dc9f10227ab 100644 --- a/packages/dmn-editor/tests/e2e/__fixtures__/edges.ts +++ b/packages/dmn-editor/tests/e2e/__fixtures__/edges.ts @@ -50,6 +50,27 @@ export class Edges { await (await this.get({ from: args.from, to: args.to })).dblclick(); } + public async addWaypoint2(args: { from: string; to: string; waypointIndex?: number }) { + const dAttribute = await ( + await (await this.get({ from: args.from, to: args.to })).locator("path").first() + ).getAttribute("d"); + + const edgeSegments = dAttribute?.match(/M [0-9]*,[0-9]* L [0-9]*,[0-9]*/); + + if (edgeSegments) { + const edgeSegment = args.waypointIndex ? edgeSegments[Math.max(0, args.waypointIndex - 1)] : edgeSegments[0]; + const from = edgeSegment.split(/ L [0-9]*,[0-9]*/)[0]; + const to = edgeSegment.split(/M [0-9]*,[0-9]* /)[1]; + + const fromPoint = { x: parseInt(from.slice(2).split(",")[0]), y: parseInt(from.slice(2).split(",")[1]) }; + const toPoint = { x: parseInt(to.slice(2).split(",")[0]), y: parseInt(to.slice(2).split(",")[1]) }; + + const targetPoint = { x: (fromPoint.x + toPoint.x) / 2, y: (fromPoint.y + toPoint.y) / 2 }; + + await this.diagram.dblclick(targetPoint); + } + } + public async moveWaypoint(args: { from: string; to: string; diff --git a/packages/dmn-editor/tests/e2e/drdArtifacts/addAssociationWaypoint.spec.ts b/packages/dmn-editor/tests/e2e/drdArtifacts/addAssociationWaypoint.spec.ts index 25447caa37d..3f091c0c459 100644 --- a/packages/dmn-editor/tests/e2e/drdArtifacts/addAssociationWaypoint.spec.ts +++ b/packages/dmn-editor/tests/e2e/drdArtifacts/addAssociationWaypoint.spec.ts @@ -35,8 +35,8 @@ test.describe("Add edge waypoint - Association", () => { }); }); - test("should attach single Association waypoint to the DOM", async ({ edges }) => { - await edges.addWaypoint({ from: DefaultNodeName.INPUT_DATA, to: DefaultNodeName.TEXT_ANNOTATION }); + test.only("should attach single Association waypoint to the DOM", async ({ edges }) => { + await edges.addWaypoint2({ from: DefaultNodeName.INPUT_DATA, to: DefaultNodeName.TEXT_ANNOTATION }); await expect( await edges.getWaypoint({