2015-05-05 06:35:04 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-30 21:06:38 +00:00
|
|
|
describe("Zotero.CollectionTreeView", function() {
|
2015-06-08 08:12:45 +00:00
|
|
|
var win, cv;
|
2015-04-30 21:06:38 +00:00
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
win = yield loadZoteroPane();
|
2015-06-08 08:12:45 +00:00
|
|
|
cv = win.ZoteroPane.collectionsView;
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
2015-05-22 23:15:21 +00:00
|
|
|
beforeEach(function () {
|
2015-05-25 02:57:46 +00:00
|
|
|
// TODO: Add a selectCollection() function and select a collection instead?
|
|
|
|
return selectLibrary(win);
|
2015-05-22 23:15:21 +00:00
|
|
|
})
|
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
|
|
|
});
|
|
|
|
|
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;
|
2015-05-22 23:15:21 +00:00
|
|
|
yield cv.selectLibrary(libraryID);
|
2015-05-22 18:40:04 +00:00
|
|
|
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-06-01 19:31:57 +00:00
|
|
|
describe("#expandToCollection()", function () {
|
|
|
|
it("should expand a collection to a subcollection", function* () {
|
|
|
|
var collection1 = yield createDataObject('collection');
|
|
|
|
var collection2 = createUnsavedDataObject('collection');
|
|
|
|
collection2.parentID = collection1.id;
|
2015-06-02 07:33:05 +00:00
|
|
|
yield collection2.saveTx({
|
2015-06-01 19:31:57 +00:00
|
|
|
skipSelect: true
|
|
|
|
});
|
|
|
|
var row = cv.getRowIndexByID("C" + collection1.id);
|
|
|
|
assert.isFalse(cv.isContainerOpen(row));
|
|
|
|
|
|
|
|
yield cv.expandToCollection(collection2.id);
|
|
|
|
|
|
|
|
// Make sure parent row position hasn't changed
|
|
|
|
assert.equal(cv.getRowIndexByID("C" + collection1.id), row);
|
|
|
|
// Parent should have been opened
|
|
|
|
assert.isTrue(cv.isContainerOpen(row));
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-05-25 05:43:07 +00:00
|
|
|
describe("#selectByID()", function () {
|
2015-05-25 02:04:40 +00:00
|
|
|
it("should select the trash", function* () {
|
2015-06-08 08:12:45 +00:00
|
|
|
yield cv.selectByID("T1");
|
|
|
|
var row = cv.selection.currentIndex;
|
|
|
|
var treeRow = cv.getRow(row);
|
2015-05-25 02:04:40 +00:00
|
|
|
assert.ok(treeRow.isTrash());
|
|
|
|
assert.equal(treeRow.ref.libraryID, Zotero.Libraries.userLibraryID);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-05-25 05:43:07 +00:00
|
|
|
describe("#selectWait()", function () {
|
|
|
|
it("shouldn't hang if row is already selected", function* () {
|
2015-06-08 08:12:45 +00:00
|
|
|
var row = cv.getRowIndexByID("T" + Zotero.Libraries.userLibraryID);
|
|
|
|
cv.selection.select(row);
|
2015-05-25 05:43:07 +00:00
|
|
|
yield Zotero.Promise.delay(50);
|
2015-06-08 08:12:45 +00:00
|
|
|
yield cv.selectWait(row);
|
2015-05-25 05:43:07 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-04-30 21:06:38 +00:00
|
|
|
describe("#notify()", function () {
|
|
|
|
it("should select a new collection", function* () {
|
|
|
|
// 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
|
2015-06-08 08:12:45 +00:00
|
|
|
var selected = cv.getSelectedCollection(true);
|
2015-04-30 21:06:38 +00:00
|
|
|
assert.equal(selected, id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't select a new collection if skipNotifier is passed", function* () {
|
|
|
|
// 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
|
2015-06-08 08:12:45 +00:00
|
|
|
assert.equal(cv.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't select a new collection if skipSelect is passed", function* () {
|
|
|
|
// 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
|
2015-06-08 08:12:45 +00:00
|
|
|
assert.equal(cv.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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-25 02:57:46 +00:00
|
|
|
yield selectLibrary(win);
|
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
|
2015-06-08 08:12:45 +00:00
|
|
|
assert.equal(cv.getSelectedLibraryID(), Zotero.Libraries.userLibraryID);
|
2015-04-30 21:06:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-06-08 08:12:45 +00:00
|
|
|
var selected = cv.getSelectedCollection(true);
|
2015-04-30 21:06:38 +00:00
|
|
|
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
|
2015-06-08 08:12:45 +00:00
|
|
|
selected = cv.getSelectedCollection(true);
|
2015-04-30 21:06:38 +00:00
|
|
|
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 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-06-08 08:04:38 +00:00
|
|
|
|
|
|
|
it("should remove a group and all children", function* () {
|
|
|
|
// Make sure Group Libraries separator and header exist already,
|
|
|
|
// since otherwise they'll interfere with the count
|
|
|
|
yield getGroup();
|
|
|
|
|
|
|
|
var originalRowCount = cv.rowCount;
|
|
|
|
|
|
|
|
var group = yield createGroup();
|
|
|
|
yield createDataObject('collection', { libraryID: group.libraryID });
|
|
|
|
var c = yield createDataObject('collection', { libraryID: group.libraryID });
|
|
|
|
yield createDataObject('collection', { libraryID: group.libraryID, parentID: c.id });
|
|
|
|
yield createDataObject('collection', { libraryID: group.libraryID });
|
|
|
|
yield createDataObject('collection', { libraryID: group.libraryID });
|
|
|
|
|
|
|
|
// Group, collections, and trash
|
|
|
|
assert.equal(cv.rowCount, originalRowCount + 7);
|
|
|
|
|
|
|
|
var spy = sinon.spy(cv, "refresh");
|
|
|
|
try {
|
|
|
|
yield group.eraseTx();
|
|
|
|
|
|
|
|
assert.equal(cv.rowCount, originalRowCount);
|
|
|
|
// Make sure the tree wasn't refreshed
|
|
|
|
sinon.assert.notCalled(spy);
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
spy.restore();
|
|
|
|
}
|
|
|
|
})
|
2015-04-30 21:06:38 +00:00
|
|
|
})
|
2015-05-22 23:15:21 +00:00
|
|
|
|
|
|
|
describe("#drop()", function () {
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
/**
|
|
|
|
* Simulate a drag and drop
|
|
|
|
*
|
|
|
|
* @param {String} targetRowID - Tree row id (e.g., "L123")
|
|
|
|
* @param {Integer[]} itemIDs
|
|
|
|
* @param {Promise} [promise] - If a promise is provided, it will be waited for and its
|
|
|
|
* value returned after the drag. Otherwise, an item 'add'
|
|
|
|
* event will be waited for, and the added ids will be
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
var drop = Zotero.Promise.coroutine(function* (targetRowID, itemIDs, promise) {
|
2015-06-08 08:12:45 +00:00
|
|
|
var row = cv.getRowIndexByID(targetRowID);
|
2015-05-22 23:15:21 +00:00
|
|
|
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
var stub = sinon.stub(Zotero.DragDrop, "getDragTarget");
|
2015-06-08 08:12:45 +00:00
|
|
|
stub.returns(cv.getRow(row));
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
if (!promise) {
|
|
|
|
promise = waitForItemEvent("add");
|
|
|
|
}
|
2015-06-08 08:12:45 +00:00
|
|
|
yield cv.drop(row, 0, {
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
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 itemIDs.join(",");
|
2015-05-22 23:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add observer to wait for add
|
|
|
|
var result = yield promise;
|
|
|
|
stub.restore();
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var canDrop = Zotero.Promise.coroutine(function* (targetRowID, itemIDs) {
|
2015-06-08 08:12:45 +00:00
|
|
|
var row = cv.getRowIndexByID(targetRowID);
|
2015-05-22 23:15:21 +00:00
|
|
|
|
|
|
|
var stub = sinon.stub(Zotero.DragDrop, "getDragTarget");
|
2015-06-08 08:12:45 +00:00
|
|
|
stub.returns(cv.getRow(row));
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
var dt = {
|
2015-05-22 23:15:21 +00:00
|
|
|
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') {
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
return itemIDs.join(",");
|
2015-05-22 23:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
};
|
2015-06-08 08:12:45 +00:00
|
|
|
var canDrop = cv.canDropCheck(row, 0, dt);
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
if (canDrop) {
|
2015-06-08 08:12:45 +00:00
|
|
|
canDrop = yield cv.canDropCheckAsync(row, 0, dt);
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
}
|
2015-05-22 23:15:21 +00:00
|
|
|
stub.restore();
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
return canDrop;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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 });
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
|
|
|
|
var ids = yield drop("C" + collection.id, [item.id], deferred.promise);
|
|
|
|
|
2015-05-22 23:15:21 +00:00
|
|
|
Zotero.Notifier.unregisterObserver(observerID);
|
2015-06-02 07:33:05 +00:00
|
|
|
|
2015-06-08 08:12:45 +00:00
|
|
|
yield cv.selectCollection(collection.id);
|
2015-05-22 23:15:21 +00:00
|
|
|
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);
|
|
|
|
})
|
2015-05-24 01:10:07 +00:00
|
|
|
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
it("should copy an item with an attachment to a group", function* () {
|
2015-06-02 07:33:05 +00:00
|
|
|
var group = yield createGroup();
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
|
|
|
|
var item = yield createDataObject('item', false, { skipSelect: true });
|
2015-05-24 01:10:07 +00:00
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
var attachment = yield Zotero.Attachments.importFromFile({
|
2015-05-24 01:10:07 +00:00
|
|
|
file: file,
|
|
|
|
parentItemID: item.id
|
|
|
|
});
|
|
|
|
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
// Hack to unload relations to test proper loading
|
|
|
|
//
|
|
|
|
// Probably need a better method for this
|
|
|
|
item._loaded.relations = false;
|
|
|
|
attachment._loaded.relations = false;
|
2015-05-24 01:10:07 +00:00
|
|
|
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
var ids = yield drop("L" + group.libraryID, [item.id]);
|
2015-05-24 01:10:07 +00:00
|
|
|
|
2015-06-08 08:12:45 +00:00
|
|
|
yield cv.selectLibrary(group.libraryID);
|
2015-05-24 01:10:07 +00:00
|
|
|
yield waitForItemsLoad(win);
|
|
|
|
|
2015-06-02 07:33:05 +00:00
|
|
|
// Check parent
|
|
|
|
var itemsView = win.ZoteroPane.itemsView;
|
2015-05-24 01:10:07 +00:00
|
|
|
assert.equal(itemsView.rowCount, 1);
|
|
|
|
var treeRow = itemsView.getRow(0);
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
assert.equal(treeRow.ref.libraryID, group.libraryID);
|
2015-05-24 01:10:07 +00:00
|
|
|
assert.equal(treeRow.ref.id, ids[0]);
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
// New item should link back to original
|
|
|
|
var linked = yield item.getLinkedItem(group.libraryID);
|
|
|
|
assert.equal(linked.id, treeRow.ref.id);
|
2015-06-02 07:33:05 +00:00
|
|
|
|
|
|
|
// Check attachment
|
|
|
|
assert.isTrue(itemsView.isContainer(0));
|
|
|
|
yield itemsView.toggleOpenState(0);
|
|
|
|
assert.equal(itemsView.rowCount, 2);
|
|
|
|
treeRow = itemsView.getRow(1);
|
|
|
|
assert.equal(treeRow.ref.id, ids[1]);
|
|
|
|
// New attachment should link back to original
|
|
|
|
linked = yield attachment.getLinkedItem(group.libraryID);
|
|
|
|
assert.equal(linked.id, treeRow.ref.id);
|
|
|
|
|
2015-06-07 19:40:04 +00:00
|
|
|
yield Zotero.DB.executeTransaction(function* () {
|
|
|
|
return group.erase();
|
|
|
|
})
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should not copy an item or its attachment to a group twice", function* () {
|
|
|
|
var group = yield getGroup();
|
|
|
|
|
|
|
|
var itemTitle = Zotero.Utilities.randomString();
|
|
|
|
var item = yield createDataObject('item', false, { skipSelect: true });
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var attachment = yield Zotero.Attachments.importFromFile({
|
|
|
|
file: file,
|
|
|
|
parentItemID: item.id
|
|
|
|
});
|
|
|
|
var attachmentTitle = Zotero.Utilities.randomString();
|
|
|
|
attachment.setField('title', attachmentTitle);
|
2015-06-02 07:33:05 +00:00
|
|
|
yield attachment.saveTx();
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
|
|
|
|
var ids = yield drop("L" + group.libraryID, [item.id]);
|
|
|
|
assert.isFalse(yield canDrop("L" + group.libraryID, [item.id]));
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should remove a linked, trashed item in a group from the trash and collections", function* () {
|
|
|
|
var group = yield getGroup();
|
|
|
|
var collection = yield createDataObject('collection', { libraryID: group.libraryID });
|
|
|
|
|
|
|
|
var item = yield createDataObject('item', false, { skipSelect: true });
|
|
|
|
var ids = yield drop("L" + group.libraryID, [item.id]);
|
|
|
|
|
|
|
|
var droppedItem = yield item.getLinkedItem(group.libraryID);
|
|
|
|
droppedItem.setCollections([collection.id]);
|
|
|
|
droppedItem.deleted = true;
|
2015-06-02 07:33:05 +00:00
|
|
|
yield droppedItem.saveTx();
|
Relations overhaul (requires new DB upgrade from 4.0)
Relations are now properties of collections and items rather than
first-class objects, stored in separate collectionRelations and
itemRelations tables with ids for subjects, with foreign keys to the
associated data objects.
Related items now use dc:relation relations rather than a separate table
(among other reasons, because API syncing won't necessarily sync both
items at the same time, so they can't be stored by id).
The UI assigns related-item relations bidirectionally, and checks for
related-item and linked-object relations are done unidirectionally by
default.
dc:isReplacedBy is now dc:replaces, so that the subject is an existing
object, and the predicate is now named
Zotero.Attachments.replacedItemPredicate.
Some additional work is still needed, notably around following
replaced-item relations, and migration needs to be tested more fully,
but this seems to mostly work.
2015-06-02 00:09:39 +00:00
|
|
|
|
|
|
|
// Add observer to wait for collection add
|
|
|
|
var deferred = Zotero.Promise.defer();
|
|
|
|
var observerID = Zotero.Notifier.registerObserver({
|
|
|
|
notify: function (event, type, ids) {
|
|
|
|
if (event == 'refresh' && type == 'trash' && ids[0] == group.libraryID) {
|
|
|
|
setTimeout(function () {
|
|
|
|
deferred.resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'trash', 'test');
|
|
|
|
var ids = yield drop("L" + group.libraryID, [item.id], deferred.promise);
|
|
|
|
Zotero.Notifier.unregisterObserver(observerID);
|
|
|
|
|
|
|
|
assert.isFalse(droppedItem.deleted);
|
|
|
|
// Should be removed from collections when removed from trash
|
|
|
|
assert.lengthOf(droppedItem.getCollections(), 0);
|
2015-05-24 01:10:07 +00:00
|
|
|
})
|
2015-05-22 23:15:21 +00:00
|
|
|
})
|
2015-04-30 21:06:38 +00:00
|
|
|
})
|