Browse Source

+ QUnit

tests
RubaXa 9 years ago
parent
commit
652098ad86
  1. 14
      tests/index.html
  2. 9
      tests/sortable.tests.js
  3. 13
      tests/src/qunit.ext.js
  4. 6
      tests/src/simulate.js

14
tests/index.html

@ -8,7 +8,6 @@
<title>Sortable :: Tests</title>
</head>
<body>
<div id="canvas">
<ul id="simple">
<li>item 1</li>
@ -17,11 +16,24 @@
</ul>
</div>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.21.0.css"/>
<script src="//code.jquery.com/qunit/qunit-1.21.0.js"></script>
<script src="./src/raf.js"></script>
<script src="./src/simulate.js"></script>
<script src="./src/qunit.ext.js"></script>
<script src="../Sortable.js"></script>
<script>
Sortable.create(simple);
</script>
<script src="./sortable.tests.js"></script>
</body>
</html>

9
tests/sortable.tests.js

@ -1,8 +1,8 @@
'use strict';
Sortable.create(simple);
QUnit.module('Sortable');
simulateDrag({
QUnit.sortableTest('simple', {
from: {
el: '#simple',
index: 0
@ -12,6 +12,7 @@ simulateDrag({
el: '#simple',
index: 'last'
}
}, function () {
}, function (assert, scope) {
assert.ok(scope.toList.contains(scope.target), 'container');
assert.equal(scope.target, scope.toList.lastElementChild, 'position');
});

13
tests/src/qunit.ext.js

@ -0,0 +1,13 @@
(function () {
'use strict';
QUnit.sortableTest = function sortableTest(name, options, fn) {
QUnit.test(name, function (assert) {
var done = assert.async();
var data = simulateDrag(options, function () {
fn(assert, data, options);
done();
});
});
};
})();

6
tests/src/simulate.js

@ -108,6 +108,12 @@
callback();
}
});
return {
target: fromEl,
fromList: fromEl.parentNode,
toList: toEl.parentNode
};
}

Loading…
Cancel
Save