mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-04 17:03:41 -04:00
Publish tests.
This commit is contained in:
parent
5a8ecd593d
commit
c396800dfa
40 changed files with 21478 additions and 1 deletions
117
test/tests/unit/view/viewmode.js
Normal file
117
test/tests/unit/view/viewmode.js
Normal file
|
@ -0,0 +1,117 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ID = 'view/viewmode';
|
||||
var DEPS = ['_', '$', 'core/event', 'core/resource', 'core/settings', 'core/store'];
|
||||
|
||||
describe('module "' + ID + '"', function () {
|
||||
|
||||
before(function () {
|
||||
|
||||
this.definition = modulejs._private.definitions[ID];
|
||||
|
||||
this.xSettings = {
|
||||
view: {}
|
||||
};
|
||||
this.xResource = {
|
||||
image: sinon.stub().returns('/some/path/' + util.uniqId() + '.png')
|
||||
};
|
||||
this.xStore = {
|
||||
get: sinon.stub(),
|
||||
put: sinon.stub()
|
||||
};
|
||||
this.xEvent = {
|
||||
sub: sinon.stub()
|
||||
};
|
||||
this.applyFn = function () {
|
||||
|
||||
this.xResource.image.reset();
|
||||
this.xStore.get.reset();
|
||||
this.xStore.put.reset();
|
||||
this.xEvent.sub.reset();
|
||||
|
||||
return this.definition.fn(_, $, this.xEvent, this.xResource, this.xSettings, this.xStore);
|
||||
};
|
||||
});
|
||||
|
||||
after(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
util.restoreHtml();
|
||||
$('<div id="sidebar"/>').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', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.lengthOf($('#sidebar > .block > .l10n-view'), 1);
|
||||
});
|
||||
|
||||
it('adds Style', function () {
|
||||
|
||||
var styleTagCount = $('head > style').length;
|
||||
this.applyFn();
|
||||
assert.lengthOf($('head > style'), styleTagCount + 1);
|
||||
});
|
||||
|
||||
it('subscribes to 1 event', function () {
|
||||
|
||||
this.applyFn();
|
||||
assert.isTrue(this.xEvent.sub.calledOnce);
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue