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

Revision: 113438
Author:   catrope
Date:     2012-03-09 00:38:35 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
Add tests for unwrapping a list

This also excercises unwrapEach. One of the tests is still subtly broken
in that the attributes on the listItems aren't preserved, I'll fix that
next.

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 00:38:34 UTC (rev 113437)
+++ trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js   
2012-03-09 00:38:35 UTC (rev 113438)
@@ -801,7 +801,7 @@
        );
 } );
 
-test( 've.dm.DocumentNode.prepareWrap', 1, function() {
+test( 've.dm.DocumentNode.prepareWrap', 2, function() {
        var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
        
        // Test 1
@@ -815,4 +815,25 @@
                ],
                'prepareWrap changes a paragraph to a heading'
        );
+       
+       // Test 2
+       deepEqual(
+               documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 
'list' } ], [], [ { 'type': 'listItem' } ], [] ).getOperations(),
+               [
+                       { 'type': 'retain', 'length': 11 },
+                       { 'type': 'replace', 'remove': [ { 'type': 'list' } ], 
'replacement': [] },
+                       { 'type': 'replace', 'remove': [ { 'type': 'listItem' } 
], 'replacement': [] },
+                       { 'type': 'retain', 'length': 3 },
+                       { 'type': 'replace', 'remove': [ { 'type': '/listItem' 
} ], 'replacement': [] },
+                       { 'type': 'replace', 'remove': [ { 'type': 'listItem' } 
], 'replacement': [] },
+                       { 'type': 'retain', 'length': 3 },
+                       { 'type': 'replace', 'remove': [ { 'type': '/listItem' 
} ], 'replacement': [] },
+                       { 'type': 'replace', 'remove': [ { 'type': 'listItem' } 
], 'replacement': [] },
+                       { 'type': 'retain', 'length': 3 },
+                       { 'type': 'replace', 'remove': [ { 'type': '/listItem' 
} ], 'replacement': [] },
+                       { 'type': 'replace', 'remove': [ { 'type': '/list' } ], 
'replacement': [] },
+                       { 'type': 'retain', 'length': 6 }
+               ],
+               'prepareWrap unwraps a list'
+       );
 } );
\ No newline at end of file

Modified: 
trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js
===================================================================
--- trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js   
2012-03-09 00:38:34 UTC (rev 113437)
+++ trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js   
2012-03-09 00:38:35 UTC (rev 113438)
@@ -1,6 +1,6 @@
 module( 've/dm' );
 
-test( 've.dm.TransactionProcessor', 35, function() {
+test( 've.dm.TransactionProcessor', 37, function() {
        var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
 
        // FIXME: These tests shouldn't use prepareFoo() because those functions
@@ -407,7 +407,7 @@
        
        var paragraphToHeading = documentModel.prepareWrap( new ve.Range( 1, 4 
), [ { 'type': 'paragraph' } ], [ { 'type': 'heading', 'level': 2 } ], [], [] );
        
-       // Test 33
+       // Test 34
        ve.dm.TransactionProcessor.commit( documentModel, paragraphToHeading );
        deepEqual(
                documentModel.getData( new ve.Range( 0, 5 ) ),
@@ -421,7 +421,7 @@
                'changing paragraph to heading'
        );
        
-       // Test 34
+       // Test 35
        ve.dm.TransactionProcessor.rollback( documentModel, paragraphToHeading 
);
        deepEqual(
                documentModel.getData( new ve.Range( 0, 5 ) ),
@@ -434,4 +434,60 @@
                ],
                'rollback puts paragraph back'
        );
+       
+       var unwrapList = documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 
'type': 'list' } ], [] , [ { 'type': 'listItem' } ], [] );
+       
+       // Test 36
+       ve.dm.TransactionProcessor.commit( documentModel, unwrapList );
+       deepEqual(
+               documentModel.getData( new ve.Range( 7, 21 ) ),
+               [
+                       { 'type': 'tableCell' },
+                       { 'type': 'paragraph' },
+                       'd',
+                       { 'type': '/paragraph' },
+                       { 'type': 'paragraph' },
+                       'e',
+                       { 'type': '/paragraph' },
+                       { 'type': 'paragraph' },
+                       'f',
+                       { 'type': '/paragraph' },
+                       { 'type': 'paragraph' },
+                       'g',
+                       { 'type': '/paragraph' },
+                       { 'type': '/tableCell' }
+               ],
+               'unwrapping the list produces a cell with four adjacent 
paragraphs'
+       );
+       
+       // Test 37
+       ve.dm.TransactionProcessor.rollback( documentModel, unwrapList );
+       deepEqual(
+               documentModel.getData( new ve.Range( 7, 29 ) ),
+               [
+                       { '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' }
+               ],
+               'rollback puts the list back'
+       );
 } );


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

Reply via email to