Add test cases for inserting a paragraph break (</p><p>) in the middle of a paragraph. Interestingly, committing this insertion actually works, but rolling it back doesn't.

This commit is contained in:
Roan Kattouw 2011-11-09 20:24:13 +00:00
parent ef3c84bd2e
commit 25a04133b0

View file

@ -547,9 +547,13 @@ test( 'es.DocumentModel.prepareInsertion', 11, function() {
);
} );
test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 12, function() {
test( 'es.DocumentModel.commit, es.DocumentModel.rollback', /*18*/ 15, function() {
var documentModel = es.DocumentModel.newFromPlainObject( esTest.obj );
// 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(
0, 'set', 'test', 1
);
@ -717,4 +721,73 @@ test( 'es.DocumentModel.commit, es.DocumentModel.rollback', 12, function() {
],
'rollback keeps model tree up to date with removals'
);
var paragraphBreak = documentModel.prepareInsertion( 2, [ { 'type': '/paragraph' }, { 'type': 'paragraph' } ] );
// Test 13
documentModel.commit( paragraphBreak );
deepEqual(
documentModel.getData( new es.Range( 0, 7 ) ),
[
{ 'type': 'paragraph' },
'a',
{ 'type': '/paragraph' },
{ 'type': 'paragraph' },
['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }],
{ 'type': '/paragraph' }
],
'commit applies an insertion transaction that splits the paragraph'
);
// Test 14
deepEqual(
documentModel.getChildren()[0].getContent(),
['a'],
'commit keeps model tree up to date with paragraph split (paragraph 1)'
);
// Test 15
deepEqual(
documentModel.getChildren()[1].getContent(),
[
['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
],
'commit keeps model tree up to date with paragraph split (paragraph 2)'
);
/* FIXME broken
// Test 16
documentModel.rollback( paragraphBreak );
deepEqual(
documentModel.getData( new es.Range( 0, 5 ) ),
[
{ 'type': 'paragraph' },
'a',
['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }],
{ 'type': '/paragraph' }
],
'rollback reverses the effect of a paragraph split on the content'
);
// Test 17
deepEqual(
documentModel.getChildren()[0].getContent(),
[
'a',
['b', { 'type': 'textStyle/bold', 'hash': '#textStyle/bold' }],
['c', { 'type': 'textStyle/italic', 'hash': '#textStyle/italic' }]
],
'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)'
);
*/
} );