mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 22:45:14 -04:00
Update tests.
This commit is contained in:
parent
4f83c95d20
commit
093296dbac
3 changed files with 66 additions and 78 deletions
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ID = 'boot';
|
var ID = 'boot';
|
||||||
var DEPS = ['$'];
|
var DEPS = ['$', 'core/server'];
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
|
@ -11,31 +11,24 @@ describe('module \'' + ID + '\'', function () {
|
||||||
this.definition = modulejs._private.definitions[ID];
|
this.definition = modulejs._private.definitions[ID];
|
||||||
|
|
||||||
this.xConfig = util.uniqObj();
|
this.xConfig = util.uniqObj();
|
||||||
this.xAjaxResult = {
|
|
||||||
done: sinon.stub().callsArgWith(0, this.xConfig),
|
|
||||||
fail: sinon.stub().callsArg(0),
|
|
||||||
always: sinon.stub().callsArg(0)
|
|
||||||
};
|
|
||||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
|
||||||
this.xDefine = sinon.stub(modulejs, 'define');
|
this.xDefine = sinon.stub(modulejs, 'define');
|
||||||
this.xRequire = sinon.stub(modulejs, 'require');
|
this.xRequire = sinon.stub(modulejs, 'require');
|
||||||
|
this.xServer = {
|
||||||
|
request: sinon.stub().callsArgWith(1, this.xConfig)
|
||||||
|
};
|
||||||
|
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
this.xAjaxResult.done.reset();
|
|
||||||
this.xAjaxResult.fail.reset();
|
|
||||||
this.xAjaxResult.always.reset();
|
|
||||||
this.xAjax.reset();
|
|
||||||
this.xDefine.reset();
|
this.xDefine.reset();
|
||||||
this.xRequire.reset();
|
this.xRequire.reset();
|
||||||
|
this.xServer.request.reset();
|
||||||
|
|
||||||
return this.definition.fn($);
|
return this.definition.fn($, this.xServer);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
|
|
||||||
this.xAjax.restore();
|
|
||||||
this.xDefine.restore();
|
this.xDefine.restore();
|
||||||
this.xRequire.restore();
|
this.xRequire.restore();
|
||||||
util.restoreHtml();
|
util.restoreHtml();
|
||||||
|
@ -90,7 +83,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
it('no data-module', function () {
|
it('no data-module', function () {
|
||||||
|
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
@ -99,25 +92,29 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
$('<script/>').attr('data-module', 'test').appendTo('head');
|
$('<script/>').attr('data-module', 'test').appendTo('head');
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('data-module=\'info\'', function () {
|
it('data-module=\'info\'', function () {
|
||||||
|
|
||||||
|
var expectedData = {
|
||||||
|
action: 'get',
|
||||||
|
setup: true,
|
||||||
|
options: true,
|
||||||
|
types: true,
|
||||||
|
refresh: true
|
||||||
|
};
|
||||||
|
|
||||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
$('<script/>').attr('data-module', 'info').appendTo('head');
|
||||||
|
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
assert.isTrue(this.xServer.request.calledOnce);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].url, 'index.php');
|
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].type, 'post');
|
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].dataType, 'json');
|
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||||
|
|
||||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
|
||||||
assert.isFalse(this.xAjaxResult.fail.called);
|
|
||||||
assert.isFalse(this.xAjaxResult.always.called);
|
|
||||||
|
|
||||||
assert.isTrue(this.xDefine.calledOnce);
|
assert.isTrue(this.xDefine.calledOnce);
|
||||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
||||||
|
@ -128,18 +125,23 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
it('data-module=\'index\'', function () {
|
it('data-module=\'index\'', function () {
|
||||||
|
|
||||||
|
var expectedData = {
|
||||||
|
action: 'get',
|
||||||
|
setup: true,
|
||||||
|
options: true,
|
||||||
|
types: true,
|
||||||
|
theme: true,
|
||||||
|
langs: true
|
||||||
|
};
|
||||||
|
|
||||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
$('<script/>').attr('data-module', 'index').appendTo('head');
|
||||||
|
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
assert.isTrue(this.xServer.request.calledOnce);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].url, '.');
|
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].type, 'post');
|
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||||
assert.strictEqual(this.xAjax.lastCall.args[0].dataType, 'json');
|
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||||
|
|
||||||
assert.isTrue(this.xAjaxResult.done.calledOnce);
|
|
||||||
assert.isFalse(this.xAjaxResult.fail.called);
|
|
||||||
assert.isFalse(this.xAjaxResult.always.called);
|
|
||||||
|
|
||||||
assert.isTrue(this.xDefine.calledOnce);
|
assert.isTrue(this.xDefine.calledOnce);
|
||||||
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
assert.deepEqual(this.xDefine.lastCall.args, ['config', this.xConfig]);
|
||||||
|
@ -152,7 +154,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
$('html').addClass('no-browser');
|
$('html').addClass('no-browser');
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
@ -162,7 +164,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
$('html').addClass('no-browser');
|
$('html').addClass('no-browser');
|
||||||
$('<script/>').attr('data-module', 'test').appendTo('head');
|
$('<script/>').attr('data-module', 'test').appendTo('head');
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
@ -172,7 +174,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
$('html').addClass('no-browser');
|
$('html').addClass('no-browser');
|
||||||
$('<script/>').attr('data-module', 'info').appendTo('head');
|
$('<script/>').attr('data-module', 'info').appendTo('head');
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
@ -182,7 +184,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
$('html').addClass('no-browser');
|
$('html').addClass('no-browser');
|
||||||
$('<script/>').attr('data-module', 'index').appendTo('head');
|
$('<script/>').attr('data-module', 'index').appendTo('head');
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
assert.isFalse(this.xAjax.called);
|
assert.isFalse(this.xServer.request.called);
|
||||||
assert.isFalse(this.xDefine.called);
|
assert.isFalse(this.xDefine.called);
|
||||||
assert.isFalse(this.xRequire.called);
|
assert.isFalse(this.xRequire.called);
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ID = 'core/server';
|
var ID = 'core/server';
|
||||||
var DEPS = ['_', '$', 'core/location'];
|
var DEPS = ['_', '$'];
|
||||||
var $submitEl;
|
var $submitEl;
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
describe('module \'' + ID + '\'', function () {
|
||||||
|
@ -11,10 +11,6 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.definition = modulejs._private.definitions[ID];
|
this.definition = modulejs._private.definitions[ID];
|
||||||
|
|
||||||
this.xAbsHref = util.uniqId();
|
|
||||||
this.xLocation = {
|
|
||||||
getAbsHref: sinon.stub().returns(this.xAbsHref)
|
|
||||||
};
|
|
||||||
this.xAjaxResult = {
|
this.xAjaxResult = {
|
||||||
done: sinon.stub().returnsThis(),
|
done: sinon.stub().returnsThis(),
|
||||||
fail: sinon.stub().returnsThis(),
|
fail: sinon.stub().returnsThis(),
|
||||||
|
@ -29,7 +25,6 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
this.xLocation.getAbsHref.reset();
|
|
||||||
this.xAjaxResult.done.reset();
|
this.xAjaxResult.done.reset();
|
||||||
this.xAjaxResult.fail.reset();
|
this.xAjaxResult.fail.reset();
|
||||||
this.xAjaxResult.always.reset();
|
this.xAjaxResult.always.reset();
|
||||||
|
@ -37,7 +32,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
this.xSubmit.reset();
|
this.xSubmit.reset();
|
||||||
$submitEl = undefined;
|
$submitEl = undefined;
|
||||||
|
|
||||||
return this.definition.fn(_, $, this.xLocation);
|
return this.definition.fn(_, $);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -108,10 +103,9 @@ describe('module \'' + ID + '\'', function () {
|
||||||
var res = instance.request(xData, spy);
|
var res = instance.request(xData, spy);
|
||||||
|
|
||||||
assert.isUndefined(res);
|
assert.isUndefined(res);
|
||||||
assert.isTrue(this.xLocation.getAbsHref.calledOnce);
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
assert.isTrue(this.xAjax.calledOnce);
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||||
url: this.xAbsHref,
|
url: '?',
|
||||||
data: xData,
|
data: xData,
|
||||||
type: 'post',
|
type: 'post',
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
|
@ -135,10 +129,9 @@ describe('module \'' + ID + '\'', function () {
|
||||||
var res = instance.request(xData, spy);
|
var res = instance.request(xData, spy);
|
||||||
|
|
||||||
assert.isUndefined(res);
|
assert.isUndefined(res);
|
||||||
assert.isTrue(this.xLocation.getAbsHref.calledOnce);
|
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
assert.isTrue(this.xAjax.calledOnce);
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
assert.deepEqual(this.xAjax.lastCall.args, [{
|
||||||
url: this.xAbsHref,
|
url: '?',
|
||||||
data: xData,
|
data: xData,
|
||||||
type: 'post',
|
type: 'post',
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
|
@ -180,7 +173,7 @@ describe('module \'' + ID + '\'', function () {
|
||||||
assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
|
assert.strictEqual($submitEl.get(0).tagName.toLowerCase(), 'form');
|
||||||
assert.strictEqual($submitEl.attr('method'), 'post');
|
assert.strictEqual($submitEl.attr('method'), 'post');
|
||||||
assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
|
assert.strictEqual($submitEl.attr('style').replace(/\s+/g, ''), 'display:none;');
|
||||||
assert.strictEqual($submitEl.attr('action'), this.xAbsHref);
|
assert.strictEqual($submitEl.attr('action'), '?');
|
||||||
|
|
||||||
var $children = $submitEl.children();
|
var $children = $submitEl.children();
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var ID = 'main/info';
|
var ID = 'main/info';
|
||||||
var DEPS = ['$', 'config'];
|
var DEPS = ['$', 'config', 'core/server'];
|
||||||
|
|
||||||
describe('module \'' + ID + '\'', function () {
|
describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
|
@ -15,27 +15,20 @@ describe('module \'' + ID + '\'', function () {
|
||||||
VERSION: util.uniqId()
|
VERSION: util.uniqId()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.xAjaxResult = {
|
this.xServer = {
|
||||||
done: sinon.stub(),
|
request: sinon.stub()
|
||||||
fail: sinon.stub(),
|
|
||||||
always: sinon.stub()
|
|
||||||
};
|
};
|
||||||
this.xAjax = sinon.stub($, 'ajax').returns(this.xAjaxResult);
|
|
||||||
|
|
||||||
this.applyFn = function () {
|
this.applyFn = function () {
|
||||||
|
|
||||||
this.xAjaxResult.done.reset();
|
this.xServer.request.reset();
|
||||||
this.xAjaxResult.fail.reset();
|
|
||||||
this.xAjaxResult.always.reset();
|
|
||||||
this.xAjax.reset();
|
|
||||||
|
|
||||||
return this.definition.fn($, this.xConfig);
|
return this.definition.fn($, this.xConfig, this.xServer);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
|
|
||||||
this.xAjax.restore();
|
|
||||||
util.restoreHtml();
|
util.restoreHtml();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -132,20 +125,20 @@ describe('module \'' + ID + '\'', function () {
|
||||||
it('login works', function () {
|
it('login works', function () {
|
||||||
|
|
||||||
var pass = util.uniqId();
|
var pass = util.uniqId();
|
||||||
|
var expectedData = {
|
||||||
|
action: 'login',
|
||||||
|
pass: pass
|
||||||
|
};
|
||||||
|
|
||||||
this.xConfig.setup.AS_ADMIN = false;
|
this.xConfig.setup.AS_ADMIN = false;
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
$('#pass').val(pass);
|
$('#pass').val(pass);
|
||||||
$('#login').trigger('click');
|
$('#login').trigger('click');
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
assert.isTrue(this.xServer.request.calledOnce);
|
||||||
url: 'index.php',
|
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||||
type: 'post',
|
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||||
dataType: 'json',
|
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||||
data: {
|
|
||||||
action: 'login',
|
|
||||||
pass: pass
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -188,18 +181,18 @@ describe('module \'' + ID + '\'', function () {
|
||||||
|
|
||||||
it('logout works', function () {
|
it('logout works', function () {
|
||||||
|
|
||||||
|
var expectedData = {
|
||||||
|
action: 'logout'
|
||||||
|
};
|
||||||
|
|
||||||
this.xConfig.setup.AS_ADMIN = true;
|
this.xConfig.setup.AS_ADMIN = true;
|
||||||
this.applyFn();
|
this.applyFn();
|
||||||
$('#logout').trigger('click');
|
$('#logout').trigger('click');
|
||||||
assert.isTrue(this.xAjax.calledOnce);
|
|
||||||
assert.deepEqual(this.xAjax.lastCall.args, [{
|
assert.isTrue(this.xServer.request.calledOnce);
|
||||||
url: 'index.php',
|
assert.isPlainObject(this.xServer.request.lastCall.args[0]);
|
||||||
type: 'post',
|
assert.deepEqual(this.xServer.request.lastCall.args[0], expectedData);
|
||||||
dataType: 'json',
|
assert.isFunction(this.xServer.request.lastCall.args[1]);
|
||||||
data: {
|
|
||||||
action: 'logout'
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue