Translate and add items to library on drag

This commit is contained in:
Adomas Venčkauskas 2016-02-01 14:59:30 +00:00 committed by Dan Stillman
parent 6da0845f4b
commit 5e706c31ad
12 changed files with 190 additions and 87 deletions

View file

@ -609,72 +609,106 @@ describe("Zotero.CollectionTreeView", function() {
// TODO: Check deeper subcollection open states
})
})
it("should move a subcollection and its subcollection up under another collection", function* () {
var collectionA = yield createDataObject('collection', { name: "A" }, { skipSelect: true });
var collectionB = yield createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = yield createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = yield createDataObject('collection', { name: "D" }, { skipSelect: true });
var collectionE = yield createDataObject('collection', { name: "E" }, { skipSelect: true });
var collectionF = yield createDataObject('collection', { name: "F" }, { skipSelect: true });
var collectionG = yield createDataObject('collection', { name: "G", parentKey: collectionE.key });
var collectionH = yield createDataObject('collection', { name: "H", parentKey: collectionG.key });
var colIndexA = cv.getRowIndexByID('C' + collectionA.id);
var colIndexB = cv.getRowIndexByID('C' + collectionB.id);
var colIndexC = cv.getRowIndexByID('C' + collectionC.id);
var colIndexD = cv.getRowIndexByID('C' + collectionD.id);
var colIndexE = cv.getRowIndexByID('C' + collectionE.id);
var colIndexF = cv.getRowIndexByID('C' + collectionF.id);
var colIndexG = cv.getRowIndexByID('C' + collectionG.id);
var colIndexH = cv.getRowIndexByID('C' + collectionH.id);
yield cv.selectCollection(collectionG.id);
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
var observerID = Zotero.Notifier.registerObserver({
notify: function (event, type, ids, extraData) {
if (type == 'collection' && event == 'modify' && ids[0] == collectionG.id) {
setTimeout(function () {
deferred.resolve();
}, 50);
it("should move a subcollection and its subcollection up under another collection", function* () {
var collectionA = yield createDataObject('collection', { name: "A" }, { skipSelect: true });
var collectionB = yield createDataObject('collection', { name: "B", parentKey: collectionA.key });
var collectionC = yield createDataObject('collection', { name: "C", parentKey: collectionB.key });
var collectionD = yield createDataObject('collection', { name: "D" }, { skipSelect: true });
var collectionE = yield createDataObject('collection', { name: "E" }, { skipSelect: true });
var collectionF = yield createDataObject('collection', { name: "F" }, { skipSelect: true });
var collectionG = yield createDataObject('collection', { name: "G", parentKey: collectionE.key });
var collectionH = yield createDataObject('collection', { name: "H", parentKey: collectionG.key });
var colIndexA = cv.getRowIndexByID('C' + collectionA.id);
var colIndexB = cv.getRowIndexByID('C' + collectionB.id);
var colIndexC = cv.getRowIndexByID('C' + collectionC.id);
var colIndexD = cv.getRowIndexByID('C' + collectionD.id);
var colIndexE = cv.getRowIndexByID('C' + collectionE.id);
var colIndexF = cv.getRowIndexByID('C' + collectionF.id);
var colIndexG = cv.getRowIndexByID('C' + collectionG.id);
var colIndexH = cv.getRowIndexByID('C' + collectionH.id);
yield cv.selectCollection(collectionG.id);
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
var observerID = Zotero.Notifier.registerObserver({
notify: function (event, type, ids, extraData) {
if (type == 'collection' && event == 'modify' && ids[0] == collectionG.id) {
setTimeout(function () {
deferred.resolve();
}, 50);
}
}
}
}, 'collection', 'test');
yield Zotero.Promise.delay(2000);
yield drop(
'collection',
{
row: colIndexD,
orient: 0
},
[collectionG.id],
deferred.promise
);
Zotero.Notifier.unregisterObserver(observerID);
var newColIndexA = cv.getRowIndexByID('C' + collectionA.id);
var newColIndexB = cv.getRowIndexByID('C' + collectionB.id);
var newColIndexC = cv.getRowIndexByID('C' + collectionC.id);
var newColIndexD = cv.getRowIndexByID('C' + collectionD.id);
var newColIndexE = cv.getRowIndexByID('C' + collectionE.id);
var newColIndexF = cv.getRowIndexByID('C' + collectionF.id);
var newColIndexG = cv.getRowIndexByID('C' + collectionG.id);
var newColIndexH = cv.getRowIndexByID('C' + collectionH.id);
assert.isFalse(cv.isContainerOpen(newColIndexE));
assert.isTrue(cv.isContainerEmpty(newColIndexE));
assert.isTrue(cv.isContainerOpen(newColIndexD));
assert.isFalse(cv.isContainerEmpty(newColIndexD));
assert.equal(newColIndexD, newColIndexG - 1);
assert.equal(newColIndexG, newColIndexH - 1);
// TODO: Check deeper subcollection open states
}, 'collection', 'test');
yield Zotero.Promise.delay(2000);
yield drop(
'collection',
{
row: colIndexD,
orient: 0
},
[collectionG.id],
deferred.promise
);
Zotero.Notifier.unregisterObserver(observerID);
var newColIndexA = cv.getRowIndexByID('C' + collectionA.id);
var newColIndexB = cv.getRowIndexByID('C' + collectionB.id);
var newColIndexC = cv.getRowIndexByID('C' + collectionC.id);
var newColIndexD = cv.getRowIndexByID('C' + collectionD.id);
var newColIndexE = cv.getRowIndexByID('C' + collectionE.id);
var newColIndexF = cv.getRowIndexByID('C' + collectionF.id);
var newColIndexG = cv.getRowIndexByID('C' + collectionG.id);
var newColIndexH = cv.getRowIndexByID('C' + collectionH.id);
assert.isFalse(cv.isContainerOpen(newColIndexE));
assert.isTrue(cv.isContainerEmpty(newColIndexE));
assert.isTrue(cv.isContainerOpen(newColIndexD));
assert.isFalse(cv.isContainerEmpty(newColIndexD));
assert.equal(newColIndexD, newColIndexG - 1);
assert.equal(newColIndexG, newColIndexH - 1);
// TODO: Check deeper subcollection open states
})
})
describe("with feed items", function () {
it('should add a translated feed item recovered from an URL', function* (){
var feed = yield createFeed();
var collection = yield createDataObject('collection', false, { skipSelect: true });
var url = getTestDataItemUrl('metadata/journalArticle-single.html');
var feedItem = yield createDataObject('feedItem', {libraryID: feed.libraryID}, { skipSelect: true });
feedItem.setField('url', url);
yield feedItem.forceSaveTx();
var translateFn = sinon.spy(feedItem, 'translate');
// Add observer to wait for collection add
var deferred = Zotero.Promise.defer();
var itemIds;
var ids = (yield drop('item', 'C' + collection.id, [feedItem.id])).ids;
// Check that the translated item was the one that was created after drag
var item;
yield translateFn.returnValues[0].then(function(i) {
item = i;
assert.equal(item.id, ids[0]);
});
yield cv.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);
})
})
})
})

