mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 19:09:29 +00:00
8b09dd7650
By removing the transaction listeners from surface fragments we no longer have to make sure they are always manually destroyed. In order to retain the functionality of having fragments update with transactions elsewhere we keep a pointer to a place in the new complete history stack in the surface. The complete history stack records all transactions, even undone ones. Whenever getRange is called we replay all transactions in the complete history (in the correct order) since the fragment was last updated. Also in this commit: * Updated Format/IndentationAction to test undo(). This increases coverage of surface fragment behaviour. * .range is always accessed by .getRange now, although as an optimisation we can use the noCopy mode when we a sure the returned range will not be modified. * Added undo test to .update (previously .onTransact) Bug: 47343 Change-Id: I9e9818da1baa8319a3002f6d74fd1aad6732a8f5
66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
/*!
|
|
* 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 */
|
|
|
|
function runIndentationChangeTest( assert, range, method, expectedSelection, expectedData, expectedOriginalData, msg ) {
|
|
var selection,
|
|
dom = ve.createDocumentFromHTML( ve.dm.example.isolationHTML ),
|
|
surface = new ve.Surface( new ve.init.Target( $( '<div>' ) ), dom ),
|
|
indentationAction = new ve.IndentationAction( surface ),
|
|
data = ve.copyArray( surface.getModel().getDocument().getFullData() ),
|
|
originalData = ve.copyArray( data );
|
|
|
|
expectedData( data );
|
|
if ( expectedOriginalData ) {
|
|
expectedOriginalData( originalData );
|
|
}
|
|
|
|
surface.getModel().change( null, range );
|
|
indentationAction[method]();
|
|
|
|
assert.deepEqual( surface.getModel().getDocument().getFullData(), data, msg + ': data models match' );
|
|
assert.deepEqual( surface.getModel().getSelection(), expectedSelection, msg + ': selections match' );
|
|
|
|
selection = surface.getModel().undo();
|
|
|
|
assert.deepEqual( surface.getModel().getDocument().getFullData(), originalData, msg + ' (undo): data models match' );
|
|
assert.deepEqual( selection, range, msg + ' (undo): selections match' );
|
|
|
|
surface.destroy();
|
|
}
|
|
|
|
QUnit.test( 'decrease', 2, function ( assert ) {
|
|
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 );
|
|
}
|
|
} );
|