Skip to content

Commit

Permalink
Merge pull request BaiduFE#293 from tianlili/dev
Browse files Browse the repository at this point in the history
添加公共用例
  • Loading branch information
bellcliff committed Jun 24, 2011
2 parents fe71165 + 91a7ea4 commit 443f319
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 8 deletions.
12 changes: 6 additions & 6 deletions test/baidu/i18n/tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function() {
function mySetup() {
baidu.i18n.cultures = baidu.i18n.cultures || {};
baidu.i18n.cultures['en-CA'] = {
calendar : {
dateFormat : 'yyyy-MM-dd',
Expand Down Expand Up @@ -55,12 +56,11 @@
var s = QUnit.moduleStart;
QUnit.moduleStart = function() {
var args = arguments, self = this;
stop();
ua.importsrc('baidu.i18n.cultures', function() {
// stop();
// ua.importsrc('baidu.i18n.cultures', function() {
mySetup();
start();
// start();
s.apply(self, args);
});
// });
};
})();

})();
2 changes: 1 addition & 1 deletion test/baidu/ui/ColorPalette.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module('baidu.ui.ColorPicker.ColorPalette');
module('baidu.ui.ColorPalette');

function createColorPalette(options) {
var colorPalette = baidu.ui.create(baidu.ui.ColorPalette,
Expand Down
1 change: 1 addition & 0 deletions test/tools/br/case.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function print_js($cov=false, $release=false){
print '<script type="text/javascript" src="js/Tangram-1.3.8.js"></script>'."\n";
print '<script type="text/javascript" src="js/testrunner.js"></script>'."\n";
print '<script type="text/javascript" src="js/ext_qunit.js"></script>'."\n";
print '<script type="text/javascript" src="js/commonTest.js"></script>'."\n";
print '<script type="text/javascript" src="js/UserAction.js"></script>'."\n";
print '<script type="text/javascript" src="js/tools.js"></script>'."\n";

Expand Down
215 changes: 215 additions & 0 deletions test/tools/br/js/commonTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/**
* 封装ui公共用例
* render
* open
* close
* update
* dispose
* disable
* enable
*/

var commonTests = function(testName) {
var p = window;
var flag = true;
for ( var i = 0; i < testName.length; i++) {
if (typeof (p[testName[i]]) == 'undefined') {
flag = false;
}
if (i == testName.length - 1 && typeof (p[testName[i]]) != 'undefined') {
if (!window['baidu']['ui'])
flag = false;
else {
if (window['baidu']['ui']['Base'].renderMain != p[testName[i]].prototype.renderMain)
flag = false;
else
UI = p[testName[i]];
}
}
p = p[testName[i]];
}
if (flag)
test('common test', function() {
var div = document.createElement('div');
div.id = "div_commontest";
document.body.appendChild(div);
te.dom.push(div);

var options = {};
//baidu.ui.Decorator有些特别,必须传入一个options.ui
if(testName[2] == 'Decorator'){
var opui = baidu.ui.createUI(new Function);
opui.extend({
uiType : 'testType',
render : function(target) {
var me = this;
me.main = me.renderMain();
target && me.main.appendChild(target);
me.body = target;
me.dispatchEvent('onload');
}
});
options.ui = new opui();
}

if(testName[2] == 'Tooltip'){
options.target = te.dom[0] || div;
}

//创建组件的实例
var ui = initObject(UI, options);
var l1 = baidu.event._listeners.length;

//baidu.ui.DatePicker有些特别,封装了一个Calendar组件
if(testName[2] == 'DatePicker')
ui = ui._calendar;
//baidu.ui.Decorator有些特别,用ui.ui render
if(testName[2] == 'Decorator')
ui = ui.ui;

//测试render
test_render(ui, te.dom[0] || div);

//测试open
if(ui.open)
test_open(ui);

//测试close
if(ui.close)
test_close(ui);

//测试dispose
test_dispose(ui, l1);

});
};

function initObject(UI, options) {
var ui = new UI(options);
return ui;
};

/**
* 验证onload事件,main对象创建成功
*/
function test_render(ui, target) {
if (!ui.onload && !ui.load)
ui.load = function() {
ok(true, 'load is dispatch');
};
ui.render(target);
ok(ui.getMain() || ui.getBody(), 'render: main is render');
};


/**
* 验证onopen事件,验证dom元素是否显示
* ui:UI对象,param:open参数,beforeEvent:是否有onbeforeopen事件
*/
function test_open(ui, param) {
if (!ui.onopen)
ui.onopen = function() {
ok(true, 'open is dispatch!');
};
if (!ui.onbeforeopen && !ui.beforeopen)
ui.onbeforeopen = function() {
ok(true, 'onbeforeopen is dispatch!');
};
if (param)
ui.open(param);
else
ui.open();
ok($(ui.getMain()).css("display") != 'none', 'open: main is shown!');
};

/**
* 验证onclose事件,验证dom元素是否隐藏 ui:UI对象,param:close参数,beforeEvent:是否有onbeforeclose事件
*/
function test_close(ui, param) {
if (!ui.onclose)
ui.onclose = function() {
ok(true, 'close is dispatch!');
};
if (ui.onbeforeclose && !ui.beforeclose)
ui.onbeforeclose = function() {
ok(true, 'ondeforeclose is dispatch!');
};
if (param)
ui.close(param);
else
ui.close();
ok(!isShown(ui.getMain()), 'close: main is hide!');
};

/**
* 验证options是否全部复制给me,验证onupdate事件
*/
function test_update(ui, options) {
if (!ui.onupdate)
ui.onupdate = function() {
ok(true, 'onupdate is dispatch!');
};
if (options)
ui.update(options);
for ( var key in options) {
if (ui.key && ui.key === options.key)
continue;
else
ok(false, key + ' is not updated!');
}
;
};

/**
* dispose验证事件有没被清除,验证main有没被删掉
*/
function test_dispose(ui, l1) {
ui.dispose();
equal(baidu.dom.g(ui.getId()), null, 'disposed');
equals(baidu.event._listeners.length, l1, 'event removed all');
};

/**
* 验证disabled变量,验证ondisable事件被触发
*/
function test_disable(ui) {
ui.disable();
if (!ui.ondisable)
ui.ondisable = function() {
ok(true, 'ondisable is dispatch!');
};
if (ui.disabled)
equal(ui.disabled, true, 'check disabled');
if (ui.statable) {
var body = ui.getBody();
if (body.className.match('disabled'))
ok(true, 'disabled class is add!');
else if (ui.getMain().className.match('disabled'))
ok(true, 'disabled class is add!');
else
ok(false, 'disabled class is not add!');
}
};

/**
* 与disable函数结合使用来测试,验证disabled变量,验证onenable事件
*/
function test_enable() {
ui.disable();
ui.enable();
if (!ui.onenable)
ui.onenable = function() {
ok(true, 'onenable is dispatch!');
};
if (ui.disabled)
equal(ui.disabled, false, 'check disabled');
if (ui.statable) {
var body = ui.getBody();
if (!body.className.match('disabled'))
ok(true, 'disabled class is remove!');
else if (!ui.getMain().className.match('disabled'))
ok(true, 'disabled class is remove!');
else
ok(false, 'disabled class is not remove!');
}
};
8 changes: 7 additions & 1 deletion test/tools/br/js/ext_qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}, window._$jscoverage || null ]);
}
}
QUnit.moduleStart = function() {

QUnit.moduleStart = function(name,testEnvironment) {
stop();
/* 为批量执行等待import.php正确返回 */
var h = setInterval(function() {
Expand All @@ -26,7 +27,12 @@
start();
}
}, 20);

//田丽丽添加 调用公共用例
var testName = name.split('.');
commonTests(testName);
};

QUnit.done = function() {
_d(arguments);
d.apply(this, arguments);
Expand Down

0 comments on commit 443f319

Please sign in to comment.