2016-03-11 12:37:48 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Duplicate Items", function () {
|
|
|
|
var win, zp, cv;
|
|
|
|
|
2016-04-24 06:44:21 +00:00
|
|
|
before(function* () {
|
|
|
|
yield resetDB({
|
|
|
|
thisArg: this,
|
|
|
|
skipBundledFiles: true
|
|
|
|
});
|
2016-06-11 08:50:04 +00:00
|
|
|
|
2016-03-11 12:37:48 +00:00
|
|
|
Zotero.Prefs.clear('duplicateLibraries');
|
|
|
|
win = yield loadZoteroPane();
|
|
|
|
zp = win.ZoteroPane;
|
|
|
|
cv = zp.collectionsView;
|
2016-06-11 08:50:04 +00:00
|
|
|
});
|
|
|
|
beforeEach(function* () {
|
2016-03-11 12:37:48 +00:00
|
|
|
return selectLibrary(win);
|
|
|
|
})
|
|
|
|
after(function () {
|
2016-06-11 08:50:04 +00:00
|
|
|
win.close();
|
2016-03-11 12:37:48 +00:00
|
|
|
});
|
2022-03-09 22:26:26 +00:00
|
|
|
|
|
|
|
async function merge(itemID) {
|
|
|
|
var userLibraryID = Zotero.Libraries.userLibraryID;
|
|
|
|
|
|
|
|
var selected = await cv.selectByID('D' + userLibraryID);
|
|
|
|
assert.ok(selected);
|
|
|
|
await waitForItemsLoad(win);
|
|
|
|
|
|
|
|
// Select the first item, which should select both
|
|
|
|
var iv = zp.itemsView;
|
|
|
|
var row = iv.getRowIndexByID(itemID);
|
|
|
|
var promise = iv.waitForSelect();
|
|
|
|
clickOnItemsRow(win, iv, row);
|
|
|
|
await promise;
|
|
|
|
|
|
|
|
// Click merge button
|
|
|
|
var button = win.document.getElementById('zotero-duplicates-merge-button');
|
|
|
|
button.click();
|
|
|
|
|
|
|
|
await waitForNotifierEvent('refresh', 'trash');
|
|
|
|
}
|
2016-03-11 12:37:48 +00:00
|
|
|
|
|
|
|
describe("Merging", function () {
|
|
|
|
it("should merge two items in duplicates view", function* () {
|
|
|
|
var item1 = yield createDataObject('item', { setTitle: true });
|
|
|
|
var item2 = item1.clone();
|
|
|
|
yield item2.saveTx();
|
|
|
|
var uri2 = Zotero.URI.getItemURI(item2);
|
|
|
|
|
2022-03-09 22:26:26 +00:00
|
|
|
yield merge(item1.id);
|
2016-03-11 12:37:48 +00:00
|
|
|
|
|
|
|
// Items should be gone
|
2022-03-09 22:26:26 +00:00
|
|
|
var iv = zp.itemsView;
|
2016-03-11 12:37:48 +00:00
|
|
|
assert.isFalse(iv.getRowIndexByID(item1.id));
|
|
|
|
assert.isFalse(iv.getRowIndexByID(item2.id));
|
|
|
|
assert.isTrue(item2.deleted);
|
|
|
|
var rels = item1.getRelations();
|
|
|
|
var pred = Zotero.Relations.replacedItemPredicate;
|
|
|
|
assert.property(rels, pred);
|
|
|
|
assert.equal(rels[pred], uri2);
|
|
|
|
});
|
2016-06-11 03:26:32 +00:00
|
|
|
|
|
|
|
it("should combine collections from all items", function* () {
|
|
|
|
var collection1 = yield createDataObject('collection');
|
|
|
|
var collection2 = yield createDataObject('collection');
|
|
|
|
|
|
|
|
var item1 = yield createDataObject('item', { setTitle: true, collections: [collection1.id] });
|
|
|
|
var item2 = item1.clone();
|
|
|
|
item2.setCollections([collection2.id]);
|
|
|
|
yield item2.saveTx();
|
2022-03-09 22:26:26 +00:00
|
|
|
|
|
|
|
yield merge(item1.id);
|
2016-06-11 03:26:32 +00:00
|
|
|
|
|
|
|
// Items should be gone
|
2022-03-09 22:26:26 +00:00
|
|
|
var iv = zp.itemsView;
|
2016-06-11 03:26:32 +00:00
|
|
|
assert.isFalse(iv.getRowIndexByID(item1.id));
|
|
|
|
assert.isFalse(iv.getRowIndexByID(item2.id));
|
|
|
|
assert.isTrue(item2.deleted);
|
|
|
|
assert.isTrue(collection1.hasItem(item1.id));
|
|
|
|
assert.isTrue(collection2.hasItem(item1.id));
|
|
|
|
});
|
2016-03-11 12:37:48 +00:00
|
|
|
});
|
|
|
|
});
|