Collection/item tree selection improvements
Wait for the pane's collectionSelected() to finish before returning from collectionTreeView select methods (e.g., selectLibrary()), and wait for previous items view to finish loading before creating a new one in collectionSelected(). This ensures that the items view has been created (though not loaded) before returning from a select. The tree can still get a bit confused switching between collections, but I think we're getting closer to fixing that. Also switch the items tree to use the same pattern. This also fixes dragging items to collections (#731).
This commit is contained in:
parent
a2d4b05064
commit
61cb01b7c2
6 changed files with 297 additions and 190 deletions
|
@ -3,27 +3,31 @@
|
|||
describe("Zotero.CollectionTreeView", function() {
|
||||
var win, collectionsView;
|
||||
|
||||
// Select library
|
||||
// TODO: Add a selectCollection() function and select a collection instead
|
||||
var resetSelection = Zotero.Promise.coroutine(function* () {
|
||||
yield collectionsView.selectLibrary(Zotero.Libraries.userLibraryID);
|
||||
yield waitForItemsLoad(win);
|
||||
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
||||
});
|
||||
|
||||
// Load Zotero pane and select library
|
||||
before(function* () {
|
||||
win = yield loadZoteroPane();
|
||||
collectionsView = win.ZoteroPane.collectionsView;
|
||||
});
|
||||
beforeEach(function () {
|
||||
return resetSelection();
|
||||
})
|
||||
after(function () {
|
||||
win.close();
|
||||
});
|
||||
|
||||
// Select library
|
||||
// TODO: Add a selectCollection() function and select a collection instead
|
||||
var resetSelection = function () {
|
||||
collectionsView.selectLibrary(Zotero.Libraries.userLibraryID);
|
||||
assert.equal(collectionsView.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
||||
}
|
||||
|
||||
describe("collapse/expand", function () {
|
||||
it("should close and open My Library repeatedly", function* () {
|
||||
var libraryID = Zotero.Libraries.userLibraryID;
|
||||
var cv = collectionsView;
|
||||
cv.selectLibrary(libraryID);
|
||||
yield cv.selectLibrary(libraryID);
|
||||
var row = cv.selection.currentIndex;
|
||||
|
||||
cv.collapseLibrary(libraryID);
|
||||
|
@ -54,8 +58,6 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
|
||||
describe("#notify()", function () {
|
||||
it("should select a new collection", function* () {
|
||||
resetSelection();
|
||||
|
||||
// Create collection
|
||||
var collection = new Zotero.Collection;
|
||||
collection.name = "Select new collection";
|
||||
|
@ -67,8 +69,6 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
});
|
||||
|
||||
it("shouldn't select a new collection if skipNotifier is passed", function* () {
|
||||
resetSelection();
|
||||
|
||||
// Create collection with skipNotifier flag
|
||||
var collection = new Zotero.Collection;
|
||||
collection.name = "No select on skipNotifier";
|
||||
|
@ -81,8 +81,6 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
});
|
||||
|
||||
it("shouldn't select a new collection if skipSelect is passed", function* () {
|
||||
resetSelection();
|
||||
|
||||
// Create collection with skipSelect flag
|
||||
var collection = new Zotero.Collection;
|
||||
collection.name = "No select on skipSelect";
|
||||
|
@ -100,7 +98,7 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
collection.name = "No select on modify";
|
||||
var id = yield collection.saveTx();
|
||||
|
||||
resetSelection();
|
||||
yield resetSelection();
|
||||
|
||||
collection.name = "No select on modify 2";
|
||||
yield collection.saveTx();
|
||||
|
@ -157,4 +155,59 @@ describe("Zotero.CollectionTreeView", function() {
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe("#drop()", function () {
|
||||
it("should add an item to a collection", function* () {
|
||||
var collection = yield createDataObject('collection', false, {
|
||||
skipSelect: true
|
||||
});
|
||||
var item = yield createDataObject('item', false, {
|
||||
skipSelect: true
|
||||
});
|
||||
var row = collectionsView.getRowByID("C" + collection.id);
|
||||
|
||||
// Add observer to wait for collection add
|
||||
var deferred = Zotero.Promise.defer();
|
||||
var observerID = Zotero.Notifier.registerObserver({
|
||||
notify: function (event, type, ids) {
|
||||
if (type == 'collection-item' && event == 'add'
|
||||
&& ids[0] == collection.id + "-" + item.id) {
|
||||
setTimeout(function () {
|
||||
deferred.resolve();
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 'collection-item', 'test');
|
||||
|
||||
// Simulate a drag and drop
|
||||
var stub = sinon.stub(Zotero.DragDrop, "getDragTarget");
|
||||
stub.returns(collectionsView.getRow(row));
|
||||
collectionsView.drop(row, 0, {
|
||||
dropEffect: 'copy',
|
||||
effectAllowed: 'copy',
|
||||
mozSourceNode: win.document.getElementById('zotero-items-tree'),
|
||||
types: {
|
||||
contains: function (type) {
|
||||
return type == 'zotero/item';
|
||||
}
|
||||
},
|
||||
getData: function (type) {
|
||||
if (type == 'zotero/item') {
|
||||
return "" + item.id;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
yield deferred.promise;
|
||||
stub.restore();
|
||||
Zotero.Notifier.unregisterObserver(observerID);
|
||||
yield collectionsView.selectCollection(collection.id);
|
||||
yield waitForItemsLoad(win);
|
||||
|
||||
var itemsView = win.ZoteroPane.itemsView
|
||||
assert.equal(itemsView.rowCount, 1);
|
||||
var treeRow = itemsView.getRow(0);
|
||||
assert.equal(treeRow.ref.id, item.id);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue