Index: trunk/extensions/VisualEditor/tests/es/es.DocumentNode.test.js |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | module( 'es/bases' ); |
3 | 3 | |
| 4 | +/* Stubs */ |
| 5 | + |
4 | 6 | function DocumentBranchNodeStub( items, name, size ) { |
5 | 7 | // Inheritance |
6 | 8 | es.DocumentBranchNode.call( this, items ); |
— | — | @@ -20,28 +22,27 @@ |
21 | 23 | |
22 | 24 | es.extendClass( DocumentBranchNodeStub, es.DocumentBranchNode ); |
23 | 25 | |
24 | | -test( 'es.DocumentNode', function() { |
| 26 | +/* Tests */ |
25 | 27 | |
26 | | - // Stub test |
27 | | - |
| 28 | +test( 'es.DocumentBranchNodeStub.getElementLength', 1, function() { |
| 29 | + // Test 1 |
28 | 30 | strictEqual( |
29 | 31 | ( new DocumentBranchNodeStub( [], 'a', 0 ) ).getElementLength(), |
30 | 32 | 2, |
31 | 33 | 'DocumentBranchNodeStub.getElementLength() returns initialized length plus 2 for elements' |
32 | 34 | ); |
| 35 | +} ); |
33 | 36 | |
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 ); |
35 | 44 | |
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 |
46 | 47 | var getRangeFromNodeTests = [ |
47 | 48 | { 'input': a, 'output': new es.Range( 0, 2 ) }, |
48 | 49 | { 'input': b, 'output': new es.Range( 2, 5 ) }, |
— | — | @@ -50,17 +51,17 @@ |
51 | 52 | { 'input': e, 'output': new es.Range( 14, 20 ) }, |
52 | 53 | { 'input': null, 'output': null } |
53 | 54 | ]; |
54 | | - |
55 | | - for ( i = 0; i < getRangeFromNodeTests.length; i++ ) { |
| 55 | + for ( var i = 0; i < getRangeFromNodeTests.length; i++ ) { |
56 | 56 | deepEqual( |
57 | 57 | root1.getRangeFromNode( getRangeFromNodeTests[i].input ), |
58 | 58 | getRangeFromNodeTests[i].output, |
59 | 59 | 'getRangeFromNode returns the correct range or null if item is not found' |
60 | 60 | ); |
61 | 61 | } |
| 62 | +} ); |
62 | 63 | |
63 | | - // getNodeFromOffset tests |
64 | | - |
| 64 | +test( 'es.DocumentBranchNode.getNodeFromOffset', 22, function() { |
| 65 | + // Tests 1 .. 22 |
65 | 66 | var getNodeFromOffsetTests = [ |
66 | 67 | { 'input': -1, 'output': null }, |
67 | 68 | { 'input': 0, 'output': a }, |
— | — | @@ -85,17 +86,17 @@ |
86 | 87 | { 'input': 19, 'output': e }, |
87 | 88 | { 'input': 20, 'output': null } |
88 | 89 | ]; |
89 | | - |
90 | | - for ( i = 0; i < getNodeFromOffsetTests.length; i++ ) { |
| 90 | + for ( var i = 0; i < getNodeFromOffsetTests.length; i++ ) { |
91 | 91 | strictEqual( |
92 | 92 | root1.getNodeFromOffset( getNodeFromOffsetTests[i].input ), |
93 | 93 | getNodeFromOffsetTests[i].output, |
94 | 94 | 'getNodeFromOffset finds the right item or returns null when out of range' |
95 | 95 | ); |
96 | 96 | } |
| 97 | +} ); |
97 | 98 | |
98 | | - // getOffsetFromNode tests |
99 | | - |
| 99 | +test( 'es.DocumentBranchNode.getOffsetFromNode', 6, function() { |
| 100 | + // Tests 1 .. 6 |
100 | 101 | var getOffsetFromNodeTests = [ |
101 | 102 | { 'input': a, 'output': 0 }, |
102 | 103 | { 'input': b, 'output': 2 }, |
— | — | @@ -104,8 +105,7 @@ |
105 | 106 | { 'input': e, 'output': 14 }, |
106 | 107 | { 'input': null, 'output': -1 } |
107 | 108 | ]; |
108 | | - |
109 | | - for ( i = 0; i < getOffsetFromNodeTests.length; i++ ) { |
| 109 | + for ( var i = 0; i < getOffsetFromNodeTests.length; i++ ) { |
110 | 110 | strictEqual( |
111 | 111 | root1.getOffsetFromNode( getOffsetFromNodeTests[i].input ), |
112 | 112 | getOffsetFromNodeTests[i].output, |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | } |
116 | 116 | } ); |
117 | 117 | |
118 | | -test( 'es.DocumentNode.selectNodes', function() { |
| 118 | +test( 'es.DocumentBranchNode.selectNodes', 21, function() { |
119 | 119 | |
120 | 120 | // selectNodes tests |
121 | 121 | |
— | — | @@ -131,6 +131,7 @@ |
132 | 132 | // TODO also nest with a more complicated nested structure, like the one from |
133 | 133 | // es.DocumentModel.test.js |
134 | 134 | |
| 135 | + // Tests 1 ... 22 |
135 | 136 | // Possible positions are: |
136 | 137 | // * before beginning |
137 | 138 | // * at beginning |
— | — | @@ -283,7 +284,6 @@ |
284 | 285 | 'desc': 'Range from at the end of a node to the middle of the next node' |
285 | 286 | } |
286 | 287 | ]; |
287 | | - |
288 | 288 | for ( var i = 0; i < selectNodesTests.length; i++ ) { |
289 | 289 | deepEqual( |
290 | 290 | root2.selectNodes( selectNodesTests[i].input ), |
Index: trunk/extensions/VisualEditor/tests/es/es.DocumentModel.test.js |
— | — | @@ -738,7 +738,7 @@ |
739 | 739 | ); |
740 | 740 | } ); |
741 | 741 | |
742 | | -test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 10, function() { |
| 742 | +test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 12, function() { |
743 | 743 | var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
744 | 744 | |
745 | 745 | var elementAttributeChange = documentModel.prepareElementAttributeChange( |
— | — | @@ -835,7 +835,7 @@ |
836 | 836 | 'd', |
837 | 837 | ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }] |
838 | 838 | ], |
839 | | - 'commit keeps model tree up to date' |
| 839 | + 'commit keeps model tree up to date with insertions' |
840 | 840 | ); |
841 | 841 | |
842 | 842 | // Test 7 |
— | — | @@ -860,7 +860,7 @@ |
861 | 861 | ['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }], |
862 | 862 | ['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }] |
863 | 863 | ], |
864 | | - 'rollback keeps model tree up to date' |
| 864 | + 'rollback keeps model tree up to date with insertions' |
865 | 865 | ); |
866 | 866 | |
867 | 867 | var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) ); |
— | — | @@ -878,6 +878,13 @@ |
879 | 879 | ); |
880 | 880 | |
881 | 881 | // 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 |
882 | 889 | documentModel.rollback( removal ); |
883 | 890 | deepEqual( |
884 | 891 | documentModel.getData( new es.Range( 0, 5 ) ), |
— | — | @@ -891,6 +898,16 @@ |
892 | 899 | 'rollback reverses the effect of a removal transaction on the content' |
893 | 900 | ); |
894 | 901 | |
| 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 | + ); |
895 | 912 | } ); |
896 | 913 | |
897 | 914 | test( 'es.DocumentDocumentModelNode child operations', 20, function() { |