mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
|
/**
|
||
|
* VisualEditor initialization tests.
|
||
|
*
|
||
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
||
|
* @license The MIT License (MIT); see LICENSE.txt
|
||
|
*/
|
||
|
|
||
|
QUnit.module( 've.init.Platform', {
|
||
|
setup: function () {
|
||
|
this.platform = ve.init.platform;
|
||
|
|
||
|
// Clone and deference instance
|
||
|
ve.init.platform = ve.cloneObject( ve.init.platform );
|
||
|
|
||
|
// Reset internal properties needed to keep tests atomic
|
||
|
ve.init.platform.parsedMessages = {};
|
||
|
|
||
|
// Platform specific properties
|
||
|
// TODO: Perhaps this warrants a clearMessages() method?
|
||
|
if ( ve.init.sa && ve.init.platform instanceof ve.init.sa.Platform ) {
|
||
|
ve.init.platform.messages = {};
|
||
|
} else if ( ve.init.mw && ve.init.platform instanceof ve.init.mw.Platform ) {
|
||
|
/*global mw */
|
||
|
this.mwMessagesValues = ve.copyObject( mw.messages.values );
|
||
|
}
|
||
|
},
|
||
|
teardown: function () {
|
||
|
ve.init.platform = this.platform;
|
||
|
if ( ve.init.mw && ve.init.platform instanceof ve.init.mw.Platform ) {
|
||
|
/*global mw */
|
||
|
mw.messages.values = this.mwMessagesValues;
|
||
|
}
|
||
|
}
|
||
|
} );
|
||
|
|
||
|
QUnit.test( 'messages', 4, function ( assert ) {
|
||
|
var platform = ve.init.platform;
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getMessage( 'foo' ),
|
||
|
'<foo>',
|
||
|
'return bracket-wrapped key as fallback'
|
||
|
);
|
||
|
|
||
|
platform.addMessages( {
|
||
|
foo: 'Foo & Bar <quux action="followed">by</quux>!',
|
||
|
bacon: 'Bacon <&> Ipsum: $1'
|
||
|
} );
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getMessage( 'foo' ),
|
||
|
'Foo & Bar <quux action="followed">by</quux>!',
|
||
|
'return plain message'
|
||
|
);
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getMessage( 'bacon', 10 ),
|
||
|
'Bacon <&> Ipsum: 10',
|
||
|
'return plain message with $# replacements'
|
||
|
);
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getMessage( 'quux' ),
|
||
|
'<quux>',
|
||
|
'return bracket-wrapped key as fallback (after set up)'
|
||
|
);
|
||
|
} );
|
||
|
|
||
|
QUnit.test( 'parsedMessage', 3, function ( assert ) {
|
||
|
var platform = ve.init.platform;
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getParsedMessage( 'foo' ),
|
||
|
'<foo>',
|
||
|
'return html escaped brackets in wrapped-key fallback'
|
||
|
);
|
||
|
|
||
|
platform.addMessages( {
|
||
|
foo: 'Foo & Bar <quux action="followed">by</quux>!',
|
||
|
bacon: 'Bacon <&> Ipsum: $1'
|
||
|
} );
|
||
|
|
||
|
platform.addParsedMessages( {
|
||
|
foo: 'Foo <quux><html></quux>'
|
||
|
} );
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getParsedMessage( 'foo' ),
|
||
|
'Foo <quux><html></quux>',
|
||
|
'prefer value from parsedMessage store'
|
||
|
);
|
||
|
|
||
|
assert.strictEqual(
|
||
|
platform.getParsedMessage( 'bacon', 10 ),
|
||
|
'Bacon <&> Ipsum: $1',
|
||
|
'fall back to html-escaped version of plain message, no $# replacements'
|
||
|
);
|
||
|
} );
|