mediawiki-extensions-Visual.../modules/ve/test/actions/ve.IndentationAction.test.js
Ed Sanders 9a7b8aacf8 Only unwrap { generated: wrapper } based on context.
Wrapper paragraphs should only be unwrapped if they are the first
element in their parent - or if there is a block level element separating
them from the previous unwrapped paragraph.

Empty paragraphs should only be unwrapped if they are empty and the
last element in their parent.

Also in this commit is a simple test for IndentationAction.decrease().

Bug: 45590
Change-Id: I1f47d12db6d57d984fd4607f667a3b62c53f3dd6
2013-03-13 00:42:16 +00:00

39 lines
1.5 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 runIndentationTest( assert, range, method, expectedSelection, expectedData, label ) {
var dom = ve.createDocumentFromHTML( ve.dm.example.isolationHTML ),
surface = new ve.Surface( $('<div>'), dom ),
indentationAction = new ve.IndentationAction( surface ),
data = ve.copyArray( surface.getModel().getDocument().getFullData() );
surface.getModel().change( null, range );
indentationAction[method]();
expectedData( data );
assert.deepEqual( surface.getModel().getDocument().getFullData(), data, label + ': data models match' );
assert.deepEqual( surface.getModel().getSelection(), expectedSelection, label + ': selections match' );
surface.destroy();
}
QUnit.test( 'decrease', 2, function ( assert ) {
var rebuilt = { 'changed': { 'rebuilt': 1 } },
createdAndRebuilt = { 'changed': { 'created': 2, 'rebuilt': 1 } };
runIndentationTest( assert, new ve.Range( 14, 16 ), 'decrease', new ve.Range( 14, 16 ), 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 } );
}, 'decrease indentation on partial selection of list item "Item 2"' );
} );