mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-23 05:52:49 +02:00
Fix a lot eslint errors.
This commit is contained in:
@@ -1,127 +1,104 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/event';
|
||||
var DEPS = ['_'];
|
||||
|
||||
var ID = 'core/event';
|
||||
var DEPS = ['_'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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);
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
describe('application', function () {
|
||||
it('returns plain object with 3 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 3);
|
||||
});
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
describe('.sub()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.sub);
|
||||
});
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
describe('.unsub()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.unsub);
|
||||
});
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
describe('.pub()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.pub);
|
||||
});
|
||||
});
|
||||
|
||||
this.applyFn();
|
||||
describe('works', function () {
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 3 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.sub()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.sub);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.unsub()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.unsub);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.pub()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.pub);
|
||||
});
|
||||
});
|
||||
|
||||
describe('works', function () {
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,221 +1,188 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/format';
|
||||
var DEPS = ['_'];
|
||||
|
||||
var ID = 'core/format';
|
||||
var DEPS = ['_'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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);
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
it('has correct id', function () {
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
it('requires correct', function () {
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
it('args for each request', function () {
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
it('has no instance', function () {
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
|
||||
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('.setDefaultMetric()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultMetric);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formatSize()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatSize);
|
||||
});
|
||||
|
||||
it('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('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(arg + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(false);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
it('inits without errors', function () {
|
||||
this.applyFn();
|
||||
});
|
||||
});
|
||||
|
||||
describe('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(arg + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(true);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setDefaultDateFormat()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultDateFormat);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formatDate()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatDate);
|
||||
});
|
||||
|
||||
it('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');
|
||||
});
|
||||
|
||||
_.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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
|
||||
describe('application', function () {
|
||||
it('returns plain object with 4 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.formatDate(arg1, arg2), exp);
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setDefaultMetric()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultMetric);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formatSize()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatSize);
|
||||
});
|
||||
|
||||
it('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('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(arg + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(false);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('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(arg + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
instance.setDefaultMetric(true);
|
||||
assert.strictEqual(instance.formatSize(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setDefaultDateFormat()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.setDefaultDateFormat);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.formatDate()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.formatDate);
|
||||
});
|
||||
|
||||
it('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');
|
||||
});
|
||||
|
||||
_.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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.formatDate(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,64 +1,49 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/langs';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
var ID = 'core/langs';
|
||||
var DEPS = ['_', 'config'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {langs: uniq.obj()};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
this.xConfig = {langs: uniq.obj()};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with right content', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.deepEqual(instance, this.xConfig.langs);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,309 +1,266 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/location';
|
||||
var DEPS = ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'];
|
||||
|
||||
var ID = 'core/location';
|
||||
var DEPS = ['_', 'core/event', 'core/modernizr', 'core/settings', 'view/notification'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
this.xModernizr = {
|
||||
history: true
|
||||
};
|
||||
this.xSettings = {view: {
|
||||
fastBrowsing: true,
|
||||
unmanagedInNewWindow: true
|
||||
}};
|
||||
this.xEvent = {
|
||||
pub: sinon.stub(),
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.xNotification = {
|
||||
set: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
this.xEvent.pub.reset();
|
||||
this.xEvent.sub.reset();
|
||||
this.xNotification.set.reset();
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xModernizr = {
|
||||
history: true
|
||||
};
|
||||
this.xSettings = {view: {
|
||||
fastBrowsing: true,
|
||||
unmanagedInNewWindow: true
|
||||
}};
|
||||
this.xEvent = {
|
||||
pub: sinon.stub(),
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.xNotification = {
|
||||
set: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xEvent.pub.reset();
|
||||
this.xEvent.sub.reset();
|
||||
this.xNotification.set.reset();
|
||||
|
||||
return this.definition.fn(_, this.xEvent, this.xModernizr, this.xSettings, this.xNotification);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
window.onpopstate = null;
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
window.onpopstate = null;
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
return this.definition.fn(_, this.xEvent, this.xModernizr, this.xSettings, this.xNotification);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
after(function () {
|
||||
window.onpopstate = null;
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
beforeEach(function () {
|
||||
window.onpopstate = null;
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
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('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);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate function when history and fastBrowsing', function () {
|
||||
|
||||
this.xModernizr.history = true;
|
||||
this.xSettings.view.fastBrowsing = true;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isFunction(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when not history and fastBrowsing', function () {
|
||||
|
||||
this.xModernizr.history = false;
|
||||
this.xSettings.view.fastBrowsing = true;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when history and not fastBrowsing', function () {
|
||||
|
||||
this.xModernizr.history = true;
|
||||
this.xSettings.view.fastBrowsing = false;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when not history and not fastBrowsing', function () {
|
||||
|
||||
this.xModernizr.history = false;
|
||||
this.xSettings.view.fastBrowsing = false;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.forceEncoding()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.forceEncoding);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['', ''],
|
||||
['//', '/'],
|
||||
['////', '/'],
|
||||
['//a///b////c//', '/a/b/c/'],
|
||||
['a b', 'a%20b'],
|
||||
['ab ', 'ab%20'],
|
||||
[' ab', '%20ab'],
|
||||
['a!b', 'a%21b'],
|
||||
['a#b', 'a%23b'],
|
||||
['a$b', 'a%24b'],
|
||||
['a&b', 'a%26b'],
|
||||
['a\'b', 'a%27b'],
|
||||
['a(b', 'a%28b'],
|
||||
['a)b', 'a%29b'],
|
||||
['a*b', 'a%2Ab'],
|
||||
['a+b', 'a%2Bb'],
|
||||
['a,b', 'a%2Cb'],
|
||||
['a:b', 'a%3Ab'],
|
||||
['a;b', 'a%3Bb'],
|
||||
['a=b', 'a%3Db'],
|
||||
['a?b', 'a%3Fb'],
|
||||
['a@b', 'a%40b'],
|
||||
['a[b', 'a%5Bb'],
|
||||
['a]b', 'a%5Db']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
|
||||
describe('application', function () {
|
||||
it('returns plain object with 7 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.forceEncoding(arg), exp);
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 7);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate function when history and fastBrowsing', function () {
|
||||
this.xModernizr.history = true;
|
||||
this.xSettings.view.fastBrowsing = true;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isFunction(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when not history and fastBrowsing', function () {
|
||||
this.xModernizr.history = false;
|
||||
this.xSettings.view.fastBrowsing = true;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when history and not fastBrowsing', function () {
|
||||
this.xModernizr.history = true;
|
||||
this.xSettings.view.fastBrowsing = false;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
|
||||
it('sets window.onpopstate to null when not history and not fastBrowsing', function () {
|
||||
this.xModernizr.history = false;
|
||||
this.xSettings.view.fastBrowsing = false;
|
||||
|
||||
assert.isNull(window.onpopstate);
|
||||
this.applyFn();
|
||||
assert.isNull(window.onpopstate);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.forceEncoding()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.forceEncoding);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['', ''],
|
||||
['//', '/'],
|
||||
['////', '/'],
|
||||
['//a///b////c//', '/a/b/c/'],
|
||||
['a b', 'a%20b'],
|
||||
['ab ', 'ab%20'],
|
||||
[' ab', '%20ab'],
|
||||
['a!b', 'a%21b'],
|
||||
['a#b', 'a%23b'],
|
||||
['a$b', 'a%24b'],
|
||||
['a&b', 'a%26b'],
|
||||
['a\'b', 'a%27b'],
|
||||
['a(b', 'a%28b'],
|
||||
['a)b', 'a%29b'],
|
||||
['a*b', 'a%2Ab'],
|
||||
['a+b', 'a%2Bb'],
|
||||
['a,b', 'a%2Cb'],
|
||||
['a:b', 'a%3Ab'],
|
||||
['a;b', 'a%3Bb'],
|
||||
['a=b', 'a%3Db'],
|
||||
['a?b', 'a%3Fb'],
|
||||
['a@b', 'a%40b'],
|
||||
['a[b', 'a%5Bb'],
|
||||
['a]b', 'a%5Db']
|
||||
], function (data) {
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.forceEncoding(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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(), window.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);
|
||||
});
|
||||
|
||||
it('sets href correct', function () {
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: false,
|
||||
isFolder: sinon.stub().returns(false)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.strictEqual($el.attr('href'), item.absHref);
|
||||
});
|
||||
|
||||
it('sets target=\'_blank\' for unmanaged folders', function () {
|
||||
this.xSettings.view.unmanagedInNewWindow = true;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: false,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.strictEqual($el.attr('target'), '_blank');
|
||||
});
|
||||
|
||||
it('does not set target=\'_blank\' for managed folders', function () {
|
||||
this.xSettings.view.unmanagedInNewWindow = true;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: true,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.isUndefined($el.attr('target'));
|
||||
});
|
||||
|
||||
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
|
||||
this.xSettings.view.unmanagedInNewWindow = false;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: true,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.isUndefined($el.attr('target'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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(), window.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);
|
||||
});
|
||||
|
||||
it('sets href correct', function () {
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: false,
|
||||
isFolder: sinon.stub().returns(false)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.strictEqual($el.attr('href'), item.absHref);
|
||||
});
|
||||
|
||||
it('sets target=\'_blank\' for unmanaged folders', function () {
|
||||
|
||||
this.xSettings.view.unmanagedInNewWindow = true;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: false,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.strictEqual($el.attr('target'), '_blank');
|
||||
});
|
||||
|
||||
it('does not set target=\'_blank\' for managed folders', function () {
|
||||
|
||||
this.xSettings.view.unmanagedInNewWindow = true;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: true,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.isUndefined($el.attr('target'));
|
||||
});
|
||||
|
||||
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
|
||||
|
||||
this.xSettings.view.unmanagedInNewWindow = false;
|
||||
|
||||
var $el = $('<a/>');
|
||||
var item = {
|
||||
absHref: uniq.id(),
|
||||
isManaged: true,
|
||||
isFolder: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var setLink = this.applyFn().setLink;
|
||||
setLink($el, item);
|
||||
|
||||
assert.isUndefined($el.attr('target'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,90 +1,69 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/modernizr';
|
||||
var DEPS = [];
|
||||
|
||||
var ID = 'core/modernizr';
|
||||
var DEPS = [];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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);
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn();
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
describe('application', function () {
|
||||
it('returns plain object with 3 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOf(_.keys(instance), 3);
|
||||
});
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
describe('.canvas', function () {
|
||||
it('is boolean', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.canvas);
|
||||
});
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
describe('.history', function () {
|
||||
it('is boolean', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.history);
|
||||
});
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
describe('.localstorage', function () {
|
||||
it('is boolean', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.localstorage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 3 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOf(_.keys(instance), 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.canvas', function () {
|
||||
|
||||
it('is boolean', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.canvas);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.history', function () {
|
||||
|
||||
it('is boolean', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.history);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.localstorage', function () {
|
||||
|
||||
it('is boolean', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isBoolean(instance.localstorage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,113 +1,92 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/resource';
|
||||
var DEPS = ['_', 'config', 'core/settings'];
|
||||
|
||||
var ID = 'core/resource';
|
||||
var DEPS = ['_', 'config', 'core/settings'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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 = {publicHref: uniq.path('/publicHref/')};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
this.xConfig = {
|
||||
theme: {
|
||||
a: 'myTheme/a.svg',
|
||||
b: 'myTheme/b.jpg'
|
||||
}
|
||||
};
|
||||
this.xSettings = {publicHref: uniq.path('/publicHref/')};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_, this.xConfig, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
describe('application', function () {
|
||||
it('returns plain object with 2 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
describe('.image()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.image);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
it('works', function () {
|
||||
var instance = this.applyFn();
|
||||
var ui = this.xSettings.publicHref + '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('has no instance', function () {
|
||||
describe('.icon()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.icon);
|
||||
});
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
});
|
||||
it('works', function () {
|
||||
var instance = this.applyFn();
|
||||
var themes = this.xSettings.publicHref + 'images/themes/';
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.image()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.image);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
var ui = this.xSettings.publicHref + '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');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.icon()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.icon);
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
var themes = this.xSettings.publicHref + '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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,193 +1,169 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/server';
|
||||
var DEPS = ['_', '$'];
|
||||
var $submitEl;
|
||||
|
||||
var ID = 'core/server';
|
||||
var DEPS = ['_', '$'];
|
||||
var $submitEl;
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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 () {
|
||||
|
||||
$submitEl = this;
|
||||
return this;
|
||||
});
|
||||
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xAjaxResult.done.reset();
|
||||
this.xAjaxResult.fail.reset();
|
||||
this.xAjaxResult.always.reset();
|
||||
this.xAjax.reset();
|
||||
this.xSubmit.reset();
|
||||
$submitEl = undefined;
|
||||
|
||||
return this.definition.fn(_, $);
|
||||
};
|
||||
});
|
||||
|
||||
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 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.request()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.request);
|
||||
});
|
||||
|
||||
it('done() works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = uniq.obj();
|
||||
var xResult = uniq.obj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: '?',
|
||||
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 () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = uniq.obj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: '?',
|
||||
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('works', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = {
|
||||
a: uniq.id(),
|
||||
b: uniq.id()
|
||||
this.xAjaxResult = {
|
||||
done: sinon.stub().returnsThis(),
|
||||
fail: sinon.stub().returnsThis(),
|
||||
always: sinon.stub().returnsThis()
|
||||
};
|
||||
var res = instance.formRequest(xData);
|
||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
||||
this.xSubmit = sinon.stub($.fn, 'submit', function () {
|
||||
$submitEl = this;
|
||||
return this;
|
||||
});
|
||||
|
||||
assert.isUndefined(res);
|
||||
this.applyFn = function () {
|
||||
this.xAjaxResult.done.reset();
|
||||
this.xAjaxResult.fail.reset();
|
||||
this.xAjaxResult.always.reset();
|
||||
this.xAjax.reset();
|
||||
this.xSubmit.reset();
|
||||
$submitEl = undefined;
|
||||
|
||||
assert.isTrue(this.xSubmit.calledOnce);
|
||||
return this.definition.fn(_, $);
|
||||
};
|
||||
});
|
||||
|
||||
assert.lengthOf($submitEl, 1);
|
||||
assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
|
||||
assert.strictEqual($submitEl.attr('method'), 'post');
|
||||
assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
|
||||
assert.strictEqual($submitEl.attr('action'), '?');
|
||||
after(function () {
|
||||
this.xAjax.restore();
|
||||
this.xSubmit.restore();
|
||||
});
|
||||
|
||||
var $children = $submitEl.children();
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.lengthOf($children, 2);
|
||||
it('has correct id', function () {
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
});
|
||||
|
||||
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);
|
||||
it('requires correct', function () {
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
});
|
||||
|
||||
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);
|
||||
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('.request()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.request);
|
||||
});
|
||||
|
||||
it('done() works', function () {
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = uniq.obj();
|
||||
var xResult = uniq.obj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: '?',
|
||||
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 () {
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = uniq.obj();
|
||||
var spy = sinon.spy();
|
||||
var res = instance.request(xData, spy);
|
||||
|
||||
assert.isUndefined(res);
|
||||
assert.isTrue(this.xAjax.calledOnce);
|
||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||
url: '?',
|
||||
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('works', function () {
|
||||
var instance = this.applyFn();
|
||||
|
||||
var xData = {
|
||||
a: uniq.id(),
|
||||
b: uniq.id()
|
||||
};
|
||||
var res = instance.formRequest(xData);
|
||||
|
||||
assert.isUndefined(res);
|
||||
|
||||
assert.isTrue(this.xSubmit.calledOnce);
|
||||
|
||||
assert.lengthOf($submitEl, 1);
|
||||
assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
|
||||
assert.strictEqual($submitEl.attr('method'), 'post');
|
||||
assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
|
||||
assert.strictEqual($submitEl.attr('action'), '?');
|
||||
|
||||
var $children = $submitEl.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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,104 +1,83 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/settings';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
var ID = 'core/settings';
|
||||
var DEPS = ['_', 'config'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
options: {
|
||||
someOptions: uniq.obj(),
|
||||
otherOptions: uniq.obj(),
|
||||
more: uniq.obj()
|
||||
},
|
||||
setup: {
|
||||
PUBLIC_HREF: uniq.id(),
|
||||
ROOT_HREF: uniq.id()
|
||||
}
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
this.xConfig = {
|
||||
options: {
|
||||
someOptions: uniq.obj(),
|
||||
otherOptions: uniq.obj(),
|
||||
more: uniq.obj()
|
||||
},
|
||||
setup: {
|
||||
PUBLIC_HREF: uniq.id(),
|
||||
ROOT_HREF: uniq.id()
|
||||
}
|
||||
};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
describe('application', function () {
|
||||
it('returns plain object with properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.isAbove(_.keys(instance).length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
describe('publics', function () {
|
||||
it('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 + 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
describe('.publicHref', function () {
|
||||
it('set correct', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.publicHref, this.xConfig.setup.PUBLIC_HREF);
|
||||
});
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
|
||||
this.applyFn();
|
||||
describe('.rootHref', function () {
|
||||
it('set correct', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.rootHref, this.xConfig.setup.ROOT_HREF);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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('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 + 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.publicHref', function () {
|
||||
|
||||
it('set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.publicHref, this.xConfig.setup.PUBLIC_HREF);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.rootHref', function () {
|
||||
|
||||
it('set correct', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.rootHref, this.xConfig.setup.ROOT_HREF);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,131 +1,108 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/store';
|
||||
var DEPS = ['core/modernizr'];
|
||||
|
||||
var ID = 'core/store';
|
||||
var DEPS = ['core/modernizr'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.storeKey = '_h5ai';
|
||||
this.xModernizr = {localstorage: true};
|
||||
this.applyFn = function () {
|
||||
|
||||
return this.definition.fn(this.xModernizr);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
describe('definition', function () {
|
||||
|
||||
it('is defined', function () {
|
||||
|
||||
assert.isPlainObject(this.definition);
|
||||
this.storeKey = '_h5ai';
|
||||
this.xModernizr = {localstorage: true};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(this.xModernizr);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
it('requires correct', function () {
|
||||
|
||||
assert.deepEqual(this.definition.deps, DEPS);
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
it('args for each request', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
|
||||
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('has no instance', function () {
|
||||
|
||||
assert.notProperty(modulejs._private.instances, ID);
|
||||
describe('application', function () {
|
||||
it('returns plain object with 2 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('inits without errors', function () {
|
||||
describe('.put()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.put);
|
||||
});
|
||||
});
|
||||
|
||||
this.applyFn();
|
||||
describe('.get()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.get);
|
||||
});
|
||||
});
|
||||
|
||||
describe('works', function () {
|
||||
it('works', function () {
|
||||
var key1 = 'test1';
|
||||
var value1 = '1234';
|
||||
var key2 = 'test2';
|
||||
var value2 = '5678';
|
||||
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"}');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('application', function () {
|
||||
|
||||
it('returns plain object with 2 properties', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.put()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.put);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.get()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.get);
|
||||
});
|
||||
});
|
||||
|
||||
describe('works', function () {
|
||||
|
||||
it('works', function () {
|
||||
|
||||
var key1 = 'test1';
|
||||
var value1 = '1234';
|
||||
var key2 = 'test2';
|
||||
var value2 = '5678';
|
||||
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"}');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,103 +1,84 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/types';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
var ID = 'core/types';
|
||||
var DEPS = ['_', 'config'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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);
|
||||
this.xConfig = {types: {
|
||||
a: ['*.a', '*.aa'],
|
||||
b: ['*.b'],
|
||||
c: ['*.c']
|
||||
}};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_, this.xConfig);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('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('.getType()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getType);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['file.a', 'a'],
|
||||
['file.aa', 'a'],
|
||||
['foo.b', 'b'],
|
||||
['some/path/file.c', 'c'],
|
||||
['/some/abs/path/file.c', 'c'],
|
||||
['file.x', 'file'],
|
||||
['foo', 'file'],
|
||||
['some/path/foo', 'file'],
|
||||
['/some/path/foo', 'file'],
|
||||
['foo/', 'folder'],
|
||||
['/', 'folder'],
|
||||
['some/path/foo/', 'folder'],
|
||||
['/some/path/foo/', 'folder']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
|
||||
describe('application', function () {
|
||||
it('returns plain object with 1 property', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.getType(arg), exp);
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getType()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.getType);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['file.a', 'a'],
|
||||
['file.aa', 'a'],
|
||||
['foo.b', 'b'],
|
||||
['some/path/file.c', 'c'],
|
||||
['/some/abs/path/file.c', 'c'],
|
||||
['file.x', 'file'],
|
||||
['foo', 'file'],
|
||||
['some/path/foo', 'file'],
|
||||
['/some/path/foo', 'file'],
|
||||
['foo/', 'folder'],
|
||||
['/', 'folder'],
|
||||
['some/path/foo/', 'folder'],
|
||||
['/some/path/foo/', 'folder']
|
||||
], function (data) {
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.getType(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
@@ -1,232 +1,201 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
var ID = 'core/util';
|
||||
var DEPS = ['_'];
|
||||
|
||||
var ID = 'core/util';
|
||||
var DEPS = ['_'];
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
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);
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn(_);
|
||||
};
|
||||
});
|
||||
|
||||
it('has correct id', function () {
|
||||
describe('definition', function () {
|
||||
it('is defined', function () {
|
||||
assert.isPlainObject(this.definition);
|
||||
});
|
||||
|
||||
assert.strictEqual(this.definition.id, ID);
|
||||
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('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('.regularCmpFn()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.regularCmpFn);
|
||||
});
|
||||
|
||||
_.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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
|
||||
describe('application', function () {
|
||||
it('returns plain object with 4 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.regularCmpFn()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.regularCmpFn);
|
||||
});
|
||||
|
||||
_.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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.naturalCmpFn()', function () {
|
||||
it('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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.escapePattern()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.escapePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', 'a'],
|
||||
['1', '1'],
|
||||
['ä', 'ä'],
|
||||
['~', '~'],
|
||||
[':', ':'],
|
||||
['_', '_'],
|
||||
['<', '<'],
|
||||
['-', '\\-'],
|
||||
['[', '\\['],
|
||||
[']', '\\]'],
|
||||
['{', '\\{'],
|
||||
['}', '\\}'],
|
||||
['(', '\\('],
|
||||
[')', '\\)'],
|
||||
['*', '\\*'],
|
||||
['+', '\\+'],
|
||||
['?', '\\?'],
|
||||
['.', '\\.'],
|
||||
[',', '\\,'],
|
||||
['\\', '\\\\'],
|
||||
['$', '\\$'],
|
||||
['^', '\\^'],
|
||||
['|', '\\|'],
|
||||
['#', '\\#'],
|
||||
[' ', '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', 'abc123'],
|
||||
['a.b+c*1', 'a\\.b\\+c\\*1']
|
||||
], function (data) {
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.escapePattern(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.parsePattern()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.parsePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', false, 'a'],
|
||||
['1', false, '1'],
|
||||
['ä', false, 'ä'],
|
||||
['~', false, '~'],
|
||||
[':', false, ':'],
|
||||
['_', false, '_'],
|
||||
['<', false, '<'],
|
||||
['-', false, '\\-'],
|
||||
['[', false, '\\['],
|
||||
[']', false, '\\]'],
|
||||
['{', false, '\\{'],
|
||||
['}', false, '\\}'],
|
||||
['(', false, '\\('],
|
||||
[')', false, '\\)'],
|
||||
['*', false, '\\*'],
|
||||
['+', false, '\\+'],
|
||||
['?', false, '\\?'],
|
||||
['.', false, '\\.'],
|
||||
[',', false, '\\,'],
|
||||
['\\', false, '\\\\'],
|
||||
['$', false, '\\$'],
|
||||
['^', false, '\\^'],
|
||||
['|', false, '\\|'],
|
||||
['#', false, '\\#'],
|
||||
[' ', false, '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', false, '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', false, 'abc123'],
|
||||
['a.b+c*1', false, 'a\\.b\\+c\\*1'],
|
||||
|
||||
['abc', true, 'a.*?b.*?c'],
|
||||
['abc def', true, 'a.*?b.*?c|d.*?e.*?f'],
|
||||
['*#a b.=', true, '\\*.*?\\#.*?a|b.*?\\..*?='],
|
||||
['re:.', true, '.'],
|
||||
[' .', true, '\\.'],
|
||||
['re: .', true, ' .']
|
||||
|
||||
], function (data) {
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.parsePattern(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.naturalCmpFn()', function () {
|
||||
|
||||
it('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(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.escapePattern()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.escapePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', 'a'],
|
||||
['1', '1'],
|
||||
['ä', 'ä'],
|
||||
['~', '~'],
|
||||
[':', ':'],
|
||||
['_', '_'],
|
||||
['<', '<'],
|
||||
['-', '\\-'],
|
||||
['[', '\\['],
|
||||
[']', '\\]'],
|
||||
['{', '\\{'],
|
||||
['}', '\\}'],
|
||||
['(', '\\('],
|
||||
[')', '\\)'],
|
||||
['*', '\\*'],
|
||||
['+', '\\+'],
|
||||
['?', '\\?'],
|
||||
['.', '\\.'],
|
||||
[',', '\\,'],
|
||||
['\\', '\\\\'],
|
||||
['$', '\\$'],
|
||||
['^', '\\^'],
|
||||
['|', '\\|'],
|
||||
['#', '\\#'],
|
||||
[' ', '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', 'abc123'],
|
||||
['a.b+c*1', 'a\\.b\\+c\\*1']
|
||||
], function (data) {
|
||||
|
||||
var arg = data[0];
|
||||
var exp = data[1];
|
||||
|
||||
it(arg + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.escapePattern(arg), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.parsePattern()', function () {
|
||||
|
||||
it('is function', function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.parsePattern);
|
||||
});
|
||||
|
||||
_.each([
|
||||
['a', false, 'a'],
|
||||
['1', false, '1'],
|
||||
['ä', false, 'ä'],
|
||||
['~', false, '~'],
|
||||
[':', false, ':'],
|
||||
['_', false, '_'],
|
||||
['<', false, '<'],
|
||||
['-', false, '\\-'],
|
||||
['[', false, '\\['],
|
||||
[']', false, '\\]'],
|
||||
['{', false, '\\{'],
|
||||
['}', false, '\\}'],
|
||||
['(', false, '\\('],
|
||||
[')', false, '\\)'],
|
||||
['*', false, '\\*'],
|
||||
['+', false, '\\+'],
|
||||
['?', false, '\\?'],
|
||||
['.', false, '\\.'],
|
||||
[',', false, '\\,'],
|
||||
['\\', false, '\\\\'],
|
||||
['$', false, '\\$'],
|
||||
['^', false, '\\^'],
|
||||
['|', false, '\\|'],
|
||||
['#', false, '\\#'],
|
||||
[' ', false, '\\ '],
|
||||
['-[]{}()*+?.,\\$^|# ', false, '\\-\\[\\]\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\\$\\^\\|\\#\\ '],
|
||||
['abc123', false, 'abc123'],
|
||||
['a.b+c*1', false, 'a\\.b\\+c\\*1'],
|
||||
|
||||
['abc', true, 'a.*?b.*?c'],
|
||||
['abc def', true, 'a.*?b.*?c|d.*?e.*?f'],
|
||||
['*#a b.=', true, '\\*.*?\\#.*?a|b.*?\\..*?='],
|
||||
['re:.', true, '.'],
|
||||
[' .', true, '\\.'],
|
||||
['re: .', true, ' .']
|
||||
|
||||
], function (data) {
|
||||
|
||||
var arg1 = data[0];
|
||||
var arg2 = data[1];
|
||||
var exp = data[2];
|
||||
|
||||
it(arg1 + ', ' + arg2 + ' => ' + exp, function () {
|
||||
|
||||
var instance = this.applyFn();
|
||||
assert.strictEqual(instance.parsePattern(arg1, arg2), exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
|
Reference in New Issue
Block a user