r102019 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102018‎ | r102019 | r102020 >
Date:18:08, 4 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Split tests up by method
Modified paths:
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js
@@ -1,5 +1,7 @@
22 module( 'es/bases' );
33
 4+/* Stubs */
 5+
46 function DocumentBranchNodeStub( items, name, size ) {
57 // Inheritance
68 es.DocumentBranchNode.call( this, items );
@@ -20,28 +22,27 @@
2123
2224 es.extendClass( DocumentBranchNodeStub, es.DocumentBranchNode );
2325
24 -test( 'es.DocumentNode', function() {
 26+/* Tests */
2527
26 - // Stub test
27 -
 28+test( 'es.DocumentBranchNodeStub.getElementLength', 1, function() {
 29+ // Test 1
2830 strictEqual(
2931 ( new DocumentBranchNodeStub( [], 'a', 0 ) ).getElementLength(),
3032 2,
3133 'DocumentBranchNodeStub.getElementLength() returns initialized length plus 2 for elements'
3234 );
 35+} );
3336
34 - // Stubs
 37+// Common stubs
 38+var a = new DocumentBranchNodeStub( [], 'a', 0 ),
 39+ b = new DocumentBranchNodeStub( [], 'b', 1 ),
 40+ c = new DocumentBranchNodeStub( [], 'c', 2 ),
 41+ d = new DocumentBranchNodeStub( [], 'd', 3 ),
 42+ e = new DocumentBranchNodeStub( [], 'e', 4 ),
 43+ root1 = new DocumentBranchNodeStub( [a, b, c, d, e], 'root1', 20 );
3544
36 - var a = new DocumentBranchNodeStub( [], 'a', 0 ),
37 - b = new DocumentBranchNodeStub( [], 'b', 1 ),
38 - c = new DocumentBranchNodeStub( [], 'c', 2 ),
39 - d = new DocumentBranchNodeStub( [], 'd', 3 ),
40 - e = new DocumentBranchNodeStub( [], 'e', 4 ),
41 - root1 = new DocumentBranchNodeStub( [a, b, c, d, e], 'root1', 20 ),
42 - i;
43 -
44 - // getRangeFromNode tests
45 -
 45+test( 'es.DocumentBranchNode.getRangeFromNode', 6, function() {
 46+ // Tests 1 .. 6
4647 var getRangeFromNodeTests = [
4748 { 'input': a, 'output': new es.Range( 0, 2 ) },
4849 { 'input': b, 'output': new es.Range( 2, 5 ) },
@@ -50,17 +51,17 @@
5152 { 'input': e, 'output': new es.Range( 14, 20 ) },
5253 { 'input': null, 'output': null }
5354 ];
54 -
55 - for ( i = 0; i < getRangeFromNodeTests.length; i++ ) {
 55+ for ( var i = 0; i < getRangeFromNodeTests.length; i++ ) {
5656 deepEqual(
5757 root1.getRangeFromNode( getRangeFromNodeTests[i].input ),
5858 getRangeFromNodeTests[i].output,
5959 'getRangeFromNode returns the correct range or null if item is not found'
6060 );
6161 }
 62+} );
6263
63 - // getNodeFromOffset tests
64 -
 64+test( 'es.DocumentBranchNode.getNodeFromOffset', 22, function() {
 65+ // Tests 1 .. 22
6566 var getNodeFromOffsetTests = [
6667 { 'input': -1, 'output': null },
6768 { 'input': 0, 'output': a },
@@ -85,17 +86,17 @@
8687 { 'input': 19, 'output': e },
8788 { 'input': 20, 'output': null }
8889 ];
89 -
90 - for ( i = 0; i < getNodeFromOffsetTests.length; i++ ) {
 90+ for ( var i = 0; i < getNodeFromOffsetTests.length; i++ ) {
9191 strictEqual(
9292 root1.getNodeFromOffset( getNodeFromOffsetTests[i].input ),
9393 getNodeFromOffsetTests[i].output,
9494 'getNodeFromOffset finds the right item or returns null when out of range'
9595 );
9696 }
 97+} );
9798
98 - // getOffsetFromNode tests
99 -
 99+test( 'es.DocumentBranchNode.getOffsetFromNode', 6, function() {
 100+ // Tests 1 .. 6
100101 var getOffsetFromNodeTests = [
101102 { 'input': a, 'output': 0 },
102103 { 'input': b, 'output': 2 },
@@ -104,8 +105,7 @@
105106 { 'input': e, 'output': 14 },
106107 { 'input': null, 'output': -1 }
107108 ];
108 -
109 - for ( i = 0; i < getOffsetFromNodeTests.length; i++ ) {
 109+ for ( var i = 0; i < getOffsetFromNodeTests.length; i++ ) {
110110 strictEqual(
111111 root1.getOffsetFromNode( getOffsetFromNodeTests[i].input ),
112112 getOffsetFromNodeTests[i].output,
@@ -114,7 +114,7 @@
115115 }
116116 } );
117117
118 -test( 'es.DocumentNode.selectNodes', function() {
 118+test( 'es.DocumentBranchNode.selectNodes', 21, function() {
119119
120120 // selectNodes tests
121121
@@ -131,6 +131,7 @@
132132 // TODO also nest with a more complicated nested structure, like the one from
133133 // es.DocumentModel.test.js
134134
 135+ // Tests 1 ... 22
135136 // Possible positions are:
136137 // * before beginning
137138 // * at beginning
@@ -283,7 +284,6 @@
284285 'desc': 'Range from at the end of a node to the middle of the next node'
285286 }
286287 ];
287 -
288288 for ( var i = 0; i < selectNodesTests.length; i++ ) {
289289 deepEqual(
290290 root2.selectNodes( selectNodesTests[i].input ),
Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js
@@ -738,7 +738,7 @@
739739 );
740740 } );
741741
742 -test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 10, function() {
 742+test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 12, function() {
743743 var documentModel = es.DocumentModel.newFromPlainObject( obj );
744744
745745 var elementAttributeChange = documentModel.prepareElementAttributeChange(
@@ -835,7 +835,7 @@
836836 'd',
837837 ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
838838 ],
839 - 'commit keeps model tree up to date'
 839+ 'commit keeps model tree up to date with insertions'
840840 );
841841
842842 // Test 7
@@ -860,7 +860,7 @@
861861 ['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
862862 ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
863863 ],
864 - 'rollback keeps model tree up to date'
 864+ 'rollback keeps model tree up to date with insertions'
865865 );
866866
867867 var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) );
@@ -878,6 +878,13 @@
879879 );
880880
881881 // Test 10
 882+ deepEqual(
 883+ documentModel.getChildren()[0].getContent(),
 884+ ['a'],
 885+ 'commit keeps model tree up to date with removals'
 886+ );
 887+
 888+ // Test 11
882889 documentModel.rollback( removal );
883890 deepEqual(
884891 documentModel.getData( new es.Range( 0, 5 ) ),
@@ -891,6 +898,16 @@
892899 'rollback reverses the effect of a removal transaction on the content'
893900 );
894901
 902+ // Test 12
 903+ deepEqual(
 904+ documentModel.getChildren()[0].getContent(),
 905+ [
 906+ 'a',
 907+ ['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
 908+ ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
 909+ ],
 910+ 'rollback keeps model tree up to date with removals'
 911+ );
895912 } );
896913
897914 test( 'es.DocumentDocumentModelNode child operations', 20, function() {

Status & tagging log