From 2f1aa19ae5c62a41f40b8b9db0713b7667ccd6ed Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Mon, 8 Jul 2024 17:44:46 -0700 Subject: [PATCH] tweaks for tests to pass after React 18 upgrade (#4338) - Wait for the itemsView to be initialized in the onload listener of the Advanced Search window - moved waitForTagSelector in a few tests to avoid it resolving too early. For some tests these tweaks are always required, for others - tests would pass half the time. Again, not clear why it's necessary, potentially some flakiness from react 18? --- test/tests/advancedSearchTest.js | 8 ++++++-- test/tests/tagSelectorTest.js | 10 ++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test/tests/advancedSearchTest.js b/test/tests/advancedSearchTest.js index 974350b7e3..2776648104 100644 --- a/test/tests/advancedSearchTest.js +++ b/test/tests/advancedSearchTest.js @@ -19,10 +19,14 @@ describe("Advanced Search", function () { it("should perform a search", function* () { var item = yield createDataObject('item', { setTitle: true }); - var promise = waitForWindow('chrome://zotero/content/advancedSearch.xhtml'); + var promise = waitForWindow('chrome://zotero/content/advancedSearch.xhtml', async (win) => { + // Wait for the itemsView to be initialized in the onload listener of the window + while (!win.ZoteroAdvancedSearch.itemsView) { + await Zotero.Promise.delay(5); + } + }); zp.openAdvancedSearchWindow(); var searchWin = yield promise; - // Add condition var searchBox = searchWin.document.getElementById('zotero-search-box'); diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index a293530c7a..73ffcb32ca 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -310,6 +310,7 @@ describe("Tag Selector", function () { await Zotero.Tags.setColor(libraryID, tag2, '#BBBBBB', 2); await Zotero.Tags.setColor(libraryID, tag3, '#CCCCCC', 3); + await waitForTagSelector(win); // Colored tags should appear initially as disabled elems = getColoredTagElements(); assert.lengthOf(elems, 3); @@ -402,10 +403,9 @@ describe("Tag Selector", function () { var promise, tagSelector; // Add collection - promise = waitForTagSelector(win); var collection = yield createDataObject('collection'); yield select(win, collection); - yield promise; + yield waitForTagSelector(win); // Tag selector should be empty in new collection assert.equal(getRegularTags().length, 0); @@ -435,9 +435,8 @@ describe("Tag Selector", function () { var tagElems = tagSelectorElem.querySelectorAll('.tag-selector-item'); var count = tagElems.length; - var promise = waitForTagSelector(win); yield Zotero.Tags.setColor(libraryID, "Top", '#AAAAAA'); - yield promise; + yield waitForTagSelector(win); tagElems = tagSelectorElem.querySelectorAll('.tag-selector-item'); assert.equal(tagElems.length, count + 1); @@ -707,14 +706,13 @@ describe("Tag Selector", function () { yield Zotero.Tags.setColor(libraryID, oldTag, "#F3F3F3"); yield promise; - promise = waitForTagSelector(win); waitForDialog(function (dialogWindow, dialog) { dialogWindow.document.getElementById('loginTextbox').value = newTag; dialog.acceptDialog(); }); tagSelector.contextTag = {name: oldTag}; yield tagSelector.openRenamePrompt(); - yield promise; + yield waitForTagSelector(win);; var tags = getColoredTags(); assert.notInclude(tags, oldTag);