1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*!
* VisualEditor DataModel SourceSurfaceFragment tests.
*
* @copyright See AUTHORS.txt
*/
QUnit.module( 've.dm.SourceSurfaceFragment' );
/* Tests */
QUnit.test( 'insertContent/insertDocument', ( assert ) => {
const cases = [
{
msg: 'Heading converted to HTML',
insert: [
{ type: 'heading', attributes: { level: 1 } },
'a',
{ type: '/heading' }
],
expected: [
{ type: 'paragraph' },
...'<h1>a</h1>',
{ type: '/paragraph' }
]
},
{
msg: 'Simple text insert',
insert: 'foo',
expected: [
{ type: 'paragraph' },
...'foo',
{ type: '/paragraph' }
]
},
{
msg: 'Newline in string split to paragraphs',
insert: 'foo\nbar',
expected: [
{ type: 'paragraph' },
...'foo',
{ type: '/paragraph' },
{ type: 'paragraph' },
...'bar',
{ type: '/paragraph' }
]
},
{
msg: 'Multiline into string',
data: [
{ type: 'paragraph' },
...'foo',
{ type: '/paragraph' },
{ type: 'paragraph' },
...'bar',
{ type: '/paragraph' },
{ type: 'internalList' },
{ type: '/internalList' }
],
range: new ve.Range( 3, 7 ),
insert: 'foo\nbar',
expected: [
{ type: 'paragraph' },
...'fofoo',
{ type: '/paragraph' },
{ type: 'paragraph' },
...'barar',
{ type: '/paragraph' }
]
},
{
msg: 'Newline in string split to paragraphs',
insert: new ve.dm.Document( [
{ type: 'paragraph' },
'f', '\n', 'o', '\n', 'o', '\n', 'b', '\n', 'a', '\n', 'r',
{ type: '/paragraph' }
] ),
expected: [
{ type: 'paragraph' },
'f',
{ type: '/paragraph' },
{ type: 'paragraph' },
'o',
{ type: '/paragraph' },
{ type: 'paragraph' },
'o',
{ type: '/paragraph' },
{ type: 'paragraph' },
'b',
{ type: '/paragraph' },
{ type: 'paragraph' },
'a',
{ type: '/paragraph' },
{ type: 'paragraph' },
'r',
{ type: '/paragraph' }
]
}
];
cases.forEach( ( caseItem ) => {
const doc = ve.dm.example.createExampleDocumentFromData( caseItem.data || [ { type: 'paragraph' }, { type: '/paragraph' }, { type: 'internalList' }, { type: '/internalList' } ] ),
surface = new ve.dm.Surface( doc, { sourceMode: true } ),
fragment = surface.getLinearFragment( caseItem.range || new ve.Range( 1 ) ),
done = assert.async();
if ( caseItem.insert instanceof ve.dm.Document ) {
fragment.insertDocument( caseItem.insert );
} else {
fragment.insertContent( caseItem.insert );
}
fragment.getPending().then( () => {
assert.deepEqual(
doc.getData( doc.getDocumentRange() ),
caseItem.expected,
caseItem.msg
);
done();
} );
} );
} );
|