Add support function to reset the DB and a test that it works.
This commit is contained in:
parent
b6673511f7
commit
c7c58f8343
5 changed files with 41 additions and 2 deletions
|
@ -54,6 +54,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
||||||
this.join = join;
|
this.join = join;
|
||||||
this.randomString = randomString;
|
this.randomString = randomString;
|
||||||
this.moveToUnique = moveToUnique;
|
this.moveToUnique = moveToUnique;
|
||||||
|
this.reinit = reinit; // defined in zotero-service.js
|
||||||
|
|
||||||
// Public properties
|
// Public properties
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
|
|
|
@ -177,6 +177,21 @@ ZoteroContext.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return zContext;
|
return zContext;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down Zotero, calls a callback (that may return a promise),
|
||||||
|
* then reinitializes Zotero. Returns a promise that is resolved
|
||||||
|
* when this process completes.
|
||||||
|
*/
|
||||||
|
"reinit":function(cb, isConnector) {
|
||||||
|
Services.obs.notifyObservers(zContext.Zotero, "zotero-before-reload", isConnector ? "connector" : "full");
|
||||||
|
return zContext.Zotero.shutdown().then(function() {
|
||||||
|
return cb ? cb() : false;
|
||||||
|
}).finally(function() {
|
||||||
|
makeZoteroContext(isConnector);
|
||||||
|
zContext.Zotero.init(zInitOptions);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -165,3 +165,14 @@ function getTestDataDirectory() {
|
||||||
return Services.io.newURI(resource.resolveURI(resURI), null, null).
|
return Services.io.newURI(resource.resolveURI(resURI), null, null).
|
||||||
QueryInterface(Components.interfaces.nsIFileURL).file;
|
QueryInterface(Components.interfaces.nsIFileURL).file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the Zotero DB and restarts Zotero. Returns a promise resolved
|
||||||
|
* when this finishes.
|
||||||
|
*/
|
||||||
|
function resetDB() {
|
||||||
|
var db = Zotero.getZoteroDatabase();
|
||||||
|
return Zotero.reinit(function() {
|
||||||
|
db.remove(false);
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
var TESTS = {
|
var TESTS = {
|
||||||
"recognizePDF":["recognizePDF.js"],
|
"support":["support.js"],
|
||||||
|
"utilities":["utilities.js"],
|
||||||
"lookup":["lookup.js"],
|
"lookup":["lookup.js"],
|
||||||
"utilities":["utilities.js"]
|
"recognizePDF":["recognizePDF.js"]
|
||||||
};
|
};
|
||||||
|
|
11
test/tests/support.js
Normal file
11
test/tests/support.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe("Support Functions for Unit Testing", function() {
|
||||||
|
describe("resetDB", function() {
|
||||||
|
it("should restore the DB to factory settings", function() {
|
||||||
|
var quickstart = Zotero.Items.erase(1);
|
||||||
|
assert.equal(Zotero.Items.get(1), false);
|
||||||
|
return resetDB().then(function() {
|
||||||
|
assert.equal(Zotero.Items.get(1).getField("url"), "http://zotero.org/support/quick_start_guide");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue