From db4d7d58384d59769010f8515ba378aada1fe0aa Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 19 Jan 2024 02:47:32 -0500 Subject: [PATCH] Fix recognizeDocument test failures Wait for all progress-queue rows to be done processing before moving on to the next test. Without this, preview rendering or other operations can cause test failures by delaying the `ZoteroPane.selectItems()` call for the new parent item in `_processItem()` until the middle of a following test (due to the await for file renaming [1]). If it's delayed until after the next attachment has been created, the previous parent item will be selected after the new attachment and `recognizeSelected()` in the test won't work. This is most pronounced with the reader, but it was apparently happening previously due to something else, hence the explicit item selection (now removed) in one test. [1] https://github.com/zotero/zotero/blob/21e50add60ee1533cb7e528c7edc08f2f1ccddb1/chrome/content/zotero/xpcom/recognizeDocument.js#L289-L301 --- test/tests/recognizeDocumentTest.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/tests/recognizeDocumentTest.js b/test/tests/recognizeDocumentTest.js index f01fba8b8d..74acc66267 100644 --- a/test/tests/recognizeDocumentTest.js +++ b/test/tests/recognizeDocumentTest.js @@ -13,11 +13,18 @@ describe("Document Recognition", function() { yield selectLibrary(win); }); - afterEach(function() { + afterEach(async function() { for(let win of getWindows("chrome://zotero/content/progressQueueDialog.xhtml")) { win.close(); } - Zotero.ProgressQueues.get('recognize').cancel(); + + // Wait for all rows to be done processing + var queue = Zotero.ProgressQueues.get('recognize'); + while (queue.getRows().some(row => row.status == Zotero.ProgressQueue.ROW_PROCESSING)) { + await Zotero.Promise.delay(50); + } + + queue.cancel(); Zotero.RecognizeDocument.recognizeStub = null; Zotero.Prefs.clear('autoRenameFiles.linked'); }); @@ -436,7 +443,6 @@ describe("Document Recognition", function() { file: testDir, collections: [collection.id] }); - await win.ZoteroPane.selectItem(attachment.id); // No idea why this is necessary for only this test win.ZoteroPane.recognizeSelected();