Skip to content

Commit

Permalink
Fix intermittents failure on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Oct 27, 2023
1 parent 517a262 commit d72fd9c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 46 deletions.
7 changes: 5 additions & 2 deletions test/integration/find_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("find bar", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("find_all.pdf#zoom=100", ".textLayer");
pages = await loadAndWait("find_all.pdf", ".textLayer", 100);
});

afterAll(async () => {
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("find bar", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("xfa_imm5257e.pdf#zoom=100", ".xfaLayer");
pages = await loadAndWait("xfa_imm5257e.pdf", ".xfaLayer");
});

afterAll(async () => {
Expand All @@ -91,6 +91,9 @@ describe("find bar", () => {
await page.type("#findInput", "preferences");
await page.waitForSelector("#findInput[data-status='']");
await page.waitForSelector(".xfaLayer .highlight");
await page.waitForFunction(
() => !!document.querySelector("#findResultsCount")?.textContent
);
const resultElement = await page.waitForSelector("#findResultsCount");
const resultText = await resultElement.evaluate(el => el.textContent);
/** Unicode bidi isolation characters. */
Expand Down
96 changes: 72 additions & 24 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ const waitForPositionChange = (page, selector, 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", () => {
let pages;
Expand Down Expand Up @@ -300,22 +314,23 @@ describe("FreeText Editor", () => {
it("must check that aria-owns is correct", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
await page.$eval(".textLayer", el => {
for (const span of el.querySelectorAll(
`span[role="presentation"]`
)) {
if (span.innerText.includes("Stacks are simple to create")) {
span.setAttribute("pdfjs", true);
}
}
});

await scrollIntoView(page, `span[pdfjs="true"]`);

const [stacksRect, oldAriaOwns] = await page.$eval(
".textLayer",
`span[pdfjs="true"]`,
el => {
for (const span of el.querySelectorAll(
`span[role="presentation"]`
)) {
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;
const { x, y, width, height } = el.getBoundingClientRect();
return [{ x, y, width, height }, el.getAttribute("aria-owns")];
}
);

Expand Down Expand Up @@ -345,6 +360,7 @@ describe("FreeText Editor", () => {
expect(ariaOwns.endsWith("_7-editor"))
.withContext(`In ${browserName}`)
.toEqual(true);
await scrollIntoView(page, ".annotationEditorLayer");
})
);
});
Expand Down Expand Up @@ -2236,6 +2252,7 @@ describe("FreeText Editor", () => {
});
await page.type(`${getEditorSelector(0)} .internal`, data);
// Commit.
await cancelFocusIn(page, getEditorSelector(0));
await page.keyboard.press("Escape");
await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled`
Expand Down Expand Up @@ -2488,6 +2505,7 @@ describe("FreeText Editor", () => {
await page.type(`${getEditorSelector(0)} .internal`, data);

// Commit.
await cancelFocusIn(page, getEditorSelector(0));
await page.keyboard.press("Escape");
await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled`
Expand Down Expand Up @@ -2541,20 +2559,35 @@ describe("FreeText Editor", () => {
const { x, y } = el.getBoundingClientRect();
return { x, y };
});
const selectorEditor = getEditorSelector(0);
await page.mouse.click(rect.x + 10, rect.y + 10);
await page.waitForSelector(getEditorSelector(0), {
await page.waitForSelector(selectorEditor, {
visible: true,
});
await page.type(`${getEditorSelector(0)} .internal`, "Hello");
await page.type(`${selectorEditor} .internal`, "Hello");

// Commit.
await cancelFocusIn(page, selectorEditor);
await page.keyboard.press("Escape");
await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled`
await page.waitForSelector(`${selectorEditor} .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.
await page.keyboard.press("End");
await scrollIntoView(page, `.page[data-page-number = "14"]`);

const page14Selector = `.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`;
await page.waitForSelector(page14Selector, {
Expand Down Expand Up @@ -2638,20 +2671,35 @@ describe("FreeText Editor", () => {
const { x, y } = el.getBoundingClientRect();
return { x, y };
});
const selectorEditor = getEditorSelector(0);
await page.mouse.click(rect.x + 10, rect.y + 10);
await page.waitForSelector(getEditorSelector(0), {
await page.waitForSelector(selectorEditor, {
visible: true,
});
await page.type(`${getEditorSelector(0)} .internal`, "Hello");
await page.type(`${selectorEditor} .internal`, "Hello");

// Commit.
await cancelFocusIn(page, selectorEditor);
await page.keyboard.press("Escape");
await page.waitForSelector(
`${getEditorSelector(0)} .overlay.enabled`
await page.waitForSelector(`${selectorEditor} .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.
await kbGoToEnd(page);
await scrollIntoView(page, `.page[data-page-number = "14"]`);
await page.waitForSelector(
`.page[data-page-number = "14"] > .annotationEditorLayer.freetextEditing`,
{
Expand Down
28 changes: 8 additions & 20 deletions test/integration/test_utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -252,34 +252,22 @@ async function waitForTextLayer(page) {
}

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 => {
const element = document.querySelector(sel);
element.scrollIntoView({ behavior: "instant", block: "start" });
}, selector);
await promise;
await page.waitForFunction(
sel => {
const toolbarHeight = document
.querySelector("#toolbarContainer")
.getBoundingClientRect().height;
const element = document.querySelector(sel);
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
Expand Down

0 comments on commit d72fd9c

Please sign in to comment.