/*! * 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': 'abc' }, { 'msg': 'Bold character, plain character, italic character', 'data': [ { 'type': 'paragraph' }, ['a', [ { 'type': 'textStyle/bold' } ]], 'b', ['c', [ { 'type': 'textStyle/italic' } ]], { 'type': '/paragraph' } ], 'html': 'abc' }, { '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': 'abc' }, { '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': 'abc' }, { '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': 'abc' }, { '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': 'abcdefghi' }, { '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': 'abcdefghi' }, { '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': 'abcdefghi' }, { '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': 'abcdefghi' }, { 'msg': 'Annotation spanning text and inline nodes', 'data': [ { 'type': 'paragraph' }, 'a', ['b', [ { 'type': 'textStyle/bold' } ]], { 'type': 'MWentity', 'attributes': { 'character': 'c', 'html/0/typeof': 'mw:Entity' }, 'annotations': [ { 'type': 'textStyle/bold' } ] }, { 'type': '/MWentity' }, ['d', [ { 'type': 'textStyle/bold' } ]], { 'type': 'alienInline', 'attributes': { 'domElements': $( 'e' ).toArray() }, 'annotations': [ { 'type': 'textStyle/bold' } ] }, { 'type': '/alienInline' }, { 'type': '/paragraph' } ], 'html': 'abcde' } ]; 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 = $( '
' ).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], $( '
' ).html( cases[i].html )[0], cases[i].msg ); } } );