h5ai/test/tests/unit/view/mainrow.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-04-25 13:24:34 +02:00
(function () {
2015-11-18 23:16:58 +01:00
var ID = 'view/mainrow';
var DEPS = ['$', 'view/root'];
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
describe('module \'' + ID + '\'', function () {
before(function () {
this.definition = modulejs._private.definitions[ID];
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
this.xRoot = {$el: null};
this.applyFn = function () {
return this.definition.fn($, this.xRoot);
};
2015-04-25 13:24:34 +02:00
});
2015-11-18 23:16:58 +01:00
after(function () {
util.restoreHtml();
2015-04-25 13:24:34 +02:00
});
2015-11-18 23:16:58 +01:00
beforeEach(function () {
util.restoreHtml();
this.xRoot.$el = $('<div id="root"/>').appendTo('body');
2015-04-25 13:24:34 +02:00
});
2015-11-18 23:16:58 +01:00
describe('definition', function () {
it('is defined', function () {
assert.isPlainObject(this.definition);
});
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
it('has correct id', function () {
assert.strictEqual(this.definition.id, ID);
});
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
it('requires correct', function () {
assert.deepEqual(this.definition.deps, DEPS);
});
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
it('args for each request', function () {
assert.strictEqual(this.definition.deps.length, this.definition.fn.length);
});
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
it('has no instance', function () {
assert.notProperty(modulejs._private.instances, ID);
});
2015-04-25 13:24:34 +02:00
2015-11-18 23:16:58 +01:00
it('inits without errors', function () {
this.applyFn();
});
2015-04-25 13:24:34 +02:00
});
2015-11-18 23:16:58 +01:00
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);
});
2015-04-25 13:24:34 +02:00
});
2015-11-18 23:16:58 +01:00
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');
});
2015-04-25 13:24:34 +02:00
});
});
}());