mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
fe5f4fdce0
* Use plain text rather than HTML in TextNode ** Bypasses HTML parsing, and doesn't cause regeneration of nodes like appending to .innerHTML does ** We were only using HTML so we could use entities, so replace those with \uNNNN sequences * Use native DOM functionality rather than jQuery * Inline flushBuffer() Change-Id: I7c6376b55cc0f1420a01a77b365b073fe1636263
146 lines
4.2 KiB
JavaScript
146 lines
4.2 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable TextNode tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ce.TextNode' );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'getAnnotatedHtml', function ( assert ) {
|
|
var i, len, cases, doc,
|
|
store = new ve.dm.IndexValueStore();
|
|
|
|
cases = [
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [ 'a', 'b', 'c' ]
|
|
},
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
['c', [ { 'type': 'textStyle/bold' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
['c', [ { 'type': 'textStyle/bold' } ]]
|
|
]
|
|
},
|
|
{
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
'b',
|
|
['c', [ { 'type': 'textStyle/italic' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': [
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
'b',
|
|
['c', [ { 'type': 'textStyle/italic' } ]]
|
|
]
|
|
},
|
|
{
|
|
// [ ]
|
|
'data': [{ 'type': 'paragraph' },' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', ' ', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', ' ', '\u00a0', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][A][ ][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', 'A', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', 'A', ' ', '\u00a0', ' ', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][A][ ][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', 'A', ' ', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', 'A', ' ', '\u00a0', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][A][ ][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', 'A', ' ', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][A][ ]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', 'A', ' ',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', ' ', 'A', '\u00a0' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][ ][ ][A]
|
|
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', 'A',{ 'type': '/paragraph' }],
|
|
'html': [ '\u00a0', ' ', '\u00a0', ' ', '\u00a0', 'A' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/paragraph' }],
|
|
'html': [ '\u21b5', 'A', '\u21b5', 'B', '\u21b5' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/paragraph' }],
|
|
'html': [ '\u279e', 'A', '\u279e', 'B', '\u279e' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'preformatted' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/preformatted' }],
|
|
'html': [ '\n', 'A', '\n', 'B', '\n' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'preformatted' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/preformatted' }],
|
|
'html': [ '\t', 'A', '\t', 'B', '\t' ]
|
|
},
|
|
{
|
|
// [ ][ ][ ][A][ ][ ]
|
|
'data': [{ 'type': 'preformatted' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/preformatted' }],
|
|
'html': [ ' ', ' ', ' ', 'A', ' ', ' ' ]
|
|
},
|
|
{
|
|
'data': [{ 'type': 'paragraph' }, '&', '<', '>', '\'', '"', { 'type': '/paragraph' }],
|
|
'html': [ '&', '<', '>', '\'', '"' ]
|
|
}
|
|
];
|
|
QUnit.expect( cases.length );
|
|
for ( i = 0, len = cases.length; i < len; i++ ) {
|
|
doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[i].data, store ) );
|
|
ve.dm.example.preprocessAnnotations( cases[i].html, store );
|
|
assert.deepEqual(
|
|
( new ve.ce.TextNode( doc.documentNode.getChildren()[0].getChildren()[0] ) ).getAnnotatedHtml(),
|
|
cases[i].html
|
|
);
|
|
}
|
|
} );
|