Actualización
This commit is contained in:
211
plugin/mindmap/edit-mindmap/vendor/test/test_composition.html
vendored
Normal file
211
plugin/mindmap/edit-mindmap/vendor/test/test_composition.html
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>test Composition</title>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<link href="../css/qunit.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="../js/base.js"></script>
|
||||
<script type="text/javascript" src="../js/lib/tools/qunit.js"></script>
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
<script type="text/javascript">
|
||||
/*global ok, console, k, kampfer, test, QUnit*/
|
||||
kampfer.require('mindMap.Composition');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<h1 id="qunit-header">QUnit for Composition</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">
|
||||
test markup, will be hidden
|
||||
</div>
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
<script type="text/javascript">
|
||||
test('实例化Composition对象', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
ok(obj, '成功实例化Composition对象');
|
||||
ok(obj.constructor === kampfer.mindMap.Composition, 'constructor正确');
|
||||
ok(obj instanceof kampfer.mindMap.Composition, 'instanceof Composition : true');
|
||||
ok(obj instanceof kampfer.events.EventTarget, 'instanceof EventTarget : true');
|
||||
ok(obj instanceof kampfer.Class, 'instanceof Class : true');
|
||||
ok(('_parent' in obj) && !obj._parent, '_parent属性存在,但未初始化');
|
||||
ok(('_id' in obj) && !obj._id, '_id属性存在,但未初始化');
|
||||
ok(('_children' in obj) && !obj._children, '_children属性存在,但未初始化');
|
||||
});
|
||||
|
||||
test('Composition.setParent', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var p = {name:'parent'};
|
||||
var parent = new kampfer.mindMap.Composition();
|
||||
|
||||
try{
|
||||
obj.setParent(obj);
|
||||
}catch(e) {
|
||||
ok(!obj._parent, '无法将composition对象的parent设为它自己');
|
||||
}
|
||||
|
||||
try{
|
||||
obj.setParent(p);
|
||||
}catch(e) {
|
||||
ok(!obj._parent, 'composition对象的parent不能是非composition对象');
|
||||
}
|
||||
|
||||
obj.setParent(parent);
|
||||
ok(obj._parent === parent, '可以通过setParent方法设置parent');
|
||||
ok(obj._parentEventTarget === parent, 'setParent方法会设置_parentEventTarget');
|
||||
|
||||
var pp = new kampfer.mindMap.Composition();
|
||||
try {
|
||||
obj.setParent(pp);
|
||||
} catch(e) {
|
||||
ok(true, 'composition有parent后无法再设置parent');
|
||||
}
|
||||
|
||||
obj.setParent(null);
|
||||
//不要使用setParent(null)来达到删除parent的目的
|
||||
ok(obj.getParent() === null, '可以设置parent为null');
|
||||
});
|
||||
|
||||
test('Composition.getParent', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var p = new kampfer.mindMap.Composition();
|
||||
obj.setParent(p);
|
||||
ok(obj.getParent() === p, '可以通过getParent方法获得_parent');
|
||||
});
|
||||
|
||||
test('Composition.addChlid', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
var o = {};
|
||||
|
||||
try{
|
||||
obj.addChild(o);
|
||||
} catch(e) {
|
||||
ok(true, 'addChild方法只接受composition对象作为参数');
|
||||
}
|
||||
|
||||
var hasId = !!c._id;
|
||||
obj.addChild(c);
|
||||
|
||||
var cid = c._id;
|
||||
ok(!hasId && cid, 'addChild调用child的getId方法');
|
||||
ok(obj._children[cid] === c, 'addChild设置parent的_children属性');
|
||||
ok(c._parent === obj, 'addChild设置child的_parent属性');
|
||||
});
|
||||
|
||||
test('Composition.getChild', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
var cid = 'kampfer';
|
||||
|
||||
ok(obj.getChild(cid) == null, '');
|
||||
|
||||
c.setId(cid);
|
||||
obj.addChild(c);
|
||||
ok(obj.getChild(cid) === c, '');
|
||||
});
|
||||
|
||||
test('Composition.eachChild', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
var c1 = new kampfer.mindMap.Composition();
|
||||
|
||||
var execed = false;
|
||||
obj.eachChild(function(child, id) {
|
||||
execed = true;
|
||||
});
|
||||
ok(!execed, 'parent没有child时,callback不执行');
|
||||
|
||||
obj.addChild(c);
|
||||
obj.eachChild(function(child, id) {
|
||||
if(obj.getChild(id) === child) {
|
||||
execed = true;
|
||||
}
|
||||
});
|
||||
ok(execed, 'callback接受两个参数,第一个是child,第二个是id');
|
||||
|
||||
obj.addChild(c1);
|
||||
var execCount1 = 0;
|
||||
obj.eachChild(function(child, id) {
|
||||
execCount1++;
|
||||
});
|
||||
var execCount2 = 0;
|
||||
obj.eachChild(function(child, id) {
|
||||
execCount2++;
|
||||
if(child === c) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
ok(execCount1 === 2 && execCount2 === 1, 'callback返回false会提前终止迭代');
|
||||
});
|
||||
|
||||
test('Composition.removeChlid', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
var c1 = new kampfer.mindMap.Composition();
|
||||
obj.addChild(c);
|
||||
|
||||
obj.removeChild(c._id);
|
||||
ok( true, 'removeChild接受id字符串作为参数' );
|
||||
ok( !obj.getChild(c._id), 'removeChild将parent的children[child.id]设置为null' );
|
||||
ok( c.getParent() === null, 'removeChild将child的parnet设置为null' );
|
||||
|
||||
obj.addChild(c);
|
||||
|
||||
obj.removeChild(c);
|
||||
if( !obj.getChild(c._id) && c.getParent() === null ) {
|
||||
ok( true, 'removeChild也接受composition对象作为参数' );
|
||||
}
|
||||
|
||||
obj.addChild(c);
|
||||
|
||||
obj.removeChild('kampfer');
|
||||
obj.removeChild(c1);
|
||||
ok(c._id in obj._children, '删除不存在child对parent不造成影响' );
|
||||
});
|
||||
|
||||
//未测试有parent的情况
|
||||
test('Composition.setId', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
obj.addChild(c);
|
||||
var oldId = c._id;
|
||||
c.setId('kampfer');
|
||||
ok(c._id === 'kampfer', '修改child的id');
|
||||
ok(obj.getChild('kampfer') === c, '修改parent中保存的child');
|
||||
ok(!obj.getChild(oldId), 'parent中不再保留旧id');
|
||||
});
|
||||
|
||||
test('Composition.getId', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var hasId = !!obj._id;
|
||||
ok( !hasId && obj.getId(), 'composition没有id的情况下调用getId,将生成一个id');
|
||||
|
||||
obj = new kampfer.mindMap.Composition();
|
||||
obj.setId('kampfer');
|
||||
ok( obj.getId() === 'kampfer', 'composition有id时调用getId将直接返回id' );
|
||||
});
|
||||
|
||||
test('Composition.dispose', function() {
|
||||
var obj = new kampfer.mindMap.Composition();
|
||||
var c = new kampfer.mindMap.Composition();
|
||||
var p = new kampfer.mindMap.Composition();
|
||||
//obj.setParent(p);
|
||||
p.addChild(obj);
|
||||
obj.addChild(c);
|
||||
//console.log(obj);
|
||||
var hasParent = !!obj._parent;
|
||||
var hasChild = obj._children && obj._children[c._id];
|
||||
obj.dispose();
|
||||
ok( hasParent && !obj._parent, '_parent被释放');
|
||||
ok( hasChild && !obj._children, '_children被释放');
|
||||
console.log(obj);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
91
plugin/mindmap/edit-mindmap/vendor/test/test_domDepth.html
vendored
Normal file
91
plugin/mindmap/edit-mindmap/vendor/test/test_domDepth.html
vendored
Normal file
File diff suppressed because one or more lines are too long
394
plugin/mindmap/edit-mindmap/vendor/test/test_events.html
vendored
Normal file
394
plugin/mindmap/edit-mindmap/vendor/test/test_events.html
vendored
Normal file
@@ -0,0 +1,394 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>test events</title>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<link href="../css/qunit.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="../js/base.js"></script>
|
||||
<script type="text/javascript" src="../js/lib/tools/qunit.js"></script>
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
<script type="text/javascript">
|
||||
/*global ok, console, k, kampfer, test, QUnit*/
|
||||
kampfer.require('events');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<h1 id="qunit-header">QUnit for events</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div style="display:none;">
|
||||
<div id="parent_fix">
|
||||
<div id="child_fix">child</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
<script type="text/javascript">
|
||||
/*global kampfer, k, ok, test, QUnit, module, window*/
|
||||
QUnit.config.reorder = false;
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
var p = $('parent_fix'),
|
||||
c = $('child_fix'),
|
||||
liaowei = {
|
||||
name : 'liaowei',
|
||||
nickName : 'kampfer',
|
||||
sex : 'male',
|
||||
age : '25',
|
||||
job : 'Engineer'
|
||||
};
|
||||
|
||||
test('初始状态,缓存为空', function() {
|
||||
var events = kampfer.dataManager._data(c).events;
|
||||
ok(!events, 'elemData.events不存在');
|
||||
});
|
||||
|
||||
module('DOM事件');
|
||||
test('为DOM绑定事件', function() {
|
||||
var key = kampfer.events.addEvent(c, 'click', kampfer.emptyFn);
|
||||
|
||||
ok( key !== undefined, '成功执行addEvent都将返回一个key' );
|
||||
|
||||
var events = kampfer.dataManager._data(c, 'events');
|
||||
ok( events, 'addEvent生成了events');
|
||||
ok( kampfer.type(events) === 'object', 'events是object' );
|
||||
ok( events.click, 'addEvent生成了events.click' );
|
||||
ok( kampfer.type(events.click) === 'array', 'events.click是数组' );
|
||||
ok( events.click.length === 1, 'events.click.length = 1' );
|
||||
ok( events.proxy, 'addEvent生成了events.proxy' );
|
||||
ok( kampfer.type(events.proxy) === 'object', 'events.proxy是object' );
|
||||
ok( kampfer.type(events.proxy.click) === 'function',
|
||||
'第一次为对象绑定click事件,将生成一个proxy函数并通过native方法绑定到对象上,proxy函数被存储到events.proxy对象中');
|
||||
|
||||
var handlerObj = events.click[0];
|
||||
ok( handlerObj instanceof kampfer.events.HandlerObj,
|
||||
'用户操作被保存在一个handlerObj对象中,该对象储存在events.click中');
|
||||
ok( handlerObj.key === key, 'handlerObj.key正确' );
|
||||
ok( handlerObj.handler === kampfer.emptyFn, 'handlerObj.handler正确' );
|
||||
ok( handlerObj.scope === undefined, 'handlerObj.scope正常' );
|
||||
ok( handlerObj.type === 'click', 'handlerObj.type正常' );
|
||||
|
||||
k.events.removeEventByKey(c, 'click', key);
|
||||
});
|
||||
|
||||
test('为DOM重复绑定事件', function(){
|
||||
var emptyFn = function() {};
|
||||
|
||||
var key = kampfer.events.addEvent(c, 'click', emptyFn);
|
||||
var events = kampfer.dataManager._data(c, 'events');
|
||||
var length = events.click.length;
|
||||
var click = events.proxy.click;
|
||||
|
||||
var key2 = kampfer.events.addEvent(c, 'click', emptyFn);
|
||||
var length2 = events.click.length;
|
||||
var click2 = events.proxy.click;
|
||||
|
||||
ok( length === 1 && length2 === 2 &&
|
||||
events.click[1].key === key2 && events.click[0].key === key,
|
||||
'handlerObj被push入events.click数组' );
|
||||
ok( click === click2, '重复绑定相同事件(click)不会生成新的proxy函数' );
|
||||
|
||||
ok( !events.focus, 'events.focus不存在' );
|
||||
ok( !events.proxy.focus, 'events.proxy.focus不存在' );
|
||||
var key3 = kampfer.events.addEvent(c, 'focus', function() {});
|
||||
ok( events.focus, 'events.focus存在' );
|
||||
ok( events.proxy.focus, 'events.proxy.focus存在' );
|
||||
ok( events.focus[0] instanceof kampfer.events.HandlerObj &&
|
||||
events.focus[0].key === key3, 'events.focus[0]是一个handlerObj实例' );
|
||||
|
||||
k.events.removeEventByKey(c, 'click', key);
|
||||
k.events.removeEventByKey(c, 'click', key2);
|
||||
k.events.removeEventByKey(c, 'focus', key3);
|
||||
});
|
||||
|
||||
test('同时绑定不同事件', function(){
|
||||
var evts = '';
|
||||
var handler = function(event) {
|
||||
evts += event.type;
|
||||
};
|
||||
var events = k.dataManager._data(c, 'events');
|
||||
|
||||
ok( !events, '没有存储用户操作' );
|
||||
|
||||
var key = k.events.addEvent(c, ['click', 'mouseover'], handler);
|
||||
k.events.fireEvent(c, ['click', 'mouseover']);
|
||||
|
||||
ok( evts === 'clickmouseover', '成功绑定不同事件');
|
||||
ok( !key, '同时绑定多个事件无法正确获得key');
|
||||
|
||||
events = k.dataManager._data(c, 'events');
|
||||
ok( events.click.length === 1 && events.mouseover.length === 1, '用户操作被存储' );
|
||||
ok( events.proxy.click && events.proxy.mouseover, '成功生成proxy' );
|
||||
|
||||
k.events.removeEvent(c, 'click');
|
||||
k.events.removeEvent(c, 'mouseover');
|
||||
});
|
||||
|
||||
test('触发DOM事件', function(){
|
||||
var handler = function() {
|
||||
ok(true, 'click事件被触发');
|
||||
};
|
||||
|
||||
var key = kampfer.events.addEvent(c, 'click', handler);
|
||||
var key2 = kampfer.events.addEvent(c, 'click', handler);
|
||||
|
||||
kampfer.events.fireEvent(c, 'click');
|
||||
|
||||
ok( key !== key2, '重复绑定相同操作成功');
|
||||
|
||||
k.events.removeEventByKey(c, 'click', key);
|
||||
k.events.removeEventByKey(c, 'click', key2);
|
||||
});
|
||||
|
||||
test('检查this与event', function() {
|
||||
var handler = function(event) {
|
||||
ok(this === c, 'this正常');
|
||||
ok(event instanceof kampfer.events.Event, 'event是kampfer.events.Event的实例');
|
||||
ok(event.type === 'click', 'event.type正确');
|
||||
ok(event.target === c, 'event.target正确');
|
||||
ok(event.currentTarget === c, 'event.currentTarget正确');
|
||||
};
|
||||
|
||||
var key = kampfer.events.addEvent(c, 'click', handler);
|
||||
kampfer.events.fireEvent(c, 'click');
|
||||
|
||||
k.events.removeEventByKey(c, 'click', key);
|
||||
});
|
||||
|
||||
test('传递自定义数据', function() {
|
||||
var handler = function(event) {
|
||||
ok( event.owner, '成功传递了自定义数据' );
|
||||
ok( event.owner.name === 'liaowei', '自定义数据的键值正确' );
|
||||
};
|
||||
|
||||
var key = k.events.addEvent(c, 'click', handler);
|
||||
k.events.fireEvent(c, 'click', {owner:liaowei});
|
||||
|
||||
k.events.removeEventByKey(c, 'click', key);
|
||||
});
|
||||
|
||||
test('取得单个事件的封装函数', function() {
|
||||
var handler = function() {};
|
||||
var key = k.events.addEvent(c, 'click', handler);
|
||||
var handlerObj = k.events.getHandlerObj(c, 'click', handler);
|
||||
ok(key === handlerObj.key, '成功');
|
||||
k.events.removeEvent(c, 'click');
|
||||
});
|
||||
|
||||
test('冒泡测试', function() {
|
||||
var path = '';
|
||||
var type = 'click';
|
||||
var isThisCorrect = [];
|
||||
var isEventCorrect = [];
|
||||
|
||||
function checkThis(objThis, obj, msg) {
|
||||
if( (kampfer.isWindow(objThis) &&
|
||||
kampfer.isWindow(obj)) ||
|
||||
objThis === obj) {
|
||||
isThisCorrect.push(1);
|
||||
} else {
|
||||
isThisCorrect.push(0);
|
||||
}
|
||||
}
|
||||
|
||||
function checkEvent(event, thisObj) {
|
||||
if( event.type === type &&
|
||||
event.currentTarget === thisObj &&
|
||||
event.target === c ) {
|
||||
isEventCorrect.push(1);
|
||||
} else {
|
||||
isEventCorrect.push(0);
|
||||
}
|
||||
}
|
||||
|
||||
k.events.addEvent(c, type, function(event) {
|
||||
checkThis(this, c);
|
||||
checkEvent(event, this);
|
||||
path += 'c';
|
||||
});
|
||||
k.events.addEvent(p, type, function(event) {
|
||||
checkThis(this, p);
|
||||
checkEvent(event, this);
|
||||
path += ' p';
|
||||
});
|
||||
k.events.addEvent(document, type, function(event) {
|
||||
checkThis(this, document);
|
||||
checkEvent(event, this);
|
||||
path += ' document';
|
||||
});
|
||||
k.events.addEvent(window, type, function(event) {
|
||||
checkThis(this, window);
|
||||
checkEvent(event, this);
|
||||
path += ' window';
|
||||
});
|
||||
|
||||
k.events.fireEvent(c, type);
|
||||
ok(path === 'c p document window', 'path : c=>p=>document=>window');
|
||||
ok(isThisCorrect.join('') === '1111', '冒泡过程中this正确');
|
||||
ok(isEventCorrect.join('') === '1111', '冒泡过程中event正确');
|
||||
|
||||
k.events.removeEvent(c, 'click');
|
||||
k.events.removeEvent(p, 'click');
|
||||
k.events.removeEvent(document, 'click');
|
||||
k.events.removeEvent(window, 'click');
|
||||
});
|
||||
|
||||
module('自定义事件');
|
||||
var target = {};
|
||||
//TODO 1.可以重复绑定同一函数
|
||||
test('绑定自定义事件', function() {
|
||||
var data = k.dataManager._data(target, 'events');
|
||||
ok(!data, '缓存为空');
|
||||
|
||||
var key = k.events.addEvent(target, 'cry', function(){});
|
||||
data = k.dataManager._data(target, 'events');
|
||||
ok(data, '缓存不再为空');
|
||||
ok(kampfer.type(data.cry) === 'array', 'events[type]是数组');
|
||||
ok(data.cry[0] instanceof kampfer.events.HandlerObj, 'events[type]的项是kampfer.events.HandlerObj的实例');
|
||||
ok(data.proxy.cry, 'proxy缓存存在');
|
||||
var length = data.cry.length;
|
||||
var proxy = data.proxy.cry;
|
||||
var cry = data.cry[0];
|
||||
|
||||
var fn = function() {};
|
||||
var key2 = k.events.addEvent(target, 'cry', fn);
|
||||
var length2 = data.cry.length;
|
||||
var proxy2 = data.proxy.cry;
|
||||
ok( length2 === length + 1 &&
|
||||
data.cry[0] === cry &&
|
||||
data.cry[1].handler === fn, '重复绑定事件会向events[type]中push项目')
|
||||
ok(proxy === proxy2, '重复绑定不改变proxy');
|
||||
|
||||
k.events.removeEvent(target, 'cry');
|
||||
});
|
||||
|
||||
test('同时绑定多个事件', function() {
|
||||
var events = k.dataManager._data(target, 'events');
|
||||
var handler = function() {};
|
||||
ok(!events, '缓存为空');
|
||||
k.events.addEvent(target, ['say','cry','talk'], handler);
|
||||
|
||||
data = k.dataManager._data(target, 'events');
|
||||
events = k.dataManager._data(target, 'events');
|
||||
ok('say' in events, '');
|
||||
ok(events.say[0].handler === handler);
|
||||
ok('cry' in events, '');
|
||||
ok(events.cry[0].handler === handler);
|
||||
ok('talk' in events, '');
|
||||
ok(events.talk[0].handler === handler);
|
||||
ok(events._count === 4, '');
|
||||
ok('say' in events.proxy, '');
|
||||
ok(events.proxy.say.srcElement === target);
|
||||
ok('cry' in events.proxy, '');
|
||||
ok(events.proxy.cry.srcElement === target);
|
||||
ok('talk' in events.proxy, '');
|
||||
ok(events.proxy.talk.srcElement === target);
|
||||
ok(events.proxy._count === 3, '');
|
||||
|
||||
k.events.removeEvent(target, 'cry');
|
||||
k.events.removeEvent(target, 'say');
|
||||
k.events.removeEvent(target, 'talk');
|
||||
});
|
||||
|
||||
test('触发自定义事件', function() {
|
||||
var ret = '';
|
||||
var key = k.events.addEvent(target, 'cry', function() {
|
||||
ret += 'target cry';
|
||||
});
|
||||
k.events.fireEvent(target, 'cry');
|
||||
ok( ret === 'target cry', '事件被触发');
|
||||
k.events.removeEvent(target, 'cry');
|
||||
});
|
||||
|
||||
test('同时触发多个自定义事件', function() {
|
||||
var ret = [];
|
||||
var handler = function(event) {
|
||||
ret.push(event.type);
|
||||
};
|
||||
k.events.addEvent(target, ['say','cry','talk'], handler);
|
||||
k.events.fireEvent(target, ['say','cry','talk']);
|
||||
ok(ret.join(' ') === 'say cry talk', '事件按绑定顺序触发');
|
||||
|
||||
k.events.removeEvent(target, 'cry');
|
||||
k.events.removeEvent(target, 'say');
|
||||
k.events.removeEvent(target, 'talk');
|
||||
});
|
||||
|
||||
test('触发不存在的事件', function() {
|
||||
k.events.fireEvent(target, 'cry');
|
||||
ok(true, '触发不存在的事件不报错');
|
||||
});
|
||||
|
||||
test('触发自定义事件时的参数检测', function() {
|
||||
var key = k.events.addEvent(target, 'cry', function(event) {
|
||||
ok(this === target, 'this正常');
|
||||
ok(event.type === 'cry', 'event.type正常');
|
||||
ok(event.target === target, 'event.target正常');
|
||||
ok(event.fuck === true, '额外参数正常');
|
||||
});
|
||||
k.events.fireEvent(target, 'cry', {fuck:true});
|
||||
k.events.removeEvent(target, 'cry');
|
||||
});
|
||||
|
||||
test('通过removeEventByKey删除自定义事件', function() {
|
||||
var key = k.events.addEvent(target, 'say', function(){});
|
||||
var key2 = k.events.addEvent(target, 'say', function(){});
|
||||
var data = k.dataManager._data(target, 'events');
|
||||
ok(data.say.length === 2);
|
||||
ok(data.proxy.say);
|
||||
ok(data.proxy._count === 1);
|
||||
k.events.removeEventByKey(target, 'say', key);
|
||||
ok(data.say.length === 1);
|
||||
ok(data.say[0].key === key2);
|
||||
ok(data.proxy.say);
|
||||
ok(data.proxy._count === 1);
|
||||
//传递并不存在key
|
||||
k.events.removeEventByKey(target, 'say', 999999);
|
||||
ok(data.say.length === 1);
|
||||
ok(data.say[0].key === key2);
|
||||
ok(data.proxy.say);
|
||||
ok(data.proxy._count === 1);
|
||||
k.events.removeEventByKey(target, 'say', key2);
|
||||
data = k.dataManager._data(target, 'events');
|
||||
ok(!data);
|
||||
});
|
||||
|
||||
test('通过removeEvent删除自定义事件', function() {
|
||||
var data = k.dataManager._data(target, 'events');
|
||||
ok(!data);
|
||||
k.events.addEvent(target, ['say', 'say'], function() {});
|
||||
data = k.dataManager._data(target, 'events');
|
||||
ok(data.say.length === 2);
|
||||
ok(data.proxy.say);
|
||||
ok(data.proxy._count === 1);
|
||||
k.events.removeEvent(target, 'say');
|
||||
data = k.dataManager._data(target, 'events');
|
||||
ok(!data);
|
||||
});
|
||||
|
||||
test('plain object的自定义事件冒泡', function(){
|
||||
var child = {
|
||||
getParent : function() {
|
||||
return target;
|
||||
}
|
||||
};
|
||||
var ret = [];
|
||||
k.events.addEvent(child, 'say', function() {
|
||||
ret.push('child say');
|
||||
});
|
||||
k.events.addEvent(target, 'say', function() {
|
||||
ret.push('target say');
|
||||
});
|
||||
k.events.fireEvent(child, 'say');
|
||||
ok( ret.join('=>') === 'child say=>target say' );
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
67
plugin/mindmap/edit-mindmap/vendor/test/test_index.html
vendored
Normal file
67
plugin/mindmap/edit-mindmap/vendor/test/test_index.html
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>test mapController.js</title>
|
||||
<script type="text/javascript" src="../js/base.js"></script>
|
||||
<script type="text/javascript">
|
||||
kampfer.require('mindMap.MapController');
|
||||
</script>
|
||||
<style type="text/css">
|
||||
*{padding:0;margin:0;}
|
||||
.map{width:3000px;height:1500px;position:absolute;background-color:blue;}
|
||||
#container{width:1000px;height:500px;overflow:hidden;position:relative;background-color:red;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
<script type="text/javascript">
|
||||
//fake data
|
||||
var data = {
|
||||
//节点信息
|
||||
nodes : {
|
||||
//根节点
|
||||
root : {
|
||||
id : 'root',
|
||||
//父节点列表
|
||||
parents : [],
|
||||
//子节点列表
|
||||
children : [],
|
||||
//内容(文字)
|
||||
content : '',
|
||||
//位置信息
|
||||
offset : {
|
||||
x : 10,
|
||||
y : 10
|
||||
},
|
||||
//样式信息
|
||||
style : 'root'
|
||||
},
|
||||
//其他节点
|
||||
nodeOne : {
|
||||
id : 'a',
|
||||
},
|
||||
nodeTwo : {
|
||||
id : 'b',
|
||||
}
|
||||
},
|
||||
//map配置信息
|
||||
config : {}
|
||||
};
|
||||
|
||||
var map = new kampfer.mindMap.MapController(data, {
|
||||
cssName : 'map',
|
||||
parentNode : document.getElementById('container')
|
||||
});
|
||||
map.render();
|
||||
map.show();
|
||||
|
||||
var map2 = new kampfer.mindMap.MapController(data, {
|
||||
cssName : 'map2',
|
||||
parentNode : document.getElementById('container')
|
||||
});
|
||||
map2.render();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
18
plugin/mindmap/edit-mindmap/vendor/test/test_parentNode_null.html
vendored
Normal file
18
plugin/mindmap/edit-mindmap/vendor/test/test_parentNode_null.html
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<div style="position: absolute;top: -10000px;left: -10000px;width: 1000px;height: 1000px;">
|
||||
test markup, will be hidden
|
||||
<div id="parent_fix">
|
||||
<div id="child_fix">child</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var c = document.getElementById('child_fix');
|
||||
var p = document.getElementById('parnet_fix');
|
||||
console.log( c.parentNode === p );
|
||||
console.log( c.parentNode );
|
||||
console.log( p );
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
25
plugin/mindmap/edit-mindmap/vendor/test/test_template.html
vendored
Normal file
25
plugin/mindmap/edit-mindmap/vendor/test/test_template.html
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>test template</title>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<link href="../css/qunit.css" rel="stylesheet" type="text/css" />
|
||||
<script type="text/javascript" src="../js/base.js"></script>
|
||||
<script type="text/javascript" src="../js/lib/tools/qunit.js"></script>
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- 共用文件,不要修改 start -->
|
||||
<h1 id="qunit-header">QUnit for test</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture">
|
||||
test markup, will be hidden
|
||||
</div>
|
||||
<!-- 共用文件,不要修改 end -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user