r100724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100723‎ | r100724 | r100725 >
Date:18:40, 25 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added removal tests for commit and rollback
Modified paths:
  • /trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
@@ -242,17 +242,17 @@
243243 'getContent can return a middle portion of the content'
244244 );
245245
 246+ // Test 4
246247 try {
247248 documentModel[0].getContent( new es.Range( -1, 3 ) );
248249 } catch ( negativeIndexError ) {
249 - // Test 4
250250 ok( true, 'getContent throws exceptions when given a range with start < 0' );
251251 }
252252
 253+ // Test 5
253254 try {
254255 documentModel[0].getContent( new es.Range( 0, 4 ) );
255256 } catch ( outOfRangeError ) {
256 - // Test 5
257257 ok( true, 'getContent throws exceptions when given a range with end > length' );
258258 }
259259
@@ -314,20 +314,20 @@
315315 'prepareElementAttributeChange retains data before and after attribute change'
316316 );
317317
 318+ // Test 3
318319 try {
319320 documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 );
320321 } catch ( invalidOffsetError ) {
321 - // Test 3
322322 ok(
323323 true,
324324 'prepareElementAttributeChange throws an exception when offset is not an element'
325325 );
326326 }
327327
 328+ // Test 4
328329 try {
329330 documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 );
330331 } catch ( closingElementError ) {
331 - // Test 4
332332 ok(
333333 true,
334334 'prepareElementAttributeChange throws an exception when offset is a closing element'
@@ -499,12 +499,13 @@
500500 );
501501 } );
502502
503 -test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 2, function() {
 503+test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 4, function() {
504504 var documentModel = es.DocumentModel.newFromPlainObject( obj );
505505
506 - var tx = documentModel.prepareInsertion( 4, ['d'] );
507 - documentModel.commit( tx );
 506+ var insertion = documentModel.prepareInsertion( 4, ['d'] );
508507
 508+ // Test 1
 509+ documentModel.commit( insertion );
509510 deepEqual(
510511 documentModel.getData( new es.Range( 0, 6 ) ),
511512 [
@@ -515,12 +516,40 @@
516517 'd',
517518 { 'type': '/paragraph' }
518519 ],
519 - 'commit applies a transaction to the content'
 520+ 'commit applies an insertion transaction to the content'
520521 );
521522
522 - documentModel.rollback( tx );
 523+ // Test 2
 524+ documentModel.rollback( insertion );
 525+ deepEqual(
 526+ documentModel.getData( new es.Range( 0, 5 ) ),
 527+ [
 528+ { 'type': 'paragraph' },
 529+ 'a',
 530+ ['b', { 'type': 'bold', 'hash': '#bold' }],
 531+ ['c', { 'type': 'italic', 'hash': '#italic' }],
 532+ { 'type': '/paragraph' }
 533+ ],
 534+ 'rollback reverses the effect of an insertion transaction on the content'
 535+ );
523536
 537+ var removal = documentModel.prepareRemoval( new es.Range( 2, 4 ) );
 538+
 539+ // Test 3
 540+ documentModel.commit( removal );
524541 deepEqual(
 542+ documentModel.getData( new es.Range( 0, 3 ) ),
 543+ [
 544+ { 'type': 'paragraph' },
 545+ 'a',
 546+ { 'type': '/paragraph' }
 547+ ],
 548+ 'commit applies a removal transaction to the content'
 549+ );
 550+
 551+ // Test 4
 552+ documentModel.rollback( removal );
 553+ deepEqual(
525554 documentModel.getData( new es.Range( 0, 5 ) ),
526555 [
527556 { 'type': 'paragraph' },
@@ -529,6 +558,7 @@
530559 ['c', { 'type': 'italic', 'hash': '#italic' }],
531560 { 'type': '/paragraph' }
532561 ],
533 - 'rollback reverses the effect of a transaction on the content'
 562+ 'rollback reverses the effect of a removal transaction on the content'
534563 );
 564+
535565 } );

Status & tagging log