mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 20:14:37 -04:00
Update tests.
This commit is contained in:
parent
18a62ca831
commit
787eae7a80
22 changed files with 113 additions and 161 deletions
5
.jscsrc
5
.jscsrc
|
@ -1,11 +1,8 @@
|
||||||
{
|
{
|
||||||
"disallowDanglingUnderscores": {
|
|
||||||
"allExcept": ["_exception", "_obj" , "_private"]
|
|
||||||
},
|
|
||||||
"disallowEmptyBlocks": true,
|
"disallowEmptyBlocks": true,
|
||||||
"disallowImplicitTypeConversion": [
|
"disallowImplicitTypeConversion": [
|
||||||
"binary",
|
"binary",
|
||||||
"boolean",
|
//"boolean",
|
||||||
"numeric",
|
"numeric",
|
||||||
"string"
|
"string"
|
||||||
],
|
],
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
"mocha": false,
|
"mocha": false,
|
||||||
"modulejs": false,
|
"modulejs": false,
|
||||||
"sinon": false,
|
"sinon": false,
|
||||||
|
"uniq": false,
|
||||||
"util": false
|
"util": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
48
test/lib/uniq.js
Normal file
48
test/lib/uniq.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* uniq 0.3.1 - http://larsjung.de/uniq/ */
|
||||||
|
(function (root, factory) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
module.exports = factory();
|
||||||
|
} else {
|
||||||
|
root.uniq = factory();
|
||||||
|
}
|
||||||
|
}(this, function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var PREFIX = 'UNIQ-';
|
||||||
|
var SUFFIX = '-ID';
|
||||||
|
var LENGTH = 4;
|
||||||
|
var ZERO_PAD = new Array(LENGTH + 1).join('0');
|
||||||
|
var RE_ID = new RegExp('^' + PREFIX + '\\d{' + LENGTH + '}' + SUFFIX + '$');
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
|
||||||
|
function id() {
|
||||||
|
|
||||||
|
counter += 1;
|
||||||
|
return PREFIX + (ZERO_PAD + counter).substr(-LENGTH) + SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isId(sequence) {
|
||||||
|
|
||||||
|
return RE_ID.test(sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
function obj() {
|
||||||
|
|
||||||
|
return {_uniq_id: id()};
|
||||||
|
}
|
||||||
|
|
||||||
|
function path(suffix) {
|
||||||
|
|
||||||
|
return '/_uniq_path/' + id() + (suffix ? suffix : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
isId: isId,
|
||||||
|
obj: obj,
|
||||||
|
path: path
|
||||||
|
};
|
||||||
|
}));
|
|
@ -9,8 +9,8 @@ describe('view', function () {
|
||||||
this.storeKey = '_h5ai';
|
this.storeKey = '_h5ai';
|
||||||
this.xConfig = {
|
this.xConfig = {
|
||||||
setup: {
|
setup: {
|
||||||
PUBLIC_HREF: util.uniqPath('-PUBLIC/'),
|
PUBLIC_HREF: uniq.path('-PUBLIC/'),
|
||||||
ROOT_HREF: util.uniqPath('-ROOT/')
|
ROOT_HREF: uniq.path('-ROOT/')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,44 +38,10 @@ describe('premisses', function () {
|
||||||
assert.strictEqual(util, window.util);
|
assert.strictEqual(util, window.util);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('util.uniqId() works', function () {
|
it('uniq is global object', function () {
|
||||||
|
|
||||||
assert.isFunction(util.uniqId);
|
assert.isPlainObject(util);
|
||||||
|
assert.strictEqual(util, window.util);
|
||||||
var uid1 = parseInt(util.uniqId().replace(/\D/g, ''), 10);
|
|
||||||
|
|
||||||
assert.isTrue(util.isUniqId(util.uniqId()));
|
|
||||||
assert.notEqual(util.uniqId(), util.uniqId());
|
|
||||||
assert.notDeepEqual(util.uniqId(), util.uniqId());
|
|
||||||
assert.notStrictEqual(util.uniqId(), util.uniqId());
|
|
||||||
|
|
||||||
var uid2 = parseInt(util.uniqId().replace(/\D/g, ''), 10);
|
|
||||||
assert.strictEqual(uid2, uid1 + 8);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('util.uniqObj() works', function () {
|
|
||||||
|
|
||||||
assert.isFunction(util.uniqId);
|
|
||||||
|
|
||||||
assert.lengthOfKeys(util.uniqObj(), 1);
|
|
||||||
assert.isTrue(util.isUniqId(util.uniqObj().uniqId));
|
|
||||||
assert.notEqual(util.uniqObj(), util.uniqObj());
|
|
||||||
assert.notDeepEqual(util.uniqObj(), util.uniqObj());
|
|
||||||
assert.notStrictEqual(util.uniqObj(), util.uniqObj());
|
|
||||||
assert.notEqual(util.uniqObj().uniqId, util.uniqObj().uniqId);
|
|
||||||
assert.notDeepEqual(util.uniqObj().uniqId, util.uniqObj().uniqId);
|
|
||||||
assert.notStrictEqual(util.uniqObj().uniqId, util.uniqObj().uniqId);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('util.uniqPath() works', function () {
|
|
||||||
|
|
||||||
assert.isFunction(util.uniqPath);
|
|
||||||
|
|
||||||
assert.notEqual(util.uniqPath(), util.uniqPath());
|
|
||||||
assert.notDeepEqual(util.uniqPath(), util.uniqPath());
|
|
||||||
assert.notStrictEqual(util.uniqPath(), util.uniqPath());
|
|
||||||
assert.strictEqual(util.uniqPath('abc').substr(-3), 'abc');
|
|
||||||
assert.strictEqual(util.uniqPath('xyz/').substr(-4), 'xyz/');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('assert.isPlainObject() works', function () {
|
it('assert.isPlainObject() works', function () {
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
this.definition = modulejs._private.definitions[ID];
|
||||||
|
|
||||||
this.xConfig = util.uniqObj();
|
this.xConfig = uniq.obj();
|
||||||
this.xDefine = sinon.stub(modulejs, 'define');
|
this.xDefine = sinon.stub(modulejs, 'define');
|
||||||
this.xRequire = sinon.stub(modulejs, 'require');
|
this.xRequire = sinon.stub(modulejs, 'require');
|
||||||
this.xServer = {
|
this.xServer = {
|
||||||
|
|
|
@ -53,7 +53,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
assert.isPlainObject(instance);
|
assert.isPlainObject(instance);
|
||||||
assert.lengthOfKeys(instance, 1);
|
assert.lengthOfKeys(instance, 1);
|
||||||
assert.isTrue(util.isUniqId(instance.uniqId));
|
assert.isTrue(uniq.isId(instance._uniq_id));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
this.definition = modulejs._private.definitions[ID];
|
||||||
|
|
||||||
this.xConfig = {langs: util.uniqObj()};
|
this.xConfig = {langs: uniq.obj()};
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
return this.definition.fn(_, this.xConfig);
|
return this.definition.fn(_, this.xConfig);
|
||||||
|
|
|
@ -242,7 +242,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var $el = $('<a/>');
|
var $el = $('<a/>');
|
||||||
var item = {
|
var item = {
|
||||||
absHref: util.uniqId(),
|
absHref: uniq.id(),
|
||||||
isManaged: false,
|
isManaged: false,
|
||||||
isFolder: sinon.stub().returns(false)
|
isFolder: sinon.stub().returns(false)
|
||||||
};
|
};
|
||||||
|
@ -259,7 +259,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var $el = $('<a/>');
|
var $el = $('<a/>');
|
||||||
var item = {
|
var item = {
|
||||||
absHref: util.uniqId(),
|
absHref: uniq.id(),
|
||||||
isManaged: false,
|
isManaged: false,
|
||||||
isFolder: sinon.stub().returns(true)
|
isFolder: sinon.stub().returns(true)
|
||||||
};
|
};
|
||||||
|
@ -276,7 +276,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var $el = $('<a/>');
|
var $el = $('<a/>');
|
||||||
var item = {
|
var item = {
|
||||||
absHref: util.uniqId(),
|
absHref: uniq.id(),
|
||||||
isManaged: true,
|
isManaged: true,
|
||||||
isFolder: sinon.stub().returns(true)
|
isFolder: sinon.stub().returns(true)
|
||||||
};
|
};
|
||||||
|
@ -293,7 +293,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var $el = $('<a/>');
|
var $el = $('<a/>');
|
||||||
var item = {
|
var item = {
|
||||||
absHref: util.uniqId(),
|
absHref: uniq.id(),
|
||||||
isManaged: true,
|
isManaged: true,
|
||||||
isFolder: sinon.stub().returns(true)
|
isFolder: sinon.stub().returns(true)
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
b: 'myTheme/b.jpg'
|
b: 'myTheme/b.jpg'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.xSettings = {publicHref: util.uniqPath('/publicHref/')};
|
this.xSettings = {publicHref: uniq.path('/publicHref/')};
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
return this.definition.fn(_, this.xConfig, this.xSettings);
|
return this.definition.fn(_, this.xConfig, this.xSettings);
|
||||||
|
@ -62,7 +62,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
assert.isPlainObject(instance);
|
assert.isPlainObject(instance);
|
||||||
assert.lengthOf(_.keys(instance), 2);
|
assert.lengthOfKeys(instance, 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
assert.isPlainObject(instance);
|
assert.isPlainObject(instance);
|
||||||
assert.lengthOf(_.keys(instance), 2);
|
assert.lengthOfKeys(instance, 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
|
|
||||||
var xData = util.uniqObj();
|
var xData = uniq.obj();
|
||||||
var xResult = util.uniqObj();
|
var xResult = uniq.obj();
|
||||||
var spy = sinon.spy();
|
var spy = sinon.spy();
|
||||||
var res = instance.request(xData, spy);
|
var res = instance.request(xData, spy);
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
|
|
||||||
var xData = util.uniqObj();
|
var xData = uniq.obj();
|
||||||
var spy = sinon.spy();
|
var spy = sinon.spy();
|
||||||
var res = instance.request(xData, spy);
|
var res = instance.request(xData, spy);
|
||||||
|
|
||||||
|
@ -160,8 +160,8 @@ describe('module \'' + ID + '\'', function () {
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
|
|
||||||
var xData = {
|
var xData = {
|
||||||
a: util.uniqId(),
|
a: uniq.id(),
|
||||||
b: util.uniqId()
|
b: uniq.id()
|
||||||
};
|
};
|
||||||
var res = instance.formRequest(xData);
|
var res = instance.formRequest(xData);
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,13 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.xConfig = {
|
this.xConfig = {
|
||||||
options: {
|
options: {
|
||||||
someOptions: util.uniqObj(),
|
someOptions: uniq.obj(),
|
||||||
otherOptions: util.uniqObj(),
|
otherOptions: uniq.obj(),
|
||||||
more: util.uniqObj()
|
more: uniq.obj()
|
||||||
},
|
},
|
||||||
setup: {
|
setup: {
|
||||||
PUBLIC_HREF: util.uniqId(),
|
PUBLIC_HREF: uniq.id(),
|
||||||
ROOT_HREF: util.uniqId()
|
ROOT_HREF: uniq.id()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
|
@ -12,7 +12,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.xConfig = {
|
this.xConfig = {
|
||||||
setup: {
|
setup: {
|
||||||
VERSION: util.uniqId()
|
VERSION: uniq.id()
|
||||||
},
|
},
|
||||||
options: {}
|
options: {}
|
||||||
};
|
};
|
||||||
|
@ -136,7 +136,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
it('login works', function () {
|
it('login works', function () {
|
||||||
|
|
||||||
var pass = util.uniqId();
|
var pass = uniq.id();
|
||||||
var expectedData = {
|
var expectedData = {
|
||||||
action: 'login',
|
action: 'login',
|
||||||
pass: pass
|
pass: pass
|
||||||
|
|
|
@ -10,19 +10,19 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
this.definition = modulejs._private.definitions[ID];
|
||||||
|
|
||||||
this.xRootName = util.uniqId();
|
this.xRootName = uniq.id();
|
||||||
this.xTypes = {
|
this.xTypes = {
|
||||||
getType: sinon.stub().returns(util.uniqId())
|
getType: sinon.stub().returns(uniq.id())
|
||||||
};
|
};
|
||||||
this.xEvent = util.uniqObj();
|
this.xEvent = uniq.obj();
|
||||||
this.xSettings = {
|
this.xSettings = {
|
||||||
rootHref: util.uniqPath('/' + this.xRootName + '/')
|
rootHref: uniq.path('/' + this.xRootName + '/')
|
||||||
};
|
};
|
||||||
this.xServer = util.uniqObj();
|
this.xServer = uniq.obj();
|
||||||
this.xLocation = {
|
this.xLocation = {
|
||||||
forceEncoding: sinon.stub().returnsArg(0),
|
forceEncoding: sinon.stub().returnsArg(0),
|
||||||
getDomain: sinon.stub().returns(util.uniqId()),
|
getDomain: sinon.stub().returns(uniq.id()),
|
||||||
getAbsHref: sinon.stub().returns(util.uniqId())
|
getAbsHref: sinon.stub().returns(uniq.id())
|
||||||
};
|
};
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ describe('module \'' + ID + '\'', function () {
|
||||||
this.xResource = {
|
this.xResource = {
|
||||||
image: sinon.stub().throws('invalid image request')
|
image: sinon.stub().throws('invalid image request')
|
||||||
};
|
};
|
||||||
this.xResource.image.withArgs('back').returns(util.uniqPath('-back.png'));
|
this.xResource.image.withArgs('back').returns(uniq.path('-back.png'));
|
||||||
this.xResource.image.withArgs('sidebar').returns(util.uniqPath('-sidebar.png'));
|
this.xResource.image.withArgs('sidebar').returns(uniq.path('-sidebar.png'));
|
||||||
this.xStore = {
|
this.xStore = {
|
||||||
get: sinon.stub().returns(false),
|
get: sinon.stub().returns(false),
|
||||||
put: sinon.stub()
|
put: sinon.stub()
|
||||||
|
|
|
@ -16,14 +16,14 @@ describe('module \'' + ID + '\'', function () {
|
||||||
};
|
};
|
||||||
this.xFormat = {
|
this.xFormat = {
|
||||||
setDefaultMetric: sinon.stub(),
|
setDefaultMetric: sinon.stub(),
|
||||||
formatDate: sinon.stub().returns(util.uniqId()),
|
formatDate: sinon.stub().returns(uniq.id()),
|
||||||
formatSize: sinon.stub().returns(util.uniqId())
|
formatSize: sinon.stub().returns(uniq.id())
|
||||||
};
|
};
|
||||||
this.xLocation = {
|
this.xLocation = {
|
||||||
setLink: sinon.stub().returns(util.uniqId())
|
setLink: sinon.stub().returns(uniq.id())
|
||||||
};
|
};
|
||||||
this.xResource = {
|
this.xResource = {
|
||||||
icon: sinon.stub().returns(util.uniqId())
|
icon: sinon.stub().returns(uniq.id())
|
||||||
};
|
};
|
||||||
this.xSettings = {view: {
|
this.xSettings = {view: {
|
||||||
binaryPrefix: false,
|
binaryPrefix: false,
|
||||||
|
@ -253,7 +253,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
it('sets correct class to #view-hint', function () {
|
it('sets correct class to #view-hint', function () {
|
||||||
|
|
||||||
var key = util.uniqId();
|
var key = uniq.id();
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
instance.setHint(key);
|
instance.setHint(key);
|
||||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
||||||
|
@ -261,7 +261,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
it('removes all other classes from #view-hint', function () {
|
it('removes all other classes from #view-hint', function () {
|
||||||
|
|
||||||
var key = util.uniqId();
|
var key = uniq.id();
|
||||||
var instance = this.applyFn();
|
var instance = this.applyFn();
|
||||||
$('#view-hint').addClass('a');
|
$('#view-hint').addClass('a');
|
||||||
instance.setHint(key);
|
instance.setHint(key);
|
||||||
|
@ -407,10 +407,10 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
// return {
|
// return {
|
||||||
// isFolder: sinon.stub().returns(false),
|
// isFolder: sinon.stub().returns(false),
|
||||||
// label: util.uniqId(),
|
// label: uniq.id(),
|
||||||
// time: 0,
|
// time: 0,
|
||||||
// size: 0,
|
// size: 0,
|
||||||
// type: util.uniqId(),
|
// type: uniq.id(),
|
||||||
// isManaged: false,
|
// isManaged: false,
|
||||||
// icon: null,
|
// icon: null,
|
||||||
// isCurrentParentFolder: sinon.stub().returns(false)
|
// isCurrentParentFolder: sinon.stub().returns(false)
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
pub: sinon.stub()
|
pub: sinon.stub()
|
||||||
};
|
};
|
||||||
this.xResource = {
|
this.xResource = {
|
||||||
image: sinon.stub().returns(util.uniqPath('-image.png'))
|
image: sinon.stub().returns(uniq.path('-image.png'))
|
||||||
};
|
};
|
||||||
this.xSettings = {view: {
|
this.xSettings = {view: {
|
||||||
modeToggle: false
|
modeToggle: false
|
||||||
|
|
17
test/util/assert.js
Normal file
17
test/util/assert.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = chai.assert;
|
||||||
|
|
||||||
|
assert.lengthOfKeys = function (val, count, msg) {
|
||||||
|
|
||||||
|
var keyCount = _.keys(val).length;
|
||||||
|
assert(keyCount === count, msg ? msg : 'expected ' + val + ' to have ' + count + ' keys, but has ' + keyCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.isPlainObject = function (val, msg) {
|
||||||
|
|
||||||
|
assert($.isPlainObject(val), msg ? msg : 'expected ' + val + ' to be a plain Object');
|
||||||
|
};
|
||||||
|
|
||||||
|
}());
|
|
@ -1,18 +0,0 @@
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
chai.Assertion.addChainableMethod('isPlainObject', function () {
|
|
||||||
|
|
||||||
this.assert(
|
|
||||||
$.isPlainObject(this._obj),
|
|
||||||
'expected ' + this._obj + ' to be a plain Object',
|
|
||||||
'expected ' + this._obj + ' not to be a plain Object'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
chai.assert.isPlainObject = function (val, msg) {
|
|
||||||
|
|
||||||
new chai.Assertion(val, msg).to.be.isPlainObject();
|
|
||||||
};
|
|
||||||
|
|
||||||
}());
|
|
|
@ -1,20 +0,0 @@
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
chai.Assertion.addChainableMethod('lengthOfKeys', function (count) {
|
|
||||||
|
|
||||||
var keyCount = _.keys(this._obj).length;
|
|
||||||
|
|
||||||
this.assert(
|
|
||||||
keyCount === count,
|
|
||||||
'expected ' + this._obj + ' to have ' + count + ' keys, but has ' + keyCount,
|
|
||||||
'expected ' + this._obj + ' not to have ' + count + ' keys, but has ' + keyCount
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
chai.assert.lengthOfKeys = function (val, count, msg) {
|
|
||||||
|
|
||||||
new chai.Assertion(val, msg).to.be.lengthOfKeys(count);
|
|
||||||
};
|
|
||||||
|
|
||||||
}());
|
|
|
@ -11,7 +11,7 @@ function clearModulejs() {
|
||||||
|
|
||||||
function mockConfigModule() {
|
function mockConfigModule() {
|
||||||
|
|
||||||
modulejs.define('config', window.util.uniqObj());
|
modulejs.define('config', window.uniq.obj());
|
||||||
}
|
}
|
||||||
|
|
||||||
window.util = window.util || {};
|
window.util = window.util || {};
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var PREFIX = 'UNIQ-';
|
|
||||||
var SUFFIX = '-ID';
|
|
||||||
var LENGTH = 4;
|
|
||||||
var RE = new RegExp('^' + PREFIX + '\\d{' + LENGTH + '}' + SUFFIX + '$');
|
|
||||||
|
|
||||||
var counter = 0;
|
|
||||||
|
|
||||||
function uniqId() {
|
|
||||||
|
|
||||||
counter += 1;
|
|
||||||
return PREFIX + ('00000000' + counter).substr(-LENGTH) + SUFFIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUniqId(uid) {
|
|
||||||
|
|
||||||
return RE.test(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
function uniqObj() {
|
|
||||||
|
|
||||||
return {uniqId: uniqId()};
|
|
||||||
}
|
|
||||||
|
|
||||||
function uniqPath(suffix) {
|
|
||||||
|
|
||||||
return '/some/path/' + uniqId() + (suffix ? suffix : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
window.util = window.util || {};
|
|
||||||
window.util.uniqId = uniqId;
|
|
||||||
window.util.isUniqId = isUniqId;
|
|
||||||
window.util.uniqObj = uniqObj;
|
|
||||||
window.util.uniqPath = uniqPath;
|
|
||||||
|
|
||||||
}());
|
|
Loading…
Add table
Add a link
Reference in a new issue