describe("Support Functions for Unit Testing", function() { describe("resetDB", function() { it("should restore the DB to factory settings", async function () { await Zotero.DB.queryAsync("CREATE TABLE testTable (foo INTEGER PRIMARY KEY)"); assert.isTrue(await Zotero.DB.tableExists('testTable')); await resetDB({ thisArg: this }); assert.isFalse(await Zotero.DB.tableExists('testTable')); }); }); 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 let field = zItem.getField(prop, false, true); if (prop === "accessDate") field = Zotero.Date.sqlToISO8601(field); assert.equal(field, item[prop], 'inserted item property has the same value as sample data'); } if (item.creators) { // Compare creators for (let i=0; i