commit a64282118bfbe2a03d3c13ba0324bf558b3334ce
parent 84ff141eddb3501078e6edcbd662aa5131f28235
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 8 May 2015 16:01:25 -0400
Fix items-count updating in right-hand pane
And some other tweaks to ZoteroPane.itemSelected()
Diffstat:
3 files changed, 72 insertions(+), 15 deletions(-)
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -1226,10 +1226,14 @@ var ZoteroPane = new function()
/**
- * @return {Promise}
+ * @return {Promise<Boolean>} - Promise that resolves to true if an item was selected,
+ * or false if not (used for tests, though there could possibly
+ * be a better test for whether the item pane changed)
*/
this.itemSelected = function (event) {
return Zotero.spawn(function* () {
+ yield Zotero.DB.waitForTransaction();
+
var selectedItems = this.itemsView.getSelectedItems();
// Check if selection has actually changed. The onselect event that calls this
@@ -1237,13 +1241,11 @@ var ZoteroPane = new function()
// such as whenever selectEventsSuppressed is set to false.
var ids = selectedItems.map(item => item.id);
ids.sort();
- if (Zotero.Utilities.arrayEquals(_lastSelectedItems, ids)) {
+ if (ids.length && Zotero.Utilities.arrayEquals(_lastSelectedItems, ids)) {
return false;
}
_lastSelectedItems = ids;
- yield Zotero.DB.waitForTransaction();
-
if (!this.itemsView) {
Zotero.debug("Items view not available in itemSelected", 2);
return false;
@@ -1405,6 +1407,8 @@ var ZoteroPane = new function()
}
this.setItemPaneMessage(msg);
+
+ return false;
}
}
@@ -1424,7 +1428,7 @@ var ZoteroPane = new function()
}
throw e;
}.bind(this));
- };
+ }
/**
diff --git a/test/content/support.js b/test/content/support.js
@@ -48,16 +48,7 @@ var loadZoteroPane = Zotero.Promise.coroutine(function* () {
// there or it should be good enough here.
yield Zotero.Promise.delay(52);
- var zp = win.ZoteroPane;
- var cv = zp.collectionsView;
- var resolve1, resolve2;
- var promise1 = new Zotero.Promise(() => resolve1 = arguments[0]);
- var promise2 = new Zotero.Promise(() => resolve2 = arguments[0]);
- cv.addEventListener('load', () => resolve1())
- yield promise1;
- cv.selection.select(0);
- zp.addEventListener('itemsLoaded', () => resolve2());
- yield promise2;
+ yield waitForItemsLoad(win, 0);
return win;
});
@@ -85,6 +76,22 @@ function waitForWindow(uri) {
return deferred.promise;
}
+var waitForItemsLoad = function (win, collectionRowToSelect) {
+ var resolve;
+ var promise = new Zotero.Promise(() => resolve = arguments[0]);
+ var zp = win.ZoteroPane;
+ var cv = zp.collectionsView;
+ cv.addEventListener('load', function () {
+ if (collectionRowToSelect !== undefined) {
+ cv.selection.select(collectionRowToSelect);
+ }
+ zp.addEventListener('itemsLoaded', function () {
+ resolve();
+ });
+ });
+ return promise;
+}
+
/**
* Waits for a single item event. Returns a promise for the item ID(s).
*/
diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js
@@ -34,4 +34,50 @@ describe("ZoteroPane", function() {
assert.equal(item.getField('title'), value);
})
});
+
+ describe("#itemSelected()", function () {
+ it("should update the item count", function* () {
+ var collection = new Zotero.Collection;
+ collection.name = "Count Test";
+ var id = yield collection.save();
+ yield waitForItemsLoad(win);
+
+ // Unselected, with no items in view
+ assert.equal(
+ doc.getElementById('zotero-item-pane-message').value,
+ Zotero.getString('pane.item.unselected.zero', 0)
+ );
+
+ // Unselected, with one item in view
+ var item = new Zotero.Item('newspaperArticle');
+ item.setCollections([id]);
+ var itemID1 = yield item.save({
+ skipSelect: true
+ });
+ assert.equal(
+ doc.getElementById('zotero-item-pane-message').value,
+ Zotero.getString('pane.item.unselected.singular', 1)
+ );
+
+ // Unselected, with multiple items in view
+ var item = new Zotero.Item('audioRecording');
+ item.setCollections([id]);
+ var itemID2 = yield item.save({
+ skipSelect: true
+ });
+ assert.equal(
+ doc.getElementById('zotero-item-pane-message').value,
+ Zotero.getString('pane.item.unselected.plural', 2)
+ );
+
+ // Multiple items selected
+ var promise = zp.itemsView._getItemSelectedPromise();
+ zp.itemsView.rememberSelection([itemID1, itemID2]);
+ yield promise;
+ assert.equal(
+ doc.getElementById('zotero-item-pane-message').value,
+ Zotero.getString('pane.item.selected.multiple', 2)
+ );
+ })
+ })
})