2013-03-04 16:24:09 +00:00
|
|
|
/*!
|
2013-05-14 23:45:42 +00:00
|
|
|
* VisualEditor UserInterface Actions IndentationAction tests.
|
2013-03-04 16:24:09 +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.IndentationAction' );
|
2013-03-04 16:24:09 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2013-04-22 11:20:26 +00:00
|
|
|
function runIndentationChangeTest( assert, range, method, expectedSelection, expectedData, expectedOriginalData, 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,
|
|
|
|
indentationAction = new ve.ui.IndentationAction( surface ),
|
2013-07-28 20:51:32 +00:00
|
|
|
data = ve.copy( surface.getModel().getDocument().getFullData() ),
|
|
|
|
originalData = ve.copy( data );
|
2013-04-22 11:20:26 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-05-13 17:27:21 +00:00
|
|
|
QUnit.test( 'increase/decrease', 2, function ( assert ) {
|
2013-04-22 11:20:26 +00:00
|
|
|
var i,
|
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 14, 16 ),
|
|
|
|
'method': 'decrease',
|
|
|
|
'expectedSelection': new ve.Range( 14, 16 ),
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedData': function ( data ) {
|
2013-04-22 11:20:26 +00:00
|
|
|
data.splice( 11, 2, { 'type': '/list' }, { 'type': 'paragraph' } );
|
2013-02-16 00:27:03 +00:00
|
|
|
data.splice( 19, 2, { 'type': '/paragraph' }, { 'type': 'list', 'attributes': { 'style': 'bullet' } } );
|
2013-04-22 11:20:26 +00:00
|
|
|
},
|
2013-05-06 11:34:32 +00:00
|
|
|
'expectedOriginalData': function ( data ) {
|
2013-04-22 11:20:26 +00:00
|
|
|
// 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"'
|
2013-05-12 20:58:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 3, 19 ),
|
|
|
|
'method': 'decrease',
|
|
|
|
'expectedSelection': new ve.Range( 1, 15 ),
|
|
|
|
'expectedData': function ( data ) {
|
|
|
|
data.splice( 0, 2 );
|
|
|
|
data.splice( 8, 2 );
|
|
|
|
data.splice( 16, 1, { 'type': 'list', 'attributes': { 'style': 'bullet' } } );
|
|
|
|
delete data[0].internal;
|
|
|
|
delete data[8].internal;
|
|
|
|
},
|
|
|
|
'expectedOriginalData': function ( data ) {
|
|
|
|
// generated: 'wrapper' is removed by the action and not restored by undo
|
|
|
|
delete data[2].internal;
|
|
|
|
delete data[12].internal;
|
|
|
|
},
|
|
|
|
'msg': 'decrease indentation on Items 1 & 2'
|
2013-05-13 17:27:21 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'range': new ve.Range( 3, 19 ),
|
|
|
|
'method': 'increase',
|
|
|
|
'expectedSelection': new ve.Range( 5, 21 ),
|
|
|
|
'expectedData': function ( data ) {
|
|
|
|
data.splice( 0, 0, { 'type': 'list', 'attributes': { 'style': 'bullet' } }, { 'type': 'listItem' } );
|
|
|
|
data.splice( 23, 0, { 'type': '/list' }, { 'type': '/listItem' } );
|
|
|
|
},
|
|
|
|
'msg': 'increase indentation on Items 1 & 2'
|
2013-04-22 11:20:26 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
} );
|