mediawiki-extensions-Visual.../tests/ve/ce/nodes/ve.ce.TextNode.test.js
Trevor Parscal c40174b60c Changed to use MIT license per agreement with the VisualEditor team
This license change is aimed at maximizing the reusability of this code
in other projects. VisualEditor is more than just an awesome editor for
MediaWiki, it's the new editor for the entire internet.

Added license and author files, plus mentions of the license to all
VisualEditor PHP, JavaScript and CSS files. Parser files have not been
modified but are effectively re-licensed since there's no overriding
license information. 3rd party libraries are not changed, but are all
already MIT licensed.

Change-Id: I895b256325db7c8689756edab34523de4418b0f2
2012-07-19 13:25:45 -07:00

285 lines
8.2 KiB
JavaScript

/**
* VisualEditor content editable TextNode tests.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
module( 've.ce.TextNode' );
/* Tests */
test( 'getHtml', 22, function() {
var cases = [
{
'data': [
{ 'type': 'paragraph' },
'a',
'b',
'c',
{ 'type': '/paragraph' }
],
'html': 'abc'
},
{
'data': [
{ 'type': 'paragraph' },
['a', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
['b', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
['c', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
{ 'type': '/paragraph' }
],
'html': '<b>abc</b>'
},
{
'data': [
{ 'type': 'paragraph' },
['a', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
'b',
['c', { '{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' } }],
{ 'type': '/paragraph' }
],
'html': '<b>a</b>b<i>c</i>'
},
{
'data': [
{ 'type': 'paragraph' },
['a', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['b', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['c', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
{ 'type': '/paragraph' }
],
'html': '<b><i><u>abc</u></i></b>'
},
{
'data': [
{ 'type': 'paragraph' },
['a', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['b', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
['c', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' }
}],
{ 'type': '/paragraph' }
],
'html': '<b><i><u>abc</u></i></b>'
},
{
'data': [
{ 'type': 'paragraph' },
['a', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
'b',
['c', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' }
}],
{ 'type': '/paragraph' }
],
'html': '<b><i><u>a</u></i></b>b<u><b><i>c</i></b></u>'
},
{
'data': [
{ 'type': 'paragraph' },
'a',
'b',
'c',
['d', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['e', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
['f', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' }
}],
'g',
'h',
'i',
{ 'type': '/paragraph' }
],
'html': 'abc<b><i><u>def</u></i></b>ghi'
},
{
'data': [
{ 'type': 'paragraph' },
'a',
'b',
'c',
['d', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['e', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['f', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { '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'
},
{
'data': [
{ 'type': 'paragraph' },
'a',
'b',
'c',
['d', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
['e', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['f', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' }
}],
'g',
'h',
'i',
{ 'type': '/paragraph' }
],
'html': 'abc<i><u><b>d</b>e<b>f</b></u></i>ghi'
},
{
'data': [
{ 'type': 'paragraph' },
'a',
'b',
'c',
['d', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
['e', {
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' },
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' }
}],
['f', {
'{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
'g',
'h',
'i',
{ 'type': '/paragraph' }
],
'html': 'abc<i><u><b>d</b></u></i><u><b>ef</b></u>ghi'
},
{
// [ ]
'data': [{ 'type': 'paragraph' },{ 'type': '/paragraph' }],
'html': ''
},
{
// [ ]
'data': [{ 'type': 'paragraph' },' ',{ 'type': '/paragraph' }],
'html': '&nbsp;'
},
{
// [ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp;&nbsp;'
},
{
// [ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp;'
},
{
// [ ][ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp;&nbsp;'
},
{
// [ ][ ][ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp; &nbsp;'
},
{
// [ ][ ][ ][ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp; &nbsp;&nbsp;'
},
{
// [ ][A][ ][ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', 'A', ' ', ' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp;A &nbsp; &nbsp;'
},
{
// [ ][ ][A][ ][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', 'A', ' ', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; A &nbsp;&nbsp;'
},
{
// [ ][ ][ ][A][ ][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', 'A', ' ', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp;A &nbsp;'
},
{
// [ ][ ][ ][ ][A][ ]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', 'A', ' ',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp; A&nbsp;'
},
{
// [ ][ ][ ][ ][ ][A]
'data': [{ 'type': 'paragraph' },' ', ' ', ' ', ' ', ' ', 'A',{ 'type': '/paragraph' }],
'html': '&nbsp; &nbsp; &nbsp;A'
}
];
for ( var i = 0; i < cases.length; i++ ) {
equal(
( new ve.ce.TextNode(
( new ve.dm.Document( cases[i].data ) )
.documentNode.getChildren()[0].getChildren()[0] )
).getHtml(),
cases[i].html
);
}
} );