mediawiki-extensions-Visual.../modules/ve/test/init/ve.init.Platform.test.js
Roan Kattouw 94879a98b7 Use jquery.i18n for standalone i18n
VisualEditor.php:
* Make jquery.i18n a dependency of ext.visualEditor.standalone

makeStaticLoader.php:
* Remove ve.init.platform.addMessages() call with PHP-generated messages
* Add fake module for jquery.i18n
** Needed because the module might come from MW core
** Also add special treatment for fallbacks.js and language scripts

ve.init.sa.Platform.js:
* Remove basic message system, replace with jquery.i18n
* Add initialize method that loads messages for current language and
  fallbacks

ve.init.sa.Target.js:
* Wait for the platform to initialize before actually doing things
* Add .setup() method to allow callers to short-circuit this process
** This is convenient for callers of ve.init.sa.Target in the test suite

ve.ce.test.js:
* Use existing ve.test.utils function for creating a surface

ve.test.utils.js:
* Call .setup() on the target so we can get a surface synchronously

ve.init.Platform.test.js:
* Make these tests async, wait for the platform to initialize
* Allow for missing messages to be output either as <foo> (MW)
  or foo (jquery.i18n)
* Get rid of message clearing code, namespace test messages instead

Change-Id: Iac7dfd327eadf9b503a61510574d35d748faac92
2013-12-17 21:16:26 +01:00

76 lines
2.1 KiB
JavaScript

/*!
* VisualEditor initialization tests.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.init.Platform' );
QUnit.asyncTest( 'messages', 4, function ( assert ) {
var platform = ve.init.platform;
platform.getInitializedPromise().done( function () {
QUnit.start();
assert.ok(
/^<?platformtest-foo\>?$/.test( platform.getMessage( 'platformtest-foo' ) ),
'return plain key as fallback, possibly wrapped in brackets'
);
platform.addMessages( {
'platformtest-foo': 'Foo & Bar <quux action="followed">by</quux>!',
'platformtest-bacon': 'Bacon <&> Ipsum: $1'
} );
assert.strictEqual(
platform.getMessage( 'platformtest-foo' ),
'Foo & Bar <quux action="followed">by</quux>!',
'return plain message'
);
assert.strictEqual(
platform.getMessage( 'platformtest-bacon', 10 ),
'Bacon <&> Ipsum: 10',
'return plain message with $# replacements'
);
assert.ok(
/^<?platformtest-quux\>?$/.test( platform.getMessage( 'platformtest-quux' ) ),
'return plain key as fallback, possibly wrapped in brackets (after set up)'
);
} );
} );
QUnit.asyncTest( 'parsedMessage', 3, function ( assert ) {
var platform = ve.init.platform;
platform.getInitializedPromise().done( function () {
QUnit.start();
assert.ok(
/^(&lt;)?platformtest-quux(&gt;)?$/.test( platform.getMessage( 'platformtest-quux' ) ),
'any brackets in fallbacks are HTML-escaped'
);
platform.addMessages( {
'platformtest-foo': 'Foo & Bar <quux action="followed">by</quux>!',
'platformtest-bacon': 'Bacon <&> Ipsum: $1'
} );
platform.addParsedMessages( {
'platformtest-foo': 'Foo <quux>&lt;html&gt;</quux>'
} );
assert.strictEqual(
platform.getParsedMessage( 'platformtest-foo' ),
'Foo <quux>&lt;html&gt;</quux>',
'prefer value from parsedMessage store'
);
assert.strictEqual(
platform.getParsedMessage( 'platformtest-bacon', 10 ),
'Bacon &lt;&amp;&gt; Ipsum: $1',
'fall back to html-escaped version of plain message, no $# replacements'
);
} );
} );