Fix old-style 'collection' condition for My Library in saved searches

This commit is contained in:
Dan Stillman 2017-02-18 14:19:30 -05:00
parent 07ea9dae84
commit bb0fa73899
2 changed files with 28 additions and 0 deletions

View file

@ -1153,6 +1153,9 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
// Old-style library-key hash
if (objKey.indexOf('_') != -1) {
[objLibraryID, objKey] = objKey.split('_');
if (objLibraryID === "0") {
objLibraryID = Zotero.Libraries.userLibraryID;
}
}
// libraryID assigned on search
else if (this.libraryID !== null) {

View file

@ -135,6 +135,17 @@ describe("Zotero.Search", function() {
assert.sameMembers(matches, [item.id]);
});
it("should find item in collection in old-style format", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [col.id] });
var s = new Zotero.Search();
s.libraryID = item.libraryID;
s.addCondition('collection', 'is', "0_" + col.key);
var matches = yield s.search();
assert.sameMembers(matches, [item.id]);
});
it("should find items not in collection", function* () {
var col = yield createDataObject('collection');
var item = yield createDataObject('item', { collections: [col.id] });
@ -169,6 +180,20 @@ describe("Zotero.Search", function() {
var matches = yield s.search();
assert.sameMembers(matches, [item.id]);
});
it("should find item in subcollection in recursive mode with old-style key", function* () {
var col1 = yield createDataObject('collection');
var col2 = yield createDataObject('collection', { parentID: col1.id });
var item = yield createDataObject('item', { collections: [col2.id] });
var s = new Zotero.Search();
s.libraryID = item.libraryID;
s.addCondition('collection', 'is', "0_" + col1.key);
s.addCondition('recursive', 'true');
var matches = yield s.search();
assert.sameMembers(matches, [item.id]);
});
});
describe("fileTypeID", function () {