Skip to content

Commit 32f2a74

Browse files
authored
elyra-ai#2238 Write function to compare transform string in Cypress tests (elyra-ai#2225)
Signed-off-by: Jerin George <[email protected]>
1 parent c9c9bc3 commit 32f2a74

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

canvas_modules/harness/cypress/e2e/canvas/zoom.cy.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ describe("Test zoomToReveal function returns the appropriate zoom object for a n
9999
cy.verifyCanvasTransform(undefined);
100100
// Zooming the canvas.
101101
cy.clickToolbarZoomOut();
102-
// TODO -- write function to test these +/- 2 px.
103-
// cy.verifyCanvasTransform("translate(45.81818181818181,32.22727272727275) scale(0.9090909090909091)");
102+
cy.verifyCanvasTransform("translate(45.81818181818181,32.22727272727275) scale(0.9090909090909091)");
104103
// Test get Zoom to reveal & ZoomTo
105104
cy.selectEntryFromDropdown("Histogram");
106105
cy.setXPercentOffset(70);
@@ -145,15 +144,13 @@ describe("Test zoomToReveal function returns the appropriate zoom object for a l
145144
cy.verifyCanvasTransform(undefined);
146145
// Zooming the canvas.
147146
cy.clickToolbarZoomOut();
148-
// TODO -- write function to test these +/- 2 px.
149-
// cy.verifyCanvasTransform("translate(45.81818181818181,32.22727272727275) scale(0.9090909090909091)");
147+
cy.verifyCanvasTransform("translate(45.81818181818181,32.22727272727275) scale(0.9090909090909091)");
150148
// Test get Zoom to reveal & ZoomTo
151149
cy.selectEntryFromDropdown("Binding (entry) node-Execution node");
152150
cy.setXPercentOffset(70);
153151
cy.setYPercentOffset(60);
154152
cy.submitAPI();
155-
// TODO -- write function to test these +/- 2 px.
156-
// cy.verifyCanvasTransform("translate(498.32727272727266,290.85454545454536) scale(0.9090909090909091)");
153+
cy.verifyCanvasTransform("translate(498.32727272727266,290.85454545454536) scale(0.9090909090909091)");
157154
});
158155
});
159156

canvas_modules/harness/cypress/support/canvas/verification-cmds.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,22 @@ Cypress.Commands.add("verifyNotificationIconType", (type) => {
13711371
Cypress.Commands.add("verifyCanvasTransform", (movString) => {
13721372
cy.get("#canvas-div-0 .d3-canvas-group")
13731373
.invoke("attr", "transform")
1374-
.should("eq", movString);
1374+
.should((actualTransformString) => {
1375+
// Verify the movString passed is a string
1376+
if (typeof movString === "string") {
1377+
const expectedValues = parseTransformString(movString);
1378+
const actualValues = parseTransformString(actualTransformString);
1379+
// Compare each part of the transform with compareRange
1380+
compareCloseTo(actualValues.translateX, expectedValues.translateX);
1381+
compareCloseTo(actualValues.translateY, expectedValues.translateY);
1382+
compareCloseTo(actualValues.scale, expectedValues.scale);
1383+
} else if (typeof movString === "undefined") {
1384+
expect(actualTransformString).to.be.undefined;
1385+
} else {
1386+
throw new Error("Expected movString to be a string or undefined");
1387+
}
1388+
});
1389+
13751390
});
13761391

13771392
Cypress.Commands.add("verifyNotificationCounter", (count) => {
@@ -1427,7 +1442,7 @@ Cypress.Commands.add("verifyNotificationCenterDoesntExist", (hidden) => {
14271442
Cypress.Commands.add("verifyNotificationCenterContent", (id, content) => {
14281443
if (typeof content === "string" && content.length > 0) {
14291444
cy.get(".notification-panel-" + id).should("contain", content);
1430-
} else if (typeof content === "string" && content.length === 0) {
1445+
} else if (typeof content === "string" && content.length === 0) {
14311446
cy.get(".notification-panel-" + id).should("be.empty");
14321447
} else {
14331448
cy.get(".notification-panel-" + id).should("not.exist");
@@ -1481,6 +1496,19 @@ function verifyPath(actualPath, expectedPath) {
14811496
}
14821497
}
14831498

1499+
function parseTransformString(transformString) {
1500+
const translateMatch = transformString.match(/translate\(([^,]+),([^)]+)\)/);
1501+
const scaleMatch = transformString.match(/scale\(([^)]+)\)/);
1502+
if (!translateMatch || !scaleMatch) {
1503+
throw new Error("invalid string format");
1504+
}
1505+
return {
1506+
translateX: parseFloat(translateMatch[1]),
1507+
translateY: parseFloat(translateMatch[2]),
1508+
scale: parseFloat(scaleMatch[1])
1509+
};
1510+
}
1511+
14841512
function compareCloseTo(value, compareValue) {
14851513
expect(Number(value)).to.be.closeTo(Number(compareValue), Cypress.env("compareRange"));
14861514
}

0 commit comments

Comments
 (0)