2013-02-21 01:30:02 +00:00
|
|
|
/*!
|
2013-05-14 23:45:42 +00:00
|
|
|
* VisualEditor UserInterface Actions FormatAction tests.
|
2013-02-21 01:30:02 +00:00
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-05-14 23:45:42 +00:00
|
|
|
QUnit.module( 've.ui.FormatAction' );
|
2013-02-21 01:30:02 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
QUnit.test( 'convert', function ( assert ) {
|
|
|
|
var i,
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 14, 16 ),
|
2013-07-03 01:30:10 +00:00
|
|
|
'type': 'heading',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': { level: 2 },
|
|
|
|
'expectedSelection': new ve.Range( 14, 16 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 12, 1, { 'type': 'heading', 'attributes': { 'level': 2 } } );
|
|
|
|
data.splice( 19, 1, { 'type': '/heading' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-07-03 01:30:10 +00:00
|
|
|
'msg': 'converting partial selection of list item "Item 2" to level 2 heading'
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 15, 50 ),
|
2013-07-03 01:30:10 +00:00
|
|
|
'type': 'heading',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': { level: 3 },
|
2013-07-03 01:30:10 +00:00
|
|
|
'expectedSelection': new ve.Range( 15, 50 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 12, 1, { 'type': 'heading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 19, 1, { 'type': '/heading' } );
|
|
|
|
data.splice( 22, 1, { 'type': 'heading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 29, 1, { 'type': '/heading' } );
|
|
|
|
data.splice( 32, 1, { 'type': 'heading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 42, 1, { 'type': '/heading' } );
|
|
|
|
data.splice( 45, 1, { 'type': 'heading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 52, 1, { 'type': '/heading' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
'msg': 'converting partial selection across two lists surrounding a paragraph'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 4, 28 ),
|
2013-07-03 01:30:10 +00:00
|
|
|
'type': 'heading',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': { level: 1 },
|
2013-07-03 01:30:10 +00:00
|
|
|
'expectedSelection': new ve.Range( 4, 28 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 2, 1, { 'type': 'heading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 9, 1, { 'type': '/heading' } );
|
|
|
|
data.splice( 12, 1, { 'type': 'heading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 19, 1, { 'type': '/heading' } );
|
|
|
|
data.splice( 22, 1, { 'type': 'heading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 29, 1, { 'type': '/heading' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-07-03 01:30:10 +00:00
|
|
|
'msg': 'converting partial selection of all list items to level 1 headings'
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 5, 26 ),
|
2013-07-03 01:30:10 +00:00
|
|
|
'type': 'preformatted',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': undefined,
|
2013-07-03 01:30:10 +00:00
|
|
|
'expectedSelection': new ve.Range( 5, 26 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 2, 1, { 'type': 'preformatted' } );
|
|
|
|
data.splice( 9, 1, { 'type': '/preformatted' } );
|
|
|
|
data.splice( 12, 1, { 'type': 'preformatted' } );
|
|
|
|
data.splice( 19, 1, { 'type': '/preformatted' } );
|
|
|
|
data.splice( 22, 1, { 'type': 'preformatted' } );
|
|
|
|
data.splice( 29, 1, { 'type': '/preformatted' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-07-03 01:30:10 +00:00
|
|
|
'msg': 'converting partial selection of some list items to preformatted text'
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 146, 159 ),
|
|
|
|
'type': 'paragraph',
|
|
|
|
'attributes': undefined,
|
|
|
|
'expectedSelection': new ve.Range( 146, 159 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-02-16 00:27:03 +00:00
|
|
|
data.splice( 145, 1, { 'type': 'paragraph' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
data.splice( 159, 1, { 'type': '/paragraph' } );
|
|
|
|
},
|
|
|
|
'msg': 'converting heading in list item to paragraph'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 165, 180 ),
|
|
|
|
'type': 'paragraph',
|
|
|
|
'attributes': undefined,
|
|
|
|
'expectedSelection': new ve.Range( 165, 180 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-02-16 00:27:03 +00:00
|
|
|
data.splice( 162, 1, { 'type': 'paragraph' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
data.splice( 183, 1, { 'type': '/paragraph' } );
|
|
|
|
},
|
2013-07-03 01:30:10 +00:00
|
|
|
'msg': 'converting preformatted in list item to paragraph'
|
2013-04-22 11:20:26 +00:00
|
|
|
}
|
|
|
|
];
|
2013-02-21 01:30:02 +00:00
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
QUnit.expect( cases.length * 4 );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.test.utils.runFormatConverterTest( assert, cases[i].range, cases[i].type, cases[i].attributes, cases[i].expectedSelection, cases[i].expectedData, cases[i].msg );
|
2013-04-22 11:20:26 +00:00
|
|
|
}
|
2013-02-21 01:30:02 +00:00
|
|
|
} );
|