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?
This commit is contained in:
Bogdan Abaev 2024-07-08 17:44:46 -07:00 committed by Dan Stillman
parent fd93af8305
commit 2f1aa19ae5
2 changed files with 10 additions and 8 deletions

View file

@ -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');

View file

@ -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);