jquery-ui/ui/tests/autodrag.html

155 lines
4.7 KiB
HTML
Raw Normal View History

2008-05-24 14:09:23 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery UI - Automated Tests</title>
2008-05-24 22:30:03 +00:00
<script type="text/javascript" src="../../jquery/jquery-1.2.6.js"></script>
2008-05-24 14:09:23 +00:00
<script type="text/javascript" src="../../ui/source/ui.core.js"></script>
<script type="text/javascript" src="../../ui/source/ui.draggable.js"></script>
<script type="text/javascript" src="../../ui/source/ui.selectable.js"></script>
2008-05-24 14:09:23 +00:00
<script type="text/javascript" src="ui.testmouse.js"></script>
2008-05-24 14:09:23 +00:00
<style type="text/css">
html, body { height: 100%; }
2008-05-24 14:09:23 +00:00
#main { height: 100%; }
#foo { position: relative; margin: 10px; padding: 10px; border: 3px solid gray; width: 200px; height: 200px; background: #eef; text-align: center; }
#foo * { margin: 4px; }
.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; }
.ui-selectable .msg-missing-class { display: none !important; background: red; color: white; font-weight: bold; }
.ui-selectable .msg-enabled { display: block; }
.ui-selectable .msg-disabled { display: none; }
.ui-selectable-disabled .msg-enabled { display: none !important; }
.ui-selectable-disabled .msg-disabled { display: block !important; }
//.ui-selectee { border: 1px solid white; }
.ui-selecting { background: Highlight; color: HighlightText; outline: 1px dotted white; }
.ui-selected { background: Highlight; color: HighlightText; outline: 1px dotted black; }
2008-05-24 14:09:23 +00:00
</style>
<script type="text/javascript">
$(function() {
var speed = "fast";
2008-05-24 14:09:23 +00:00
2008-05-26 14:30:37 +00:00
var queue;
var start = function() {
queue = tests.slice().reverse(); // clone
$("#status").text("Running...");
2008-05-26 14:30:37 +00:00
nextTest();
}
var stop = function() {
$("#status").text("Ready");
teardown();
2008-05-26 14:30:37 +00:00
}
2008-05-26 14:30:37 +00:00
var tests = [];
var nextTest = function() {
if (queue.length) {
var nTest = queue.pop();
teardown(function() {
setupAndRun(nTest);
});
2008-05-26 14:30:37 +00:00
} else {
stop();
}
}
var num = 0;
2008-05-26 14:30:37 +00:00
var addTest = function(fn) {
num += 1;
tests.push({
num: num,
fn: fn
});
2008-05-26 14:30:37 +00:00
}
var setupAndRun = function(nTest) {
$('#testnum').text(nTest.num);
$('#sandbox').hide()
.append('<ul id="foo">' +
'<li class="msg-missing-class">THIS TEXT SHOULD NOT BE VISIBLE</li>' +
'<li class="msg-enabled">enabled</li>' +
'<li class="msg-disabled">disabled</li>' +
'<li>Item 2</li>' +
'<li>Item 3</li>' +
'<li>Item 4</li>' +
'<li>Item 5</li>' +
'<li>Item 6</li>' +
'<li>Item 7</li>' +
'<li>Item 8</li>' +
'</ul>')
$('#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();
}
var plugin = "draggable";
plugin = "selectable"
var testFn = "testMouse";
var testArgs = ["drag", 40, 50];
//1
addTest(function() { $("#foo")[plugin]()[testFn].apply($("#foo"), testArgs); });
//2
addTest(function() { $("#foo")[plugin]({ disabled: true })[testFn].apply($("#foo"), testArgs); });
addTest(function() { $("#foo")[plugin]({ disabled: false })[testFn].apply($("#foo"), testArgs); });
//4
addTest(function() { $("#foo")[plugin]()[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
addTest(function() { $("#foo")[plugin]()[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
//6
addTest(function() { $("#foo")[plugin]()[plugin]('enable')[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
addTest(function() { $("#foo")[plugin]()[plugin]('disable')[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
//8
addTest(function() { $("#foo")[plugin]({ disabled: false })[plugin]('disable')[testFn].apply($("#foo"), testArgs); });
addTest(function() { $("#foo")[plugin]({ disabled: true })[plugin]('enable')[testFn].apply($("#foo"), testArgs); });
//10
addTest(function() { $("#foo")[plugin]({ disabled: false }).data('disabled.' + plugin, true)[testFn].apply($("#foo"), testArgs); });
addTest(function() { $("#foo")[plugin]({ disabled: true }).data('disabled.' + plugin, false)[testFn].apply($("#foo"), testArgs); });
$('#begin').click(function() {
2008-05-26 14:30:37 +00:00
start();
2008-05-24 14:09:23 +00:00
});
});
</script>
</head>
<body>
<div id="main">
<h1>jQuery UI - Automated Tests</h1>
2008-05-24 14:09:23 +00:00
<div>
Status: <span id="status">Ready</span>
</div>
<div>
Test: <span id="testnum"></span>
</div>
<div style="height: 3em;"><button id="begin">Run Test</button></div>
<div id="sandbox">
2008-05-24 14:09:23 +00:00
</div>
</div>
</body>
</html>