ff7919553c
Get rid of data_access.js, at long last. Existing calls to Zotero.getCollections() will need to be replaced with Zotero.Collections.getByLibrary() or .getByParent(). Also removes Zotero.Collection::getCollections(), which is redundant with Zotero.Collections.getByLibrary(), and Zotero.Collections.add(). The latter didn't didn't include a libraryID anyway, so code might as well just use 'new Zotero.Collection' instead.
48 lines
2.3 KiB
JavaScript
48 lines
2.3 KiB
JavaScript
describe("Zotero.Collections", function () {
|
|
describe("#getByLibrary()", function () {
|
|
it("should get all root collections in a library", function* () {
|
|
var col1 = yield createDataObject('collection');
|
|
var col2 = yield createDataObject('collection');
|
|
var col3 = yield createDataObject('collection', { parentID: col2.id });
|
|
var cols = yield Zotero.Collections.getByLibrary(Zotero.Libraries.userLibraryID);
|
|
assert.isAbove(cols.length, 1);
|
|
assert.includeMembers(cols.map(col => col.id), [col1.id, col2.id]);
|
|
assert.ok(cols.every(col =>
|
|
col.libraryID == Zotero.Libraries.userLibraryID && !col.parentID
|
|
));
|
|
})
|
|
|
|
it("should get all collections in a library in recursive mode", function* () {
|
|
var col1 = yield createDataObject('collection');
|
|
var col2 = yield createDataObject('collection');
|
|
var col3 = yield createDataObject('collection', { parentID: col2.id });
|
|
var cols = yield Zotero.Collections.getByLibrary(Zotero.Libraries.userLibraryID, true);
|
|
assert.isAbove(cols.length, 2);
|
|
assert.includeMembers(cols.map(col => col.id), [col1.id, col2.id, col3.id]);
|
|
assert.ok(cols.every(col => col.libraryID == Zotero.Libraries.userLibraryID));
|
|
})
|
|
})
|
|
|
|
describe("#getByParent()", function () {
|
|
it("should get all direct subcollections of a library", function* () {
|
|
var col1 = yield createDataObject('collection');
|
|
var col2 = yield createDataObject('collection');
|
|
var col3 = yield createDataObject('collection', { parentID: col2.id });
|
|
assert.lengthOf((yield Zotero.Collections.getByParent(col1.id)), 0);
|
|
var cols = yield Zotero.Collections.getByParent(col2.id);
|
|
assert.lengthOf(cols, 1);
|
|
assert.sameMembers(cols.map(col => col.id), [col3.id]);
|
|
})
|
|
|
|
it("should get all collections underneath a collection in recursive mode", function* () {
|
|
var col1 = yield createDataObject('collection');
|
|
var col2 = yield createDataObject('collection');
|
|
var col3 = yield createDataObject('collection', { parentID: col2.id });
|
|
var col4 = yield createDataObject('collection', { parentID: col3.id });
|
|
assert.lengthOf((yield Zotero.Collections.getByParent(col1.id)), 0);
|
|
var cols = yield Zotero.Collections.getByParent(col2.id, true);
|
|
assert.lengthOf(cols, 2);
|
|
assert.includeMembers(cols.map(col => col.id), [col3.id, col4.id]);
|
|
})
|
|
})
|
|
})
|