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> <title>Sortable :: Tests</title>
</head> </head>
<body> <body>
<div id="canvas"> <div id="canvas">
<ul id="simple"> <ul id="simple">
<li>item 1</li> <li>item 1</li>
@ -17,11 +16,24 @@
</ul> </ul>
</div> </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/raf.js"></script>
<script src="./src/simulate.js"></script> <script src="./src/simulate.js"></script>
<script src="./src/qunit.ext.js"></script>
<script src="../Sortable.js"></script> <script src="../Sortable.js"></script>
<script>
Sortable.create(simple);
</script>
<script src="./sortable.tests.js"></script> <script src="./sortable.tests.js"></script>
</body> </body>
</html> </html>

9
tests/sortable.tests.js

@ -1,8 +1,8 @@
'use strict'; 'use strict';
Sortable.create(simple); QUnit.module('Sortable');
simulateDrag({ QUnit.sortableTest('simple', {
from: { from: {
el: '#simple', el: '#simple',
index: 0 index: 0
@ -12,6 +12,7 @@ simulateDrag({
el: '#simple', el: '#simple',
index: 'last' 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(); callback();
} }
}); });
return {
target: fromEl,
fromList: fromEl.parentNode,
toList: toEl.parentNode
};
} }

Loading…
Cancel
Save