From 306cca930fa5791ded87bc88000d40a566ed3f37 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 17 Sep 2023 14:54:46 +0200 Subject: [PATCH] Fix off-by-one errors in the "FreeText must move several annotations" integration test The x/y-coordinates are floats instead of integers like one might expect. The current approach rounds both the old and the new coordinates in order to do integer comparison. However, rounding each coordinate individually causes too much loss of precision because, depending on the decimal value, they are either rounded up or down which causes intermittent off-by-one errors. This commit fixes the problem by comparing coordinate differences instead of the coordinates themselves. The precision loss is avoided by subtracting the old from the new coordinate as-is and only rounding the final result. --- test/integration/freetext_editor_spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/freetext_editor_spec.js b/test/integration/freetext_editor_spec.js index bfb615fff..084a98e10 100644 --- a/test/integration/freetext_editor_spec.js +++ b/test/integration/freetext_editor_spec.js @@ -2254,12 +2254,12 @@ describe("FreeText Editor", () => { return { x, y }; }); const oldPos = allPositions[i]; - expect(Math.round(pos.x)) + expect(Math.round(pos.x - oldPos.x)) .withContext(`In ${browserName}`) - .toEqual(Math.round(oldPos.x + 39)); - expect(Math.round(pos.y)) + .toEqual(39); + expect(Math.round(pos.y - oldPos.y)) .withContext(`In ${browserName}`) - .toEqual(Math.round(oldPos.y + 74)); + .toEqual(74); } }) );