diff options
author | Richard Worth <rdworth@gmail.com> | 2008-05-26 20:29:22 +0000 |
---|---|---|
committer | Richard Worth <rdworth@gmail.com> | 2008-05-26 20:29:22 +0000 |
commit | 661f111abb344bfee1f1b9520de32ab5f6447409 (patch) | |
tree | 1361b218a700f0db084bdc8ffcd58199aa7fcbde /ui | |
parent | 48009db7e833e18f4400c05a57e1932aa42c674f (diff) | |
download | jquery-ui-661f111abb344bfee1f1b9520de32ab5f6447409.tar.gz jquery-ui-661f111abb344bfee1f1b9520de32ab5f6447409.zip |
auto tests - now runs multiple tests with status
Diffstat (limited to 'ui')
-rw-r--r-- | ui/tests/autodrag.html | 99 | ||||
-rw-r--r-- | ui/tests/ui.testmouse.js | 21 |
2 files changed, 78 insertions, 42 deletions
diff --git a/ui/tests/autodrag.html b/ui/tests/autodrag.html index 2f8f2b2b9..bb005b518 100644 --- a/ui/tests/autodrag.html +++ b/ui/tests/autodrag.html @@ -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 @@ html, body { height: 100%; } <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 @@ $(function() { <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>
diff --git a/ui/tests/ui.testmouse.js b/ui/tests/ui.testmouse.js index 7d734693f..d629e4bff 100644 --- a/ui/tests/ui.testmouse.js +++ b/ui/tests/ui.testmouse.js @@ -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();
|