Add getGroup() and createGroup() test support functions
getGroup() can be used to access a default group library for general group tests. createGroup() can be used to create one for a particular test or set of tests.
This commit is contained in:
parent
5a5a8a93f9
commit
c1cb832b0b
2 changed files with 26 additions and 10 deletions
|
@ -163,6 +163,30 @@ function waitForCallback(cb, interval, timeout) {
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a default group used by all tests that want one, creating one if necessary
|
||||||
|
*/
|
||||||
|
var getGroup = Zotero.lazy(function () {
|
||||||
|
return createGroup({
|
||||||
|
name: "My Group"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var createGroup = Zotero.Promise.coroutine(function* (props) {
|
||||||
|
props = props || {};
|
||||||
|
var group = new Zotero.Group;
|
||||||
|
group.id = Zotero.Utilities.rand(10000, 1000000);
|
||||||
|
group.name = props.name || "Test " + Zotero.Utilities.randomString();
|
||||||
|
group.description = props.description || "";
|
||||||
|
group.editable = props.editable || true;
|
||||||
|
group.filesEditable = props.filesEditable || true;
|
||||||
|
group.version = props.version || Zotero.Utilities.rand(1000, 10000);
|
||||||
|
yield group.save();
|
||||||
|
return group;
|
||||||
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// Data objects
|
// Data objects
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
describe("Zotero.Groups", function () {
|
describe("Zotero.Groups", function () {
|
||||||
describe("#get()", function () {
|
describe("#get()", function () {
|
||||||
it("should retrieve a newly created group", function* () {
|
it("should retrieve a newly created group", function* () {
|
||||||
var group = new Zotero.Group;
|
|
||||||
group.id = 1851251;
|
|
||||||
group.libraryID = yield Zotero.ID.get('libraries');
|
|
||||||
group.name = "Test";
|
|
||||||
group.description = "";
|
|
||||||
group.editable = true;
|
|
||||||
group.filesEditable = true;
|
|
||||||
group.version = 1234;
|
|
||||||
try {
|
try {
|
||||||
yield group.save();
|
var group = yield createGroup();
|
||||||
assert.equal(Zotero.Groups.get(1851251), group)
|
assert.equal(Zotero.Groups.get(group.id), group)
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (group) {
|
if (group) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue