https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113452

Revision: 113452
Author:   catrope
Date:     2012-03-09 02:19:50 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
Add test for replacing a table with a list. This only works because
nesting validity isn't checked yet (lists inside lists are illegal
IIRC), but for now it tests the reversal of the order of the closing
tags nicely

Modified Paths:
--------------
    trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
    trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js

Modified: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
===================================================================
--- trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js   
2012-03-09 02:10:43 UTC (rev 113451)
+++ trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js   
2012-03-09 02:19:50 UTC (rev 113452)
@@ -801,7 +801,7 @@
        );
 } );
 
-test( 've.dm.DocumentNode.prepareWrap', 5, function() {
+test( 've.dm.DocumentNode.prepareWrap', 6, function() {
        var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
        
        // Test 1
@@ -838,6 +838,19 @@
        );
        
        // Test 3
+       deepEqual(
+               documentModel.prepareWrap( new ve.Range( 8, 28 ), [ { 'type': 
'table' }, { 'type': 'tableRow' }, { 'type': 'tableCell' } ], [ { 'type': 
'list' }, { 'type': 'listItem' } ], [], [] ).getOperations(),
+               [
+                       { 'type': 'retain', 'length': 5 },
+                       { 'type': 'replace', 'remove': [ { 'type': 'table' }, { 
'type': 'tableRow' }, { 'type': 'tableCell' } ], 'replacement': [ { 'type': 
'list' }, { 'type': 'listItem' } ] },
+                       { 'type': 'retain', 'length': 20 },
+                       { 'type': 'replace', 'remove': [ { 'type': '/tableCell' 
}, { 'type': '/tableRow' }, { 'type': '/table' } ], 'replacement': [ { 'type': 
'/listItem' }, { 'type': '/list' } ] },
+                       { 'type': 'retain', 'length': 3 }
+               ],
+               'prepareWrap replaces a table with a list'
+       );
+       
+       // Test 4
        raises(
                function() {
                        documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 
'type': 'table' } ], [], [], [] );
@@ -846,7 +859,7 @@
                'prepareWrap checks integrity of unwrapOuter parameter'
        );
        
-       // Test 4
+       // Test 5
        raises(
                function() {
                        documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 
'type': 'list' } ], [], [ { 'type': 'paragraph' } ], [] );
@@ -855,7 +868,7 @@
                'prepareWrap checks integrity of unwrapEach parameter'
        );
        
-       // Test 5
+       // Test 6
        raises(
                function() {
                        documentModel.prepareWrap( new ve.Range( 1, 4 ), [ { 
'type': 'listItem' }, { 'type': 'paragraph' } ], [], [], [] );

Modified: 
trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js
===================================================================
--- trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js   
2012-03-09 02:10:43 UTC (rev 113451)
+++ trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js   
2012-03-09 02:19:50 UTC (rev 113452)
@@ -1,6 +1,6 @@
 module( 've/dm' );
 
-test( 've.dm.TransactionProcessor', 37, function() {
+test( 've.dm.TransactionProcessor', 39, function() {
        var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
 
        // FIXME: These tests shouldn't use prepareFoo() because those functions
@@ -490,4 +490,78 @@
                ],
                'rollback puts the list back'
        );
+       
+       var replaceTable = documentModel.prepareWrap( new ve.Range( 8, 28 ), [ 
{ 'type': 'table' }, { 'type': 'tableRow' }, { 'type': 'tableCell' } ],
+               [ { 'type': 'list' }, { 'type': 'listItem' } ], [], [] );
+       
+       // Test 38
+       ve.dm.TransactionProcessor.commit( documentModel, replaceTable );
+       deepEqual(
+               documentModel.getData( new ve.Range( 5, 30 ) ),
+               [
+                       { 'type': 'list' },
+                       { 'type': 'listItem' },
+                       { 'type': 'paragraph' },
+                       'd',
+                       { 'type': '/paragraph' },
+                       { 'type': 'list' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['bullet'] } },
+                       { 'type': 'paragraph' },
+                       'e',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['bullet', 'bullet'] } },
+                       { 'type': 'paragraph' },
+                       'f',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['number'] } },
+                       { 'type': 'paragraph' },
+                       'g',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': '/list' },
+                       { 'type': '/listItem' },
+                       { 'type': '/list' },
+                       { 'type': 'paragraph' }
+               ],
+               'replacing a table with the list reverses the order of the 
closing tags correctly'
+       );
+       
+       // Test 39
+       ve.dm.TransactionProcessor.rollback( documentModel, replaceTable );
+       deepEqual(
+               documentModel.getData( new ve.Range( 5, 32 ) ),
+               [
+                       { 'type': 'table' },
+                       { 'type': 'tableRow' },
+                       { 'type': 'tableCell' },
+                       { 'type': 'paragraph' },
+                       'd',
+                       { 'type': '/paragraph' },
+                       { 'type': 'list' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['bullet'] } },
+                       { 'type': 'paragraph' },
+                       'e',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['bullet', 'bullet'] } },
+                       { 'type': 'paragraph' },
+                       'f',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': 'listItem', 'attributes': { 'styles': 
['number'] } },
+                       { 'type': 'paragraph' },
+                       'g',
+                       { 'type': '/paragraph' },
+                       { 'type': '/listItem' },
+                       { 'type': '/list' },
+                       { 'type': '/tableCell' },
+                       { 'type': '/tableRow' },
+                       { 'type': '/table' },
+                       { 'type': 'paragraph' }
+               ],
+               'rollback puts the table back'
+       );
+       
 } );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to