Fix attachments & annotation box refresh bugs and add tests (#4031)

Fixes #3993
Fixes #3995
Closes #4082
This commit is contained in:
windingwind 2024-04-22 09:15:22 +08:00 committed by Dan Stillman
parent 07e8f0a01d
commit 91c0c28b5d
10 changed files with 806 additions and 49 deletions

View file

@ -384,6 +384,31 @@ async function delay(ms) {
return Zotero.Promise.delay(ms);
}
async function waitForFrame() {
return waitNoLongerThan(new Promise((resolve) => {
requestAnimationFrame(resolve);
}), 30);
}
async function waitForFrames(n) {
for (let i = 0; i < n; i++) {
await waitForFrame();
}
}
async function waitNoLongerThan(promise, ms = 1000) {
return Promise.race([
promise,
Zotero.Promise.delay(ms)
]);
}
async function waitForScrollToPane(itemDetails, paneID) {
await itemDetails._renderPromise;
itemDetails.scrollToPane(paneID, "instant");
// Wait for some frames or up to 150ms to ensure the pane is visible
await waitForFrames(5);
}
function clickOnItemsRow(win, itemsView, row) {
itemsView._treebox.scrollToRow(row);
@ -1115,3 +1140,4 @@ async function startHTTPServer(port = null) {
var baseURL = `http://localhost:${port}/`
return { httpd, port, baseURL };
}