2012-05-10 23:28:45 +00:00
|
|
|
module( 've.dm.HTMLConverter' );
|
|
|
|
|
|
|
|
// Tests
|
|
|
|
|
2012-05-11 21:07:20 +00:00
|
|
|
test( 'convertHTML', function() {
|
|
|
|
var cases = [
|
|
|
|
{
|
|
|
|
'html': '<p>abc</p>',
|
|
|
|
'linearModel': [
|
|
|
|
{ 'type': 'paragraph' },
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
'c',
|
|
|
|
{ 'type': '/paragraph' }
|
|
|
|
],
|
|
|
|
'message': 'paragraph and text'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'html': '<p><b>a</b><i>b</i><u>c</u></p>',
|
|
|
|
'linearModel': [
|
2012-05-17 18:29:50 +00:00
|
|
|
{ 'type': 'paragraph' },
|
2012-05-11 21:07:20 +00:00
|
|
|
['a', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
|
|
|
|
['b', { '{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' } }],
|
|
|
|
['c', { '{"type":"textStyle/underline"}': { 'type': 'textStyle/underline' } }],
|
2012-05-17 18:29:50 +00:00
|
|
|
{ 'type': '/paragraph' }
|
2012-05-11 21:07:20 +00:00
|
|
|
],
|
|
|
|
'message': 'bold, italic, underline'
|
2012-05-16 20:41:26 +00:00
|
|
|
},
|
|
|
|
{
|
2012-05-17 18:29:50 +00:00
|
|
|
'html': '<img src="image.png">',
|
2012-05-16 20:41:26 +00:00
|
|
|
'linearModel': [
|
2012-05-17 18:29:50 +00:00
|
|
|
{ 'type': 'image', 'attributes' : { 'html/src' : 'image.png' } },
|
2012-05-16 20:41:26 +00:00
|
|
|
{ 'type' : '/image' }
|
|
|
|
],
|
|
|
|
'message': 'image'
|
2012-05-17 18:29:50 +00:00
|
|
|
}
|
2012-05-10 23:28:45 +00:00
|
|
|
];
|
2012-05-17 18:29:50 +00:00
|
|
|
|
2012-05-11 21:07:20 +00:00
|
|
|
expect(cases.length);
|
|
|
|
|
|
|
|
for ( var i = 0; i < cases.length; i++ ) {
|
2012-05-17 18:29:50 +00:00
|
|
|
var convertedLinearModel = ve.dm.HTMLConverter.getLinearModel(
|
|
|
|
$('<div>' + cases[i].html + '</div>')[0]
|
|
|
|
);
|
2012-05-11 21:07:20 +00:00
|
|
|
|
2012-05-17 18:29:50 +00:00
|
|
|
//console.log( convertedLinearModel );
|
|
|
|
//console.log( cases[i].linearModel );
|
2012-05-11 21:07:20 +00:00
|
|
|
|
2012-05-17 18:29:50 +00:00
|
|
|
deepEqual( convertedLinearModel, cases[i].linearModel, cases[i].message);
|
2012-05-11 21:07:20 +00:00
|
|
|
}
|
2012-05-10 23:28:45 +00:00
|
|
|
} );
|