From 1a4b7121d3b4cc1020a376c37751fa97ea9cf563 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 24 Mar 2017 00:51:25 -0400 Subject: [PATCH] Move waitForTagSelector() into support.js --- test/content/support.js | 17 ++++++++++++ test/tests/tagSelectorTest.js | 51 ++++++++++++++--------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/test/content/support.js b/test/content/support.js index a53346a8cd..f3fd248230 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -201,6 +201,23 @@ var waitForItemsLoad = Zotero.Promise.coroutine(function* (win, collectionRowToS return deferred.promise; }); +var waitForTagSelector = function (win) { + var zp = win.ZoteroPane; + var deferred = Zotero.Promise.defer(); + if (zp.tagSelectorShown()) { + var tagSelector = win.document.getElementById('zotero-tag-selector'); + var onRefresh = () => { + tagSelector.removeEventListener('refresh', onRefresh); + deferred.resolve(); + }; + tagSelector.addEventListener('refresh', onRefresh); + } + else { + deferred.resolve(); + } + return deferred.promise; +}; + /** * Waits for a single item event. Returns a promise for the item ID(s). */ diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index 30bf1fba4e..9a030edec2 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -53,23 +53,12 @@ describe("Tag Selector", function () { win.close(); }); - function waitForTagSelector() { - var deferred = Zotero.Promise.defer(); - var tagSelector = doc.getElementById('zotero-tag-selector'); - var onRefresh = function (event) { - tagSelector.removeEventListener('refresh', onRefresh); - deferred.resolve(); - } - tagSelector.addEventListener('refresh', onRefresh); - return deferred.promise; - } - describe("#notify()", function () { it("should add a tag when added to an item in the library root", function* () { var promise, tagSelector; if (collectionsView.selection.currentIndex != 0) { - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield collectionsView.selectLibrary(); yield promise; } @@ -85,7 +74,7 @@ describe("Tag Selector", function () { type: 1 } ]); - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -97,7 +86,7 @@ describe("Tag Selector", function () { var promise, tagSelector; // Add collection - promise = waitForTagSelector(); + promise = waitForTagSelector(win); var collection = yield createDataObject('collection'); yield promise; @@ -112,7 +101,7 @@ describe("Tag Selector", function () { } ]); item.setCollections([collection.id]); - promise = waitForTagSelector() + promise = waitForTagSelector(win) yield item.saveTx(); yield promise; @@ -124,7 +113,7 @@ describe("Tag Selector", function () { var promise, tagSelector; // Add collection - promise = waitForTagSelector(); + promise = waitForTagSelector(win); var collection = yield createDataObject('collection'); yield promise; @@ -138,7 +127,7 @@ describe("Tag Selector", function () { tag: 'C' } ]); - promise = waitForTagSelector() + promise = waitForTagSelector(win) yield item.saveTx(); yield promise; @@ -146,7 +135,7 @@ describe("Tag Selector", function () { assert.equal(getRegularTags().length, 0); item.setCollections([collection.id]); - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -188,7 +177,7 @@ describe("Tag Selector", function () { tag: "A" } ]); - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -206,7 +195,7 @@ describe("Tag Selector", function () { it("should remove a tag when an item is removed from a collection", function* () { // Add collection - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); var collection = yield createDataObject('collection'); yield promise; @@ -218,7 +207,7 @@ describe("Tag Selector", function () { } ]); item.setCollections([collection.id]); - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -226,7 +215,7 @@ describe("Tag Selector", function () { assert.equal(getRegularTags().length, 1); item.setCollections(); - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -236,7 +225,7 @@ describe("Tag Selector", function () { it("should remove a tag when an item in a collection is moved to the trash", function* () { // Add collection - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); var collection = yield createDataObject('collection'); yield promise; @@ -248,7 +237,7 @@ describe("Tag Selector", function () { } ]); item.setCollections([collection.id]); - promise = waitForTagSelector() + promise = waitForTagSelector(win) yield item.saveTx(); yield promise; @@ -257,7 +246,7 @@ describe("Tag Selector", function () { // Move item to trash item.deleted = true; - promise = waitForTagSelector(); + promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -274,7 +263,7 @@ describe("Tag Selector", function () { tag: 'A' } ]); - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -282,7 +271,7 @@ describe("Tag Selector", function () { assert.include(getRegularTags(), "A"); // Remove tag from library - promise = waitForTagSelector(); + promise = waitForTagSelector(win); var dialogPromise = waitForDialog(); var tagSelector = doc.getElementById('zotero-tag-selector'); yield tagSelector.delete("A"); @@ -305,12 +294,12 @@ describe("Tag Selector", function () { tag: tag } ]); - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); yield item.saveTx(); yield promise; var tagSelector = doc.getElementById('zotero-tag-selector'); - promise = waitForTagSelector(); + promise = waitForTagSelector(win); var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) { dialog.document.getElementById('loginTextbox').value = newTag; dialog.document.documentElement.acceptDialog(); @@ -336,7 +325,7 @@ describe("Tag Selector", function () { tag: tag } ]); - var promise = waitForTagSelector(); + var promise = waitForTagSelector(win); yield item.saveTx(); yield promise; @@ -345,7 +334,7 @@ describe("Tag Selector", function () { assert.include(getRegularTags(), "a"); var dialogPromise = waitForDialog(false, undefined, 'chrome://zotero/content/tagColorChooser.xul'); - var tagSelectorPromise = waitForTagSelector(); + var tagSelectorPromise = waitForTagSelector(win); yield tagSelector._openColorPickerWindow(tag); yield dialogPromise; yield tagSelectorPromise;