Add tests.

This commit is contained in:
Lars Jung 2015-04-22 23:21:48 +02:00
parent 3882f1483b
commit 88854ad451
23 changed files with 171 additions and 38 deletions

View file

@ -10,8 +10,8 @@
'use strict';
var win = window;
modulejs.define('$', function () { return win.jQuery; });
modulejs.define('_', function () { return win._; });
modulejs.define('$', function () { return win.jQuery; });
modulejs.define('marked', function () { return win.marked; });
modulejs.define('modernizr', function () { return win.Modernizr; });
modulejs.define('prism', function () { return win.Prism; });

View file

@ -4,7 +4,7 @@
var ID = 'boot';
var DEPS = ['$'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {
@ -95,7 +95,7 @@ describe('module "' + ID + '"', function () {
assert.isFalse(this.xRequire.called);
});
it('data-module="test"', function () {
it('data-module=\'test\'', function () {
$('<script/>').attr('data-module', 'test').appendTo('head');
this.applyFn();
@ -104,7 +104,7 @@ describe('module "' + ID + '"', function () {
assert.isFalse(this.xRequire.called);
});
it('data-module="info"', function () {
it('data-module=\'info\'', function () {
$('<script/>').attr('data-module', 'info').appendTo('head');
@ -126,7 +126,7 @@ describe('module "' + ID + '"', function () {
assert.deepEqual(this.xRequire.lastCall.args, ['main/info']);
});
it('data-module="index"', function () {
it('data-module=\'index\'', function () {
$('<script/>').attr('data-module', 'index').appendTo('head');
@ -148,7 +148,7 @@ describe('module "' + ID + '"', function () {
assert.deepEqual(this.xRequire.lastCall.args, ['main/index']);
});
it('"no-browser"-class and no data-module', function () {
it('\'no-browser\'-class and no data-module', function () {
$('html').addClass('no-browser');
this.applyFn();
@ -157,7 +157,7 @@ describe('module "' + ID + '"', function () {
assert.isFalse(this.xRequire.called);
});
it('"no-browser"-class and data-module="test"', function () {
it('\'no-browser\'-class and data-module=\'test\'', function () {
$('html').addClass('no-browser');
$('<script/>').attr('data-module', 'test').appendTo('head');
@ -167,7 +167,7 @@ describe('module "' + ID + '"', function () {
assert.isFalse(this.xRequire.called);
});
it('"no-browser"-class and data-module="info"', function () {
it('\'no-browser\'-class and data-module=\'info\'', function () {
$('html').addClass('no-browser');
$('<script/>').attr('data-module', 'info').appendTo('head');
@ -177,7 +177,7 @@ describe('module "' + ID + '"', function () {
assert.isFalse(this.xRequire.called);
});
it('"no-browser"-class and data-module="index"', function () {
it('\'no-browser\'-class and data-module=\'index\'', function () {
$('html').addClass('no-browser');
$('<script/>').attr('data-module', 'index').appendTo('head');

View file

@ -4,7 +4,7 @@
var ID = 'config';
var DEPS = [];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/event';
var DEPS = ['_'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/format';
var DEPS = ['_'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {
@ -112,7 +112,7 @@ describe('module "' + ID + '"', function () {
var arg = data[0];
var exp = data[1];
it('.formatSize(' + arg + ') => "' + exp + '"', function () {
it('.formatSize(' + arg + ') => \'' + exp + '\'', function () {
var instance = this.applyFn();
instance.setDefaultMetric(false);
@ -148,7 +148,7 @@ describe('module "' + ID + '"', function () {
var arg = data[0];
var exp = data[1];
it('.formatSize(' + arg + ') => "' + exp + '"', function () {
it('.formatSize(' + arg + ') => \'' + exp + '\'', function () {
var instance = this.applyFn();
instance.setDefaultMetric(true);
@ -209,7 +209,7 @@ describe('module "' + ID + '"', function () {
var arg2 = data[1];
var exp = data[2];
it('.formatDate(' + arg1 + ', ' + arg2 + ') => "' + exp + '"', function () {
it('.formatDate(' + arg1 + ', \'' + arg2 + '\') => \'' + exp + '\'', function () {
var instance = this.applyFn();
assert.strictEqual(instance.formatDate(arg1, arg2), exp);

View file

@ -4,7 +4,7 @@
var ID = 'core/langs';
var DEPS = ['_', 'config'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/location';
var DEPS = ['_', 'modernizr', 'core/event', 'core/notify', 'core/settings'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {
@ -111,7 +111,7 @@ describe('module "' + ID + '"', function () {
var arg = data[0];
var exp = data[1];
it('.forceEncoding("' + arg + '") => "' + exp + '"', function () {
it('.forceEncoding(\'' + arg + '\') => \'' + exp + '\'', function () {
var instance = this.applyFn();
assert.strictEqual(instance.forceEncoding(arg), exp);
@ -199,7 +199,7 @@ describe('module "' + ID + '"', function () {
assert.strictEqual($el.attr('href'), item.absHref);
});
it('sets target="_blank" for unmanaged folders', function () {
it('sets target=\'_blank\' for unmanaged folders', function () {
this.xSettings.unmanagedInNewWindow = true;
@ -216,7 +216,7 @@ describe('module "' + ID + '"', function () {
assert.strictEqual($el.attr('target'), '_blank');
});
it('does not set target="_blank" for managed folders', function () {
it('does not set target=\'_blank\' for managed folders', function () {
this.xSettings.unmanagedInNewWindow = true;
@ -233,7 +233,7 @@ describe('module "' + ID + '"', function () {
assert.isUndefined($el.attr('target'));
});
it('does not set target="_blank" for unmanaged folders if disabled', function () {
it('does not set target=\'_blank\' for unmanaged folders if disabled', function () {
this.xSettings.unmanagedInNewWindow = false;

View file

@ -4,7 +4,7 @@
var ID = 'core/notify';
var DEPS = ['$'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/resource';
var DEPS = ['_', 'config', 'core/settings'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -5,7 +5,7 @@ var ID = 'core/server';
var DEPS = ['_', '$', 'config', 'core/location'];
var $submitSnap;
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/settings';
var DEPS = ['_', 'config'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/store';
var DEPS = ['modernizr'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/types';
var DEPS = ['_', 'config'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'core/util';
var DEPS = [];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {
@ -81,7 +81,7 @@ describe('module "' + ID + '"', function () {
var arg2 = data[1];
var exp = data[2];
it('.regularCmpFn("' + arg1 + '", "' + arg2 + '") => "' + exp + '"', function () {
it('.regularCmpFn(\'' + arg1 + '\', \'' + arg2 + '\') => \'' + exp + '\'', function () {
var instance = this.applyFn();
assert.strictEqual(instance.regularCmpFn(arg1, arg2), exp);
@ -111,7 +111,7 @@ describe('module "' + ID + '"', function () {
var arg2 = data[1];
var exp = data[2];
it('.naturalCmpFn("' + arg1 + '", "' + arg2 + '") => "' + exp + '"', function () {
it('.naturalCmpFn(\'' + arg1 + '\', \'' + arg2 + '\') => \'' + exp + '\'', function () {
var instance = this.applyFn();
assert.strictEqual(instance.naturalCmpFn(arg1, arg2), exp);

View file

@ -0,0 +1,133 @@
(function () {
'use strict';
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);
};
this.titleBak = document.title;
this.dummyTitle = util.uniqId();
});
after(function () {
document.title = this.titleBak;
});
beforeEach(function () {
document.title = this.dummyTitle;
});
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(String(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);
});
});
});
});
}());

View file

@ -13,7 +13,7 @@ describe('libs', function () {
_.each(libs, function (lib, id) {
describe('module "' + id + '"', function () {
describe('module \'' + id + '\'', function () {
it('is defined', function () {

View file

@ -4,7 +4,7 @@
var ID = 'main/index';
var DEPS = ['_', 'core/event'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'main/info';
var DEPS = ['$', 'config'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'model/item';
var DEPS = ['_', 'core/event', 'core/location', 'core/server', 'core/settings', 'core/types'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'view/base';
var DEPS = ['$', 'config'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'view/content';
var DEPS = ['_', '$', 'core/event', 'core/format', 'core/location', 'core/resource', 'core/settings'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'view/sidebar';
var DEPS = ['$', 'core/resource', 'core/store'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {

View file

@ -4,7 +4,7 @@
var ID = 'view/viewmode';
var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'core/store'];
describe('module "' + ID + '"', function () {
describe('module \'' + ID + '\'', function () {
before(function () {