Permalink
Browse files

根据drag的修改(不再设置margin为0)更新用例

[Testcase]根据drag的修改(不再设置margin为0)更新用例
drag: 不再设置margin为0
draggable:static的元素,不能拖动,并且不改static为relative
  • Loading branch information...
tianlili
tianlili committed Apr 1, 2012
1 parent d342200 commit 8aaab4dfaab3c34b1f496680be4181ab2d7f36ca
Showing with 156 additions and 70 deletions.
  1. +100 −59 test/baidu/dom/drag.js
  2. +56 −11 test/baidu/dom/draggable.js
View
@@ -47,10 +47,10 @@ module('baidu.dom.drag');
timeout ? setTimeout(callback, timeout) : callback();
},
check : function() {
equals(parseInt($(div).css('left')), dc.check.left,
"check left after drag");
equals(parseInt($(div).css('top')), dc.check.left,
"check top after drag");
equals(baidu.dom.getPosition(div).left, dc.check.left,
"check left after drag");
equals(baidu.dom.getPosition(div).top, dc.check.left,
"check top after drag");
}
};
return dc;
@@ -62,33 +62,34 @@ module('baidu.dom.drag');
*/
test('base and events', function() {
expect(5);
var noDragging = true;
var dc = window.drag_check({
ondragstart : function() {
ok(true, 'drag start');
},
ondrag : function() {
if (noDragging) {
ok(true, 'dragging');
noDragging = false;
}
},
ondragend : function() {
ok(true, 'drag end');
}
});
// 启动前,等待200
QUnit.stop();
ua.fnQueue().add(function() {
dc.move({
clientX : 50,
clientY : 50
ua.importsrc("baidu.dom.getPosition", function(){
var noDragging = true;
var dc = window.drag_check({
ondragstart : function() {
ok(true, 'drag start');
},
ondrag : function() {
if (noDragging) {
ok(true, 'dragging');
noDragging = false;
}
},
ondragend : function() {
ok(true, 'drag end');
}
});
}, 50).add(function() {
dc.check.left = 50;
dc.check();
dc.d.stop();
}, 50).add(QUnit.start, 50).next();
ua.fnQueue().add(function() {
dc.move({
clientX : 50,
clientY : 50
});
}, 50).add(function() {
dc.check.left = 50;
dc.check();
dc.d.stop();
}, 50).add(QUnit.start, 50).next();
}, "baidu.dom.getPosition", "baidu.dom.drag");
});
test('update', function() {
@@ -158,6 +159,7 @@ test('range and update range', function() {
});
test('margin', function() {
stop();
var div = document.createElement("div");
div.id = 'test_margin_div';
document.body.appendChild(div);
@@ -171,21 +173,24 @@ test('margin', function() {
clientY : 0
});
var d = baidu.dom.drag(div);
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
d.stop();
equals(baidu.dom.getPosition(div).left, "70", "left right");
equals(baidu.dom.getPosition(div).top, "70", "top right");
document.body.removeChild(div);
start();
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
d.stop();
equals(baidu.dom.getPosition(div).left, "70", "left right");
equals(baidu.dom.getPosition(div).top, "70", "top right");
equals(div.style["margin"], "20px", "The margin is not changed");
document.body.removeChild(div);
start();
}, 20);
}, 20);
stop();
});
test('margin autoStop', function() {
stop();
var div = document.createElement("div");
div.id = 'test_margin_div';
document.body.appendChild(div);
@@ -199,47 +204,83 @@ test('margin autoStop', function() {
clientY : 0
});
var d = baidu.dom.drag(div);
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
ua.mouseup(document.body);
equals(baidu.dom.getPosition(div).left, "70", "left right");
equals(baidu.dom.getPosition(div).top, "70", "top right");
document.body.removeChild(div);
start();
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
ua.mouseup(document.body);
equals(baidu.dom.getPosition(div).left, "70", "left right");
equals(baidu.dom.getPosition(div).top, "70", "top right");
equals(div.style["margin"], "20px", "The margin is not changed");
document.body.removeChild(div);
start();
}, 20);
}, 20);
stop();
});
test('no margin', function() {
stop();
var div = document.createElement("div");
div.id = 'test_margin_div';
document.body.appendChild(div);
$("#test_margin_div").css('position', 'absolute').css(
'height', 10).css('width', 10).css(
'background-color', 'red').css('left', 0).css('top',
0);
$("#test_margin_div").css('margin', '0');
$("#test_margin_div").css('margin', '0px');
ua.mousemove(document.body, {
clientX : 0,
clientY : 0
});
var d = baidu.dom.drag(div);
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
equals(baidu.dom.getPosition(div).left, "50", "left right");
equals(baidu.dom.getPosition(div).top, "50", "top right");
d.stop();
document.body.removeChild(div);
start();
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
equals(baidu.dom.getPosition(div).left, "50", "left right");
equals(baidu.dom.getPosition(div).top, "50", "top right");
equals(div.style["margin"], "0px", "The margin is not changed");
d.stop();
document.body.removeChild(div);
start();
}, 20);
}, 20);
});
test('border', function() {
stop();
ua.importsrc("baidu.dom.getPosition", function(){
var div = document.createElement("div");
div.id = 'test_margin_div';
document.body.appendChild(div);
$("#test_margin_div").css('position', 'absolute').css(
'height', 10).css('width', 10).css("top", 0).css("left", 0).
css('background-color', 'green').css('border', '5px');
ua.mousemove(document.body, {
clientX : 0,
clientY : 0
});
var d = baidu.dom.drag(div);
setTimeout(function(){
ua.mousemove(document.body, {
clientX : 50,
clientY : 50
});
setTimeout(function(){
d.stop();
equals(baidu.dom.getPosition(div).left, "50", "left right");
equals(baidu.dom.getPosition(div).top, "50", "top right");
document.body.removeChild(div);
start();
}, 20);
}, 20);
}, "baidu.dom.getPosition", "baidu.dom.drag");
});
// test('drag with update', function() {
// stop();
// expect(2);
@@ -11,12 +11,16 @@ var clear = function(element, dd, needstart) {
/* need move mouse before testing */
test('check return value', function() {
stop();
expect(1);
var div = document.createElement('div');
document.body.appendChild(div);
var div1 = baidu.dom.draggable(div);
ok(baidu.lang.isFunction(div1.cancel), "check return function");
clear(div, div1);
ua.importsrc("baidu.dom.getPosition", function(){
var div = document.createElement('div');
document.body.appendChild(div);
var div1 = baidu.dom.draggable(div);
ok(baidu.lang.isFunction(div1.cancel), "check return function");
clear(div, div1);
start();
}, "baidu.dom.getPosition", "baidu.dom.drag");
});
test('drag,no options', function() {
@@ -40,8 +44,48 @@ test('drag,no options', function() {
var move = function(ele, x, y) {
if (x >= 100) {
ua.mouseup(ele);
equal(parseInt($(ele).css('left')), 100);
equal(parseInt($(ele).css('top')), 50);
equal(baidu.dom.getPosition(div).left, 100, "stop left");
equal(baidu.dom.getPosition(div).top, 50, "stop top");
clear(div, div1, true);
} else {
ua.mousemove(document, {
clientX : x + 10,
clientY : y + 5
});
setTimeout(function() {
move(ele, x + 10, y + 5);
}, 20);
}
};
move(div, 0, 0);
});
test('drag, static', function() {
stop();
expect(3);
var div = document.createElement('div');
document.body.appendChild(div);
$(div).css('position', 'static').css('left', '0').css('top', '0').css(
'backgroundColor', 'red').css('width', '100px').css('height',
'100px');
var oleft = baidu.dom.getPosition(div).left;
var otop = baidu.dom.getPosition(div).top;
var div1 = baidu.dom.draggable(div);// 注册onmousedown事件
ua.mousemove(div, {
clientX : 0,
clientY : 0
});
ua.mousedown(div, {
clientX : 0,
clientY : 0
});
var move = function(ele, x, y) {
if (x >= 100) {
ua.mouseup(ele);
equal(baidu.dom.getPosition(div).left, oleft, "stop left, the ele is not dragged");
equal(baidu.dom.getPosition(div).top, otop, "stop top, the ele is not dragged");
equal($(div).css('position'), 'static', "The ele is still static");
clear(div, div1, true);
} else {
ua.mousemove(document, {
@@ -67,8 +111,8 @@ test('options', function() {
'red');
var div1 = baidu.dom.draggable('div_test', {
ondragstart : function(ele, op) {
equal(parseInt($(ele).css('left')), 0, 'start left');
equal(parseInt($(ele).css('top')), 0, 'start top');
equal(baidu.dom.getPosition(div).left, 0, 'start left');
equal(baidu.dom.getPosition(div).top, 0, 'start top');
},
ondrag : function(ele, op) {
ok(true, 'drag');
@@ -127,8 +171,8 @@ test('undraggble', function() {
endX : 12,
endY : 12,
callback : function() {
equals(parseInt($(div).css('left')), 0);
equals(parseInt($(div).css('top')), 0);
equals(baidu.dom.getPosition(div).left, 0);
equals(baidu.dom.getPosition(div).top, 0);
clear(div, div1, true);
}
});
@@ -181,6 +225,7 @@ test('ddManager', function() {
clear(div, div1, true);
}, 60);
});
//
//// 测试非static元素是否可以正确移动,为便于定位,元素追加至某有特殊定位的父元素中
//test('element none static', function() {

0 comments on commit 8aaab4d

Please sign in to comment.