r113438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113437‎ | r113438 | r113439 >
Date:00:38, 9 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/ve/ve.dm.DocumentNode.test.js
@@ -801,7 +801,7 @@
802802 );
803803 } );
804804
805 -test( 've.dm.DocumentNode.prepareWrap', 1, function() {
 805+test( 've.dm.DocumentNode.prepareWrap', 2, function() {
806806 var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
807807
808808 // Test 1
@@ -815,4 +815,25 @@
816816 ],
817817 'prepareWrap changes a paragraph to a heading'
818818 );
 819+
 820+ // Test 2
 821+ deepEqual(
 822+ documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'list' } ], [], [ { 'type': 'listItem' } ], [] ).getOperations(),
 823+ [
 824+ { 'type': 'retain', 'length': 11 },
 825+ { 'type': 'replace', 'remove': [ { 'type': 'list' } ], 'replacement': [] },
 826+ { 'type': 'replace', 'remove': [ { 'type': 'listItem' } ], 'replacement': [] },
 827+ { 'type': 'retain', 'length': 3 },
 828+ { 'type': 'replace', 'remove': [ { 'type': '/listItem' } ], 'replacement': [] },
 829+ { 'type': 'replace', 'remove': [ { 'type': 'listItem' } ], 'replacement': [] },
 830+ { 'type': 'retain', 'length': 3 },
 831+ { 'type': 'replace', 'remove': [ { 'type': '/listItem' } ], 'replacement': [] },
 832+ { 'type': 'replace', 'remove': [ { 'type': 'listItem' } ], 'replacement': [] },
 833+ { 'type': 'retain', 'length': 3 },
 834+ { 'type': 'replace', 'remove': [ { 'type': '/listItem' } ], 'replacement': [] },
 835+ { 'type': 'replace', 'remove': [ { 'type': '/list' } ], 'replacement': [] },
 836+ { 'type': 'retain', 'length': 6 }
 837+ ],
 838+ 'prepareWrap unwraps a list'
 839+ );
819840 } );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/tests/ve/ve.dm.TransactionProcessor.test.js
@@ -1,6 +1,6 @@
22 module( 've/dm' );
33
4 -test( 've.dm.TransactionProcessor', 35, function() {
 4+test( 've.dm.TransactionProcessor', 37, function() {
55 var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
66
77 // FIXME: These tests shouldn't use prepareFoo() because those functions
@@ -407,7 +407,7 @@
408408
409409 var paragraphToHeading = documentModel.prepareWrap( new ve.Range( 1, 4 ), [ { 'type': 'paragraph' } ], [ { 'type': 'heading', 'level': 2 } ], [], [] );
410410
411 - // Test 33
 411+ // Test 34
412412 ve.dm.TransactionProcessor.commit( documentModel, paragraphToHeading );
413413 deepEqual(
414414 documentModel.getData( new ve.Range( 0, 5 ) ),
@@ -421,7 +421,7 @@
422422 'changing paragraph to heading'
423423 );
424424
425 - // Test 34
 425+ // Test 35
426426 ve.dm.TransactionProcessor.rollback( documentModel, paragraphToHeading );
427427 deepEqual(
428428 documentModel.getData( new ve.Range( 0, 5 ) ),
@@ -434,4 +434,60 @@
435435 ],
436436 'rollback puts paragraph back'
437437 );
 438+
 439+ var unwrapList = documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'list' } ], [] , [ { 'type': 'listItem' } ], [] );
 440+
 441+ // Test 36
 442+ ve.dm.TransactionProcessor.commit( documentModel, unwrapList );
 443+ deepEqual(
 444+ documentModel.getData( new ve.Range( 7, 21 ) ),
 445+ [
 446+ { 'type': 'tableCell' },
 447+ { 'type': 'paragraph' },
 448+ 'd',
 449+ { 'type': '/paragraph' },
 450+ { 'type': 'paragraph' },
 451+ 'e',
 452+ { 'type': '/paragraph' },
 453+ { 'type': 'paragraph' },
 454+ 'f',
 455+ { 'type': '/paragraph' },
 456+ { 'type': 'paragraph' },
 457+ 'g',
 458+ { 'type': '/paragraph' },
 459+ { 'type': '/tableCell' }
 460+ ],
 461+ 'unwrapping the list produces a cell with four adjacent paragraphs'
 462+ );
 463+
 464+ // Test 37
 465+ ve.dm.TransactionProcessor.rollback( documentModel, unwrapList );
 466+ deepEqual(
 467+ documentModel.getData( new ve.Range( 7, 29 ) ),
 468+ [
 469+ { 'type': 'tableCell' },
 470+ { 'type': 'paragraph' },
 471+ 'd',
 472+ { 'type': '/paragraph' },
 473+ { 'type': 'list' },
 474+ { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
 475+ { 'type': 'paragraph' },
 476+ 'e',
 477+ { 'type': '/paragraph' },
 478+ { 'type': '/listItem' },
 479+ { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
 480+ { 'type': 'paragraph' },
 481+ 'f',
 482+ { 'type': '/paragraph' },
 483+ { 'type': '/listItem' },
 484+ { 'type': 'listItem', 'attributes': { 'styles': ['number'] } },
 485+ { 'type': 'paragraph' },
 486+ 'g',
 487+ { 'type': '/paragraph' },
 488+ { 'type': '/listItem' },
 489+ { 'type': '/list' },
 490+ { 'type': '/tableCell' }
 491+ ],
 492+ 'rollback puts the list back'
 493+ );
438494 } );

Status & tagging log