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