mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-23 22:13:02 +02:00
Publish tests.
This commit is contained in:
118
test/tests/unit/core/event.js
Normal file
118
test/tests/unit/core/event.js
Normal file
@@ -0,0 +1,118 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/event';
|
||||
var DEPS = ['_'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 3 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.sub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.sub);
|
||||
});
|
||||
|
||||
it('.unsub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.unsub);
|
||||
});
|
||||
|
||||
it('.pub() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.pub);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var topic = 'topic';
|
||||
var arg1 = 'arg1';
|
||||
var arg2 = 'arg2';
|
||||
var arg3 = 'arg3';
|
||||
var subSpy = sinon.spy();
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.sub(topic, subSpy);
|
||||
instance.pub(topic, arg1, arg2, arg3);
|
||||
|
||||
assert.isTrue(subSpy.calledOnce);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
|
||||
instance.pub(topic, arg1, arg2);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
|
||||
instance.unsub(topic, subSpy);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
|
||||
instance.pub(topic, arg1);
|
||||
|
||||
assert.isTrue(subSpy.calledTwice);
|
||||
assert.deepEqual(subSpy.firstCall.args, [arg1, arg2, arg3]);
|
||||
assert.deepEqual(subSpy.secondCall.args, [arg1, arg2]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
215
test/tests/unit/core/format.js
Normal file
215
test/tests/unit/core/format.js
Normal file
@@ -0,0 +1,215 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/format';
|
||||
var DEPS = ['_'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 4 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.setDefaultMetric() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultMetric);
|
||||
});
|
||||
|
||||
it('.formatSize() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatSize);
|
||||
});
|
||||
|
||||
it('.setDefaultDateFormat() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultDateFormat);
|
||||
});
|
||||
|
||||
it('.formatDate() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatDate);
|
||||
});
|
||||
|
||||
it('.formatSize() defaults to decimal metric', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.formatSize(1024), '1 KB');
|
||||
instance.setDefaultMetric(true);
|
||||
assert.strictEqual(instance.formatSize(1024), '1 KiB');
|
||||
instance.setDefaultMetric(false);
|
||||
assert.strictEqual(instance.formatSize(1024), '1 KB');
|
||||
});
|
||||
|
||||
describe('.formatSize() with decimal metric', function () {
|
||||
|
||||
_.each([
|
||||
[0, '0 B'],
|
||||
[10, '10 B'],
|
||||
[999, '999 B'],
|
||||
[1000, '1 KB'],
|
||||
[1001, '1 KB'],
|
||||
[1499, '1 KB'],
|
||||
[1500, '2 KB'],
|
||||
[999999, '1000 KB'],
|
||||
[1000000, '1.0 MB'],
|
||||
[1000001, '1.0 MB'],
|
||||
[1230000, '1.2 MB'],
|
||||
[1250000, '1.3 MB'],
|
||||
[999999999, '1000.0 MB'],
|
||||
[1000000000, '1.0 GB'],
|
||||
[1250000000, '1.3 GB'],
|
||||
[999999999999, '1000.0 GB'],
|
||||
[1000000000000, '1.0 TB'],
|
||||
[1250000000000, '1.3 TB']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it('.formatSize(' + arg + ') => "' + exp + '"', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(false);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formatSize() with binary metric', function () {
|
||||
|
||||
_.each([
|
||||
[0, '0 B'],
|
||||
[10, '10 B'],
|
||||
[999, '999 B'],
|
||||
[1000, '1000 B'],
|
||||
[1001, '1001 B'],
|
||||
[1024, '1 KiB'],
|
||||
[1499, '1 KiB'],
|
||||
[1500, '1 KiB'],
|
||||
[999999, '977 KiB'],
|
||||
[1000000, '977 KiB'],
|
||||
[1000001, '977 KiB'],
|
||||
[1230000, '1.2 MiB'],
|
||||
[1250000, '1.2 MiB'],
|
||||
[999999999, '953.7 MiB'],
|
||||
[1000000000, '953.7 MiB'],
|
||||
[1250000000, '1.2 GiB'],
|
||||
[999999999999, '931.3 GiB'],
|
||||
[1000000000000, '931.3 GiB'],
|
||||
[1250000000000, '1.1 TiB']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it('.formatSize(' + arg + ') => "' + exp + '"', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(true);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('.formatDate() with default format', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.formatDate(0), '');
|
||||
assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00');
|
||||
assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59');
|
||||
assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53');
|
||||
|
||||
instance.setDefaultDateFormat('YYYY-MM-DD HH:mm:ss');
|
||||
assert.strictEqual(instance.formatDate(0), '');
|
||||
assert.strictEqual(instance.formatDate(1000), '1970-01-01 01:00:01');
|
||||
assert.strictEqual(instance.formatDate(-1000), '1970-01-01 00:59:59');
|
||||
assert.strictEqual(instance.formatDate(1400000000000), '2014-05-13 18:53:20');
|
||||
|
||||
instance.setDefaultDateFormat('H YY s');
|
||||
assert.strictEqual(instance.formatDate(0), '');
|
||||
assert.strictEqual(instance.formatDate(1000), '1 70 1');
|
||||
assert.strictEqual(instance.formatDate(-1000), '0 70 59');
|
||||
assert.strictEqual(instance.formatDate(1400000000000), '18 14 20');
|
||||
});
|
||||
|
||||
describe('.formatDate()', function () {
|
||||
|
||||
_.each([
|
||||
[0, 'YYYY-MM-DD HH:mm:ss', ''],
|
||||
[1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 01:00:01'],
|
||||
[-1000, 'YYYY-MM-DD HH:mm:ss', '1970-01-01 00:59:59'],
|
||||
[1400000000000, 'YYYY-MM-DD HH:mm:ss', '2014-05-13 18:53:20'],
|
||||
[1400000000000, 'XYYYYXMMXDDXHHXmmXssX', 'X2014X05X13X18X53X20X'],
|
||||
[1400000000000, 'YYYY YY Y MM M DD D HH H mm m ss s', '2014 14 2014 05 5 13 13 18 18 53 53 20 20']
|
||||
], function (data) {
|
||||
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it('.formatDate(' + arg1 + ', ' + arg2 + ') => "' + exp + '"', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.formatDate(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
64
test/tests/unit/core/langs.js
Normal file
64
test/tests/unit/core/langs.js
Normal file
@@ -0,0 +1,64 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/langs';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {langs: util.uniqObj()};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with right content', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.deepEqual(instance, this.xConfig.langs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
155
test/tests/unit/core/location.js
Normal file
155
test/tests/unit/core/location.js
Normal file
@@ -0,0 +1,155 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/location';
|
||||
var DEPS = ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xModernizr = {
|
||||
history: true
|
||||
};
|
||||
this.xSettings = {
|
||||
smartBrowsing: true,
|
||||
unmanagedInNewWindow: true
|
||||
};
|
||||
this.xEvent = {
|
||||
pub: sinon.stub(),
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.xNotify = {
|
||||
set: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xModernizr, this.xEvent, this.xNotify, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 7 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 7);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
describe('.forceEncoding()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.forceEncoding);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getDomain()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getDomain);
|
||||
});
|
||||
|
||||
it('returns document.domain', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.getDomain(), document.domain);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getAbsHref()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getAbsHref);
|
||||
});
|
||||
|
||||
it('returns null before .setLocation()', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isNull(instance.getAbsHref());
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getItem()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getItem);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setLocation()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setLocation);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.refresh()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.refresh);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setLink()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setLink);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
111
test/tests/unit/core/notify.js
Normal file
111
test/tests/unit/core/notify.js
Normal file
@@ -0,0 +1,111 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/notify';
|
||||
var DEPS = ['$'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn($);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 1 property', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
|
||||
it('adds HTML', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#notify'), 1);
|
||||
assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), '');
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.set() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.ok(_.isFunction(instance.set));
|
||||
});
|
||||
|
||||
it('.set() works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
instance.set();
|
||||
assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), '');
|
||||
|
||||
instance.set('hello');
|
||||
assert.lengthOf($('#notify:visible'), 1);
|
||||
assert.strictEqual($('#notify').text(), 'hello');
|
||||
|
||||
instance.set('world');
|
||||
assert.lengthOf($('#notify:visible'), 1);
|
||||
assert.strictEqual($('#notify').text(), 'world');
|
||||
|
||||
instance.set();
|
||||
// assert.lengthOf($('#notify:visible'), 0);
|
||||
assert.strictEqual($('#notify').text(), 'world');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
110
test/tests/unit/core/resource.js
Normal file
110
test/tests/unit/core/resource.js
Normal file
@@ -0,0 +1,110 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/resource';
|
||||
var DEPS = ['_', 'config', 'core/settings'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
theme: {
|
||||
a: 'myTheme/a.svg',
|
||||
b: 'myTheme/b.jpg'
|
||||
}
|
||||
};
|
||||
this.xSettings = {appHref: '/some/app/href/'};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOf(_.keys(instance), 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.image() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.image);
|
||||
});
|
||||
|
||||
it('.icon() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.icon);
|
||||
});
|
||||
|
||||
it('.image() works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
var ui = this.xSettings.appHref + 'client/images/ui/';
|
||||
|
||||
assert.strictEqual(instance.image(), ui + 'undefined.svg');
|
||||
assert.strictEqual(instance.image(1), ui + '1.svg');
|
||||
assert.strictEqual(instance.image(''), ui + '.svg');
|
||||
assert.strictEqual(instance.image('a'), ui + 'a.svg');
|
||||
});
|
||||
|
||||
it('.icon() works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
var themes = this.xSettings.appHref + 'client/images/themes/';
|
||||
|
||||
assert.strictEqual(instance.icon(''), themes + 'default/file.svg');
|
||||
assert.strictEqual(instance.icon('a'), themes + 'myTheme/a.svg');
|
||||
assert.strictEqual(instance.icon('a-sub'), themes + 'myTheme/a.svg');
|
||||
assert.strictEqual(instance.icon('b'), themes + 'myTheme/b.jpg');
|
||||
assert.strictEqual(instance.icon('x'), themes + 'default/x.svg');
|
||||
assert.strictEqual(instance.icon('y'), themes + 'default/file.svg');
|
||||
assert.strictEqual(instance.icon('y-sub'), themes + 'default/file.svg');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
300
test/tests/unit/core/server.js
Normal file
300
test/tests/unit/core/server.js
Normal file
@@ -0,0 +1,300 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/server';
|
||||
var DEPS = ['_', '$', 'config', 'core/location'];
|
||||
var $submitSnap;
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
setup: {
|
||||
API: true,
|
||||
BACKEND: util.uniqId(),
|
||||
SERVER_NAME: util.uniqId(),
|
||||
SERVER_VERSION: util.uniqId()
|
||||
}
|
||||
};
|
||||
this.xAbsHref = util.uniqId();
|
||||
this.xLocation = {
|
||||
getAbsHref: sinon.stub().returns(this.xAbsHref)
|
||||
};
|
||||
this.xAjaxResult = {
|
||||
done: sinon.stub().returnsThis(),
|
||||
fail: sinon.stub().returnsThis(),
|
||||
always: sinon.stub().returnsThis()
|
||||
};
|
||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
||||
this.xSubmit = sinon.stub($.fn, 'submit', function () {
|
||||
|
||||
$submitSnap = this;
|
||||
return this;
|
||||
});
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xLocation.getAbsHref.reset();
|
||||
this.xAjaxResult.done.reset();
|
||||
this.xAjaxResult.fail.reset();
|
||||
this.xAjaxResult.always.reset();
|
||||
this.xAjax.reset();
|
||||
this.xSubmit.reset();
|
||||
$submitSnap = undefined;
|
||||
|
||||
return this.definition.fn(_, $, this.xConfig, this.xLocation);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
this.xAjax.restore();
|
||||
this.xSubmit.restore();
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 6 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOf(_.keys(instance), 6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.backend is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.backend, this.xConfig.setup.BACKEND);
|
||||
});
|
||||
|
||||
it('.name is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.name, this.xConfig.setup.SERVER_NAME);
|
||||
});
|
||||
|
||||
it('.version is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.version, this.xConfig.setup.SERVER_VERSION);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.api', function () {
|
||||
|
||||
it('set correct (false)', function () {
|
||||
|
||||
this.xConfig.setup.API = false;
|
||||
var instance = this.applyFn();
|
||||
assert.isFalse(instance.api);
|
||||
});
|
||||
|
||||
it('set correct (falsy)', function () {
|
||||
|
||||
this.xConfig.setup.API = null;
|
||||
var instance = this.applyFn();
|
||||
assert.isFalse(instance.api);
|
||||
});
|
||||
|
||||
it('set correct (truthy)', function () {
|
||||
|
||||
this.xConfig.setup.API = 1;
|
||||
var instance = this.applyFn();
|
||||
assert.isFalse(instance.api);
|
||||
});
|
||||
|
||||
it('set correct (true)', function () {
|
||||
|
||||
this.xConfig.setup.API = true;
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(instance.api);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.request()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.request);
|
||||
});
|
||||
|
||||
it('no result if no API', function () {
|
||||
|
||||
this.xConfig.setup.API = false;
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = util.uniqObj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xAjaxResult.done.called);
|
||||
assert.isFalse(this.xAjaxResult.fail.called);
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.deepEqual(spy.lastCall.args, []);
|
||||
});
|
||||
|
||||
it('done() works', function () {
|
||||
|
||||
this.xConfig.setup.API = true;
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = util.uniqObj();
|
||||
var xResult = util.uniqObj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xLocation.getAbsHref.calledOnce);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: this.xAbsHref,
|
||||
data: xData,
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
}]);
|
||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
||||
assert.isTrue(this.xAjaxResult.fail.calledOnce);
|
||||
assert.isFalse(spy.called);
|
||||
|
||||
this.xAjaxResult.done.callArgWith(0, xResult);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.deepEqual(spy.firstCall.args, [xResult]);
|
||||
});
|
||||
|
||||
it('fail() works', function () {
|
||||
|
||||
this.xConfig.setup.API = true;
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = util.uniqObj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xLocation.getAbsHref.calledOnce);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: this.xAbsHref,
|
||||
data: xData,
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
}]);
|
||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
||||
assert.isTrue(this.xAjaxResult.fail.calledOnce);
|
||||
assert.isFalse(spy.called);
|
||||
|
||||
this.xAjaxResult.fail.callArg(0);
|
||||
|
||||
assert.isTrue(spy.calledOnce);
|
||||
assert.deepEqual(spy.firstCall.args, []);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formRequest()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formRequest);
|
||||
});
|
||||
|
||||
it('does nothing if no API', function () {
|
||||
|
||||
this.xConfig.setup.API = false;
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = util.uniqObj();
|
||||
var res = instance.formRequest(xData);
|
||||
|
||||
assert.isUndefined(res);
|
||||
|
||||
assert.isFalse(this.xSubmit.called);
|
||||
assert.isUndefined($submitSnap);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
this.xConfig.setup.API = true;
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = {
|
||||
a: util.uniqId(),
|
||||
b: util.uniqId()
|
||||
};
|
||||
var res = instance.formRequest(xData);
|
||||
|
||||
assert.isUndefined(res);
|
||||
|
||||
assert.isTrue(this.xSubmit.calledOnce);
|
||||
|
||||
assert.lengthOf($submitSnap, 1);
|
||||
assert.strictEqual($submitSnap.get(0).tagName.toLowerCase(), 'form');
|
||||
assert.strictEqual($submitSnap.attr('method'), 'post');
|
||||
assert.strictEqual($submitSnap.attr('style'), 'display:none;');
|
||||
assert.strictEqual($submitSnap.attr('action'), this.xAbsHref);
|
||||
|
||||
var $children = $submitSnap.children();
|
||||
|
||||
assert.lengthOf($children, 2);
|
||||
|
||||
assert.strictEqual($children.eq(0).attr('type'), 'hidden');
|
||||
assert.strictEqual($children.eq(0).attr('name'), 'a');
|
||||
assert.strictEqual($children.eq(0).attr('value'), xData.a);
|
||||
|
||||
assert.strictEqual($children.eq(1).attr('type'), 'hidden');
|
||||
assert.strictEqual($children.eq(1).attr('name'), 'b');
|
||||
assert.strictEqual($children.eq(1).attr('value'), xData.b);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
105
test/tests/unit/core/settings.js
Normal file
105
test/tests/unit/core/settings.js
Normal file
@@ -0,0 +1,105 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/settings';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
options: {
|
||||
someOptions: util.uniqObj(),
|
||||
otherOptions: util.uniqObj(),
|
||||
more: util.uniqObj()
|
||||
},
|
||||
setup: {
|
||||
APP_HREF: util.uniqId(),
|
||||
ROOT_HREF: util.uniqId(),
|
||||
CURRENT_HREF: util.uniqId()
|
||||
}
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.isAbove(_.keys(instance).length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('are extended from options', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.someOptions, this.xConfig.options.someOptions);
|
||||
assert.strictEqual(instance.otherOptions, this.xConfig.options.otherOptions);
|
||||
assert.strictEqual(instance.more, this.xConfig.options.more);
|
||||
assert.strictEqual(_.keys(instance).length, _.keys(this.xConfig.options).length + 3);
|
||||
});
|
||||
|
||||
it('.appHref is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.appHref, this.xConfig.setup.APP_HREF);
|
||||
});
|
||||
|
||||
it('.rootHref is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.rootHref, this.xConfig.setup.ROOT_HREF);
|
||||
});
|
||||
|
||||
it('.currentHref is set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.currentHref, this.xConfig.setup.CURRENT_HREF);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
126
test/tests/unit/core/store.js
Normal file
126
test/tests/unit/core/store.js
Normal file
@@ -0,0 +1,126 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/store';
|
||||
var DEPS = ['modernizr'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.storeKey = '_h5ai';
|
||||
this.storeBackup = window.localStorage.getItem(this.storeKey);
|
||||
this.xModernizr = {localstorage: true};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(this.xModernizr);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
if (this.storeBackup) {
|
||||
window.localStorage.setItem(this.storeKey, this.storeBackup);
|
||||
} else {
|
||||
window.localStorage.removeItem(this.storeKey);
|
||||
}
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
var key1 = 'test1';
|
||||
var value1 = '1234';
|
||||
var key2 = 'test2';
|
||||
var value2 = '5678';
|
||||
|
||||
it('.put() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.put);
|
||||
});
|
||||
|
||||
it('.get() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.get);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
assert.isNull(window.localStorage.getItem(this.storeKey));
|
||||
|
||||
assert.isUndefined(instance.get(key1));
|
||||
assert.isNull(window.localStorage.getItem(this.storeKey));
|
||||
|
||||
assert.isUndefined(instance.put(key1, value1));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
||||
|
||||
assert.strictEqual(instance.get(key1), value1);
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
||||
|
||||
assert.isUndefined(instance.put(key1, undefined));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
|
||||
|
||||
assert.isUndefined(instance.get(key1));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{}');
|
||||
|
||||
assert.isUndefined(instance.put(key1, value1));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234"}');
|
||||
|
||||
assert.isUndefined(instance.put(key2, value2));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test1":"1234","test2":"5678"}');
|
||||
|
||||
assert.isUndefined(instance.put(key1, undefined));
|
||||
assert.strictEqual(window.localStorage.getItem(this.storeKey), '{"test2":"5678"}');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
95
test/tests/unit/core/types.js
Normal file
95
test/tests/unit/core/types.js
Normal file
@@ -0,0 +1,95 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/types';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {types: {
|
||||
a: ['*.a', '*.aa'],
|
||||
b: ['*.b'],
|
||||
c: ['*.c']
|
||||
}};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 1 property', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.getType() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getType);
|
||||
});
|
||||
|
||||
it('.getType() works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.getType('file.a'), 'a');
|
||||
assert.strictEqual(instance.getType('file.aa'), 'a');
|
||||
assert.strictEqual(instance.getType('foo.b'), 'b');
|
||||
assert.strictEqual(instance.getType('some/path/file.c'), 'c');
|
||||
assert.strictEqual(instance.getType('/some/abs/path/file.c'), 'c');
|
||||
assert.strictEqual(instance.getType('file.x'), 'file');
|
||||
assert.strictEqual(instance.getType('foo'), 'file');
|
||||
assert.strictEqual(instance.getType('some/path/foo'), 'file');
|
||||
assert.strictEqual(instance.getType('/some/path/foo'), 'file');
|
||||
assert.strictEqual(instance.getType('foo/'), 'folder');
|
||||
assert.strictEqual(instance.getType('/'), 'folder');
|
||||
assert.strictEqual(instance.getType('some/path/foo/'), 'folder');
|
||||
assert.strictEqual(instance.getType('/some/path/foo/'), 'folder');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
120
test/tests/unit/core/util.js
Normal file
120
test/tests/unit/core/util.js
Normal file
@@ -0,0 +1,120 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'core/util';
|
||||
var DEPS = [];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn();
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('publics', function () {
|
||||
|
||||
it('.regularCmpFn() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.regularCmpFn);
|
||||
});
|
||||
|
||||
it('.naturalCmpFn() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.naturalCmpFn);
|
||||
});
|
||||
|
||||
_.each([
|
||||
[0, 0, 0],
|
||||
[1, 0, 1],
|
||||
[1, 2, -1],
|
||||
['a', 'a', 0],
|
||||
['b', 'a', 1],
|
||||
['a', 'b', -1],
|
||||
['a 2', 'a 10', 1]
|
||||
], function (data) {
|
||||
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it('.regularCmpFn("' + arg1 + '", "' + arg2 + '") => "' + exp + '"', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
|
||||
_.each([
|
||||
[0, 0, 0],
|
||||
[1, 0, 1],
|
||||
[1, 2, -1],
|
||||
['a', 'a', 0],
|
||||
['b', 'a', 1],
|
||||
['a', 'b', -1],
|
||||
['a 2', 'a 10', -1]
|
||||
], function (data) {
|
||||
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it('.naturalCmpFn("' + arg1 + '", "' + arg2 + '") => "' + exp + '"', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
Reference in New Issue
Block a user