mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
db9f941fa6
Objectives: * Rename this.$ to this.$element * Rename this.$$ to this.$ * Get rid of the need to use this.frame.$$ * Rename OO.ui.Element.get$$ to OO.ui.Element.getJQuery Changes: (using Sublime Text regex patterns) * Replace "get$$" with "getJQuery" * Replace "\.(\$)([^\$a-zA-Z])" with ".$element$2" * Replace "\.(\$\$)" with ".$" * Replace "'$$'" with "'$'" * Set this.$ to null in constructor of OO.ui.Window * Set this.$ to this.frame.$ in initialize method of OO.ui.Window * Replace "\.(frame.\$)([^\$a-zA-Z])" with ".\$$2" Bonus: * Use this.$() in a bunch of places where $() was erroneously used Change-Id: If3d870124ab8d10f8223532cda95c2b2b075db94
96 lines
2.8 KiB
JavaScript
96 lines
2.8 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable BranchNode tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ce.BranchNode' );
|
|
|
|
/* Stubs */
|
|
|
|
ve.ce.BranchNodeStub = function VeCeBranchNodeStub( model, $element ) {
|
|
// Parent constructor
|
|
ve.ce.BranchNode.call( this, model, $element );
|
|
};
|
|
|
|
OO.inheritClass( ve.ce.BranchNodeStub, ve.ce.BranchNode );
|
|
|
|
ve.ce.BranchNodeStub.static.name = 'branch-stub';
|
|
|
|
ve.ce.BranchNodeStub.static.canBeSplit = true;
|
|
|
|
ve.ce.BranchNodeStub.prototype.getTagName = function () {
|
|
var style = this.model.getAttribute( 'style' ),
|
|
types = { 'a': 'a', 'b': 'b' };
|
|
|
|
return types[style];
|
|
};
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.BranchNodeStub );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'canBeSplit', 1, function ( assert ) {
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
assert.equal( node.canBeSplit(), true );
|
|
} );
|
|
|
|
QUnit.test( 'canHaveChildren', 1, function ( assert ) {
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
assert.equal( node.canHaveChildren(), true );
|
|
} );
|
|
|
|
QUnit.test( 'canHaveChildrenNotContent', 1, function ( assert ) {
|
|
var node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub() );
|
|
|
|
assert.equal( node.canHaveChildrenNotContent(), true );
|
|
} );
|
|
|
|
QUnit.test( 'updateTagName', 4, function ( assert ) {
|
|
var attributes = { 'style': 'a' },
|
|
node = new ve.ce.BranchNodeStub( new ve.dm.BranchNodeStub( [], {
|
|
'type': 'branch-stub', 'attributes': attributes
|
|
} ) );
|
|
|
|
// Add content to the node
|
|
node.$element.text( 'hello' );
|
|
|
|
// Modify attribute
|
|
attributes.style = 'b';
|
|
node.updateTagName();
|
|
|
|
assert.equal( node.$element.get( 0 ).nodeName.toLowerCase(), 'b', 'DOM element type gets converted' );
|
|
assert.equal( node.$element.hasClass( 've-ce-branchNode' ), true, 'old classes are added to new wrapper' );
|
|
assert.equal( !!node.$element.data( 'view' ), true, 'data added to new wrapper' );
|
|
assert.equal( node.$element.text(), 'hello', 'contents are added to new wrapper' );
|
|
} );
|
|
|
|
QUnit.test( 'onSplice', 7, function ( assert ) {
|
|
var modelA = new ve.dm.BranchNodeStub(),
|
|
modelB = new ve.dm.BranchNodeStub(),
|
|
modelC = new ve.dm.BranchNodeStub(),
|
|
viewA = new ve.ce.BranchNodeStub( modelA );
|
|
|
|
// Insertion tests
|
|
modelA.splice( 0, 0, modelB, modelC );
|
|
|
|
assert.equal( viewA.getChildren().length, 2 );
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
|
assert.deepEqual( viewA.getChildren()[1].getModel(), modelC );
|
|
|
|
// Removal tests
|
|
modelA.splice( 0, 1 );
|
|
|
|
assert.equal( viewA.getChildren().length, 1 );
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelC );
|
|
|
|
// Removal and insertion tests
|
|
modelA.splice( 0, 1, modelB );
|
|
|
|
assert.equal( viewA.getChildren().length, 1 );
|
|
assert.deepEqual( viewA.getChildren()[0].getModel(), modelB );
|
|
} );
|