describe("Support Functions for Unit Testing", function() { describe("resetDB", function() { it("should restore the DB to factory settings", function* () { this.timeout(60000); yield Zotero.Items.erase(1); assert.isFalse(yield Zotero.Items.getAsync(1)); yield resetDB(); var item = yield Zotero.Items.getAsync(1); assert.isObject(item); yield item.loadItemData(); assert.equal(item.getField("url"), "https://www.zotero.org/support/quick_start_guide"); }); }); describe("loadSampleData", function() { it("should load data from file", function() { let data = loadSampleData('journalArticle'); assert.isObject(data, 'loaded data object'); assert.isNotNull(data); assert.isAbove(Object.keys(data).length, 0, 'data object is not empty'); }); }); describe("populateDBWithSampleData", function() { it("should populate database with data", Zotero.Promise.coroutine(function* () { let data = loadSampleData('journalArticle'); yield populateDBWithSampleData(data); let skipFields = ['id', 'itemType', 'creators']; // Special comparisons for (let itemName in data) { let item = data[itemName]; assert.isAbove(item.id, 0, 'assigned new item ID'); let zItem = yield Zotero.Items.getAsync(item.id); assert.ok(zItem, 'inserted item into database'); // Compare item type assert.equal(item.itemType, Zotero.ItemTypes.getName(zItem.itemTypeID), 'inserted item has the same item type'); // Compare simple properties for (let prop in item) { if (skipFields.indexOf(prop) != -1) continue; // Using base-mapped fields assert.equal(item[prop], zItem.getField(prop, false, true), 'inserted item property has the same value as sample data'); } if (item.creators) { // Compare creators for (let i=0; i