Merge pull request #17036 from calixteman/fix_test_freetext
[Editor] Remove almost all the waitForTimeout from the freetext integration tests
This commit is contained in:
commit
46940a5a52
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,7 @@ const {
|
|||||||
getComputedStyleSelector,
|
getComputedStyleSelector,
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
getFirstSerialized,
|
getFirstSerialized,
|
||||||
|
scrollIntoView,
|
||||||
} = require("./test_utils.js");
|
} = require("./test_utils.js");
|
||||||
|
|
||||||
describe("Interaction", () => {
|
describe("Interaction", () => {
|
||||||
@ -538,12 +539,7 @@ describe("Interaction", () => {
|
|||||||
text = await actAndWaitForInput(
|
text = await actAndWaitForInput(
|
||||||
page,
|
page,
|
||||||
getSelector(refOpen),
|
getSelector(refOpen),
|
||||||
async () => {
|
() => scrollIntoView(page, getSelector(refOpen)),
|
||||||
await page.evaluate(selector => {
|
|
||||||
const element = window.document.querySelector(selector);
|
|
||||||
element.scrollIntoView();
|
|
||||||
}, getSelector(refOpen));
|
|
||||||
},
|
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
expect(text)
|
expect(text)
|
||||||
@ -818,9 +814,7 @@ describe("Interaction", () => {
|
|||||||
"window.PDFViewerApplication.scriptingReady === true"
|
"window.PDFViewerApplication.scriptingReady === true"
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.evaluate(selector => {
|
await scrollIntoView(page, getSelector("171R"));
|
||||||
window.document.querySelector(selector).scrollIntoView();
|
|
||||||
}, getSelector("171R"));
|
|
||||||
|
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
for (const [id, val] of [
|
for (const [id, val] of [
|
||||||
@ -853,11 +847,7 @@ describe("Interaction", () => {
|
|||||||
|
|
||||||
// Some unrendered annotations have been updated, so check
|
// Some unrendered annotations have been updated, so check
|
||||||
// that they've the correct value when rendered.
|
// that they've the correct value when rendered.
|
||||||
await page.evaluate(() => {
|
await scrollIntoView(page, '.page[data-page-number = "4"]');
|
||||||
window.document
|
|
||||||
.querySelector('.page[data-page-number = "4"]')
|
|
||||||
.scrollIntoView();
|
|
||||||
});
|
|
||||||
await page.waitForSelector(getSelector("299R"), {
|
await page.waitForSelector(getSelector("299R"), {
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
});
|
});
|
||||||
|
@ -97,16 +97,27 @@ function getSelectedEditors(page) {
|
|||||||
}
|
}
|
||||||
exports.getSelectedEditors = getSelectedEditors;
|
exports.getSelectedEditors = getSelectedEditors;
|
||||||
|
|
||||||
async function waitForEvent(page, eventName, timeout = 30000) {
|
async function waitForEvent(page, eventName, timeout = 5000) {
|
||||||
await Promise.race([
|
const hasTimedout = await Promise.race([
|
||||||
// add event listener and wait for event to fire before returning
|
// add event listener and wait for event to fire before returning
|
||||||
page.evaluate(name => {
|
page.evaluate(
|
||||||
return new Promise(resolve => {
|
name =>
|
||||||
document.addEventListener(name, resolve, { once: true });
|
new Promise(resolve => {
|
||||||
});
|
document.addEventListener(name, () => resolve(false), { once: true });
|
||||||
}, eventName),
|
}),
|
||||||
page.waitForTimeout(timeout),
|
eventName
|
||||||
|
),
|
||||||
|
page.evaluate(
|
||||||
|
timeOut =>
|
||||||
|
new Promise(resolve => {
|
||||||
|
setTimeout(() => resolve(true), timeOut);
|
||||||
|
}),
|
||||||
|
timeout
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
if (hasTimedout === true) {
|
||||||
|
console.log(`waitForEvent: timeout waiting for ${eventName}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.waitForEvent = waitForEvent;
|
exports.waitForEvent = waitForEvent;
|
||||||
|
|
||||||
@ -119,15 +130,27 @@ const waitForStorageEntries = async (page, nEntries) => {
|
|||||||
};
|
};
|
||||||
exports.waitForStorageEntries = waitForStorageEntries;
|
exports.waitForStorageEntries = waitForStorageEntries;
|
||||||
|
|
||||||
const waitForSelectedEditor = async (page, selector) => {
|
const waitForSerialized = async (page, nEntries) => {
|
||||||
await page.waitForFunction(
|
await page.waitForFunction(
|
||||||
sel => document.querySelector(sel).classList.contains("selectedEditor"),
|
n =>
|
||||||
|
(window.PDFViewerApplication.pdfDocument.annotationStorage.serializable
|
||||||
|
.map?.size ?? 0) === n,
|
||||||
{},
|
{},
|
||||||
selector
|
nEntries
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
exports.waitForSerialized = waitForSerialized;
|
||||||
|
|
||||||
|
const waitForSelectedEditor = async (page, selector) => {
|
||||||
|
await page.waitForSelector(`${selector}.selectedEditor`);
|
||||||
|
};
|
||||||
exports.waitForSelectedEditor = waitForSelectedEditor;
|
exports.waitForSelectedEditor = waitForSelectedEditor;
|
||||||
|
|
||||||
|
const waitForUnselectedEditor = async (page, selector) => {
|
||||||
|
await page.waitForSelector(`${selector}:not(.selectedEditor)`);
|
||||||
|
};
|
||||||
|
exports.waitForUnselectedEditor = waitForUnselectedEditor;
|
||||||
|
|
||||||
const mockClipboard = async pages => {
|
const mockClipboard = async pages => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pages.map(async ([_, page]) => {
|
pages.map(async ([_, page]) => {
|
||||||
@ -203,6 +226,7 @@ async function dragAndDropAnnotation(page, startX, startY, tX, tY) {
|
|||||||
await page.waitForTimeout(10);
|
await page.waitForTimeout(10);
|
||||||
await page.mouse.move(startX + tX, startY + tY);
|
await page.mouse.move(startX + tX, startY + tY);
|
||||||
await page.mouse.up();
|
await page.mouse.up();
|
||||||
|
await page.waitForSelector("#viewer:not(.noUserSelect)");
|
||||||
}
|
}
|
||||||
exports.dragAndDropAnnotation = dragAndDropAnnotation;
|
exports.dragAndDropAnnotation = dragAndDropAnnotation;
|
||||||
|
|
||||||
@ -217,3 +241,39 @@ async function waitForAnnotationEditorLayer(page) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer;
|
exports.waitForAnnotationEditorLayer = waitForAnnotationEditorLayer;
|
||||||
|
|
||||||
|
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 element = document.querySelector(sel);
|
||||||
|
const { top, bottom } = element.getBoundingClientRect();
|
||||||
|
return Math.abs(top) < 100 || Math.abs(bottom - window.innerHeight) < 100;
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
selector
|
||||||
|
);
|
||||||
|
}
|
||||||
|
exports.scrollIntoView = scrollIntoView;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user