Move waitForTagSelector() into support.js
This commit is contained in:
parent
f4eb8ed3bb
commit
1a4b7121d3
2 changed files with 37 additions and 31 deletions
|
@ -201,6 +201,23 @@ var waitForItemsLoad = Zotero.Promise.coroutine(function* (win, collectionRowToS
|
||||||
return deferred.promise;
|
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).
|
* Waits for a single item event. Returns a promise for the item ID(s).
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -53,23 +53,12 @@ describe("Tag Selector", function () {
|
||||||
win.close();
|
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 () {
|
describe("#notify()", function () {
|
||||||
it("should add a tag when added to an item in the library root", function* () {
|
it("should add a tag when added to an item in the library root", function* () {
|
||||||
var promise, tagSelector;
|
var promise, tagSelector;
|
||||||
|
|
||||||
if (collectionsView.selection.currentIndex != 0) {
|
if (collectionsView.selection.currentIndex != 0) {
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield collectionsView.selectLibrary();
|
yield collectionsView.selectLibrary();
|
||||||
yield promise;
|
yield promise;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +74,7 @@ describe("Tag Selector", function () {
|
||||||
type: 1
|
type: 1
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -97,7 +86,7 @@ describe("Tag Selector", function () {
|
||||||
var promise, tagSelector;
|
var promise, tagSelector;
|
||||||
|
|
||||||
// Add collection
|
// Add collection
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
var collection = yield createDataObject('collection');
|
var collection = yield createDataObject('collection');
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -112,7 +101,7 @@ describe("Tag Selector", function () {
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
item.setCollections([collection.id]);
|
item.setCollections([collection.id]);
|
||||||
promise = waitForTagSelector()
|
promise = waitForTagSelector(win)
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -124,7 +113,7 @@ describe("Tag Selector", function () {
|
||||||
var promise, tagSelector;
|
var promise, tagSelector;
|
||||||
|
|
||||||
// Add collection
|
// Add collection
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
var collection = yield createDataObject('collection');
|
var collection = yield createDataObject('collection');
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -138,7 +127,7 @@ describe("Tag Selector", function () {
|
||||||
tag: 'C'
|
tag: 'C'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
promise = waitForTagSelector()
|
promise = waitForTagSelector(win)
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -146,7 +135,7 @@ describe("Tag Selector", function () {
|
||||||
assert.equal(getRegularTags().length, 0);
|
assert.equal(getRegularTags().length, 0);
|
||||||
|
|
||||||
item.setCollections([collection.id]);
|
item.setCollections([collection.id]);
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -188,7 +177,7 @@ describe("Tag Selector", function () {
|
||||||
tag: "A"
|
tag: "A"
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -206,7 +195,7 @@ describe("Tag Selector", function () {
|
||||||
|
|
||||||
it("should remove a tag when an item is removed from a collection", function* () {
|
it("should remove a tag when an item is removed from a collection", function* () {
|
||||||
// Add collection
|
// Add collection
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
var collection = yield createDataObject('collection');
|
var collection = yield createDataObject('collection');
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -218,7 +207,7 @@ describe("Tag Selector", function () {
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
item.setCollections([collection.id]);
|
item.setCollections([collection.id]);
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -226,7 +215,7 @@ describe("Tag Selector", function () {
|
||||||
assert.equal(getRegularTags().length, 1);
|
assert.equal(getRegularTags().length, 1);
|
||||||
|
|
||||||
item.setCollections();
|
item.setCollections();
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
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* () {
|
it("should remove a tag when an item in a collection is moved to the trash", function* () {
|
||||||
// Add collection
|
// Add collection
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
var collection = yield createDataObject('collection');
|
var collection = yield createDataObject('collection');
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -248,7 +237,7 @@ describe("Tag Selector", function () {
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
item.setCollections([collection.id]);
|
item.setCollections([collection.id]);
|
||||||
promise = waitForTagSelector()
|
promise = waitForTagSelector(win)
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -257,7 +246,7 @@ describe("Tag Selector", function () {
|
||||||
|
|
||||||
// Move item to trash
|
// Move item to trash
|
||||||
item.deleted = true;
|
item.deleted = true;
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -274,7 +263,7 @@ describe("Tag Selector", function () {
|
||||||
tag: 'A'
|
tag: 'A'
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -282,7 +271,7 @@ describe("Tag Selector", function () {
|
||||||
assert.include(getRegularTags(), "A");
|
assert.include(getRegularTags(), "A");
|
||||||
|
|
||||||
// Remove tag from library
|
// Remove tag from library
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
var dialogPromise = waitForDialog();
|
var dialogPromise = waitForDialog();
|
||||||
var tagSelector = doc.getElementById('zotero-tag-selector');
|
var tagSelector = doc.getElementById('zotero-tag-selector');
|
||||||
yield tagSelector.delete("A");
|
yield tagSelector.delete("A");
|
||||||
|
@ -305,12 +294,12 @@ describe("Tag Selector", function () {
|
||||||
tag: tag
|
tag: tag
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
var tagSelector = doc.getElementById('zotero-tag-selector');
|
var tagSelector = doc.getElementById('zotero-tag-selector');
|
||||||
promise = waitForTagSelector();
|
promise = waitForTagSelector(win);
|
||||||
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
|
var promptPromise = waitForWindow("chrome://global/content/commonDialog.xul", function (dialog) {
|
||||||
dialog.document.getElementById('loginTextbox').value = newTag;
|
dialog.document.getElementById('loginTextbox').value = newTag;
|
||||||
dialog.document.documentElement.acceptDialog();
|
dialog.document.documentElement.acceptDialog();
|
||||||
|
@ -336,7 +325,7 @@ describe("Tag Selector", function () {
|
||||||
tag: tag
|
tag: tag
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
var promise = waitForTagSelector();
|
var promise = waitForTagSelector(win);
|
||||||
yield item.saveTx();
|
yield item.saveTx();
|
||||||
yield promise;
|
yield promise;
|
||||||
|
|
||||||
|
@ -345,7 +334,7 @@ describe("Tag Selector", function () {
|
||||||
assert.include(getRegularTags(), "a");
|
assert.include(getRegularTags(), "a");
|
||||||
|
|
||||||
var dialogPromise = waitForDialog(false, undefined, 'chrome://zotero/content/tagColorChooser.xul');
|
var dialogPromise = waitForDialog(false, undefined, 'chrome://zotero/content/tagColorChooser.xul');
|
||||||
var tagSelectorPromise = waitForTagSelector();
|
var tagSelectorPromise = waitForTagSelector(win);
|
||||||
yield tagSelector._openColorPickerWindow(tag);
|
yield tagSelector._openColorPickerWindow(tag);
|
||||||
yield dialogPromise;
|
yield dialogPromise;
|
||||||
yield tagSelectorPromise;
|
yield tagSelectorPromise;
|
||||||
|
|
Loading…
Reference in a new issue