/*!
* 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(
/^?$/.test( platform.getMessage( 'platformtest-foo' ) ),
'return plain key as fallback, possibly wrapped in brackets'
);
platform.addMessages( {
'platformtest-foo': 'Foo & Bar by!',
'platformtest-bacon': 'Bacon <&> Ipsum: $1'
} );
assert.strictEqual(
platform.getMessage( 'platformtest-foo' ),
'Foo & Bar by!',
'return plain message'
);
assert.strictEqual(
platform.getMessage( 'platformtest-bacon', 10 ),
'Bacon <&> Ipsum: 10',
'return plain message with $# replacements'
);
assert.ok(
/^?$/.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(
/^(<)?platformtest-quux(>)?$/.test( platform.getMessage( 'platformtest-quux' ) ),
'any brackets in fallbacks are HTML-escaped'
);
platform.addMessages( {
'platformtest-foo': 'Foo & Bar by!',
'platformtest-bacon': 'Bacon <&> Ipsum: $1'
} );
platform.addParsedMessages( {
'platformtest-foo': 'Foo <html>'
} );
assert.strictEqual(
platform.getParsedMessage( 'platformtest-foo' ),
'Foo <html>',
'prefer value from parsedMessage store'
);
assert.strictEqual(
platform.getParsedMessage( 'platformtest-bacon', 10 ),
'Bacon <&> Ipsum: $1',
'fall back to html-escaped version of plain message, no $# replacements'
);
} );
} );