mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-14 09:54:21 +02:00
Publish tests.
This commit is contained in:
12
test/tests/integration/first.js
Normal file
12
test/tests/integration/first.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
describe('first', function () {
|
||||
|
||||
it('nothing here', function () {
|
||||
|
||||
assert.isTrue(true);
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
192
test/tests/unit/boot.js
Normal file
192
test/tests/unit/boot.js
Normal file
@@ -0,0 +1,192 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'boot';
|
||||
var DEPS = ['$'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = util.uniqObj();
|
||||
this.xAjaxResult = {
|
||||
done: sinon.stub().callsArgWith(0, this.xConfig),
|
||||
fail: sinon.stub().callsArg(0),
|
||||
always: sinon.stub().callsArg(0)
|
||||
};
|
||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
||||
this.xDefine = sinon.stub(modulejs, 'define');
|
||||
this.xRequire = sinon.stub(modulejs, 'require');
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xAjaxResult.done.reset();
|
||||
this.xAjaxResult.fail.reset();
|
||||
this.xAjaxResult.always.reset();
|
||||
this.xAjax.reset();
|
||||
this.xDefine.reset();
|
||||
this.xRequire.reset();
|
||||
|
||||
return this.definition.fn($);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
this.xAjax.restore();
|
||||
this.xDefine.restore();
|
||||
this.xRequire.restore();
|
||||
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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('no data-module', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('data-module="test"', function () {
|
||||
|
||||
$('<script/>').attr('data-module', 'test').appendTo('head');
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('data-module="info"', function () {
|
||||
|
||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
||||
|
||||
this.applyFn();
|
||||
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].url, 'server/php/index.php');
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].type, 'POST');
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].dataType, 'json');
|
||||
|
||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
||||
assert.isFalse(this.xAjaxResult.fail.called);
|
||||
assert.isFalse(this.xAjaxResult.always.called);
|
||||
|
||||
assert.isTrue(this.xDefine.calledOnce);
|
||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
||||
|
||||
assert.isTrue(this.xRequire.calledOnce);
|
||||
assert.deepEqual(this.xRequire.lastCall.args, ['main/info']);
|
||||
});
|
||||
|
||||
it('data-module="index"', function () {
|
||||
|
||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
||||
|
||||
this.applyFn();
|
||||
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].url, '.');
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].type, 'POST');
|
||||
assert.strictEqual(this.xAjax.lastCall.args[0].dataType, 'json');
|
||||
|
||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
||||
assert.isFalse(this.xAjaxResult.fail.called);
|
||||
assert.isFalse(this.xAjaxResult.always.called);
|
||||
|
||||
assert.isTrue(this.xDefine.calledOnce);
|
||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
||||
|
||||
assert.isTrue(this.xRequire.calledOnce);
|
||||
assert.deepEqual(this.xRequire.lastCall.args, ['main/index']);
|
||||
});
|
||||
|
||||
it('"no-browser"-class and no data-module', function () {
|
||||
|
||||
$('html').addClass('no-browser');
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('"no-browser"-class and data-module="test"', function () {
|
||||
|
||||
$('html').addClass('no-browser');
|
||||
$('<script/>').attr('data-module', 'test').appendTo('head');
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('"no-browser"-class and data-module="info"', function () {
|
||||
|
||||
$('html').addClass('no-browser');
|
||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('"no-browser"-class and data-module="index"', function () {
|
||||
|
||||
$('html').addClass('no-browser');
|
||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xAjax.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
61
test/tests/unit/config.js
Normal file
61
test/tests/unit/config.js
Normal file
@@ -0,0 +1,61 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'config';
|
||||
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();
|
||||
});
|
||||
|
||||
it('is only dummy definition', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
assert.isTrue(util.isUniqId(instance.uniqId));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
40
test/tests/unit/libs.js
Normal file
40
test/tests/unit/libs.js
Normal file
@@ -0,0 +1,40 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
describe('libs', function () {
|
||||
|
||||
var libs = {
|
||||
_: window._,
|
||||
$: window.jQuery,
|
||||
marked: window.marked,
|
||||
modernizr: window.Modernizr,
|
||||
prism: window.Prism
|
||||
};
|
||||
|
||||
_.each(libs, function (lib, id) {
|
||||
|
||||
describe('module "' + id + '"', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isDefined(modulejs._private.definitions[id]);
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, id);
|
||||
});
|
||||
|
||||
it('returns global lib', function () {
|
||||
|
||||
var definition = modulejs._private.definitions[id];
|
||||
var instance = definition.fn();
|
||||
assert.isDefined(instance);
|
||||
assert.strictEqual(instance, lib);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
119
test/tests/unit/main/index.js
Normal file
119
test/tests/unit/main/index.js
Normal file
@@ -0,0 +1,119 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'main/index';
|
||||
var DEPS = ['_', 'core/event'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xEvent = {pub: sinon.stub()};
|
||||
this.xDefine = sinon.stub(modulejs, 'define');
|
||||
this.xRequire = sinon.stub(modulejs, 'require');
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xEvent.pub.reset();
|
||||
this.xDefine.reset();
|
||||
this.xRequire.reset();
|
||||
return this.definition.fn(_, this.xEvent);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
this.xDefine.restore();
|
||||
this.xRequire.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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('publishes "ready" event', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xEvent.pub.calledOnce);
|
||||
assert.deepEqual(this.xEvent.pub.firstCall.args, ['ready']);
|
||||
});
|
||||
|
||||
it('requires all views and extensions (only)', function () {
|
||||
|
||||
this.applyFn();
|
||||
var re = /^(view|ext)\//;
|
||||
var self = this;
|
||||
var counter = 0;
|
||||
|
||||
_.each(modulejs.state(), function (state, id) {
|
||||
|
||||
if (re.test(id)) {
|
||||
counter += 1;
|
||||
assert.isTrue(self.xRequire.calledWithExactly(id));
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(self.xRequire.callCount, counter);
|
||||
});
|
||||
|
||||
it('requires views before extensions', function () {
|
||||
|
||||
this.applyFn();
|
||||
var foundExtension = false;
|
||||
var reView = /^view\//;
|
||||
var reExt = /^ext\//;
|
||||
|
||||
_.each(this.xRequire.args, function (args) {
|
||||
|
||||
if (foundExtension) {
|
||||
assert.match(args[0], reExt);
|
||||
} else if (reExt.test(args[0])) {
|
||||
foundExtension = true;
|
||||
} else {
|
||||
assert.match(args[0], reView);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
208
test/tests/unit/main/info.js
Normal file
208
test/tests/unit/main/info.js
Normal file
@@ -0,0 +1,208 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'main/info';
|
||||
var DEPS = ['$', 'config'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
setup: {
|
||||
VERSION: util.uniqId()
|
||||
}
|
||||
};
|
||||
this.xAjaxResult = {
|
||||
done: sinon.stub(),
|
||||
fail: sinon.stub(),
|
||||
always: sinon.stub()
|
||||
};
|
||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xAjaxResult.done.reset();
|
||||
this.xAjaxResult.fail.reset();
|
||||
this.xAjaxResult.always.reset();
|
||||
this.xAjax.reset();
|
||||
|
||||
return this.definition.fn($, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
this.xAjax.restore();
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div id="content"/>').appendTo('body');
|
||||
});
|
||||
|
||||
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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('adds HTML #login-wrapper', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #login-wrapper'), 1);
|
||||
});
|
||||
|
||||
describe('no admin', function () {
|
||||
|
||||
it('adds HTML #pass', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #pass'), 1);
|
||||
});
|
||||
|
||||
it('sets #pass val to empty string', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#login-wrapper > #pass').val(), '');
|
||||
});
|
||||
|
||||
it('adds HTML #login', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #login'), 1);
|
||||
});
|
||||
|
||||
it('does not add HTML #logout', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #logout'), 0);
|
||||
});
|
||||
|
||||
it('does not add HTML #tests', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #tests'), 0);
|
||||
});
|
||||
|
||||
it('login works', function () {
|
||||
|
||||
var pass = util.uniqId();
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
$('#pass').val(pass);
|
||||
$('#login').trigger('click');
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: 'server/php/index.php',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: {
|
||||
action: 'login',
|
||||
pass: pass
|
||||
}
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('as admin', function () {
|
||||
|
||||
it('does not add HTML #pass', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #pass'), 0);
|
||||
});
|
||||
|
||||
it('does not add #login', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #login'), 0);
|
||||
});
|
||||
|
||||
it('adds HTML #logout', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #logout'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #tests', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #tests'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #test (14x)', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#tests > .test').length, 14);
|
||||
});
|
||||
|
||||
it('logout works', function () {
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
$('#logout').trigger('click');
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: 'server/php/index.php',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: {
|
||||
action: 'logout'
|
||||
}
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
83
test/tests/unit/model/item.js
Normal file
83
test/tests/unit/model/item.js
Normal file
@@ -0,0 +1,83 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'model/item';
|
||||
var DEPS = ['_', 'core/event', 'core/location', 'core/server', 'core/settings', 'core/types'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xTypes = util.uniqObj();
|
||||
this.xEvent = util.uniqObj();
|
||||
this.xSettings = util.uniqObj();
|
||||
this.xServer = util.uniqObj();
|
||||
this.xLocation = util.uniqObj();
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xEvent, this.xLocation, this.xServer, this.xSettings, this.xTypes);
|
||||
};
|
||||
});
|
||||
|
||||
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('.get() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.get);
|
||||
});
|
||||
|
||||
it('.remove() is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.remove);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
48
test/tests/unit/modulejs.js
Normal file
48
test/tests/unit/modulejs.js
Normal file
@@ -0,0 +1,48 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
describe('modulejs', function () {
|
||||
|
||||
it('is global', function () {
|
||||
|
||||
assert.isObject(modulejs);
|
||||
assert.strictEqual(modulejs, window.modulejs);
|
||||
});
|
||||
|
||||
it('.define() is function', function () {
|
||||
|
||||
assert.isFunction(modulejs.define);
|
||||
});
|
||||
|
||||
it('.require() is function', function () {
|
||||
|
||||
assert.isFunction(modulejs.require);
|
||||
});
|
||||
|
||||
it('.state() is function', function () {
|
||||
|
||||
assert.isFunction(modulejs.state);
|
||||
});
|
||||
|
||||
it('.log() is function', function () {
|
||||
|
||||
assert.isFunction(modulejs.log);
|
||||
});
|
||||
|
||||
it('._private is object', function () {
|
||||
|
||||
assert.isObject(modulejs._private);
|
||||
});
|
||||
|
||||
it('has definitions', function () {
|
||||
|
||||
assert.isAbove(_.keys(modulejs._private.definitions).length, 0);
|
||||
});
|
||||
|
||||
it('has no instances', function () {
|
||||
|
||||
assert.lengthOfKeys(modulejs._private.instances, 0);
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
85
test/tests/unit/premisses.js
Normal file
85
test/tests/unit/premisses.js
Normal file
@@ -0,0 +1,85 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
describe('premisses', function () {
|
||||
|
||||
it('window is the global object', function () {
|
||||
|
||||
assert.isObject(window);
|
||||
assert.strictEqual(window, util.GLOBAL);
|
||||
});
|
||||
|
||||
it('util is global object', function () {
|
||||
|
||||
assert.isPlainObject(util);
|
||||
assert.strictEqual(util, window.util);
|
||||
});
|
||||
|
||||
it('util.uniqId() works', function () {
|
||||
|
||||
assert.isFunction(util.uniqId);
|
||||
|
||||
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);
|
||||
|
||||
var uid1 = parseInt(util.uniqObj().uniqId.replace(/\D/g, ''), 10);
|
||||
|
||||
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);
|
||||
|
||||
var uid2 = parseInt(util.uniqObj().uniqId.replace(/\D/g, ''), 10);
|
||||
assert.strictEqual(uid2, uid1 + 15);
|
||||
});
|
||||
|
||||
it('assert.isPlainObject() works', function () {
|
||||
|
||||
assert.isFunction(assert.isPlainObject);
|
||||
|
||||
assert.isPlainObject({});
|
||||
assert.isPlainObject({a: 1});
|
||||
assert.isPlainObject(Object());
|
||||
assert.isPlainObject(new Object());
|
||||
|
||||
assert.throws(function () { assert.isPlainObject(); });
|
||||
assert.throws(function () { assert.isPlainObject(1); });
|
||||
assert.throws(function () { assert.isPlainObject('a'); });
|
||||
assert.throws(function () { assert.isPlainObject(new Date()); });
|
||||
assert.throws(function () { assert.isPlainObject(/a/); });
|
||||
assert.throws(function () { assert.isPlainObject(function () {}); });
|
||||
});
|
||||
|
||||
it('assert.lengthOfKeys() works', function () {
|
||||
|
||||
assert.isFunction(assert.lengthOfKeys);
|
||||
|
||||
assert.lengthOfKeys({}, 0);
|
||||
assert.lengthOfKeys({a: true}, 1);
|
||||
assert.lengthOfKeys({a: true, b: 0, c: undefined}, 3);
|
||||
|
||||
assert.throws(function () { assert.lengthOfKeys(); });
|
||||
assert.throws(function () { assert.lengthOfKeys(1); });
|
||||
assert.throws(function () { assert.lengthOfKeys('a'); });
|
||||
assert.throws(function () { assert.lengthOfKeys({}); });
|
||||
assert.throws(function () { assert.lengthOfKeys({}, 1); });
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
142
test/tests/unit/view/base.js
Normal file
142
test/tests/unit/view/base.js
Normal file
@@ -0,0 +1,142 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'view/base';
|
||||
var DEPS = ['$', 'config'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {setup: {VERSION: util.uniqId()}};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn($, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div ID="fallback"/>').appendTo('body');
|
||||
$('<div id="fallback-hints"/>').appendTo('body');
|
||||
});
|
||||
|
||||
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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('removes HTML #fallback', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#fallback'), 0);
|
||||
});
|
||||
|
||||
it('removes HTML #fallback-hints', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#fallback-hints'), 0);
|
||||
});
|
||||
|
||||
it('adds HTML #topbar', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('body > #topbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #toolbar', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #toolbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #crumbbar', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #crumbbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #main-row', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('body > #main-row'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #sidebar', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#main-row > #sidebar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #backlink', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #backlink'), 1);
|
||||
});
|
||||
|
||||
it('#backlink has correct href', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#backlink').attr('href'), 'http://larsjung.de/h5ai/');
|
||||
});
|
||||
|
||||
it('#backlink has correct title', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#backlink').attr('title'), 'powered by h5ai ' + this.xConfig.setup.VERSION);
|
||||
});
|
||||
|
||||
it('#backlink has correct text', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#backlink > div').eq(0).text(), 'powered');
|
||||
assert.strictEqual($('#backlink > div').eq(1).text(), 'by h5ai');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
129
test/tests/unit/view/content.js
Normal file
129
test/tests/unit/view/content.js
Normal file
@@ -0,0 +1,129 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'view/content';
|
||||
var DEPS = ['_', '$', 'core/event', 'core/format', 'core/location', 'core/resource', 'core/settings'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xSettings = util.uniqObj();
|
||||
this.xResource = {
|
||||
icon: sinon.stub().returns('/some/path/' + util.uniqId() + '-icon.png')
|
||||
};
|
||||
this.xFormat = {
|
||||
formatSize: sinon.stub().returns(util.uniqId()),
|
||||
formatDate: sinon.stub().returns(util.uniqId()),
|
||||
setDefaultMetric: sinon.stub()
|
||||
};
|
||||
this.xEvent = {
|
||||
sub: sinon.stub(),
|
||||
pub: sinon.stub()
|
||||
};
|
||||
this.xLocation = {
|
||||
setLink: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xResource.icon.reset();
|
||||
this.xFormat.formatSize.reset();
|
||||
this.xFormat.formatDate.reset();
|
||||
this.xFormat.setDefaultMetric.reset();
|
||||
this.xEvent.sub.reset();
|
||||
this.xEvent.pub.reset();
|
||||
this.xLocation.setLink.reset();
|
||||
|
||||
return this.definition.fn(_, $, this.xEvent, this.xFormat, this.xLocation, this.xResource, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div id="main-row"/>').appendTo('body');
|
||||
});
|
||||
|
||||
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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('adds HTML #content', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#main-row > #content'), 1);
|
||||
});
|
||||
|
||||
it('sets default metric', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xFormat.setDefaultMetric.calledOnce);
|
||||
});
|
||||
|
||||
it('subscribes to 2 events', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xEvent.sub.calledTwice);
|
||||
});
|
||||
|
||||
it('subscribes to "location.changed"', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual(this.xEvent.sub.firstCall.args[0], 'location.changed');
|
||||
assert.isFunction(this.xEvent.sub.firstCall.args[1]);
|
||||
});
|
||||
|
||||
it('subscribes to "location.refreshed"', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual(this.xEvent.sub.secondCall.args[0], 'location.refreshed');
|
||||
assert.isFunction(this.xEvent.sub.secondCall.args[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
127
test/tests/unit/view/sidebar.js
Normal file
127
test/tests/unit/view/sidebar.js
Normal file
@@ -0,0 +1,127 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'view/sidebar';
|
||||
var DEPS = ['$', 'core/resource', 'core/store'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xResource = {
|
||||
image: sinon.stub().throws('invalid image request')
|
||||
};
|
||||
this.xResource.image.withArgs('back').returns('/some/path/' + util.uniqId() + '-back.png');
|
||||
this.xResource.image.withArgs('sidebar').returns('/some/path/' + util.uniqId() + '-sidebar.png');
|
||||
this.xStore = {
|
||||
get: sinon.stub().returns(false),
|
||||
put: sinon.stub()
|
||||
};
|
||||
this.xStore.get.returns(false);
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xResource.image.reset();
|
||||
this.xStore.get.reset();
|
||||
this.xStore.put.reset();
|
||||
|
||||
return this.definition.fn($, this.xResource, this.xStore);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div id="toolbar"/>').appendTo('body');
|
||||
$('<div id="sidebar"/>').appendTo('body');
|
||||
});
|
||||
|
||||
|
||||
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.instance = this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('adds HTML #sidebar-toggle', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
|
||||
});
|
||||
|
||||
it('toggle works', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#sidebar:visible'), 0);
|
||||
|
||||
this.xStore.get.returns(false).reset();
|
||||
this.xStore.put.reset();
|
||||
|
||||
$('#sidebar-toggle').trigger('click');
|
||||
|
||||
assert.isTrue(this.xStore.get.calledOnce);
|
||||
assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
|
||||
assert.isTrue(this.xStore.put.calledOnce);
|
||||
assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
|
||||
assert.isTrue(this.xStore.put.lastCall.args[1]);
|
||||
|
||||
assert.lengthOf($('#sidebar:visible'), 1);
|
||||
|
||||
this.xStore.get.returns(true).reset();
|
||||
this.xStore.put.reset();
|
||||
|
||||
$('#sidebar-toggle').trigger('click');
|
||||
|
||||
assert.isTrue(this.xStore.get.calledOnce);
|
||||
assert.strictEqual(this.xStore.get.lastCall.args[0], 'sidebarIsVisible');
|
||||
assert.isTrue(this.xStore.put.calledOnce);
|
||||
assert.strictEqual(this.xStore.put.lastCall.args[0], 'sidebarIsVisible');
|
||||
assert.isFalse(this.xStore.put.lastCall.args[1]);
|
||||
|
||||
assert.lengthOf($('#sidebar:visible'), 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
117
test/tests/unit/view/viewmode.js
Normal file
117
test/tests/unit/view/viewmode.js
Normal file
@@ -0,0 +1,117 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'view/viewmode';
|
||||
var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'core/store'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xSettings = {
|
||||
view: {}
|
||||
};
|
||||
this.xResource = {
|
||||
image: sinon.stub().returns('/some/path/' + util.uniqId() + '.png')
|
||||
};
|
||||
this.xStore = {
|
||||
get: sinon.stub(),
|
||||
put: sinon.stub()
|
||||
};
|
||||
this.xEvent = {
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xResource.image.reset();
|
||||
this.xStore.get.reset();
|
||||
this.xStore.put.reset();
|
||||
this.xEvent.sub.reset();
|
||||
|
||||
return this.definition.fn(_, $, this.xEvent, this.xResource, this.xSettings, this.xStore);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div id="sidebar"/>').appendTo('body');
|
||||
});
|
||||
|
||||
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 undefined', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isUndefined(instance);
|
||||
});
|
||||
|
||||
it('adds HTML', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#sidebar > .block > .l10n-view'), 1);
|
||||
});
|
||||
|
||||
it('adds Style', function () {
|
||||
|
||||
var styleTagCount = $('head > style').length;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
||||
});
|
||||
|
||||
it('subscribes to 1 event', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xEvent.sub.calledOnce);
|
||||
});
|
||||
|
||||
it('subscribes to "location.changed"', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.strictEqual(this.xEvent.sub.firstCall.args[0], 'location.changed');
|
||||
assert.isFunction(this.xEvent.sub.firstCall.args[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
Reference in New Issue
Block a user