mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
9ff6737f4c
Rather than using namespaced linmod attributes, store the preserved HTML attributes in the .htmlAttributes property of the linear model element, in a nested structure to allow for easier treatment of child nodes. Also added attribute order preservation by storing attributes as an object plus an array of keys. ve.ce.Node.js: * Remove html/* attribute synchronization. Doesn't make sense any more because these things aren't in the attributes object any more. I don't think it ever made sense because these attributes were never supposed to be changed anyway. ve.ce.View.js: * Replace renderAttributes() with a simple wrapper around renderHtmlAttributeList() ve.dm.Converter.js: * Add buildHtmlAttributeList() and renderHtmlAttributes() for building and rendering HTML attribute lists ve.dm.Model.js: * Add getter for .htmlAttributes ve.dm.Node.js: * Drop .htmlAttributes on clone, and remove logic dropping html/* ve.ui.MWCategoryWidget.js: * Remove html/0/about hack, was already unnecessary and now doesn't work any more tests/: * UPDATE ALL THE TESTS Change-Id: I620573afd70d36ade6b80413075b6e1f4a435abe
264 lines
6.6 KiB
JavaScript
264 lines
6.6 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable ContentBranchNode tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ce.ContentBranchNode' );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'getRenderedContents', function ( assert ) {
|
|
var i, len, doc, $rendered, $wrapper,
|
|
cases = [
|
|
{
|
|
'msg': 'Plain text without annotations',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'abc'
|
|
},
|
|
{
|
|
'msg': 'Bold text',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
['c', [ { 'type': 'textStyle/bold' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': '<b>abc</b>'
|
|
},
|
|
{
|
|
'msg': 'Bold character, plain character, italic character',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [ { 'type': 'textStyle/bold' } ]],
|
|
'b',
|
|
['c', [ { 'type': 'textStyle/italic' } ]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': '<b>a</b>b<i>c</i>'
|
|
},
|
|
{
|
|
'msg': 'Bold, italic and underlined text (same order)',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['b', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['c', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': '<b><i><u>abc</u></i></b>'
|
|
},
|
|
{
|
|
'msg': 'Varying order in consecutive range doesn\'t affect rendering',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['b', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' }
|
|
]],
|
|
['c', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' }
|
|
]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': '<b><i><u>abc</u></i></b>'
|
|
},
|
|
{
|
|
'msg': 'Varying order in non-consecutive range does affect rendering',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
['a', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
'b',
|
|
['c', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' }
|
|
]],
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': '<b><i><u>a</u></i></b>b<u><b><i>c</i></b></u>'
|
|
},
|
|
{
|
|
'msg': 'Text annotated in varying order, surrounded by plain text',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
['d', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['e', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' }
|
|
]],
|
|
['f', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' }
|
|
]],
|
|
'g',
|
|
'h',
|
|
'i',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'abc<b><i><u>def</u></i></b>ghi'
|
|
},
|
|
{
|
|
'msg': 'Out-of-order closings do not produce misnested tags',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
['d', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['e', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['f', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' }
|
|
]],
|
|
'g',
|
|
'h',
|
|
'i',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'abc<b><i><u>d</u></i></b><i><u>e<b>f</b></u></i>ghi'
|
|
},
|
|
{
|
|
'msg': 'Additional openings are added inline, even when out of order',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
['d', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' }
|
|
]],
|
|
['e', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['f', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/italic' }
|
|
]],
|
|
'g',
|
|
'h',
|
|
'i',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'abc<i><u><b>d</b>e<b>f</b></u></i>ghi'
|
|
},
|
|
{
|
|
'msg': 'Out-of-order closings surrounded by plain text',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
'b',
|
|
'c',
|
|
['d', [
|
|
{ 'type': 'textStyle/italic' },
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' }
|
|
]],
|
|
['e', [
|
|
{ 'type': 'textStyle/bold' },
|
|
{ 'type': 'textStyle/underline' }
|
|
]],
|
|
['f', [
|
|
{ 'type': 'textStyle/underline' },
|
|
{ 'type': 'textStyle/bold' }
|
|
]],
|
|
'g',
|
|
'h',
|
|
'i',
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'abc<i><u><b>d</b></u></i><b><u>ef</u></b>ghi'
|
|
},
|
|
{
|
|
'msg': 'Annotation spanning text and inline nodes',
|
|
'data': [
|
|
{ 'type': 'paragraph' },
|
|
'a',
|
|
['b', [ { 'type': 'textStyle/bold' } ]],
|
|
{
|
|
'type': 'MWentity',
|
|
'attributes': { 'character': 'c' },
|
|
'htmlAttributes': [ { 'keys': [ 'typeof' ], 'values': { 'typeof': 'mw:Entity' } } ],
|
|
'annotations': [ { 'type': 'textStyle/bold' } ]
|
|
},
|
|
{ 'type': '/MWentity' },
|
|
['d', [ { 'type': 'textStyle/bold' } ]],
|
|
{
|
|
'type': 'alienInline',
|
|
'attributes': { 'domElements': $( '<tt>e</tt>' ).toArray() },
|
|
'annotations': [ { 'type': 'textStyle/bold' } ]
|
|
},
|
|
{ 'type': '/alienInline' },
|
|
{ 'type': '/paragraph' }
|
|
],
|
|
'html': 'a<b>b<span typeof="mw:Entity" class="ve-ce-leafNode ' +
|
|
've-ce-MWEntityNode" contenteditable="false">c</span>d<span ' +
|
|
'class="ve-ce-leafNode ve-ce-generatedContentNode ve-ce-protectedNode ' +
|
|
've-ce-alienNode ve-ce-alienInlineNode" ' +
|
|
'contenteditable="false"><tt>e</tt></span></b>'
|
|
}
|
|
];
|
|
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 ) );
|
|
$rendered = ( new ve.ce.ParagraphNode( doc.documentNode.getChildren()[0] ) ).getRenderedContents();
|
|
$wrapper = $( '<div>' ).append( $rendered );
|
|
// HACK strip out all the class="ve-ce-TextStyleAnnotation ve-ce-TextStyleBoldAnnotation" crap
|
|
$wrapper.find( '.ve-ce-TextStyleAnnotation' ).removeAttr( 'class' );
|
|
assert.equalDomElement( $wrapper[0], $( '<div>' ).html( cases[i].html )[0], cases[i].msg );
|
|
}
|
|
} );
|