r98564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98563‎ | r98564 | r98565 >
Date:21:09, 30 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added more tests for es.ModelNode
Modified paths:
  • /trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js (added) (history)
  • /trunk/parsers/wikidom/tests/hype/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/test.js (deleted) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/test.js
@@ -1,47 +0,0 @@
2 -module( 'Base classes' );
3 -
4 -test( 'es.ModelNode', function() {
5 - var modelNode1 = new es.ModelNode(),
6 - modelNode2 = new es.ModelNode(),
7 - modelNode3 = new es.ModelNode(),
8 - modelNode4 = new es.ModelNode();
9 -
10 - // Event triggering is detected using a callback that increments a number
11 - var updates = 0;
12 - modelNode1.on( 'update', function() {
13 - updates++
14 - } );
15 -
16 - // Array methods
17 -
18 - modelNode1.push( modelNode2 );
19 - equal( updates, 1, 'es.ModelNode emits update events on push' );
20 - equal( modelNode1[0], modelNode2, 'es.ModelNode appends Node on push' );
21 -
22 - modelNode1.unshift( modelNode3 );
23 - equal( updates, 2, 'es.ModelNode emits update events on unshift' );
24 - equal( modelNode1[0], modelNode3, 'es.ModelNode prepends Node on unshift' );
25 -
26 - modelNode1.splice( 1, 0, modelNode4 );
27 - equal( updates, 3, 'es.ModelNode emits update events on splice' );
28 - equal( modelNode1[1], modelNode4, 'es.ModelNode inserts Node on splice' );
29 -
30 - modelNode1.reverse();
31 - equal( updates, 4, 'es.ModelNode emits update events on reverse' );
32 -
33 - modelNode1.pop();
34 - equal( updates, 5, 'es.ModelNode emits update events on pop' );
35 - deepEqual(
36 - modelNode1.slice( 0 ),
37 - [modelNode3, modelNode2],
38 - 'es.ModelNode removes last Node on pop'
39 - );
40 -
41 - modelNode1.shift();
42 - equal( updates, 6, 'es.ModelNode emits update events on shift' );
43 - deepEqual(
44 - modelNode1.slice( 0 ),
45 - [modelNode2],
46 - 'es.ModelNode removes first Node on shift'
47 - );
48 -} );
Index: trunk/parsers/wikidom/tests/hype/es.ModelNode.test.js
@@ -0,0 +1,86 @@
 2+module( 'Base classes' );
 3+
 4+test( 'es.ModelNode', 17, function() {
 5+ // Example data (integers) is used for simplicity of testing
 6+ var modelNode1 = new es.ModelNode(),
 7+ modelNode2 = new es.ModelNode( [1] ),
 8+ modelNode3 = new es.ModelNode( [1, 2]),
 9+ modelNode4 = new es.ModelNode( [1, 2, 3] );
 10+
 11+ // Event triggering is detected using a callback that increments a counter
 12+ var updates = 0;
 13+ modelNode1.on( 'update', function() {
 14+ updates++;
 15+ } );
 16+ var attaches = 0;
 17+ modelNode2.on( 'attach', function() {
 18+ attaches++;
 19+ } );
 20+ var detaches = 0;
 21+ modelNode2.on( 'detach', function() {
 22+ detaches++;
 23+ } );
 24+
 25+ /** @covers es.ModelNode.push */
 26+ modelNode1.push( modelNode2 );
 27+ equal( updates, 1, 'es.ModelNode emits update events on push' );
 28+ equal( modelNode1[0], modelNode2, 'es.ModelNode appends node on push' );
 29+
 30+ /** @covers es.ModelNode.attach */
 31+ equal( attaches, 1, 'es.ModelNode emits attach events when added to another node' );
 32+
 33+ /** @covers es.ModelNode.unshift */
 34+ modelNode1.unshift( modelNode3 );
 35+ equal( updates, 2, 'es.ModelNode emits update events on unshift' );
 36+ equal( modelNode1[0], modelNode3, 'es.ModelNode prepends node on unshift' );
 37+
 38+ /** @covers es.ModelNode.splice */
 39+ modelNode1.splice( 1, 0, modelNode4 );
 40+ equal( updates, 3, 'es.ModelNode emits update events on splice' );
 41+ equal( modelNode1[1], modelNode4, 'es.ModelNode inserts node on splice' );
 42+
 43+ /** @covers es.ModelNode.reverse */
 44+ modelNode1.reverse();
 45+ equal( updates, 4, 'es.ModelNode emits update events on reverse' );
 46+
 47+ /** @covers es.ModelNode.sort */
 48+ modelNode1.sort( function( a, b ) {
 49+ return a.length < b.length ? -1 : 1;
 50+ } );
 51+ equal( updates, 5, 'es.ModelNode emits update events on sort' );
 52+ deepEqual(
 53+ modelNode1.slice( 0 ),
 54+ [modelNode2, modelNode3, modelNode4],
 55+ 'es.ModelNode properly orders nodes on sort'
 56+ );
 57+
 58+ /** @covers es.ModelNode.pop */
 59+ modelNode1.pop();
 60+ equal( updates, 6, 'es.ModelNode emits update events on pop' );
 61+ deepEqual(
 62+ modelNode1.slice( 0 ),
 63+ [modelNode2, modelNode3],
 64+ 'es.ModelNode removes last node on pop'
 65+ );
 66+
 67+ /** @covers es.ModelNode.shift */
 68+ modelNode1.shift();
 69+ equal( updates, 7, 'es.ModelNode emits update events on shift' );
 70+ deepEqual(
 71+ modelNode1.slice( 0 ),
 72+ [modelNode3],
 73+ 'es.ModelNode removes first Node on shift'
 74+ );
 75+
 76+ /** @covers es.ModelNode.detach */
 77+ equal( detaches, 1, 'es.ModelNode emits detach events when removed from another node' );
 78+
 79+ /** @covers es.ModelNode.getParent */
 80+ strictEqual( modelNode3.getParent(), modelNode1, 'Child nodes have correct parent reference' );
 81+
 82+ try {
 83+ var view = modelNode3.createView();
 84+ } catch ( err ){
 85+ ok( true, 'Calling createView on a plain ModelNode throws an exception' );
 86+ }
 87+} );
Index: trunk/parsers/wikidom/tests/hype/index.html
@@ -17,6 +17,6 @@
1818 <script src="../../lib/hype/bases/es.ViewNode.js"></script>
1919 <script src="../../lib/jquery.js"></script>
2020 <script src="../../lib/qunit.js"></script>
21 - <script src="test.js"></script>
 21+ <script src="es.ModelNode.test.js"></script>
2222 </body>
2323 </html>

Status & tagging log