Restore related-items tests for Zotero.Translate.ItemGetter
This commit is contained in:
parent
1777fd16f0
commit
d80aa97ebd
1 changed files with 82 additions and 65 deletions
|
@ -1072,67 +1072,73 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
assert.equal(translatorItem.collections.length, 1, 'item in a single nested collection lists one collection');
|
||||
assert.equal(translatorItem.collections[0], collections[2].key, 'item in a single collection identifies correct collection');
|
||||
}));
|
||||
// it('should return item relations in expected format', Zotero.Promise.coroutine(function* () {
|
||||
// let getter = new Zotero.Translate.ItemGetter();
|
||||
// let items;
|
||||
|
||||
// yield Zotero.DB.executeTransaction(function* () {
|
||||
// items = [
|
||||
// new Zotero.Item('journalArticle'), // Item with no relations
|
||||
it('should return item relations in expected format', Zotero.Promise.coroutine(function* () {
|
||||
let getter = new Zotero.Translate.ItemGetter();
|
||||
let items;
|
||||
|
||||
// new Zotero.Item('journalArticle'), // Relation set on this item
|
||||
// new Zotero.Item('journalArticle'), // To this item
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
items = [
|
||||
new Zotero.Item('journalArticle'), // Item with no relations
|
||||
|
||||
// new Zotero.Item('journalArticle'), // This item is related to two items below
|
||||
// new Zotero.Item('journalArticle'), // But this item is not related to the item below
|
||||
// new Zotero.Item('journalArticle')
|
||||
// ];
|
||||
// yield Zotero.Promise.all(items.map(item => item.save()));
|
||||
new Zotero.Item('journalArticle'), // Bidirectional relations
|
||||
new Zotero.Item('journalArticle'), // between these items
|
||||
|
||||
// yield items[1].addRelatedItem(items[2].id);
|
||||
new Zotero.Item('journalArticle'), // This item is related to two items below
|
||||
new Zotero.Item('journalArticle'), // But this item is not related to the item below
|
||||
new Zotero.Item('journalArticle')
|
||||
];
|
||||
yield Zotero.Promise.all(items.map(item => item.save()));
|
||||
|
||||
// yield items[3].addRelatedItem(items[4].id);
|
||||
// yield items[3].addRelatedItem(items[5].id);
|
||||
// });
|
||||
yield items[1].addRelatedItem(items[2]);
|
||||
yield items[2].addRelatedItem(items[1]);
|
||||
|
||||
// getter._itemsLeft = items.slice();
|
||||
yield items[3].addRelatedItem(items[4]);
|
||||
yield items[4].addRelatedItem(items[3]);
|
||||
yield items[3].addRelatedItem(items[5]);
|
||||
yield items[5].addRelatedItem(items[3]);
|
||||
});
|
||||
|
||||
// let translatorItem = getter.nextItem();
|
||||
// assert.isObject(translatorItem.relations, 'item with no relations has a relations object');
|
||||
// assert.equal(Object.keys(translatorItem.relations).length, 0, 'item with no relations does not list any relations');
|
||||
getter._itemsLeft = items.slice();
|
||||
|
||||
// translatorItem = getter.nextItem();
|
||||
// assert.isObject(translatorItem.relations, 'item that is the subject of a single relation has a relations object');
|
||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of a single relation list one relations predicate');
|
||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation uses "dc:relation" as the predicate');
|
||||
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation lists "dc:relation" object as a string');
|
||||
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[2]), 'item that is the subject of a single relation identifies correct object URI');
|
||||
let translatorItem = getter.nextItem();
|
||||
assert.isObject(translatorItem.relations, 'item with no relations has a relations object');
|
||||
assert.equal(Object.keys(translatorItem.relations).length, 0, 'item with no relations does not list any relations');
|
||||
|
||||
// translatorItem = getter.nextItem();
|
||||
// assert.isObject(translatorItem.relations, 'item that is the object of a single relation has a relations object');
|
||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of a single relation list one relations predicate');
|
||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of a single relation uses "dc:relation" as the predicate');
|
||||
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the object of a single relation lists "dc:relation" object as a string');
|
||||
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[1]), 'item that is the object of a single relation identifies correct subject URI');
|
||||
translatorItem = getter.nextItem();
|
||||
|
||||
// translatorItem = getter.nextItem();
|
||||
// assert.isObject(translatorItem.relations, 'item that is the subject of two relations has a relations object');
|
||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of two relations list one relations predicate');
|
||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of two relations uses "dc:relation" as the predicate');
|
||||
// assert.isArray(translatorItem.relations['dc:relation'], 'item that is the subject of two relations lists "dc:relation" object as an array');
|
||||
// assert.equal(translatorItem.relations['dc:relation'].length, 2, 'item that is the subject of two relations lists two relations in the "dc:relation" array');
|
||||
// assert.deepEqual(translatorItem.relations['dc:relation'].sort(),
|
||||
// [Zotero.URI.getItemURI(items[4]), Zotero.URI.getItemURI(items[5])].sort(),
|
||||
// 'item that is the subject of two relations identifies correct object URIs'
|
||||
// );
|
||||
assert.isObject(translatorItem.relations, 'item that is the subject of a single relation has a relations object');
|
||||
assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of a single relation lists one relations predicate');
|
||||
assert.lengthOf(translatorItem.relations['dc:relation'], 1, 'item that is the subject of a single relation lists one "dc:relation" object');
|
||||
assert.equal(translatorItem.relations['dc:relation'][0], Zotero.URI.getItemURI(items[2]), 'item that is the subject of a single relation identifies correct object URI');
|
||||
|
||||
// We currently assign these bidirectionally above, so this is a bit redundant
|
||||
translatorItem = getter.nextItem();
|
||||
assert.isObject(translatorItem.relations, 'item that is the object of a single relation has a relations object');
|
||||
assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of a single relation list one relations predicate');
|
||||
assert.lengthOf(translatorItem.relations['dc:relation'], 1, 'item that is the object of a single relation lists one "dc:relation" object');
|
||||
assert.equal(translatorItem.relations['dc:relation'][0], Zotero.URI.getItemURI(items[1]), 'item that is the object of a single relation identifies correct subject URI');
|
||||
|
||||
translatorItem = getter.nextItem();
|
||||
assert.isObject(translatorItem.relations, 'item that is the subject of two relations has a relations object');
|
||||
assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of two relations list one relations predicate');
|
||||
assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of two relations uses "dc:relation" as the predicate');
|
||||
assert.isArray(translatorItem.relations['dc:relation'], 'item that is the subject of two relations lists "dc:relation" object as an array');
|
||||
assert.equal(translatorItem.relations['dc:relation'].length, 2, 'item that is the subject of two relations lists two relations in the "dc:relation" array');
|
||||
assert.deepEqual(
|
||||
translatorItem.relations['dc:relation'].sort(),
|
||||
[Zotero.URI.getItemURI(items[4]), Zotero.URI.getItemURI(items[5])].sort(),
|
||||
'item that is the subject of two relations identifies correct object URIs'
|
||||
);
|
||||
|
||||
translatorItem = getter.nextItem();
|
||||
assert.isObject(translatorItem.relations, 'item that is the object of one relation from item with two relations has a relations object');
|
||||
assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of one relation from item with two relations list one relations predicate');
|
||||
assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of one relation from item with two relations uses "dc:relation" as the predicate');
|
||||
assert.lengthOf(translatorItem.relations['dc:relation'], 1, 'item that is the object of one relation from item with two relations lists one "dc:relation" object');
|
||||
assert.equal(translatorItem.relations['dc:relation'][0], Zotero.URI.getItemURI(items[3]), 'item that is the object of one relation from item with two relations identifies correct subject URI');
|
||||
}));
|
||||
|
||||
// translatorItem = getter.nextItem();
|
||||
// assert.isObject(translatorItem.relations, 'item that is the object of one relation from item with two relations has a relations object');
|
||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of one relation from item with two relations list one relations predicate');
|
||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of one relation from item with two relations uses "dc:relation" as the predicate');
|
||||
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the object of one relation from item with two relations lists "dc:relation" object as a string');
|
||||
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[3]), 'item that is the object of one relation from item with two relations identifies correct subject URI');
|
||||
// }));
|
||||
it('should return standalone note in expected format', Zotero.Promise.coroutine(function* () {
|
||||
let relatedItem, note, collection;
|
||||
|
||||
|
@ -1144,9 +1150,12 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
note.setNote('Note');
|
||||
note.addTag('automaticTag', 0);
|
||||
note.addTag('manualTag', 1);
|
||||
// note.addRelatedItem(relatedItem.id);
|
||||
note.addRelatedItem(relatedItem);
|
||||
yield note.save();
|
||||
|
||||
relatedItem.addRelatedItem(note);
|
||||
yield relatedItem.save();
|
||||
|
||||
collection = new Zotero.Collection;
|
||||
collection.name = 'test';
|
||||
yield collection.save();
|
||||
|
@ -1202,9 +1211,9 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
}
|
||||
|
||||
// Relations
|
||||
// assert.isObject(translatorNote.relations, 'has relations as object' + suffix);
|
||||
// assert.equal(translatorNote.relations['dc:relation'], Zotero.URI.getItemURI(relatedItem), 'relation is correct' + suffix);
|
||||
/** TODO: test other relations and multiple relations per predicate (should be an array) **/
|
||||
assert.isObject(translatorNote.relations, 'has relations as object' + suffix);
|
||||
assert.lengthOf(translatorNote.relations['dc:relation'], 1, 'has one relation' + suffix);
|
||||
assert.equal(translatorNote.relations['dc:relation'][0], Zotero.URI.getItemURI(relatedItem), 'relation is correct' + suffix);
|
||||
|
||||
if (!legacy) {
|
||||
// Collections
|
||||
|
@ -1238,7 +1247,10 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
note.addTag('manualTag', 1);
|
||||
yield note.save();
|
||||
|
||||
// note.addRelatedItem(relatedItem.id);
|
||||
note.addRelatedItem(relatedItem);
|
||||
relatedItem.addRelatedItem(note);
|
||||
yield note.save();
|
||||
yield relatedItem.save();
|
||||
});
|
||||
|
||||
let legacyMode = [false, true];
|
||||
|
@ -1306,9 +1318,9 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
}
|
||||
|
||||
// Relations
|
||||
// assert.isObject(translatorNote.relations, 'has relations as object' + suffix);
|
||||
// assert.equal(translatorNote.relations['dc:relation'], Zotero.URI.getItemURI(relatedItem), 'relation is correct' + suffix);
|
||||
/** TODO: test other relations and multiple relations per predicate (should be an array) **/
|
||||
assert.isObject(translatorNote.relations, 'has relations as object' + suffix);
|
||||
assert.lengthOf(translatorNote.relations['dc:relation'], 1, 'has one relation' + suffix);
|
||||
assert.equal(translatorNote.relations['dc:relation'][0], Zotero.URI.getItemURI(relatedItem), 'relation is correct' + suffix);
|
||||
|
||||
if (!legacy) {
|
||||
// Collections
|
||||
|
@ -1350,10 +1362,14 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
attachment.addTag('automaticTag', 0);
|
||||
attachment.addTag('manualTag', 1);
|
||||
|
||||
// attachment.addRelatedItem(relatedItem.id);
|
||||
attachment.addRelatedItem(relatedItem);
|
||||
|
||||
yield attachment.save();
|
||||
|
||||
relatedItem.addRelatedItem(attachment);
|
||||
}
|
||||
|
||||
yield relatedItem.save();
|
||||
});
|
||||
|
||||
let items = [ attachments[0], attachments[1], item ]; // Standalone attachments and item with child attachments
|
||||
|
@ -1518,8 +1534,9 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
}
|
||||
|
||||
// Relations
|
||||
// assert.isObject(attachment.relations, prefix + 'has relations as object' + suffix);
|
||||
// assert.equal(attachment.relations['dc:relation'], Zotero.URI.getItemURI(relatedItem), prefix + 'relation is correct' + suffix);
|
||||
assert.isObject(attachment.relations, prefix + 'has relations as object' + suffix);
|
||||
assert.lengthOf(attachment.relations['dc:relation'], 1, prefix + 'has one relation' + suffix);
|
||||
assert.equal(attachment.relations['dc:relation'][0], Zotero.URI.getItemURI(relatedItem), prefix + 'relation is correct' + suffix);
|
||||
/** TODO: test other relations and multiple relations per predicate (should be an array) **/
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue