/** * VisualEditor content editable TextNode tests. * * @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ QUnit.module( 've.ce.TextNode' ); /* Tests */ QUnit.test( 'getHtml', function ( assert ) { var i, len, cases; cases = [ { 'data': [ { 'type': 'paragraph' }, 'a', 'b', 'c', { 'type': '/paragraph' } ], 'html': 'abc' }, { 'data': [ { 'type': 'paragraph' }, ['a', [ { 'type': 'textStyle/bold' } ]], ['b', [ { 'type': 'textStyle/bold' } ]], ['c', [ { 'type': 'textStyle/bold' } ]], { 'type': '/paragraph' } ], 'html': 'abc' }, { 'data': [ { 'type': 'paragraph' }, ['a', [ { 'type': 'textStyle/bold' } ]], 'b', ['c', [ { 'type': 'textStyle/italic' } ]], { 'type': '/paragraph' } ], 'html': 'abc' }, { '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' }, { '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' }, { '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' }, { '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' }, { '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' }, { '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' }, { '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' }, { // [ ] 'data': [{ 'type': 'paragraph' },{ 'type': '/paragraph' }], 'html': '' }, { // [ ] 'data': [{ 'type': 'paragraph' },' ',{ 'type': '/paragraph' }], 'html': ' ' }, { // [ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ',{ 'type': '/paragraph' }], 'html': '  ' }, { // [ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': '   ' }, { // [ ][ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': '    ' }, { // [ ][ ][ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': '     ' }, { // [ ][ ][ ][ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': '      ' }, { // [ ][A][ ][ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', 'A', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': ' A    ' }, { // [ ][ ][A][ ][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', 'A', ' ', ' ', ' ',{ 'type': '/paragraph' }], 'html': '  A   ' }, { // [ ][ ][ ][A][ ][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/paragraph' }], 'html': '   A  ' }, { // [ ][ ][ ][ ][A][ ] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', 'A', ' ',{ 'type': '/paragraph' }], 'html': '    A ' }, { // [ ][ ][ ][ ][ ][A] 'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', 'A',{ 'type': '/paragraph' }], 'html': '     A' }, { 'data': [{ 'type': 'paragraph' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/paragraph' }], 'html': '↵A↵B↵' }, { 'data': [{ 'type': 'paragraph' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/paragraph' }], 'html': '➞A➞B➞' }, { 'data': [{ 'type': 'preformatted' }, '\n', 'A', '\n', 'B', '\n', { 'type': '/preformatted' }], 'html': '\nA\nB\n' }, { 'data': [{ 'type': 'preformatted' }, '\t', 'A', '\t', 'B', '\t', { 'type': '/preformatted' }], 'html': '\tA\tB\t' }, { // [ ][ ][ ][A][ ][ ] 'data': [{ 'type': 'preformatted' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/preformatted' }], 'html': ' A ' } ]; QUnit.expect( cases.length ); for ( i = 0, len = cases.length; i < len; i++ ) { ve.dm.example.preprocessAnnotations( cases[i].data ); assert.equal( ( new ve.ce.TextNode( ( new ve.dm.Document( cases[i].data ) ) .documentNode.getChildren()[0].getChildren()[0] ) ).getHtml(), cases[i].html ); } } );