2015-05-05 06:35:04 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-30 21:06:38 +00:00
|
|
|
describe("Zotero.CollectionTreeView", function() {
|
|
|
|
var win, collectionsView;
|
|
|
|
|
|
|
|
// Load Zotero pane and select library
|
|
|
|
before(function* () {
|
|
|
|
win = yield loadZoteroPane();
|
2015-05-04 06:00:52 +00:00
|
|
|
collectionsView = win.ZoteroPane.collectionsView;
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
|
|
|
after(function () {
|
2015-05-04 06:00:52 +00:00
|
|
|
win.close();
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Select library
|
|
|
|
// TODO: Add a selectCollection() function and select a collection instead
|
2015-05-04 06:17:00 +00:00
|
|
|
var resetSelection = function () {
|
|
|
|
collectionsView.selectLibrary(Zotero.Libraries.userLibraryID);
|
2015-04-30 21:06:38 +00:00
|
|
|
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
2015-05-04 06:17:00 +00:00
|
|
|
}
|
2015-04-30 21:06:38 +00:00
|
|
|
|
2015-05-22 18:40:04 +00:00
|
|
|
describe("collapse/expand", function () {
|
|
|
|
it("should close and open My Library repeatedly", function* () {
|
|
|
|
var libraryID = Zotero.Libraries.userLibraryID;
|
|
|
|
var cv = collectionsView;
|
|
|
|
cv.selectLibrary(libraryID);
|
|
|
|
var row = cv.selection.currentIndex;
|
|
|
|
|
|
|
|
cv.collapseLibrary(libraryID);
|
|
|
|
var nextRow = cv.getRow(row + 1);
|
|
|
|
assert.equal(cv.selection.currentIndex, row);
|
|
|
|
assert.ok(nextRow.isSeparator());
|
|
|
|
assert.isFalse(cv.isContainerOpen(row));
|
|
|
|
|
|
|
|
yield cv.expandLibrary(libraryID);
|
|
|
|
nextRow = cv.getRow(row + 1);
|
|
|
|
assert.equal(cv.selection.currentIndex, row);
|
|
|
|
assert.ok(!nextRow.isSeparator());
|
|
|
|
assert.ok(cv.isContainerOpen(row));
|
|
|
|
|
|
|
|
cv.collapseLibrary(libraryID);
|
|
|
|
nextRow = cv.getRow(row + 1);
|
|
|
|
assert.equal(cv.selection.currentIndex, row);
|
|
|
|
assert.ok(nextRow.isSeparator());
|
|
|
|
assert.isFalse(cv.isContainerOpen(row));
|
|
|
|
|
|
|
|
yield cv.expandLibrary(libraryID);
|
|
|
|
nextRow = cv.getRow(row + 1);
|
|
|
|
assert.equal(cv.selection.currentIndex, row);
|
|
|
|
assert.ok(!nextRow.isSeparator());
|
|
|
|
assert.ok(cv.isContainerOpen(row));
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-04-30 21:06:38 +00:00
|
|
|
describe("#notify()", function () {
|
|
|
|
it("should select a new collection", function* () {
|
2015-05-04 06:17:00 +00:00
|
|
|
resetSelection();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// Create collection
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "Select new collection";
|
2015-05-10 08:20:47 +00:00
|
|
|
var id = yield collection.saveTx();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// New collection should be selected
|
|
|
|
var selected = collectionsView.getSelectedCollection(true);
|
|
|
|
assert.equal(selected, id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't select a new collection if skipNotifier is passed", function* () {
|
2015-05-04 06:17:00 +00:00
|
|
|
resetSelection();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// Create collection with skipNotifier flag
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "No select on skipNotifier";
|
2015-05-10 08:20:47 +00:00
|
|
|
var id = yield collection.saveTx({
|
2015-04-30 21:06:38 +00:00
|
|
|
skipNotifier: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Library should still be selected
|
|
|
|
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't select a new collection if skipSelect is passed", function* () {
|
2015-05-04 06:17:00 +00:00
|
|
|
resetSelection();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// Create collection with skipSelect flag
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "No select on skipSelect";
|
2015-05-10 08:20:47 +00:00
|
|
|
var id = yield collection.saveTx({
|
2015-04-30 21:06:38 +00:00
|
|
|
skipSelect: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Library should still be selected
|
|
|
|
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't select a modified collection", function* () {
|
|
|
|
// Create collection
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "No select on modify";
|
2015-05-10 08:20:47 +00:00
|
|
|
var id = yield collection.saveTx();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
2015-05-04 06:17:00 +00:00
|
|
|
resetSelection();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
collection.name = "No select on modify 2";
|
2015-05-10 08:20:47 +00:00
|
|
|
yield collection.saveTx();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// Modified collection should not be selected
|
|
|
|
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should reselect a selected modified collection", function* () {
|
|
|
|
// Create collection
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "Reselect on modify";
|
2015-05-10 08:20:47 +00:00
|
|
|
var id = yield collection.saveTx();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
var selected = collectionsView.getSelectedCollection(true);
|
|
|
|
assert.equal(selected, id);
|
|
|
|
|
|
|
|
collection.name = "Reselect on modify 2";
|
2015-05-10 08:20:47 +00:00
|
|
|
yield collection.saveTx();
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
// Modified collection should still be selected
|
|
|
|
selected = collectionsView.getSelectedCollection(true);
|
|
|
|
assert.equal(selected, id);
|
|
|
|
});
|
2015-05-07 22:18:48 +00:00
|
|
|
|
|
|
|
it("should add a saved search after collections", function* () {
|
|
|
|
var collection = new Zotero.Collection;
|
|
|
|
collection.name = "Test";
|
2015-05-10 08:20:47 +00:00
|
|
|
var collectionID = yield collection.saveTx();
|
2015-05-07 22:18:48 +00:00
|
|
|
var cv = win.ZoteroPane.collectionsView;
|
|
|
|
|
|
|
|
var search = new Zotero.Search;
|
|
|
|
search.name = "A Test Search";
|
|
|
|
search.addCondition('title', 'contains', 'test');
|
2015-05-10 08:20:47 +00:00
|
|
|
var searchID = yield search.saveTx();
|
2015-05-07 22:18:48 +00:00
|
|
|
|
|
|
|
var collectionRow = cv._rowMap["C" + collectionID];
|
|
|
|
var searchRow = cv._rowMap["S" + searchID];
|
|
|
|
var duplicatesRow = cv._rowMap["D" + Zotero.Libraries.userLibraryID];
|
|
|
|
var unfiledRow = cv._rowMap["U" + Zotero.Libraries.userLibraryID];
|
|
|
|
|
|
|
|
assert.isAbove(searchRow, collectionRow);
|
|
|
|
// If there's a duplicates row or an unfiled row, add before those.
|
|
|
|
// Otherwise, add before the trash
|
|
|
|
if (duplicatesRow !== undefined) {
|
|
|
|
assert.isBelow(searchRow, duplicatesRow);
|
|
|
|
}
|
|
|
|
else if (unfiledRow !== undefined) {
|
|
|
|
assert.isBelow(searchRow, unfiledRow);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var trashRow = cv._rowMap["T" + Zotero.Libraries.userLibraryID];
|
|
|
|
assert.isBelow(searchRow, trashRow);
|
|
|
|
}
|
|
|
|
})
|
2015-04-30 21:06:38 +00:00
|
|
|
})
|
|
|
|
})
|