Skip to content
Permalink
Browse files

auto tests - now runs multiple tests with status

  • Loading branch information
rdworth committed May 26, 2008
1 parent 48009db commit 661f111abb344bfee1f1b9520de32ab5f6447409
Showing with 78 additions and 42 deletions.
  1. +67 −32 ui/tests/autodrag.html
  2. +11 −10 ui/tests/ui.testmouse.js
@@ -12,7 +12,13 @@

html, body { height: 100%; }
#main { height: 100%; }
.drag { position: relative; margin: 10px; padding: 10px; border: 3px solid black; cursor: move; width: 200px; height: 40px; background: #eef; }

#foo { position: relative; margin: 10px; padding: 10px; border: 3px solid gray; cursor: move; width: 200px; height: 100px; background: #eef; text-align: center; }
.ui-draggable .msg-missing-class { display: none !important; background: red; color: white; font-weight: bold; }
.ui-draggable .msg-enabled { display: block; }
.ui-draggable .msg-disabled { display: none; }
.ui-draggable-disabled .msg-enabled { display: none !important; }
.ui-draggable-disabled .msg-disabled { display: block !important; }

</style>

@@ -24,46 +30,77 @@
<script type="text/javascript">
$(function() {

$(".drag").draggable().testMouse({
speed: "fast"
});
var speed = "slow"

var queue;
var start = function() {
queue = tests.slice(); // clone
queue = tests.slice().reverse(); // clone
$("#status").text("Running...");
nextTest();
}
var stop = function() {
$("#status").text("Ready");
teardown();
}

var tests = [];
var nextTest = function() {
if (queue.length) {
queue.pop().apply();
var nTest = queue.pop();
teardown(function() {
setupAndRun(nTest);
});
} else {
stop();
}
}


var num = 0;

var addTest = function(fn) {
tests.unshift(fn);
num += 1;
tests.push({
num: num,
fn: fn
});
}

addTest(function() {
$("#d1").testMouse("drag", 100, 0, nextTest);
});

addTest(function() {
$("#d2").testMouse("drag", 100, 0, nextTest);
});

addTest(function() {
$("#d3").testMouse("drag", 100, 0, nextTest);
});

$('#begin').click(function(e) {
var setupAndRun = function(nTest) {
$('#testnum').text(nTest.num);
$('#sandbox').hide().append('<div id="foo">' +
'<div class="msg-missing-class">THIS TEXT SHOULD NOT BE VISIBLE</div>' +
'<div class="msg-enabled">enabled</div>' +
'<div class="msg-disabled">disabled</div>' +
'</div>');
$('#foo').testMouse({
speed: speed,
complete: nextTest
});
$('#sandbox').show();
nTest.fn.apply(nTest.fn);
}

var teardown = function(fn) {
$('#sandbox').hide();
$('#foo').remove();
if ($.isFunction(fn)) fn.apply();
}
//1
addTest(function() { $("#foo").draggable().testMouse("drag", 100, 100); });
//2
addTest(function() { $("#foo").draggable({ disabled: true }).testMouse("drag", 100, 100); });
addTest(function() { $("#foo").draggable({ disabled: false }).testMouse("drag", 100, 100); });
//4
addTest(function() { $("#foo").draggable().draggable('disable').testMouse("drag", 100, 100); });
addTest(function() { $("#foo").draggable().draggable('enable').testMouse("drag", 100, 100); });
//6
addTest(function() { $("#foo").draggable().draggable('enable').draggable('disable').testMouse("drag", 100, 100); });
addTest(function() { $("#foo").draggable().draggable('disable').draggable('enable').testMouse("drag", 100, 100); });
//8
addTest(function() { $("#foo").draggable({ disabled: false }).draggable('disable').testMouse("drag", 100, 100); });
addTest(function() { $("#foo").draggable({ disabled: true }).draggable('enable').testMouse("drag", 100, 100); });

$('#begin').click(function() {
start();
});

@@ -77,20 +114,18 @@

<h1>jQuery UI Draggable - Automated Test</h1>

Status: <span id="status">Ready</span>

<div style="height: 3em;"><button id="begin">Run Test</button></div>

<div class="drag" id="d1">
Drag 1
<div>
Status: <span id="status">Ready</span>
</div>

<div class="drag" id="d2">
Drag 2
<div>
Test: <span id="testnum"></span>
</div>

<div class="drag" id="d3">
Drag 3
<div style="height: 3em;"><button id="begin">Run Test</button></div>

<div id="sandbox">

</div>

</div>
@@ -8,17 +8,18 @@
* Revision: $Id: $
*/
;(function($) {

var mouseX = 0;
var mouseY = 0;

$.widget("ui.testMouse", {
mouseX: 0,
mouseY: 0,
trackMouse: function() {},
init: function() {
var self = this;
this.trackMouse = function(e) {
if (e.isTrusted !== false) {
self.mouseX = e.pageX;
self.mouseY = e.pageY;
mouseX = e.pageX;
mouseY = e.pageY;
}
}
$(document).bind("mousemove", this.trackMouse);
@@ -67,7 +68,7 @@
up: function(x, y) {
this.dispatch("mouseup", x, y);
},
drag: function(dx, dy, complete) {
drag: function(dx, dy) {
var self = this;

var center = this.center();
@@ -107,8 +108,8 @@

var testStart = function() {
self.element.bind("mouseover", updateCursor).bind("mouseout", resetCursor);
fakemouse.appendTo('body').css({ position: 'absolute', left: self.mouseX, top: self.mouseY, zIndex: 5000 });
realmouse.appendTo('body').css({ position: 'absolute', left: self.mouseX, top: self.mouseY, zIndex: 5000, opacity: 0.1 });
fakemouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000 });
realmouse.appendTo('body').css({ position: 'absolute', left: mouseX, top: mouseY, zIndex: 5000, opacity: 0.1 });
mousescreen.appendTo('body').css({ width: '100%', height: '100%', position: 'absolute', top: 0, left: 0, zIndex: 5000 })
.mousemove(function(e) { realmouse.css({ left: e.pageX, top: e.pageY }); return false; })
.mousedown(function() { return false; })
@@ -119,11 +120,11 @@
var testStop = function() {
self.element.unbind("mouseover", updateCursor).unbind("mouseout", resetCursor);
mousescreen.remove();
self.mouseX = realmouse.css("left");
self.mouseY = realmouse.css("top");
mouseX = realmouse.css("left");
mouseY = realmouse.css("top");
realmouse.remove();
fakemouse.remove();
($.isFunction(complete) && complete.apply());
self.options.complete.apply();
}

testStart();

0 comments on commit 661f111

Please sign in to comment.
You can’t perform that action at this time.