mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
ce60b54d33
This allows us to put other internal data in there in the future. Also passing it through the Node constructor properly now. * ve.dm.Node ** Rename fringeWhitespace property to internal ** Add internal parameter to constructor ** Remove setFringeWhitespace() * Increase the number of parameters passed through by ve.Factory to 3 * Pass through .internal from linmod to nodeFactory in ve.dm.Document * ve.dm.Converter ** Rename .fringeWhitespace to .internal.whitespace and make it an array ** Store a temporary reference to .internal in domElement.veInternal * Add internal to all node constructors except TextNode Tests: * Update for fringeWhitespace->internal rename * Add third parameter to ve.Factory tests * Add .internal to getNodeTreeSummary Change-Id: If20c0bb78fee3efa55f72e51e7fc261283358de7
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
/**
|
|
* VisualEditor Factory tests.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.Factory' );
|
|
|
|
/* Stubs */
|
|
|
|
ve.FactoryObjectStub = function ( a, b, c ) {
|
|
this.a = a;
|
|
this.b = b;
|
|
this.c = c;
|
|
};
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'register', 1, function ( assert ) {
|
|
var factory = new ve.Factory();
|
|
assert.throws(
|
|
function () {
|
|
factory.register( 'factory-object-stub', 'not-a-function' );
|
|
},
|
|
Error,
|
|
'throws an exception when trying to register a non-function value as a constructor'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'create', 2, function ( assert ) {
|
|
var factory = new ve.Factory();
|
|
assert.throws(
|
|
function () {
|
|
factory.create( 'factory-object-stub', 23, 'foo', { 'bar': 'baz' } );
|
|
},
|
|
Error,
|
|
'throws an exception when trying to create a object of an unregistered type'
|
|
);
|
|
factory.register( 'factory-object-stub', ve.FactoryObjectStub );
|
|
assert.deepEqual(
|
|
factory.create( 'factory-object-stub', 16, 'foo', { 'baz': 'quux' } ),
|
|
new ve.FactoryObjectStub( 16, 'foo', { 'baz': 'quux' } ),
|
|
'creates objects of a registered type and passes through arguments'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'lookup', 1, function ( assert ) {
|
|
var factory = new ve.Factory();
|
|
factory.register( 'factory-object-stub', ve.FactoryObjectStub );
|
|
assert.strictEqual( factory.lookup( 'factory-object-stub' ), ve.FactoryObjectStub );
|
|
} );
|