commit 6a47d1dc446be58b6a43ec824b420f69403639de
parent 425c86ca5ead78e74badca11af38626696476d48
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 24 Apr 2016 04:28:56 -0400
Fix #962, 5.0: Add item by identifier in collection
Also adds a test for this, but lookup tests are disabled
until #699 is resolved.
Diffstat:
2 files changed, 49 insertions(+), 39 deletions(-)
diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js
@@ -31,7 +31,7 @@ var Zotero_Lookup = new function () {
/**
* Performs a lookup by DOI, PMID, or ISBN
*/
- this.accept = function(textBox) {
+ this.accept = Zotero.Promise.coroutine(function* (textBox) {
var foundIDs = []; //keep track of identifiers to avoid duplicates
var identifier = textBox.value;
//first look for DOIs
@@ -111,43 +111,39 @@ var Zotero_Lookup = new function () {
var item;
while(item = items.pop()) {
- (function(item) {
- var translate = new Zotero.Translate.Search();
- translate.setSearch(item);
+ var translate = new Zotero.Translate.Search();
+ translate.setSearch(item);
- // be lenient about translators
- translate.getTranslators().then(function(translators) {
- translate.setTranslator(translators);
+ // be lenient about translators
+ let translators = yield translate.getTranslators();
+ translate.setTranslator(translators);
- translate.setHandler("done", function(translate, success) {
- notDone--;
- successful += success;
+ translate.setHandler("done", function(translate, success) {
+ notDone--;
+ successful += success;
- if(!notDone) { //i.e. done
- Zotero_Lookup.toggleProgress(false);
- if(successful) {
- document.getElementById("zotero-lookup-panel").hidePopup();
- } else {
- Zotero.alert(
- window,
- Zotero.getString("lookup.failure.title"),
- Zotero.getString("lookup.failure.description")
- );
- }
- }
- });
+ if(!notDone) { //i.e. done
+ Zotero_Lookup.toggleProgress(false);
+ if(successful) {
+ document.getElementById("zotero-lookup-panel").hidePopup();
+ } else {
+ Zotero.alert(
+ window,
+ Zotero.getString("lookup.failure.title"),
+ Zotero.getString("lookup.failure.description")
+ );
+ }
+ }
+ });
- translate.setHandler("itemDone", function(obj, item) {
- if(collection) collection.addItem(item.id);
- });
-
- translate.translate({ libraryID });
- });
- })(item);
+ yield translate.translate({
+ libraryID,
+ collections: collection ? [collection.id] : false
+ });
}
return false;
- }
+ });
/**
* Handles a key press
diff --git a/test/tests/lookupTest.js b/test/tests/lookupTest.js
@@ -7,18 +7,17 @@ function lookupIdentifier(win, identifier) {
describe.skip("Add Item by Identifier", function() {
var win;
- before(function() {
- this.timeout(5000);
- // Load a Zotero pane and update the translators (needed to
- // make sure they're available before we run the tests)
- return loadZoteroPane().then(function(w) {
- win = w;
- });
+
+ before(function* () {
+ win = yield loadZoteroPane();
});
+
after(function() {
win.close();
});
-
+
+ // TODO: mock external services: https://github.com/zotero/zotero/issues/699
+
it("should add an ISBN-10", function() {
this.timeout(20000);
return lookupIdentifier(win, "0838985890").then(function(ids) {
@@ -26,6 +25,7 @@ describe.skip("Add Item by Identifier", function() {
assert.equal(item.getField("title"), "Zotero: a guide for librarians, researchers, and educators");
});
});
+
it("should add an ISBN-13", function() {
this.timeout(20000);
return lookupIdentifier(win, "978-0838985892").then(function(ids) {
@@ -33,6 +33,7 @@ describe.skip("Add Item by Identifier", function() {
assert.equal(item.getField("title"), "Zotero: a guide for librarians, researchers, and educators");
});
});
+
it("should add a DOI", function() {
this.timeout(10000);
return lookupIdentifier(win, "10.4103/0976-500X.85940").then(function(ids) {
@@ -40,6 +41,7 @@ describe.skip("Add Item by Identifier", function() {
assert.equal(item.getField("title"), "Zotero: A bibliographic assistant to researcher");
});
});
+
it("should add a PMID", function() {
this.timeout(10000);
return lookupIdentifier(win, "24297125").then(function(ids) {
@@ -47,4 +49,16 @@ describe.skip("Add Item by Identifier", function() {
assert.equal(item.getField("title"), "Taking control of your digital library: how modern citation managers do more than just referencing");
});
});
+
+ it("should add an item within a collection", function* () {
+ this.timeout(10000);
+
+ var col = yield createDataObject('collection');
+ yield waitForItemsLoad(win);
+
+ var ids = yield lookupIdentifier(win, "10.4103/0976-500X.85940");
+ var item = Zotero.Items.get(ids[0]);
+ assert.equal(item.getField("title"), "Zotero: A bibliographic assistant to researcher");
+ assert.isTrue(item.inCollection(col.id));
+ });
});
\ No newline at end of file