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

126 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-04-22 11:12:45 -04:00
(function () {
'use strict';
2015-04-28 18:57:58 -04:00
var ID = 'view/notification';
2015-04-28 19:13:30 -04:00
var DEPS = ['$', 'view/root'];
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-28 19:13:30 -04:00
this.xRoot = {$el: null};
2015-04-22 11:12:45 -04:00
this.applyFn = function () {
2015-04-28 19:13:30 -04:00
return this.definition.fn($, this.xRoot);
2015-04-22 11:12:45 -04:00
};
});
after(function () {
util.restoreHtml();
});
beforeEach(function () {
util.restoreHtml();
2015-04-28 19:13:30 -04:00
this.xRoot.$el = $('<div id="root"/>').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-28 19:13:30 -04:00
it('returns plain object with 2 properties', function () {
2015-04-22 11:12:45 -04:00
var instance = this.applyFn();
assert.isPlainObject(instance);
2015-04-28 19:13:30 -04:00
assert.lengthOfKeys(instance, 2);
2015-04-22 11:12:45 -04:00
});
2015-04-28 19:13:30 -04:00
it('adds HTML #notification to #root (hidden)', function () {
2015-04-22 11:12:45 -04:00
this.applyFn();
2015-04-28 19:13:30 -04:00
assert.lengthOf($('#root > #notification'), 1);
2015-04-28 18:57:58 -04:00
assert.lengthOf($('#notification:visible'), 0);
assert.strictEqual($('#notification').text(), '');
2015-04-22 11:12:45 -04:00
});
});
2015-04-28 19:13:30 -04:00
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');
});
});
2015-04-22 13:34:35 -04:00
describe('.set()', function () {
2015-04-22 11:12:45 -04:00
2015-04-22 13:34:35 -04:00
it('is function', function () {
2015-04-22 11:12:45 -04:00
var instance = this.applyFn();
assert.ok(_.isFunction(instance.set));
});
2015-04-22 13:34:35 -04:00
it('works', function () {
2015-04-22 11:12:45 -04:00
var instance = this.applyFn();
instance.set();
2015-04-28 18:57:58 -04:00
assert.lengthOf($('#notification:visible'), 0);
assert.strictEqual($('#notification').text(), '');
2015-04-22 11:12:45 -04:00
instance.set('hello');
2015-04-28 18:57:58 -04:00
assert.lengthOf($('#notification:visible'), 1);
assert.strictEqual($('#notification').text(), 'hello');
2015-04-22 11:12:45 -04:00
instance.set('world');
2015-04-28 18:57:58 -04:00
assert.lengthOf($('#notification:visible'), 1);
assert.strictEqual($('#notification').text(), 'world');
2015-04-22 11:12:45 -04:00
instance.set();
2015-04-28 18:57:58 -04:00
// assert.lengthOf($('#notification:visible'), 0);
assert.strictEqual($('#notification').text(), 'world');
2015-04-22 11:12:45 -04:00
});
});
});
}());