mediawiki-extensions-Visual.../modules/ve/test/actions/ve.IndentationAction.test.js
Ed Sanders fdf30b1ac8 Store data in LinearData class with an index-value store for objects
Created an IndexValueStore class which can store any object and return
an integer index to its hash map.

Linear data is now stored in ve.dm.LinearData instances. Two subclasses
for element and meta data contain methods specific to those data types
(ElementLinearData and MetaLinearData).

The static methods in ve.dm.Document that inspected data at a given
offset are now instance methods of ve.dm.ElementLinearData.

AnnotationSets (which are no longer OrderedHashSets) have been moved
to /dm and also have to be instantiated with a pointer the store.

Bug: 46320
Change-Id: I249a5d48726093d1cb3e36351893f4bff85f52e2
2013-03-30 10:06:34 +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( new ve.init.Target( $( '<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"' );
} );