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
|
|
|
function runFormatConverterTest( assert, range, type, attributes, expectedSelection, expectedData, msg ) {
|
|
|
|
var selection,
|
2013-05-28 11:49:35 +00:00
|
|
|
dom = ve.createDocumentFromHtml( ve.dm.example.isolationHtml ),
|
2013-05-14 23:45:42 +00:00
|
|
|
target = new ve.init.sa.Target( $( '#qunit-fixture' ), dom ),
|
|
|
|
surface = target.surface,
|
|
|
|
formatAction = new ve.ui.FormatAction( surface ),
|
2013-04-22 11:20:26 +00:00
|
|
|
data = ve.copyArray( surface.getModel().getDocument().getFullData() ),
|
|
|
|
originalData = ve.copyArray( data );
|
|
|
|
|
|
|
|
expectedData( data );
|
2013-02-21 01:30:02 +00:00
|
|
|
|
|
|
|
surface.getModel().change( null, range );
|
|
|
|
formatAction.convert( type, attributes );
|
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
assert.deepEqual( surface.getModel().getDocument().getFullData(), data, msg + ': data models match' );
|
|
|
|
assert.deepEqual( surface.getModel().getSelection(), expectedSelection, msg + ': selections match' );
|
2013-02-21 01:30:02 +00:00
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
selection = surface.getModel().undo();
|
|
|
|
|
|
|
|
assert.deepEqual( surface.getModel().getDocument().getFullData(), originalData, msg + ' (undo): data models match' );
|
|
|
|
assert.deepEqual( selection, range, msg + ' (undo): selections match' );
|
2013-02-23 00:22:30 +00:00
|
|
|
|
|
|
|
surface.destroy();
|
2013-02-21 01:30:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
QUnit.test( 'convert', function ( assert ) {
|
|
|
|
var i,
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 14, 16 ),
|
2013-05-28 11:31:41 +00:00
|
|
|
'type': 'mwHeading',
|
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-05-28 11:31:41 +00:00
|
|
|
data.splice( 11, 2, { 'type': '/list' }, { 'type': 'mwHeading', 'attributes': { 'level': 2 } } );
|
|
|
|
data.splice( 19, 2, { 'type': '/mwHeading' }, { 'type': 'list', 'attributes': { 'style': 'bullet' } } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-05-28 11:31:41 +00:00
|
|
|
'msg': 'converting partial selection of list item "Item 2" to level 2 mwHeading'
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 15, 50 ),
|
2013-05-28 11:31:41 +00:00
|
|
|
'type': 'mwHeading',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': { level: 3 },
|
|
|
|
'expectedSelection': new ve.Range( 15, 44 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-05-28 11:31:41 +00:00
|
|
|
data.splice( 11, 2, { 'type': '/list' }, { 'type': 'mwHeading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 19, 4, { 'type': '/mwHeading' }, { 'type': 'mwHeading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 27, 4, { 'type': '/mwHeading' }, { 'type': 'mwHeading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 38, 4, { 'type': '/mwHeading' }, { 'type': 'mwHeading', 'attributes': { 'level': 3 } } );
|
|
|
|
data.splice( 46, 2, { 'type': '/mwHeading' }, { 'type': 'list', 'attributes': { 'style': 'bullet' } } );
|
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-05-28 11:31:41 +00:00
|
|
|
'type': 'mwHeading',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': { level: 1 },
|
|
|
|
'expectedSelection': new ve.Range( 2, 22 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-05-28 11:31:41 +00:00
|
|
|
data.splice( 0, 3, { 'type': 'mwHeading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 7, 4, { 'type': '/mwHeading' }, { 'type': 'mwHeading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 15, 4, { 'type': '/mwHeading' }, { 'type': 'mwHeading', 'attributes': { 'level': 1 } } );
|
|
|
|
data.splice( 23, 3, { 'type': '/mwHeading' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
|
|
|
'msg': 'converting partial selection of all list items to level 1 MWheadings'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 5, 26 ),
|
2013-05-28 11:31:41 +00:00
|
|
|
'type': 'mwPreformatted',
|
2013-04-22 11:20:26 +00:00
|
|
|
'attributes': undefined,
|
|
|
|
'expectedSelection': new ve.Range( 3, 20 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-05-28 11:31:41 +00:00
|
|
|
data.splice( 0, 3, { 'type': 'mwPreformatted' } );
|
|
|
|
data.splice( 7, 4, { 'type': '/mwPreformatted' }, { 'type': 'mwPreformatted' } );
|
|
|
|
data.splice( 15, 4, { 'type': '/mwPreformatted' }, { 'type': 'mwPreformatted' } );
|
|
|
|
data.splice( 23, 3, { 'type': '/mwPreformatted' } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-05-28 11:31:41 +00:00
|
|
|
'msg': 'converting partial selection of some list items to mwPreformatted 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' } );
|
|
|
|
},
|
|
|
|
'msg': 'converting MWpreformatted in list item to paragraph'
|
|
|
|
}
|
|
|
|
];
|
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++ ) {
|
|
|
|
runFormatConverterTest( assert, cases[i].range, cases[i].type, cases[i].attributes, cases[i].expectedSelection, cases[i].expectedData, cases[i].msg );
|
|
|
|
}
|
2013-02-21 01:30:02 +00:00
|
|
|
} );
|