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