mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-26 07:15:32 +00:00
a56e795f58
Objectives: * Split ve.Surface into ve.Editor and ve.ui.Surface * Move actions, triggers and commands to ve.ui * Move toolbar wrapping, floating, shadow and actions functionality to configurable options of ve.ui.Toolbar * Make ve.ce.Surface and ve.ui.Surface inherit ve.Element and use this.$$ for iframe friendliness * Make the toolbar separately initialized so it's possible to have a surface without one, as well as control where the toolbar is Some change notes: VisualEditor.php * Added standalone module for mediawiki integrated unit testing ve.ce.Surface.js * Remove requirement to pass in an attached container to construct object * Inherit ve.Element and use this.$$ instead of $ * Make getSelectionRect iframe friendly * Move most of the initialize stuff to a new initialize method to be called after the surface is attached to the DOM ve.init.mw.ViewPageTarget.js * Merge toolbar functions into setup/teardown methods * Add toolbar manually (since it's not added by the surface anymore) ve.init.sa.Target.js * Update new init procedure for editor, surface and toolbar separately * Move toolbar floating stuff to ve.Toolbar Change-Id: If91a9d6e76a8be8d1b5a2566394765a37d29a8a7
92 lines
3.2 KiB
JavaScript
92 lines
3.2 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Actions IndentationAction tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ui.IndentationAction' );
|
|
|
|
/* Tests */
|
|
|
|
function runIndentationChangeTest( assert, range, method, expectedSelection, expectedData, expectedOriginalData, msg ) {
|
|
var selection,
|
|
dom = ve.createDocumentFromHTML( ve.dm.example.isolationHTML ),
|
|
target = new ve.init.sa.Target( $( '#qunit-fixture' ), dom ),
|
|
surface = target.surface,
|
|
indentationAction = new ve.ui.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( 'increase/decrease', 2, function ( assert ) {
|
|
var i,
|
|
cases = [
|
|
{
|
|
'range': new ve.Range( 14, 16 ),
|
|
'method': 'decrease',
|
|
'expectedSelection': new ve.Range( 14, 16 ),
|
|
'expectedData': function ( data ) {
|
|
data.splice( 11, 2, { 'type': '/list' }, { 'type': 'paragraph' } );
|
|
data.splice( 19, 2, { 'type': '/paragraph' }, { 'type': 'list', 'attributes': { 'style': 'bullet' } } );
|
|
},
|
|
'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"'
|
|
},
|
|
{
|
|
'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'
|
|
},
|
|
{
|
|
'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'
|
|
}
|
|
];
|
|
|
|
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 );
|
|
}
|
|
} );
|