From c1cb832b0b32c4aa2e81ed0a86a001e0d7c2e82e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 1 Jun 2015 20:00:25 -0400 Subject: [PATCH] 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. --- test/content/support.js | 24 ++++++++++++++++++++++++ test/tests/groupsTest.js | 12 ++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/test/content/support.js b/test/content/support.js index 926c1f159d..7390eb3c13 100644 --- 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 index adbf8d3aa1..d5e5da1c46 100644 --- 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) {