mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-01 07:48:20 -04:00
Clean up tests.
This commit is contained in:
parent
c4fa90a747
commit
3a2e61b163
53 changed files with 70 additions and 22837 deletions
|
@ -1,106 +0,0 @@
|
|||
(function () {
|
||||
describe('view', function () {
|
||||
before(function () {
|
||||
this.configBackup = modulejs._private.definitions.config;
|
||||
this.storeKey = '_h5ai';
|
||||
this.xConfig = {
|
||||
setup: {
|
||||
PUBLIC_HREF: uniq.path('-PUBLIC/'),
|
||||
ROOT_HREF: uniq.path('-ROOT/')
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
modulejs._private.definitions.config = this.configBackup;
|
||||
util.clearModulejs();
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
delete modulejs._private.definitions.config;
|
||||
modulejs.define('config', this.xConfig);
|
||||
util.clearModulejs();
|
||||
util.restoreHtml();
|
||||
$('<div id="fallback"/>').appendTo('body');
|
||||
$('<div id="fallback-hints"/>').appendTo('body');
|
||||
});
|
||||
|
||||
describe('requiring \'view/viewmode\' sets up basic HTML', function () {
|
||||
it('runs without errors', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
});
|
||||
|
||||
it('adds id root to body', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.strictEqual($('body').attr('id'), 'root');
|
||||
});
|
||||
|
||||
it('removes HTML #fallback', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#fallback'), 0);
|
||||
});
|
||||
|
||||
it('removes HTML #fallback-hints', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#fallback-hints'), 0);
|
||||
});
|
||||
|
||||
it('adds HTML #mainrow to #root', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#root > #mainrow'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #content to #mainrow', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#mainrow > #content'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #view to #content', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#content > #view'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #items to #view', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#view > #items'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #topbar to #root', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#root > #topbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #toolbar to #topbar', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#topbar > #toolbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #flowbar to #topbar', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#topbar > #flowbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #backlink to #topbar', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#topbar > #backlink'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #sidebar-toggle to #toolbar', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#toolbar > #sidebar-toggle'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #viewmode-settings to #sidebar', function () {
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
|
||||
});
|
||||
|
||||
it('adds style to head', function () {
|
||||
var styleTagCount = $('head > style').length;
|
||||
modulejs.require('view/viewmode');
|
||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,69 +1,21 @@
|
|||
(function () {
|
||||
describe('premisses', function () {
|
||||
it('window is global object', function () {
|
||||
assert.isObject(window);
|
||||
assert.strictEqual(window, window.window);
|
||||
});
|
||||
const {test, assert} = require('scar');
|
||||
|
||||
it('document is global object', function () {
|
||||
assert.isObject(document);
|
||||
assert.strictEqual(document, window.document);
|
||||
});
|
||||
test('window is global object', () => {
|
||||
assert.equal(typeof global, 'object');
|
||||
assert.equal(global, global.window);
|
||||
});
|
||||
|
||||
it('jQuery and $ are global functions', function () {
|
||||
assert.isFunction(jQuery);
|
||||
assert.strictEqual(jQuery, window.jQuery);
|
||||
assert.strictEqual(jQuery.fn.jquery, '2.2.4');
|
||||
test('document is global object', () => {
|
||||
assert.equal(typeof global.document, 'object');
|
||||
});
|
||||
|
||||
assert.strictEqual($, jQuery);
|
||||
assert.strictEqual($, window.$);
|
||||
});
|
||||
test('jQuery and $ are global functions', () => {
|
||||
assert.equal(typeof global.jQuery, 'function');
|
||||
assert.equal(global.jQuery.fn.jquery, '2.2.4');
|
||||
assert.equal(global.jQuery, global.$);
|
||||
});
|
||||
|
||||
it('_ is global function', function () {
|
||||
assert.isFunction(_);
|
||||
assert.strictEqual(_, window._);
|
||||
assert.strictEqual(_.VERSION, '4.13.1');
|
||||
});
|
||||
|
||||
it('util is global object', function () {
|
||||
assert.isPlainObject(util);
|
||||
assert.strictEqual(util, window.util);
|
||||
});
|
||||
|
||||
it('uniq is global object', function () {
|
||||
assert.isPlainObject(uniq);
|
||||
assert.strictEqual(uniq, window.uniq);
|
||||
});
|
||||
|
||||
it('assert.isPlainObject() works', function () {
|
||||
assert.isFunction(assert.isPlainObject);
|
||||
|
||||
assert.isPlainObject({});
|
||||
assert.isPlainObject({a: 1});
|
||||
assert.isPlainObject(Object());
|
||||
assert.isPlainObject(new Object()); // eslint-disable-line no-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 () {}); });
|
||||
assert.throws(function () { assert.isPlainObject(new function A() {}); });
|
||||
});
|
||||
|
||||
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); });
|
||||
});
|
||||
});
|
||||
}());
|
||||
test('_ is global function', () => {
|
||||
assert.equal(typeof global._, 'function');
|
||||
assert.equal(global._.VERSION, '4.13.1');
|
||||
});
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'boot';
|
||||
var DEPS = ['$', 'core/server'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = uniq.obj();
|
||||
this.xDefine = sinon.stub(modulejs, 'define');
|
||||
this.xRequire = sinon.stub(modulejs, 'require');
|
||||
this.xServer = {
|
||||
request: sinon.stub().callsArgWith(1, this.xConfig)
|
||||
};
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xDefine.reset();
|
||||
this.xRequire.reset();
|
||||
this.xServer.request.reset();
|
||||
|
||||
return this.definition.fn($, this.xServer);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
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.xServer.request.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.xServer.request.called);
|
||||
assert.isFalse(this.xDefine.called);
|
||||
assert.isFalse(this.xRequire.called);
|
||||
});
|
||||
|
||||
it('data-module=\'info\'', function () {
|
||||
var expectedData = {
|
||||
action: 'get',
|
||||
setup: true,
|
||||
options: true,
|
||||
types: true,
|
||||
refresh: true
|
||||
};
|
||||
|
||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
||||
|
||||
this.applyFn();
|
||||
|
||||
assert.isTrue(this.xServer.request.calledOnce);
|
||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||
|
||||
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 () {
|
||||
var expectedData = {
|
||||
action: 'get',
|
||||
setup: true,
|
||||
options: true,
|
||||
types: true,
|
||||
theme: true,
|
||||
langs: true
|
||||
};
|
||||
|
||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
||||
|
||||
this.applyFn();
|
||||
|
||||
assert.isTrue(this.xServer.request.calledOnce);
|
||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||
|
||||
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']);
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,47 +0,0 @@
|
|||
(function () {
|
||||
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(uniq.isId(instance._uniq_id));
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,104 +0,0 @@
|
|||
(function () {
|
||||
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('.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,188 +0,0 @@
|
|||
(function () {
|
||||
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('.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,49 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'core/langs';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,266 +0,0 @@
|
|||
(function () {
|
||||
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];
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,69 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'core/modernizr';
|
||||
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.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,92 +0,0 @@
|
|||
(function () {
|
||||
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 = {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);
|
||||
});
|
||||
|
||||
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('.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,169 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'core/server';
|
||||
var DEPS = ['_', '$'];
|
||||
var $submitEl;
|
||||
|
||||
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()
|
||||
};
|
||||
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,83 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'core/settings';
|
||||
var DEPS = ['_', 'config'];
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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('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,108 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'core/store';
|
||||
var DEPS = ['core/modernizr'];
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
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('.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,84 +0,0 @@
|
|||
(function () {
|
||||
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('.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,201 +0,0 @@
|
|||
(function () {
|
||||
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 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 () {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,104 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'ext/title';
|
||||
var DEPS = ['_', 'core/event', 'core/settings'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xEvent = {
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.xSettings = {title: {
|
||||
enabled: true
|
||||
}};
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xEvent.sub.reset();
|
||||
|
||||
return this.definition.fn(_, this.xEvent, this.xSettings);
|
||||
};
|
||||
});
|
||||
|
||||
after(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('subscribes to location.changed', function () {
|
||||
this.xSettings.title.enabled = true;
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xEvent.sub.calledOnce);
|
||||
assert.strictEqual(this.xEvent.sub.lastCall.args[0], 'location.changed');
|
||||
});
|
||||
|
||||
it('does not subscribe to events if disabled', function () {
|
||||
this.xSettings.title.enabled = false;
|
||||
|
||||
this.applyFn();
|
||||
assert.isFalse(this.xEvent.sub.called);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sets title on location.changed', function () {
|
||||
_.each([
|
||||
[''],
|
||||
['a', 'a'],
|
||||
['a', 'b', 'b - a > b'],
|
||||
['a', 'b', 'c', 'c - a > b > c']
|
||||
], function (data) {
|
||||
var labels = data.slice(0, -1);
|
||||
var exp = data.slice(-1)[0];
|
||||
|
||||
it(labels + ' => ' + exp, function () {
|
||||
this.xSettings.title.enabled = true;
|
||||
|
||||
this.applyFn();
|
||||
|
||||
var fn = this.xEvent.sub.lastCall.args[1];
|
||||
var crumb = _.map(labels, function (x) { return {label: x}; });
|
||||
var item = {
|
||||
getCrumb: sinon.stub().returns(crumb)
|
||||
};
|
||||
|
||||
fn(item);
|
||||
|
||||
assert.isTrue(item.getCrumb.calledOnce);
|
||||
assert.strictEqual(document.title, exp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,29 +0,0 @@
|
|||
(function () {
|
||||
describe('libs', function () {
|
||||
var libs = {
|
||||
_: window._,
|
||||
$: window.jQuery,
|
||||
marked: window.marked,
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,102 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'main/index';
|
||||
var DEPS = ['_', 'core/location'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xLocation = {setLocation: sinon.stub()};
|
||||
this.xRequire = sinon.stub(modulejs, 'require');
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xLocation.setLocation.reset();
|
||||
this.xRequire.reset();
|
||||
return this.definition.fn(_, this.xLocation);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
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('requires view/viewmode', function () {
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xRequire.calledWithExactly('view/viewmode'));
|
||||
});
|
||||
|
||||
it('requires all extensions', function () {
|
||||
this.applyFn();
|
||||
var re = /^ext\//;
|
||||
var self = this;
|
||||
|
||||
_.each(modulejs.state(), function (state, id) {
|
||||
if (re.test(id)) {
|
||||
assert.isTrue(self.xRequire.calledWithExactly(id));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('requires only views and extensions', function () {
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xRequire.alwaysCalledWithMatch(/^(view|ext)\//));
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('calls setLocation with current href, keeping browser url', function () {
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xLocation.setLocation.calledOnce);
|
||||
assert.deepEqual(this.xLocation.setLocation.firstCall.args, [document.location.href, true]);
|
||||
assert.isTrue(this.xLocation.setLocation.calledAfter(this.xRequire));
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,180 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'main/info';
|
||||
var DEPS = ['$', 'config', 'core/resource', 'core/server'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xConfig = {
|
||||
setup: {
|
||||
VERSION: uniq.id()
|
||||
},
|
||||
options: {}
|
||||
};
|
||||
this.xResource = {
|
||||
image: sinon.stub()
|
||||
};
|
||||
this.xServer = {
|
||||
request: sinon.stub()
|
||||
};
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xServer.request.reset();
|
||||
|
||||
return this.definition.fn($, this.xConfig, this.xResource, this.xServer);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
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 #support to #content', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #support'), 1);
|
||||
assert.lengthOf($('#support > .paypal'), 1);
|
||||
assert.lengthOf($('.paypal > form'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #login-wrapper to #content', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #login-wrapper'), 1);
|
||||
});
|
||||
|
||||
describe('no admin', function () {
|
||||
it('adds HTML #pass to #login-wrapper', 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 to #login-wrapper', function () {
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #login'), 1);
|
||||
});
|
||||
|
||||
it('does not add HTML #logout to #login-wrapper', function () {
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #logout'), 0);
|
||||
});
|
||||
|
||||
it('does not add HTML #tests to #content', function () {
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #tests'), 0);
|
||||
});
|
||||
|
||||
it('login works', function () {
|
||||
var pass = uniq.id();
|
||||
var expectedData = {
|
||||
action: 'login',
|
||||
pass: pass
|
||||
};
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = false;
|
||||
this.applyFn();
|
||||
$('#pass').val(pass);
|
||||
$('#login').trigger('click');
|
||||
|
||||
assert.isTrue(this.xServer.request.calledOnce);
|
||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('as admin', function () {
|
||||
it('does not add HTML #pass to #login-wrapper', function () {
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #pass'), 0);
|
||||
});
|
||||
|
||||
it('does not add #login to #login-wrapper', function () {
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #login'), 0);
|
||||
});
|
||||
|
||||
it('adds HTML #logout to #login-wrapper', function () {
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#login-wrapper > #logout'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #tests to #content', function () {
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #tests'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #test 15x to #tests', function () {
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#tests > .test').length, 15);
|
||||
});
|
||||
|
||||
it('logout works', function () {
|
||||
var expectedData = {
|
||||
action: 'logout'
|
||||
};
|
||||
|
||||
this.xConfig.setup.AS_ADMIN = true;
|
||||
this.applyFn();
|
||||
$('#logout').trigger('click');
|
||||
|
||||
assert.isTrue(this.xServer.request.calledOnce);
|
||||
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,356 +0,0 @@
|
|||
(function () {
|
||||
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.xRootName = uniq.id();
|
||||
this.xTypes = {
|
||||
getType: sinon.stub().returns(uniq.id())
|
||||
};
|
||||
this.xEvent = uniq.obj();
|
||||
this.xSettings = {
|
||||
rootHref: uniq.path('/' + this.xRootName + '/')
|
||||
};
|
||||
this.xServer = uniq.obj();
|
||||
this.xLocation = {
|
||||
forceEncoding: sinon.stub().returnsArg(0),
|
||||
getDomain: sinon.stub().returns(uniq.id()),
|
||||
getAbsHref: sinon.stub().returns(uniq.id())
|
||||
};
|
||||
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('.get()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.get);
|
||||
});
|
||||
|
||||
it('returns null with no argument', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isNull(instance.get());
|
||||
});
|
||||
|
||||
it('returns null for no string argument', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isNull(instance.get(1));
|
||||
});
|
||||
|
||||
it('returns null for href not starting with rootHref', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isNull(instance.get('/a/'));
|
||||
});
|
||||
|
||||
describe('for rootHref', function () {
|
||||
beforeEach(function () {
|
||||
var instance = this.applyFn();
|
||||
this.item = instance.get(this.xSettings.rootHref);
|
||||
});
|
||||
|
||||
it('returns object', function () {
|
||||
assert.isObject(this.item);
|
||||
});
|
||||
|
||||
it('sets href correct', function () {
|
||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref);
|
||||
});
|
||||
|
||||
it('sets type correct', function () {
|
||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
||||
});
|
||||
|
||||
it('sets label correct', function () {
|
||||
assert.strictEqual(this.item.label, this.xRootName);
|
||||
});
|
||||
|
||||
it('sets time to null', function () {
|
||||
assert.isNull(this.item.time);
|
||||
});
|
||||
|
||||
it('sets size to null', function () {
|
||||
assert.isNull(this.item.size);
|
||||
});
|
||||
|
||||
it('sets parent to null', function () {
|
||||
assert.isNull(this.item.parent);
|
||||
});
|
||||
|
||||
it('sets isManaged to null', function () {
|
||||
assert.isNull(this.item.isManaged);
|
||||
});
|
||||
|
||||
it('sets content correct', function () {
|
||||
assert.isPlainObject(this.item.content);
|
||||
assert.lengthOfKeys(this.item.content, 0);
|
||||
});
|
||||
|
||||
it('.isFolder() returns true', function () {
|
||||
assert.isTrue(this.item.isFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isInCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isInCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentParentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentParentFolder());
|
||||
});
|
||||
|
||||
it('.isDomain() returns false', function () {
|
||||
assert.isFalse(this.item.isDomain());
|
||||
});
|
||||
|
||||
it('.isRoot() returns true', function () {
|
||||
assert.isTrue(this.item.isRoot());
|
||||
});
|
||||
|
||||
it('.isEmpty() returns true', function () {
|
||||
assert.isTrue(this.item.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('for folder href other than rootHref', function () {
|
||||
beforeEach(function () {
|
||||
var instance = this.applyFn();
|
||||
this.item = instance.get(this.xSettings.rootHref + 'a/');
|
||||
});
|
||||
|
||||
it('returns object', function () {
|
||||
assert.isObject(this.item);
|
||||
});
|
||||
|
||||
it('sets href correct', function () {
|
||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a/');
|
||||
});
|
||||
|
||||
it('sets type correct', function () {
|
||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
||||
});
|
||||
|
||||
it('sets label correct', function () {
|
||||
assert.strictEqual(this.item.label, 'a');
|
||||
});
|
||||
|
||||
it('sets time to null', function () {
|
||||
assert.isNull(this.item.time);
|
||||
});
|
||||
|
||||
it('sets size to null', function () {
|
||||
assert.isNull(this.item.size);
|
||||
});
|
||||
|
||||
it('sets parent to object', function () {
|
||||
assert.isObject(this.item.parent);
|
||||
});
|
||||
|
||||
it('parent has same constructor', function () {
|
||||
assert.strictEqual(this.item.constructor, this.item.parent.constructor);
|
||||
});
|
||||
|
||||
it('sets isManaged to null', function () {
|
||||
assert.isNull(this.item.isManaged);
|
||||
});
|
||||
|
||||
it('sets content correct', function () {
|
||||
assert.isPlainObject(this.item.content);
|
||||
assert.lengthOfKeys(this.item.content, 0);
|
||||
});
|
||||
|
||||
it('.isFolder() returns true', function () {
|
||||
assert.isTrue(this.item.isFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isInCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isInCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentParentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentParentFolder());
|
||||
});
|
||||
|
||||
it('.isDomain() returns false', function () {
|
||||
assert.isFalse(this.item.isDomain());
|
||||
});
|
||||
|
||||
it('.isRoot() returns false', function () {
|
||||
assert.isFalse(this.item.isRoot());
|
||||
});
|
||||
|
||||
it('.isEmpty() returns true', function () {
|
||||
assert.isTrue(this.item.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('for file href', function () {
|
||||
beforeEach(function () {
|
||||
var instance = this.applyFn();
|
||||
this.item = instance.get(this.xSettings.rootHref + 'a');
|
||||
});
|
||||
|
||||
it('returns object', function () {
|
||||
assert.isObject(this.item);
|
||||
});
|
||||
|
||||
it('sets href correct', function () {
|
||||
assert.strictEqual(this.item.absHref, this.xSettings.rootHref + 'a');
|
||||
});
|
||||
|
||||
it('sets type correct', function () {
|
||||
assert.strictEqual(this.item.type, this.xTypes.getType(this.absHref));
|
||||
});
|
||||
|
||||
it('sets label correct', function () {
|
||||
assert.strictEqual(this.item.label, 'a');
|
||||
});
|
||||
|
||||
it('sets time to null', function () {
|
||||
assert.isNull(this.item.time);
|
||||
});
|
||||
|
||||
it('sets size to null', function () {
|
||||
assert.isNull(this.item.size);
|
||||
});
|
||||
|
||||
it('sets parent to object', function () {
|
||||
assert.isObject(this.item.parent);
|
||||
});
|
||||
|
||||
it('parent has same constructor', function () {
|
||||
assert.strictEqual(this.item.constructor, this.item.parent.constructor);
|
||||
});
|
||||
|
||||
it('sets isManaged to null', function () {
|
||||
assert.isNull(this.item.isManaged);
|
||||
});
|
||||
|
||||
it('sets content correct', function () {
|
||||
assert.isPlainObject(this.item.content);
|
||||
assert.lengthOfKeys(this.item.content, 0);
|
||||
});
|
||||
|
||||
it('.isFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isInCurrentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isInCurrentFolder());
|
||||
});
|
||||
|
||||
it('.isCurrentParentFolder() returns false', function () {
|
||||
assert.isFalse(this.item.isCurrentParentFolder());
|
||||
});
|
||||
|
||||
it('.isDomain() returns false', function () {
|
||||
assert.isFalse(this.item.isDomain());
|
||||
});
|
||||
|
||||
it('.isRoot() returns false', function () {
|
||||
assert.isFalse(this.item.isRoot());
|
||||
});
|
||||
|
||||
it('.isEmpty() returns true', function () {
|
||||
assert.isTrue(this.item.isEmpty());
|
||||
});
|
||||
});
|
||||
|
||||
describe('parents', function () {
|
||||
beforeEach(function () {
|
||||
var instance = this.applyFn();
|
||||
this.item = instance.get(this.xSettings.rootHref + 'p/a/');
|
||||
this.parent = this.item.parent;
|
||||
this.grandpa = this.parent.parent;
|
||||
});
|
||||
|
||||
it('parent is object', function () {
|
||||
assert.isObject(this.parent);
|
||||
});
|
||||
|
||||
it('parent has correct href', function () {
|
||||
assert.strictEqual(this.parent.absHref, this.xSettings.rootHref + 'p/');
|
||||
});
|
||||
|
||||
it('parent has correct label', function () {
|
||||
assert.strictEqual(this.parent.label, 'p');
|
||||
});
|
||||
|
||||
it('parent .isEmpty() returns false', function () {
|
||||
assert.isFalse(this.parent.isEmpty());
|
||||
});
|
||||
|
||||
it('grandpa is object', function () {
|
||||
assert.isObject(this.grandpa);
|
||||
});
|
||||
|
||||
it('grandpa has correct href', function () {
|
||||
assert.strictEqual(this.grandpa.absHref, this.xSettings.rootHref);
|
||||
});
|
||||
|
||||
it('grandpa has correct label', function () {
|
||||
assert.strictEqual(this.grandpa.label, this.xRootName);
|
||||
});
|
||||
|
||||
it('grandpa .isEmpty() returns false', function () {
|
||||
assert.isFalse(this.grandpa.isEmpty());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.remove()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isFunction(instance.remove);
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,36 +0,0 @@
|
|||
(function () {
|
||||
describe('modulejs', function () {
|
||||
it('is global object', function () {
|
||||
assert.isPlainObject(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);
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,73 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/content';
|
||||
var DEPS = ['$', 'view/mainrow'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xMainrow = {$el: null};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn($, this.xMainrow);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xMainrow.$el = $('<div id="mainrow"/>').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 object with 1 property', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
|
||||
it('adds HTML #content to #mainrow', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#mainrow > #content'), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#content\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'content');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,73 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/mainrow';
|
||||
var DEPS = ['$', 'view/root'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xRoot = {$el: null};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn($, this.xRoot);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xRoot.$el = $('<div id="root"/>').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 object with 1 property', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
|
||||
it('adds HTML #mainrow to #root', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#root > #mainrow'), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#mainrow\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'mainrow');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,102 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/notification';
|
||||
var DEPS = ['$', 'view/root'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xRoot = {$el: null};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn($, this.xRoot);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xRoot.$el = $('<div id="root"/>').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 plain object with 2 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 2);
|
||||
});
|
||||
|
||||
it('adds HTML #notification to #root (hidden)', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#root > #notification'), 1);
|
||||
assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), '');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#notification\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'notification');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.set()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.set));
|
||||
});
|
||||
|
||||
it('works', function () {
|
||||
var instance = this.applyFn();
|
||||
|
||||
instance.set();
|
||||
assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), '');
|
||||
|
||||
instance.set('hello');
|
||||
assert.lengthOf($('#notification:visible'), 1);
|
||||
assert.strictEqual($('#notification').text(), 'hello');
|
||||
|
||||
instance.set('world');
|
||||
assert.lengthOf($('#notification:visible'), 1);
|
||||
assert.strictEqual($('#notification').text(), 'world');
|
||||
|
||||
instance.set();
|
||||
// assert.lengthOf($('#notification:visible'), 0);
|
||||
assert.strictEqual($('#notification').text(), 'world');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,83 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/root';
|
||||
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();
|
||||
$('<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 object with 1 property', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
|
||||
it('adds id root to body', function () {
|
||||
this.applyFn();
|
||||
assert.strictEqual($('body').attr('id'), 'root');
|
||||
});
|
||||
|
||||
it('removes HTML #fallback', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#fallback'), 0);
|
||||
});
|
||||
|
||||
it('removes HTML #fallback-hints', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#fallback-hints'), 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#root\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'root');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,121 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/sidebar';
|
||||
var DEPS = ['$', 'core/resource', 'core/store', 'view/mainrow', 'view/topbar'];
|
||||
|
||||
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(uniq.path('-back.png'));
|
||||
this.xResource.image.withArgs('sidebar').returns(uniq.path('-sidebar.png'));
|
||||
this.xStore = {
|
||||
get: sinon.stub().returns(false),
|
||||
put: sinon.stub()
|
||||
};
|
||||
this.xStore.get.returns(false);
|
||||
this.xMainrow = {$el: null};
|
||||
this.xTopbar = {$toolbar: null};
|
||||
this.applyFn = function () {
|
||||
this.xResource.image.reset();
|
||||
this.xStore.get.reset();
|
||||
this.xStore.put.reset();
|
||||
|
||||
return this.definition.fn($, this.xResource, this.xStore, this.xMainrow, this.xTopbar);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xMainrow.$el = $('<div id="mainrow"/>').appendTo('body');
|
||||
this.xTopbar.$toolbar = $('<div id="toolbar"/>').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 object with 1 property', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 1);
|
||||
});
|
||||
|
||||
it('adds HTML #sidebar-toggle to #toolbar', 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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#sidebar\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'sidebar');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,124 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/topbar';
|
||||
var DEPS = ['$', 'view/root'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xRoot = {$el: null};
|
||||
this.applyFn = function () {
|
||||
return this.definition.fn($, this.xRoot);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xRoot.$el = $('<div id="root"/>').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 object with 3 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 3);
|
||||
});
|
||||
|
||||
it('adds HTML #topbar to #root', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#root > #topbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #toolbar to #topbar', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #toolbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #flowbar to #topbar', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #flowbar'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #backlink to #topbar', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#topbar > #backlink'), 1);
|
||||
});
|
||||
|
||||
it('#backlink has correct href', function () {
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#backlink').attr('href'), 'https://larsjung.de/h5ai/');
|
||||
});
|
||||
|
||||
it('#backlink has correct title', function () {
|
||||
this.applyFn();
|
||||
assert.strictEqual($('#backlink').attr('title'), 'powered by h5ai - https://larsjung.de/h5ai/');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#topbar\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'topbar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$toolbar', function () {
|
||||
it('is $(\'#toolbar\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$toolbar);
|
||||
assert.lengthOf(instance.$toolbar, 1);
|
||||
assert.isString(instance.$toolbar.jquery);
|
||||
assert.strictEqual(instance.$toolbar.attr('id'), 'toolbar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$flowbar', function () {
|
||||
it('is $(\'#flowbar\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$flowbar);
|
||||
assert.lengthOf(instance.$flowbar, 1);
|
||||
assert.isString(instance.$flowbar.jquery);
|
||||
assert.strictEqual(instance.$flowbar.attr('id'), 'flowbar');
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
|
@ -1,385 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/view';
|
||||
var DEPS = ['_', '$', 'core/event', 'core/format', 'core/location', 'core/resource', 'core/settings', 'core/store', 'view/content'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xEvent = {
|
||||
sub: sinon.stub(),
|
||||
pub: sinon.stub()
|
||||
};
|
||||
this.xFormat = {
|
||||
setDefaultMetric: sinon.stub(),
|
||||
formatDate: sinon.stub().returns(uniq.id()),
|
||||
formatSize: sinon.stub().returns(uniq.id())
|
||||
};
|
||||
this.xLocation = {
|
||||
setLink: sinon.stub().returns(uniq.id())
|
||||
};
|
||||
this.xResource = {
|
||||
icon: sinon.stub().returns(uniq.id())
|
||||
};
|
||||
this.xSettings = {view: {
|
||||
binaryPrefix: false,
|
||||
hideFolders: false,
|
||||
hideParentFolder: false,
|
||||
modes: ['details', 'grid', 'icons'],
|
||||
setParentFolderLabels: false,
|
||||
sizes: [20, 40, 60, 80, 100, 150, 200, 250, 300, 350, 400]
|
||||
}};
|
||||
this.xStore = {
|
||||
get: sinon.stub(),
|
||||
put: sinon.stub()
|
||||
};
|
||||
this.xContent = {$el: null};
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xEvent.sub.reset();
|
||||
this.xEvent.pub.reset();
|
||||
this.xFormat.setDefaultMetric.reset();
|
||||
this.xFormat.formatDate.reset();
|
||||
this.xFormat.formatSize.reset();
|
||||
this.xLocation.setLink.reset();
|
||||
this.xResource.icon.reset();
|
||||
|
||||
return this.definition.fn(_, $, this.xEvent, this.xFormat, this.xLocation, this.xResource, this.xSettings, this.xStore, this.xContent);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xContent.$el = $('<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 object with 12 properties', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isPlainObject(instance);
|
||||
assert.lengthOfKeys(instance, 12);
|
||||
});
|
||||
|
||||
it('adds HTML #view to #content', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#content > #view'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #items to #view', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#view > #items'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #view-hint to #view', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#view > #view-hint'), 1);
|
||||
});
|
||||
|
||||
it('adds style to head', function () {
|
||||
var styleTagCount = $('head > style').length;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
||||
});
|
||||
|
||||
it('style contains possibly correct text', function () {
|
||||
this.xSettings.sizes = [20];
|
||||
this.applyFn();
|
||||
var text = $('head > style').eq(0).text();
|
||||
assert.isTrue(text.indexOf('#view.view-details.view-size-20 ') >= 0);
|
||||
assert.isTrue(text.indexOf('#view.view-grid.view-size-20 ') >= 0);
|
||||
assert.isTrue(text.indexOf('#view.view-icons.view-size-20 ') >= 0);
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$el', function () {
|
||||
it('is $(\'#view\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$el);
|
||||
assert.lengthOf(instance.$el, 1);
|
||||
assert.isString(instance.$el.jquery);
|
||||
assert.strictEqual(instance.$el.attr('id'), 'view');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.$items', function () {
|
||||
it('is $(\'#items\')', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isObject(instance.$items);
|
||||
assert.lengthOf(instance.$items, 1);
|
||||
assert.isString(instance.$items.jquery);
|
||||
assert.strictEqual(instance.$items.attr('id'), 'items');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setItems()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.setItems));
|
||||
});
|
||||
|
||||
it('publishes view.changed', function () {
|
||||
var instance = this.applyFn();
|
||||
instance.setItems();
|
||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.changeItems()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.changeItems));
|
||||
});
|
||||
|
||||
it('publishes view.changed', function () {
|
||||
var instance = this.applyFn();
|
||||
instance.setItems();
|
||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setLocation()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.setLocation));
|
||||
});
|
||||
|
||||
it('publishes view.changed', function () {
|
||||
var instance = this.applyFn();
|
||||
instance.setItems();
|
||||
assert.isTrue(this.xEvent.pub.calledTwice);
|
||||
assert.strictEqual(this.xEvent.pub.lastCall.args[0], 'view.changed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setHint()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.setHint));
|
||||
});
|
||||
|
||||
it('sets correct class to #view-hint', function () {
|
||||
var key = uniq.id();
|
||||
var instance = this.applyFn();
|
||||
instance.setHint(key);
|
||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
||||
});
|
||||
|
||||
it('removes all other classes from #view-hint', function () {
|
||||
var key = uniq.id();
|
||||
var instance = this.applyFn();
|
||||
$('#view-hint').addClass('a');
|
||||
instance.setHint(key);
|
||||
assert.strictEqual($('#view-hint').attr('class'), 'l10n-' + key);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getModes()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.getModes));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getMode()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.getMode));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setMode()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.setMode));
|
||||
});
|
||||
|
||||
it('.setMode(\'details\') changes #view class to .view-details', function () {
|
||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
||||
var instance = this.applyFn();
|
||||
instance.setMode('details');
|
||||
assert.isTrue($('#view').hasClass('view-details'));
|
||||
assert.isFalse($('#view').hasClass('view-grid'));
|
||||
assert.isFalse($('#view').hasClass('view-icons'));
|
||||
});
|
||||
|
||||
it('.setMode(\'grid\') changes #view class to .view-grid', function () {
|
||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
||||
var instance = this.applyFn();
|
||||
instance.setMode('grid');
|
||||
assert.isFalse($('#view').hasClass('view-details'));
|
||||
assert.isTrue($('#view').hasClass('view-grid'));
|
||||
assert.isFalse($('#view').hasClass('view-icons'));
|
||||
});
|
||||
|
||||
it('.setMode(\'icons\') changes #view class to .view-icons', function () {
|
||||
this.xSettings.view.modes = ['details', 'grid', 'icons'];
|
||||
var instance = this.applyFn();
|
||||
instance.setMode('icons');
|
||||
assert.isFalse($('#view').hasClass('view-details'));
|
||||
assert.isFalse($('#view').hasClass('view-grid'));
|
||||
assert.isTrue($('#view').hasClass('view-icons'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getSizes()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.getSizes));
|
||||
});
|
||||
|
||||
it('returns sorted sizes', function () {
|
||||
this.xSettings.view.sizes = [20, 60, 40];
|
||||
var instance = this.applyFn();
|
||||
assert.deepEqual(instance.getSizes(), [20, 40, 60]);
|
||||
});
|
||||
|
||||
it('returns sorted sizes', function () {
|
||||
this.xSettings.view.sizes = [60, 40, 20];
|
||||
var instance = this.applyFn();
|
||||
assert.deepEqual(instance.getSizes(), [20, 40, 60]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getSize()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.getSize));
|
||||
});
|
||||
});
|
||||
|
||||
describe('.setSize()', function () {
|
||||
it('is function', function () {
|
||||
var instance = this.applyFn();
|
||||
assert.isTrue(_.isFunction(instance.setSize));
|
||||
});
|
||||
|
||||
it('.setSize(20) changes #view class to .view-size-20', function () {
|
||||
this.xSettings.view.sizes = [20, 40, 60];
|
||||
var instance = this.applyFn();
|
||||
instance.setSize(20);
|
||||
assert.isTrue($('#view').hasClass('view-size-20'), 20);
|
||||
assert.isFalse($('#view').hasClass('view-size-40'), 40);
|
||||
assert.isFalse($('#view').hasClass('view-size-60'), 60);
|
||||
});
|
||||
|
||||
it('.setSize(40) changes #view class to .view-size-40', function () {
|
||||
this.xSettings.view.sizes = [20, 40, 60];
|
||||
var instance = this.applyFn();
|
||||
instance.setSize(20);
|
||||
instance.setSize(40);
|
||||
assert.isFalse($('#view').hasClass('view-size-20'), 20);
|
||||
assert.isTrue($('#view').hasClass('view-size-40'), 40);
|
||||
assert.isFalse($('#view').hasClass('view-size-60'), 60);
|
||||
});
|
||||
|
||||
it('.setSize(60) changes #view class to .view-size-60', function () {
|
||||
this.xSettings.view.sizes = [20, 40, 60];
|
||||
var instance = this.applyFn();
|
||||
instance.setSize(20);
|
||||
instance.setSize(60);
|
||||
assert.isFalse($('#view').hasClass('view-size-20'), 20);
|
||||
assert.isFalse($('#view').hasClass('view-size-40'), 40);
|
||||
assert.isTrue($('#view').hasClass('view-size-60'), 60);
|
||||
});
|
||||
});
|
||||
|
||||
// describe('._.createHtml()', function () {
|
||||
// before(function () {
|
||||
// this.createItem = function () {
|
||||
// return {
|
||||
// isFolder: sinon.stub().returns(false),
|
||||
// label: uniq.id(),
|
||||
// time: 0,
|
||||
// size: 0,
|
||||
// type: uniq.id(),
|
||||
// isManaged: false,
|
||||
// icon: null,
|
||||
// isCurrentParentFolder: sinon.stub().returns(false)
|
||||
// };
|
||||
// };
|
||||
// });
|
||||
|
||||
// it('is function', function () {
|
||||
// var instance = this.applyFn();
|
||||
// assert.isFunction(instance._.createHtml);
|
||||
// });
|
||||
|
||||
// it('returns jQuery instance of single HTML element', function () {
|
||||
// var item = this.createItem();
|
||||
// var instance = this.applyFn();
|
||||
// var $item = instance._.createHtml(item);
|
||||
// assert.isObject($item);
|
||||
// assert.lengthOf($item, 1);
|
||||
// assert.isString($item.jquery);
|
||||
// });
|
||||
|
||||
// it('$item.data(\'item\') is back reference to item', function () {
|
||||
// var item = this.createItem();
|
||||
// var instance = this.applyFn();
|
||||
// var $item = instance._.createHtml(item);
|
||||
// assert.strictEqual($item.data('item'), item);
|
||||
// });
|
||||
|
||||
// it('sets item.$view as reference to $item', function () {
|
||||
// var item = this.createItem();
|
||||
// var instance = this.applyFn();
|
||||
// var $item = instance._.createHtml(item);
|
||||
// assert.strictEqual(item.$view, $item);
|
||||
// });
|
||||
// });
|
||||
});
|
||||
}());
|
|
@ -1,189 +0,0 @@
|
|||
(function () {
|
||||
var ID = 'view/viewmode';
|
||||
var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'view/sidebar', 'view/topbar', 'view/view'];
|
||||
|
||||
describe('module \'' + ID + '\'', function () {
|
||||
before(function () {
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xEvent = {
|
||||
sub: sinon.stub(),
|
||||
pub: sinon.stub()
|
||||
};
|
||||
this.xResource = {
|
||||
image: sinon.stub().returns(uniq.path('-image.png'))
|
||||
};
|
||||
this.xSettings = {view: {
|
||||
modeToggle: false
|
||||
}};
|
||||
this.xSidebar = {$el: null};
|
||||
this.xTopbar = {$el: null};
|
||||
this.xView = {
|
||||
$el: null,
|
||||
getModes: sinon.stub().returns(['details', 'grid', 'icons']),
|
||||
getMode: sinon.stub(),
|
||||
setMode: sinon.stub(),
|
||||
getSizes: sinon.stub().returns([20, 30, 40]),
|
||||
getSize: sinon.stub(),
|
||||
setSize: sinon.stub()
|
||||
};
|
||||
|
||||
this.applyFn = function () {
|
||||
this.xEvent.sub.reset();
|
||||
this.xEvent.pub.reset();
|
||||
this.xResource.image.reset();
|
||||
this.xView.getModes.reset();
|
||||
this.xView.getMode.reset();
|
||||
this.xView.setMode.reset();
|
||||
this.xView.getSizes.reset();
|
||||
this.xView.getSize.reset();
|
||||
this.xView.setSize.reset();
|
||||
|
||||
return this.definition.fn(_, $, this.xEvent, this.xResource, this.xSettings, this.xSidebar, this.xTopbar, this.xView);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
util.restoreHtml();
|
||||
this.xSidebar.$el = $('<div id="sidebar"/>').appendTo('body');
|
||||
this.xTopbar.$el = $('<div id="topbar"/>').appendTo('body');
|
||||
this.xView.$el = $('<div id="view"/>').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 #viewmode-settings to #sidebar', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#sidebar > #viewmode-settings'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #viewmode-details to #viewmode-settings', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-settings > #viewmode-details'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #viewmode-grid to #viewmode-settings', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-settings > #viewmode-grid'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #viewmode-icons to #viewmode-settings', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-settings > #viewmode-icons'), 1);
|
||||
});
|
||||
|
||||
it('adds HTML #viewmode-size to #viewmode-settings', function () {
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-settings > #viewmode-size'), 1);
|
||||
});
|
||||
|
||||
it('does not add HTML #viewmode-details, #viewmode-grid, #viewmode-icons when only one mode', function () {
|
||||
this.xView.getModes.returns(['details']);
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-details'), 0);
|
||||
assert.lengthOf($('#viewmode-grid'), 0);
|
||||
assert.lengthOf($('#viewmode-icons'), 0);
|
||||
});
|
||||
|
||||
it('does not add HTML #viewmode-size when only one size', function () {
|
||||
this.xView.getSizes.returns([20]);
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#viewmode-size'), 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('works', function () {
|
||||
it('clicking #viewmode-details triggers view.setMode(\'details\')', function () {
|
||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
||||
this.applyFn();
|
||||
$('#viewmode-details').trigger('click');
|
||||
assert.isTrue(this.xView.setMode.calledOnce);
|
||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['details']);
|
||||
});
|
||||
|
||||
it('clicking #viewmode-grid triggers view.setMode(\'grid\')', function () {
|
||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
||||
this.applyFn();
|
||||
$('#viewmode-grid').trigger('click');
|
||||
assert.isTrue(this.xView.setMode.calledOnce);
|
||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['grid']);
|
||||
});
|
||||
|
||||
it('clicking #viewmode-icons triggers view.setMode(\'icons\')', function () {
|
||||
this.xView.getModes.returns(['details', 'grid', 'icons']);
|
||||
this.applyFn();
|
||||
$('#viewmode-icons').trigger('click');
|
||||
assert.isTrue(this.xView.setMode.calledOnce);
|
||||
assert.deepEqual(this.xView.setMode.lastCall.args, ['icons']);
|
||||
});
|
||||
|
||||
it('changing #viewmode-size triggers view.setSize(*)', function () {
|
||||
this.xView.getSizes.returns([20, 40, 60]);
|
||||
this.applyFn();
|
||||
|
||||
$('#viewmode-size').val(0).trigger('change');
|
||||
assert.isTrue(this.xView.setSize.calledOnce);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
|
||||
|
||||
$('#viewmode-size').val(1).trigger('change');
|
||||
assert.isTrue(this.xView.setSize.calledTwice);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
|
||||
|
||||
$('#viewmode-size').val(2).trigger('change');
|
||||
assert.isTrue(this.xView.setSize.calledThrice);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
|
||||
});
|
||||
|
||||
it('inputing #viewmode-size triggers view.setSize(*)', function () {
|
||||
this.xView.getSizes.returns([20, 40, 60]);
|
||||
this.applyFn();
|
||||
|
||||
$('#viewmode-size').val(0).trigger('input');
|
||||
assert.isTrue(this.xView.setSize.calledOnce);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [20]);
|
||||
|
||||
$('#viewmode-size').val(1).trigger('input');
|
||||
assert.isTrue(this.xView.setSize.calledTwice);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [40]);
|
||||
|
||||
$('#viewmode-size').val(2).trigger('input');
|
||||
assert.isTrue(this.xView.setSize.calledThrice);
|
||||
assert.deepEqual(this.xView.setSize.lastCall.args, [60]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue