2013-03-04 16:24:09 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor Actions IndentationAction tests.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
QUnit.module( 've.IndentationAction' );
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
function runIndentationChangeTest( assert, range, method, expectedSelection, expectedData, expectedOriginalData, msg ) {
|
|
|
|
var selection,
|
|
|
|
dom = ve.createDocumentFromHTML( ve.dm.example.isolationHTML ),
|
2013-03-20 22:35:05 +00:00
|
|
|
surface = new ve.Surface( new ve.init.Target( $( '<div>' ) ), dom ),
|
2013-03-04 16:24:09 +00:00
|
|
|
indentationAction = new ve.IndentationAction( surface ),
|
2013-04-22 11:20:26 +00:00
|
|
|
data = ve.copyArray( surface.getModel().getDocument().getFullData() ),
|
|
|
|
originalData = ve.copyArray( data );
|
|
|
|
|
|
|
|
expectedData( data );
|
|
|
|
if ( expectedOriginalData ) {
|
|
|
|
expectedOriginalData( originalData );
|
|
|
|
}
|
2013-03-04 16:24:09 +00:00
|
|
|
|
|
|
|
surface.getModel().change( null, range );
|
|
|
|
indentationAction[method]();
|
|
|
|
|
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-03-04 16:24:09 +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-03-04 16:24:09 +00:00
|
|
|
|
|
|
|
surface.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
QUnit.test( 'decrease', 2, function ( assert ) {
|
2013-04-22 11:20:26 +00:00
|
|
|
var i,
|
|
|
|
rebuilt = { 'changed': { 'rebuilt': 1 } },
|
|
|
|
createdAndRebuilt = { 'changed': { 'created': 2, 'rebuilt': 1 } },
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 14, 16 ),
|
|
|
|
'method': 'decrease',
|
|
|
|
'expectedSelection': new ve.Range( 14, 16 ),
|
|
|
|
'expectedData': function( data ) {
|
|
|
|
data[0].internal = rebuilt;
|
|
|
|
data.splice( 11, 2, { 'type': '/list' }, { 'type': 'paragraph' } );
|
|
|
|
data.splice( 19, 2, { 'type': '/paragraph' }, { 'type': 'list', 'attributes': { 'style': 'bullet' }, 'internal': createdAndRebuilt } );
|
|
|
|
},
|
|
|
|
'expectedOriginalData': function( data ) {
|
|
|
|
// generated: 'wrapper' is removed by the action and not restored by undo
|
|
|
|
delete data[12].internal;
|
|
|
|
},
|
|
|
|
'msg': 'decrease indentation on partial selection of list item "Item 2"'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
QUnit.expect( cases.length * 4 );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
|
|
runIndentationChangeTest( assert, cases[i].range, cases[i].method, cases[i].expectedSelection, cases[i].expectedData, cases[i].expectedOriginalData, cases[i].msg );
|
|
|
|
}
|
2013-03-04 16:24:09 +00:00
|
|
|
} );
|