From 70b44251ed9650a53bc1e899f5127c1bb2584141 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Fri, 5 Jul 2024 16:56:31 +0200 Subject: [PATCH] Fix the "must check that charLimit is correctly set" scripting integration test This integration test fails intermittently because we're not (correctly) awaiting the character limit increase sandbox action. For the first increase an attempt was made to handle this, but it doesn't work correctly because the text in the field is `abcdefghijklmnopq` and it's not be truncated until the sandbox action is completed, so because we didn't await that we would could pass the `value !== "abcdefgh"` check because `abcdefghijklmnopq !== abcdefgh` is true. For the second increase we didn't have a check in place. This commit fixes the issues by using the `waitForSandboxTrip` and `waitForSelector` helper functions to make sure that we can only proceed if the sandbox action is completed and the DOM element is updated. --- test/integration/scripting_spec.mjs | 48 ++++++++++------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index a69ba3f31..b1e08197b 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -1535,49 +1535,35 @@ describe("Interaction", () => { it("must check that charLimit is correctly set", async () => { await Promise.all( - pages.map(async ([browserName, page]) => { + pages.map(async ([, page]) => { await page.waitForFunction( "window.PDFViewerApplication.scriptingReady === true" ); - await clearInput(page, getSelector("7R")); - // By default the charLimit is 0 which means that the input - // length is unlimited. - await page.type(getSelector("7R"), "abcdefghijklmnopq", { - delay: 10, - }); - - let value = await page.$eval(getSelector("7R"), el => el.value); - expect(value) - .withContext(`In ${browserName}`) - .toEqual("abcdefghijklmnopq"); - - // charLimit is set to 1 - await page.click(getSelector("9R")); - + // The default charLimit is 0, which indicates unlimited text length. + await page.type(getSelector("7R"), "abcdefghij", { delay: 10 }); await page.waitForFunction( - `document.querySelector('${getSelector( - "7R" - )}').value !== "abcdefgh"` + `${getQuerySelector("7R")}.value === "abcdefghij"` ); - value = await page.$eval(getSelector("7R"), el => el.value); - expect(value).withContext(`In ${browserName}`).toEqual("a"); - - await clearInput(page, getSelector("7R")); - await page.type(getSelector("7R"), "xyz", { delay: 10 }); - - value = await page.$eval(getSelector("7R"), el => el.value); - expect(value).withContext(`In ${browserName}`).toEqual("x"); - - // charLimit is set to 2 + // Increase the charLimit to 1 (this truncates the existing text). await page.click(getSelector("9R")); + await waitForSandboxTrip(page); + await page.waitForFunction(`${getQuerySelector("7R")}.value === "a"`); await clearInput(page, getSelector("7R")); await page.type(getSelector("7R"), "xyz", { delay: 10 }); + await page.waitForFunction(`${getQuerySelector("7R")}.value === "x"`); - value = await page.$eval(getSelector("7R"), el => el.value); - expect(value).withContext(`In ${browserName}`).toEqual("xy"); + // Increase the charLimit to 2. + await page.click(getSelector("9R")); + await waitForSandboxTrip(page); + + await clearInput(page, getSelector("7R")); + await page.type(getSelector("7R"), "xyz", { delay: 10 }); + await page.waitForFunction( + `${getQuerySelector("7R")}.value === "xy"` + ); }) ); });