Fix intermittents failure on mac

This commit is contained in:
Calixte Denizet 2023-10-26 22:44:35 +02:00
parent 517a262fb1
commit d72fd9ce4f
3 changed files with 86 additions and 47 deletions

View File

@ -29,7 +29,7 @@ describe("find bar", () => {
let pages; let pages;
beforeAll(async () => { beforeAll(async () => {
pages = await loadAndWait("find_all.pdf#zoom=100", ".textLayer"); pages = await loadAndWait("find_all.pdf", ".textLayer", 100);
}); });
afterAll(async () => { afterAll(async () => {
@ -76,7 +76,7 @@ describe("find bar", () => {
let pages; let pages;
beforeAll(async () => { beforeAll(async () => {
pages = await loadAndWait("xfa_imm5257e.pdf#zoom=100", ".xfaLayer"); pages = await loadAndWait("xfa_imm5257e.pdf", ".xfaLayer");
}); });
afterAll(async () => { afterAll(async () => {
@ -91,6 +91,9 @@ describe("find bar", () => {
await page.type("#findInput", "preferences"); await page.type("#findInput", "preferences");
await page.waitForSelector("#findInput[data-status='']"); await page.waitForSelector("#findInput[data-status='']");
await page.waitForSelector(".xfaLayer .highlight"); await page.waitForSelector(".xfaLayer .highlight");
await page.waitForFunction(
() => !!document.querySelector("#findResultsCount")?.textContent
);
const resultElement = await page.waitForSelector("#findResultsCount"); const resultElement = await page.waitForSelector("#findResultsCount");
const resultText = await resultElement.evaluate(el => el.textContent); const resultText = await resultElement.evaluate(el => el.textContent);
/** Unicode bidi isolation characters. */ /** Unicode bidi isolation characters. */

View File

@ -93,6 +93,20 @@ const waitForPositionChange = (page, selector, xy) =>
xy xy
); );
const cancelFocusIn = async (page, selector) => {
page.evaluate(sel => {
const el = document.querySelector(sel);
el.addEventListener(
"focusin",
evt => {
evt.preventDefault();
evt.stopPropagation();
},
{ capture: true, once: true }
);
}, selector);
};
describe("FreeText Editor", () => { describe("FreeText Editor", () => {
describe("FreeText", () => { describe("FreeText", () => {
let pages; let pages;
@ -300,22 +314,23 @@ describe("FreeText Editor", () => {
it("must check that aria-owns is correct", async () => { it("must check that aria-owns is correct", async () => {
await Promise.all( await Promise.all(
pages.map(async ([browserName, page]) => { pages.map(async ([browserName, page]) => {
const [stacksRect, oldAriaOwns] = await page.$eval( await page.$eval(".textLayer", el => {
".textLayer", for (const span of el.querySelectorAll(
el => { `span[role="presentation"]`
for (const span of el.querySelectorAll( )) {
`span[role="presentation"]` if (span.innerText.includes("Stacks are simple to create")) {
)) { span.setAttribute("pdfjs", true);
if (span.innerText.includes("Stacks are simple to create")) {
span.setAttribute("pdfjs", true);
const { x, y, width, height } = span.getBoundingClientRect();
return [
{ x, y, width, height },
span.getAttribute("aria-owns"),
];
}
} }
return null; }
});
await scrollIntoView(page, `span[pdfjs="true"]`);
const [stacksRect, oldAriaOwns] = await page.$eval(
`span[pdfjs="true"]`,
el => {
const { x, y, width, height } = el.getBoundingClientRect();
return [{ x, y, width, height }, el.getAttribute("aria-owns")];
} }
); );
@ -345,6 +360,7 @@ describe("FreeText Editor", () => {
expect(ariaOwns.endsWith("_7-editor")) expect(ariaOwns.endsWith("_7-editor"))
.withContext(`In ${browserName}`) .withContext(`In ${browserName}`)
.toEqual(true); .toEqual(true);
await scrollIntoView(page, ".annotationEditorLayer");
}) })
); );
}); });
@ -2236,6 +2252,7 @@ describe("FreeText Editor", () => {
}); });
await page.type(`${getEditorSelector(0)} .internal`, data); await page.type(`${getEditorSelector(0)} .internal`, data);
// Commit. // Commit.
await cancelFocusIn(page, getEditorSelector(0));
await page.keyboard.press("Escape"); await page.keyboard.press("Escape");
await page.waitForSelector( await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled` `${getEditorSelector(0)} .overlay.enabled`
@ -2488,6 +2505,7 @@ describe("FreeText Editor", () => {
await page.type(`${getEditorSelector(0)} .internal`, data); await page.type(`${getEditorSelector(0)} .internal`, data);
// Commit. // Commit.
await cancelFocusIn(page, getEditorSelector(0));
await page.keyboard.press("Escape"); await page.keyboard.press("Escape");
await page.waitForSelector( await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled` `${getEditorSelector(0)} .overlay.enabled`
@ -2541,20 +2559,35 @@ describe("FreeText Editor", () => {
const { x, y } = el.getBoundingClientRect(); const { x, y } = el.getBoundingClientRect();
return { x, y }; return { x, y };
}); });
const selectorEditor = getEditorSelector(0);
await page.mouse.click(rect.x + 10, rect.y + 10); await page.mouse.click(rect.x + 10, rect.y + 10);
await page.waitForSelector(getEditorSelector(0), { await page.waitForSelector(selectorEditor, {
visible: true, visible: true,
}); });
await page.type(`${getEditorSelector(0)} .internal`, "Hello"); await page.type(`${selectorEditor} .internal`, "Hello");
// Commit. // Commit.
await cancelFocusIn(page, selectorEditor);
await page.keyboard.press("Escape"); await page.keyboard.press("Escape");
await page.waitForSelector( await page.waitForSelector(`${selectorEditor} .overlay.enabled`);
`${getEditorSelector(0)} .overlay.enabled`
// Unselect.
await page.keyboard.press("Escape");
await waitForUnselectedEditor(page, selectorEditor);
const editorRect = await page.$eval(selectorEditor, el => {
const { x, y, width, height } = el.getBoundingClientRect();
return { x, y, width, height };
});
// Select the editor created previously.
await page.mouse.click(
editorRect.x + editorRect.width / 2,
editorRect.y + editorRect.height / 2
); );
// Go to the last page. // Go to the last page.
await page.keyboard.press("End"); await scrollIntoView(page, `.page[data-page-number = "14"]`);
const page14Selector = `.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`; const page14Selector = `.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`;
await page.waitForSelector(page14Selector, { await page.waitForSelector(page14Selector, {
@ -2638,20 +2671,35 @@ describe("FreeText Editor", () => {
const { x, y } = el.getBoundingClientRect(); const { x, y } = el.getBoundingClientRect();
return { x, y }; return { x, y };
}); });
const selectorEditor = getEditorSelector(0);
await page.mouse.click(rect.x + 10, rect.y + 10); await page.mouse.click(rect.x + 10, rect.y + 10);
await page.waitForSelector(getEditorSelector(0), { await page.waitForSelector(selectorEditor, {
visible: true, visible: true,
}); });
await page.type(`${getEditorSelector(0)} .internal`, "Hello"); await page.type(`${selectorEditor} .internal`, "Hello");
// Commit. // Commit.
await cancelFocusIn(page, selectorEditor);
await page.keyboard.press("Escape"); await page.keyboard.press("Escape");
await page.waitForSelector( await page.waitForSelector(`${selectorEditor} .overlay.enabled`);
`${getEditorSelector(0)} .overlay.enabled`
// Unselect.
await page.keyboard.press("Escape");
await waitForUnselectedEditor(page, selectorEditor);
const editorRect = await page.$eval(selectorEditor, el => {
const { x, y, width, height } = el.getBoundingClientRect();
return { x, y, width, height };
});
// Select the editor created previously.
await page.mouse.click(
editorRect.x + editorRect.width / 2,
editorRect.y + editorRect.height / 2
); );
// Go to the last page. // Go to the last page.
await kbGoToEnd(page); await scrollIntoView(page, `.page[data-page-number = "14"]`);
await page.waitForSelector( await page.waitForSelector(
`.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`, `.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`,
{ {

View File

@ -252,34 +252,22 @@ async function waitForTextLayer(page) {
} }
async function scrollIntoView(page, selector) { async function scrollIntoView(page, selector) {
const promise = page.evaluate(
sel =>
new Promise(resolve => {
const el = document.querySelector(sel);
const observer = new IntersectionObserver(
() => {
observer.disconnect();
resolve();
},
{
root: document.querySelector("#viewerContainer"),
threshold: 0.1,
}
);
observer.observe(el);
}),
selector
);
await page.evaluate(sel => { await page.evaluate(sel => {
const element = document.querySelector(sel); const element = document.querySelector(sel);
element.scrollIntoView({ behavior: "instant", block: "start" }); element.scrollIntoView({ behavior: "instant", block: "start" });
}, selector); }, selector);
await promise;
await page.waitForFunction( await page.waitForFunction(
sel => { sel => {
const toolbarHeight = document
.querySelector("#toolbarContainer")
.getBoundingClientRect().height;
const element = document.querySelector(sel); const element = document.querySelector(sel);
const { top, bottom } = element.getBoundingClientRect(); const { top, bottom } = element.getBoundingClientRect();
return Math.abs(top) < 100 || Math.abs(bottom - window.innerHeight) < 100; return (
Math.abs(top) < toolbarHeight + 100 ||
Math.abs(bottom - window.innerHeight) < 100 ||
(top > toolbarHeight && bottom < window.innerHeight)
);
}, },
{}, {},
selector selector