Add Utilities.Internal.getNextName(name, existingNames)

Function to get the next available name when duplicating something
This commit is contained in:
Dan Stillman 2018-12-16 02:11:09 -05:00
parent bf6f1432c5
commit 80f6b857f6
2 changed files with 35 additions and 0 deletions

View file

@ -200,4 +200,16 @@ describe("Zotero.Utilities.Internal", function () {
assert.propertyVal(identifiers[3], "arXiv", "math.GT/0309135");
});
});
describe("#getNextName()", function () {
it("should get the next available numbered name", function () {
var existing = ['Name (1)', 'Name (3)'];
assert.equal(Zotero.Utilities.Internal.getNextName('Name', existing), 'Name (4)');
});
it("should return 'Name (1)' if no numbered names", function () {
var existing = ['Name'];
assert.equal(Zotero.Utilities.Internal.getNextName('Name', existing), 'Name (1)');
});
});
})