2012-02-07 00:12:31 +00:00
|
|
|
module( 've/dm' );
|
2011-11-14 23:10:00 +00:00
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
test( 've.dm.TransactionProcessor', 47, function() {
|
2012-02-07 00:12:31 +00:00
|
|
|
var documentModel = ve.dm.DocumentNode.newFromPlainObject( veTest.obj );
|
2011-11-14 23:10:00 +00:00
|
|
|
|
|
|
|
// FIXME: These tests shouldn't use prepareFoo() because those functions
|
|
|
|
// normalize the transactions they create and are tested separately.
|
|
|
|
// We should be creating transactions directly and feeding those into
|
|
|
|
// commit()/rollback() --Roan
|
|
|
|
var elementAttributeChange = documentModel.prepareElementAttributeChange(
|
2012-03-02 23:12:38 +00:00
|
|
|
0, 'test', 1
|
2011-11-14 23:10:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test 1
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, elementAttributeChange );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph', 'attributes': { 'test': 1 } },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'commit applies an element attribute change transaction to the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 2
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, elementAttributeChange );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses the effect of an element attribute change transaction on the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
var contentAnnotation = documentModel.prepareContentAnnotation(
|
2012-02-07 00:12:31 +00:00
|
|
|
new ve.Range( 1, 4 ), 'set', { 'type': 'textStyle/bold' }
|
2011-11-14 23:10:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Test 3
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, contentAnnotation );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
2011-11-21 22:32:22 +00:00
|
|
|
['a', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
'c',
|
2011-11-21 22:32:22 +00:00
|
|
|
{ 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' },
|
|
|
|
{ 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'commit applies a content annotation transaction to the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 4
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, contentAnnotation );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses the effect of a content annotation transaction on the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
var insertion = documentModel.prepareInsertion( 3, ['d'] );
|
|
|
|
|
|
|
|
// Test 5
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, insertion );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 6 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
'd',
|
2011-11-21 22:32:22 +00:00
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'commit applies an insertion transaction to the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 6
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
'd',
|
2011-11-21 22:32:22 +00:00
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }]
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
'commit keeps model tree up to date with insertions'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 7
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, insertion );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses the effect of an insertion transaction on the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 8
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }]
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
'rollback keeps model tree up to date with insertions'
|
|
|
|
);
|
|
|
|
|
2012-02-07 00:12:31 +00:00
|
|
|
var removal = documentModel.prepareRemoval( new ve.Range( 2, 4 ) );
|
2011-11-14 23:10:00 +00:00
|
|
|
|
|
|
|
// Test 9
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, removal );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 3 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'commit applies a removal transaction to the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 10
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
['a'],
|
|
|
|
'commit keeps model tree up to date with removals'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 11
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, removal );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses the effect of a removal transaction on the content'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 12
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }]
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
'rollback keeps model tree up to date with removals'
|
|
|
|
);
|
|
|
|
|
2011-11-15 18:17:26 +00:00
|
|
|
var paragraphBreak = documentModel.prepareInsertion(
|
|
|
|
2, [{ 'type': '/paragraph' }, { 'type': 'paragraph' }]
|
|
|
|
);
|
2011-11-14 23:10:00 +00:00
|
|
|
|
|
|
|
// Test 13
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, paragraphBreak );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 7 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': 'paragraph' },
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'commit applies an insertion transaction that splits the paragraph'
|
|
|
|
);
|
2011-11-15 18:17:26 +00:00
|
|
|
|
2011-11-14 23:10:00 +00:00
|
|
|
// Test 14
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
['a'],
|
|
|
|
'commit keeps model tree up to date with paragraph split (paragraph 1)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 15
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[1].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }]
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
'commit keeps model tree up to date with paragraph split (paragraph 2)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 16
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, paragraphBreak );
|
2011-11-14 23:10:00 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
2011-11-14 23:10:00 +00:00
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses the effect of a paragraph split on the content'
|
|
|
|
);
|
2011-11-15 18:17:26 +00:00
|
|
|
|
2011-11-14 23:10:00 +00:00
|
|
|
// Test 17
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.getChildren()[0].getContentData(),
|
2011-11-14 23:10:00 +00:00
|
|
|
[
|
|
|
|
'a',
|
2011-11-21 22:32:22 +00:00
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }]
|
2011-11-14 23:10:00 +00:00
|
|
|
],
|
|
|
|
'rollback keeps model tree up to date with paragraph split (paragraphs are merged back)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 18
|
|
|
|
deepEqual(
|
|
|
|
documentModel.getChildren()[1].getElementType(),
|
|
|
|
'table',
|
|
|
|
'rollback keeps model tree up to date with paragraph split (table follows the paragraph)'
|
|
|
|
);
|
2011-11-18 10:17:35 +00:00
|
|
|
|
2012-02-07 00:12:31 +00:00
|
|
|
var listItemMerge = documentModel.prepareRemoval( new ve.Range( 14, 19 ) );
|
2011-11-18 10:17:35 +00:00
|
|
|
|
|
|
|
// Test 19
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, listItemMerge );
|
2011-11-18 10:17:35 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 12, 22 ) ),
|
2011-11-18 10:17:35 +00:00
|
|
|
[
|
|
|
|
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'f',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/listItem' },
|
|
|
|
{ 'type': 'listItem', 'attributes': { 'styles': ['number'] } },
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'g',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/listItem' }
|
|
|
|
],
|
|
|
|
'removal merges two list items with paragraphs'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 20
|
|
|
|
deepEqual( documentModel.children[1].children[0].children[0].children[1].children.length, 2,
|
|
|
|
'removal keeps model tree up to date with list item merge (number of children)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 21
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[1].children[0].children[0].children[1].children[0].children[0].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'f' ],
|
|
|
|
'removal keeps model tree up to date with list item merge (first list item)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 22
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[1].children[0].children[0].children[1].children[1].children[0].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'g' ],
|
|
|
|
'removal keeps model tree up to date with list item merge (second list item)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 23
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[2].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'h' ],
|
|
|
|
'rollback keeps model tree up to date with list item split (final paragraph)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 24
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, listItemMerge );
|
2011-11-18 10:17:35 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 12, 27 ) ),
|
2011-11-18 10:17:35 +00:00
|
|
|
[
|
|
|
|
{ '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' }
|
|
|
|
],
|
|
|
|
'rollback reverses list item merge (splits the list items)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 25
|
|
|
|
deepEqual( documentModel.children[1].children[0].children[0].children[1].children.length, 3,
|
|
|
|
'rollback keeps model tree up to date with list item split (number of children)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 26
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[1].children[0].children[0].children[1].children[0].children[0].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'e' ],
|
|
|
|
'rollback keeps model tree up to date with list item split (first list item)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 27
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[1].children[0].children[0].children[1].children[1].children[0].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'f' ],
|
|
|
|
'rollback keeps model tree up to date with list item split (second list item)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 28
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[1].children[0].children[0].children[1].children[2].children[0].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'g' ],
|
|
|
|
'rollback keeps model tree up to date with list item split (third list item)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 29
|
|
|
|
deepEqual(
|
2011-12-05 19:41:04 +00:00
|
|
|
documentModel.children[2].getContentData(),
|
2011-11-18 10:17:35 +00:00
|
|
|
[ 'h' ],
|
|
|
|
'rollback keeps model tree up to date with list item split (final paragraph)'
|
|
|
|
);
|
|
|
|
|
2011-12-06 21:36:36 +00:00
|
|
|
var listSplit = documentModel.prepareInsertion( 17, [{ 'type': '/list' }, { 'type': 'list' }] );
|
2011-12-06 22:04:18 +00:00
|
|
|
|
2011-12-06 21:36:36 +00:00
|
|
|
// Test 30
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, listSplit );
|
2011-12-06 21:36:36 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 15, 21 ) ),
|
2011-12-06 21:36:36 +00:00
|
|
|
[
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/listItem' },
|
|
|
|
{ 'type': '/list' },
|
|
|
|
{ 'type': 'list' },
|
|
|
|
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
|
|
|
|
{ 'type': 'paragraph' }
|
|
|
|
],
|
|
|
|
'commit splits list into two lists'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 31
|
2012-03-13 00:14:38 +00:00
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children.length, 3,
|
|
|
|
'commit keeps model tree up to date with list split (number of children)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 32
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[1].getElementType(), 'list',
|
|
|
|
'commit keeps model tree up to date with list split (first list type)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 33
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[2].getElementType(), 'list',
|
|
|
|
'commit keeps model tree up to date with list split (second list type)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 34
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[1].getContentData(),
|
|
|
|
[
|
|
|
|
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'e',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/listItem' }
|
|
|
|
],
|
|
|
|
'commit keeps model tree up to date with list split (first list content)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 35
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[2].getContentData(),
|
|
|
|
[
|
|
|
|
{ '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' }
|
|
|
|
],
|
|
|
|
'commit keeps model tree up to date with list split (second list content)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 36
|
2012-02-07 00:12:31 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, listSplit );
|
2011-12-06 21:36:36 +00:00
|
|
|
deepEqual(
|
2012-02-07 00:12:31 +00:00
|
|
|
documentModel.getData( new ve.Range( 15, 19 ) ),
|
2011-12-06 21:36:36 +00:00
|
|
|
[
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': '/listItem' },
|
|
|
|
{ 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
|
|
|
|
{ 'type': 'paragraph' }
|
|
|
|
],
|
|
|
|
'rollback reverses list split'
|
|
|
|
);
|
2012-03-08 23:21:23 +00:00
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 37
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children.length, 2,
|
|
|
|
'rollback keeps model tree up to date with list split (number of children)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 38
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[1].getElementType(), 'list',
|
|
|
|
'rollback keeps model tree up to date with list split (first list type)'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Test 39
|
|
|
|
deepEqual(
|
|
|
|
documentModel.children[1].children[0].children[0].children[1].getContentData(),
|
|
|
|
[
|
|
|
|
{ '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' }
|
|
|
|
],
|
|
|
|
'rollback keeps model tree up to date with list split (first list content)'
|
|
|
|
);
|
|
|
|
|
2012-03-08 23:21:23 +00:00
|
|
|
|
|
|
|
var contentReplacement = documentModel.prepareContentReplacement( new ve.Range( 32, 33 ), [ 'i', 'j', 'k' ] );
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 40
|
2012-03-08 23:21:23 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, contentReplacement );
|
|
|
|
deepEqual(
|
|
|
|
documentModel.getData( new ve.Range( 31, 36 ) ),
|
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'i', 'j', 'k',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'replacement replaces content'
|
|
|
|
);
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 41
|
2012-03-08 23:21:23 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, contentReplacement );
|
|
|
|
deepEqual(
|
|
|
|
documentModel.getData( new ve.Range( 31, 34 ) ),
|
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'h',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback restores content'
|
|
|
|
);
|
2012-03-08 23:21:26 +00:00
|
|
|
|
|
|
|
var paragraphToHeading = documentModel.prepareWrap( new ve.Range( 1, 4 ), [ { 'type': 'paragraph' } ], [ { 'type': 'heading', 'level': 2 } ], [], [] );
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 42
|
2012-03-08 23:21:26 +00:00
|
|
|
ve.dm.TransactionProcessor.commit( documentModel, paragraphToHeading );
|
|
|
|
deepEqual(
|
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
|
|
|
[
|
|
|
|
{ 'type': 'heading', 'level': 2 },
|
|
|
|
'a',
|
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
|
|
|
{ 'type': '/heading' }
|
|
|
|
],
|
|
|
|
'changing paragraph to heading'
|
|
|
|
);
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 43
|
2012-03-08 23:21:26 +00:00
|
|
|
ve.dm.TransactionProcessor.rollback( documentModel, paragraphToHeading );
|
|
|
|
deepEqual(
|
|
|
|
documentModel.getData( new ve.Range( 0, 5 ) ),
|
|
|
|
[
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
['b', { 'type': 'textStyle/bold', 'hash': '{"type":"textStyle/bold"}' }],
|
|
|
|
['c', { 'type': 'textStyle/italic', 'hash': '{"type":"textStyle/italic"}' }],
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'rollback puts paragraph back'
|
|
|
|
);
|
2012-03-09 00:38:35 +00:00
|
|
|
|
|
|
|
var unwrapList = documentModel.prepareWrap( new ve.Range( 12, 27 ), [ { 'type': 'list' } ], [] , [ { 'type': 'listItem' } ], [] );
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 44
|
2012-03-09 00:38:35 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 45
|
2012-03-09 00:38:35 +00:00
|
|
|
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'
|
|
|
|
);
|
2012-03-09 02:19:50 +00:00
|
|
|
|
|
|
|
var replaceTable = documentModel.prepareWrap( new ve.Range( 8, 28 ), [ { 'type': 'table' }, { 'type': 'tableRow' }, { 'type': 'tableCell' } ],
|
|
|
|
[ { 'type': 'list' }, { 'type': 'listItem' } ], [], [] );
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 46
|
2012-03-09 02:19:50 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2012-03-13 00:14:38 +00:00
|
|
|
// Test 47
|
2012-03-09 02:19:50 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
|
2011-11-14 23:10:00 +00:00
|
|
|
} );
|