www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit c1cb832b0b32c4aa2e81ed0a86a001e0d7c2e82e
parent 5a5a8a93f9b2fb8960b4231934fbd5694b6f761a
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  1 Jun 2015 20:00:25 -0400

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.

Diffstat:
Mtest/content/support.js | 24++++++++++++++++++++++++
Mtest/tests/groupsTest.js | 12++----------
2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/test/content/support.js b/test/content/support.js @@ -163,6 +163,30 @@ function waitForCallback(cb, interval, timeout) { 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 // diff --git a/test/tests/groupsTest.js b/test/tests/groupsTest.js @@ -1,17 +1,9 @@ describe("Zotero.Groups", function () { describe("#get()", 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 { - yield group.save(); - assert.equal(Zotero.Groups.get(1851251), group) + var group = yield createGroup(); + assert.equal(Zotero.Groups.get(group.id), group) } finally { if (group) {