/** * 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( 'getAnnotatedHtml', function ( assert ) { var i, len, cases; 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': [] }, { // [ ] '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': [ '\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++ ) { ve.dm.example.preprocessAnnotations( cases[i].data ); ve.dm.example.preprocessAnnotations( cases[i].html ); assert.deepEqual( ( new ve.ce.TextNode( ( new ve.dm.Document( cases[i].data ) ) .documentNode.getChildren()[0].getChildren()[0] ) ).getAnnotatedHtml(), cases[i].html ); } } );