| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
QUnit.module( 've.ce.TextNode' ); |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
QUnit.test( 'getAnnotatedHtml', ( assert ) => { |
| 12 |
const cases = [ |
| 13 |
{ |
| 14 |
data: [ |
| 15 |
{ type: 'paragraph' }, |
| 16 |
...'abc', |
| 17 |
{ type: '/paragraph' } |
| 18 |
], |
| 19 |
html: [ ...'abc' ] |
| 20 |
}, |
| 21 |
{ |
| 22 |
data: [ |
| 23 |
{ type: 'paragraph' }, |
| 24 |
[ 'a', [ { type: 'textStyle/bold' } ] ], |
| 25 |
[ 'b', [ { type: 'textStyle/bold' } ] ], |
| 26 |
[ 'c', [ { type: 'textStyle/bold' } ] ], |
| 27 |
{ type: '/paragraph' } |
| 28 |
], |
| 29 |
html: [ |
| 30 |
[ 'a', [ { type: 'textStyle/bold' } ] ], |
| 31 |
[ 'b', [ { type: 'textStyle/bold' } ] ], |
| 32 |
[ 'c', [ { type: 'textStyle/bold' } ] ] |
| 33 |
] |
| 34 |
}, |
| 35 |
{ |
| 36 |
data: [ |
| 37 |
{ type: 'paragraph' }, |
| 38 |
[ 'a', [ { type: 'textStyle/bold' } ] ], |
| 39 |
'b', |
| 40 |
[ 'c', [ { type: 'textStyle/italic' } ] ], |
| 41 |
{ type: '/paragraph' } |
| 42 |
], |
| 43 |
html: [ |
| 44 |
[ 'a', [ { type: 'textStyle/bold' } ] ], |
| 45 |
'b', |
| 46 |
[ 'c', [ { type: 'textStyle/italic' } ] ] |
| 47 |
] |
| 48 |
}, |
| 49 |
{ |
| 50 |
|
| 51 |
data: [ { type: 'paragraph' }, ' ', { type: '/paragraph' } ], |
| 52 |
html: [ ' ' ] |
| 53 |
}, |
| 54 |
{ |
| 55 |
|
| 56 |
data: [ { type: 'paragraph' }, ' ', ' ', ' ', { type: '/paragraph' } ], |
| 57 |
html: [ ' ', ' ', ' ' ] |
| 58 |
}, |
| 59 |
{ |
| 60 |
|
| 61 |
data: [ { type: 'paragraph' }, ' ', ' ', ' ', 'A', ' ', ' ', { type: '/paragraph' } ], |
| 62 |
html: [ ' ', ' ', ' ', 'A', ' ', ' ' ] |
| 63 |
}, |
| 64 |
{ |
| 65 |
|
| 66 |
data: [ { type: 'paragraph' }, 'A', '\u00a0', 'A', { type: '/paragraph' } ], |
| 67 |
html: [ 'A', '\u00a0', 'A' ] |
| 68 |
}, |
| 69 |
{ |
| 70 |
data: [ { type: 'paragraph' }, '\n', 'A', '\n', 'B', '\n', { type: '/paragraph' } ], |
| 71 |
html: [ '\u21b5', 'A', '\u21b5', 'B', '\u21b5' ] |
| 72 |
}, |
| 73 |
{ |
| 74 |
data: [ { type: 'paragraph' }, '\t', 'A', '\t', 'B', '\t', { type: '/paragraph' } ], |
| 75 |
html: [ '\u279e', 'A', '\u279e', 'B', '\u279e' ] |
| 76 |
}, |
| 77 |
{ |
| 78 |
data: [ { type: 'preformatted' }, '\n', 'A', '\n', 'B', '\n', { type: '/preformatted' } ], |
| 79 |
html: [ '\n', 'A', '\n', 'B', '\n' ] |
| 80 |
}, |
| 81 |
{ |
| 82 |
data: [ { type: 'preformatted' }, '\t', 'A', '\t', 'B', '\t', { type: '/preformatted' } ], |
| 83 |
html: [ '\t', 'A', '\t', 'B', '\t' ] |
| 84 |
}, |
| 85 |
{ |
| 86 |
|
| 87 |
data: [ { type: 'preformatted' }, ' ', ' ', ' ', 'A', ' ', ' ', { type: '/preformatted' } ], |
| 88 |
html: [ ' ', ' ', ' ', 'A', ' ', ' ' ] |
| 89 |
}, |
| 90 |
{ |
| 91 |
data: [ { type: 'paragraph' }, '&', '<', '>', '\'', '"', { type: '/paragraph' } ], |
| 92 |
html: [ '&', '<', '>', '\'', '"' ] |
| 93 |
} |
| 94 |
]; |
| 95 |
|
| 96 |
const store = new ve.dm.HashValueStore(); |
| 97 |
cases.forEach( ( caseItem ) => { |
| 98 |
const doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( caseItem.data, store ) ); |
| 99 |
ve.dm.example.preprocessAnnotations( caseItem.html, store ); |
| 100 |
assert.deepEqual( |
| 101 |
( new ve.ce.TextNode( doc.getDocumentNode().getChildren()[ 0 ].getChildren()[ 0 ] ) ).getAnnotatedHtml(), |
| 102 |
caseItem.html |
| 103 |
); |
| 104 |
} ); |
| 105 |
} ); |