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

94 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-04-22 11:12:45 -04:00
(function () {
'use strict';
var ID = 'view/content';
2015-04-29 17:08:38 -04:00
var DEPS = ['$', 'view/mainrow'];
2015-04-22 11:12:45 -04:00
2015-04-22 17:21:48 -04:00
describe('module \'' + ID + '\'', function () {
2015-04-22 11:12:45 -04:00
before(function () {
this.definition = modulejs._private.definitions[ID];
2015-04-25 07:24:34 -04:00
this.xMainrow = {$el: null};
2015-04-22 11:12:45 -04:00
this.applyFn = function () {
2015-04-29 17:08:38 -04:00
return this.definition.fn($, this.xMainrow);
2015-04-22 11:12:45 -04:00
};
});
after(function () {
util.restoreHtml();
});
beforeEach(function () {
util.restoreHtml();
2015-04-29 13:47:37 -04:00
this.xMainrow.$el = $('<div id="mainrow"/>').appendTo('body');
2015-04-22 11:12:45 -04:00
});
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 () {
2015-04-29 17:08:38 -04:00
it('returns object with 1 property', function () {
2015-04-22 11:12:45 -04:00
var instance = this.applyFn();
2015-04-25 07:24:34 -04:00
assert.isPlainObject(instance);
2015-04-29 17:08:38 -04:00
assert.lengthOfKeys(instance, 1);
2015-04-22 11:12:45 -04:00
});
2015-04-29 13:47:37 -04:00
it('adds HTML #content to #mainrow', function () {
2015-04-22 11:12:45 -04:00
this.applyFn();
2015-04-29 13:47:37 -04:00
assert.lengthOf($('#mainrow > #content'), 1);
2015-04-22 11:12:45 -04:00
});
});
2015-04-25 07:24:34 -04:00
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');
});
});
2015-04-22 11:12:45 -04:00
});
}());