View file

@ -194,9 +194,7 @@ describe("Zotero.FeedItem", function () {
describe("#toggleRead()", function() {
it('should toggle state', function* () {
feed = yield createFeed();
let item = yield createDataObject('feedItem', { guid: Zotero.randomString(), libraryID: feed.id });
let item = yield createDataObject('feedItem', { libraryID });
item.isRead = false;
yield item.forceSaveTx();
@ -204,9 +202,7 @@ describe("Zotero.FeedItem", function () {
assert.isTrue(item.isRead, "item is toggled to read state");
});
it('should save if specified state is different from current', function* (){
feed = yield createFeed();
let item = yield createDataObject('feedItem', { guid: Zotero.randomString(), libraryID: feed.id });
let item = yield createDataObject('feedItem', { libraryID });
item.isRead = false;
yield item.forceSaveTx();
sinon.spy(item, 'save');
@ -220,4 +216,36 @@ describe("Zotero.FeedItem", function () {
assert.isFalse(item.save.called, "item was not saved on toggle read to same state");
});
});
describe('#translate()', function() {
before(function* () {
// Needs an open window to be able to create a hidden window for translation
yield loadBrowserWindow();
});
it('translates and saves items', function* () {
var feedItem = yield createDataObject('feedItem', {libraryID});
var url = getTestDataItemUrl('metadata/journalArticle-single.html');
feedItem.setField('url', url);
yield feedItem.forceSaveTx();
yield feedItem.translate();
assert.equal(feedItem.getField('title'), 'Scarcity or Abundance? Preserving the Past in a Digital Era');
});
it('translates and saves items to corresponding library and collection', function* () {
let group = yield createGroup();
let collection = yield createDataObject('collection', {libraryID: group.libraryID});
var feedItem = yield createDataObject('feedItem', {libraryID});
var url = getTestDataItemUrl('metadata/journalArticle-single.html');
feedItem.setField('url', url);
yield feedItem.forceSaveTx();
yield feedItem.translate(group.libraryID, collection.id);
let item = collection.getChildItems(false, false)[0];
assert.equal(item.getField('title'), 'Scarcity or Abundance? Preserving the Past in a Digital Era');
});
});
});

View file

@ -250,10 +250,10 @@ describe("Zotero.Feed", function() {
feed._feedUrl = feedUrl;
yield feed.updateFeed();
let feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
let feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573:"+feed.id);
feedItem.isRead = true;
yield feedItem.forceSaveTx();
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573:"+feed.id);
assert.isTrue(feedItem.isRead);
let oldDateModified = feedItem.dateModified;
@ -261,7 +261,7 @@ describe("Zotero.Feed", function() {
feed._feedUrl = modifiedFeedUrl;
yield feed.updateFeed();
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573:"+feed.id);
assert.notEqual(oldDateModified, feedItem.dateModified);
assert.isFalse(feedItem.isRead)