2012-06-06 17:17:30 +00:00
|
|
|
module( 've.dm.Converter' );
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2012-06-07 00:47:27 +00:00
|
|
|
test( 'getDataElementFromDomElement', function() {
|
2012-06-06 17:17:30 +00:00
|
|
|
for ( var msg in ve.dm.example.conversions ) {
|
|
|
|
var conversion = ve.dm.example.conversions[msg];
|
|
|
|
deepEqual(
|
2012-06-07 00:47:27 +00:00
|
|
|
ve.dm.converter.getDataElementFromDomElement( conversion.domElement ),
|
2012-06-06 17:17:30 +00:00
|
|
|
conversion.dataElement,
|
|
|
|
msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2012-06-07 00:47:27 +00:00
|
|
|
test( 'getDomElementFromDataElement', function() {
|
2012-06-06 17:17:30 +00:00
|
|
|
for ( var msg in ve.dm.example.conversions ) {
|
|
|
|
var conversion = ve.dm.example.conversions[msg];
|
|
|
|
deepEqual(
|
2012-06-07 00:47:27 +00:00
|
|
|
ve.example.getDomElementSummary(
|
|
|
|
ve.dm.converter.getDomElementFromDataElement( conversion.dataElement )
|
2012-06-06 17:17:30 +00:00
|
|
|
),
|
2012-06-07 00:47:27 +00:00
|
|
|
ve.example.getDomElementSummary( conversion.domElement ),
|
|
|
|
msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'getDataFromDom', function() {
|
|
|
|
var cases = {
|
2012-06-07 21:30:06 +00:00
|
|
|
'paragraph with plain text': {
|
2012-06-07 00:47:27 +00:00
|
|
|
'html': '<p>abc</p>',
|
|
|
|
'data': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
]
|
|
|
|
},
|
2012-06-07 21:30:06 +00:00
|
|
|
'annotated text with bold, italic, underline formatting': {
|
2012-06-07 00:47:27 +00:00
|
|
|
'html': '<p><b>a</b><i>b</i><u>c</u></p>',
|
|
|
|
'data': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
['a', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
|
|
|
|
['b', { '{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' } }],
|
|
|
|
['c', { '{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' } }],
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'image': {
|
|
|
|
'html': '<img src="image.png">',
|
|
|
|
'data': [
|
|
|
|
{ 'type': 'image', 'attributes' : { 'html/src' : 'image.png' } },
|
|
|
|
{ 'type' : '/image' }
|
|
|
|
]
|
2012-06-07 21:16:10 +00:00
|
|
|
},
|
2012-06-07 21:30:06 +00:00
|
|
|
'paragraph with alienInline inside': {
|
2012-06-07 21:16:10 +00:00
|
|
|
'html': '<p>a<a href="b.html" data-mw-gc="">b</a>c</p>',
|
|
|
|
'data': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
{
|
|
|
|
'type': 'alienInline',
|
|
|
|
'attributes': { 'html': '<a href="b.html" data-mw-gc="">b</a>' }
|
|
|
|
},
|
2012-06-07 21:30:06 +00:00
|
|
|
{ 'type': '/alienInline' },
|
2012-06-07 21:16:10 +00:00
|
|
|
'c',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
]
|
2012-06-07 21:30:06 +00:00
|
|
|
},
|
|
|
|
'paragraphs with an alienBlock between them': {
|
|
|
|
'html': '<p>abc</p><p data-mw-gc="">abc</p><p>def</p>',
|
|
|
|
'data': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c',
|
|
|
|
{ 'type': '/paragraph' },
|
|
|
|
{ 'type': 'alienBlock', 'attributes': { 'html': '<p data-mw-gc="">abc</p>' } },
|
|
|
|
{ 'type': '/alienBlock' },
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'd',
|
|
|
|
'e',
|
|
|
|
'f',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
]
|
2012-06-07 00:47:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for ( var msg in cases ) {
|
|
|
|
deepEqual(
|
|
|
|
ve.dm.converter.getDataFromDom( $( '<div></div>' ).html( cases[msg].html )[0] ),
|
|
|
|
cases[msg].data,
|
2012-06-06 17:17:30 +00:00
|
|
|
msg
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|