Esanders has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/334724 )
Change subject: Create dummy platform and target for tests ...................................................................... Create dummy platform and target for tests Change-Id: I078c244ef524669da477a43f9b37c847252e5ad7 --- M build/modules.json M tests/index.html D tests/init/ve.init.Platform.test.js M tests/init/ve.init.sa.Platform.test.js M tests/ve.test.utils.js 5 files changed, 87 insertions(+), 80 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/24/334724/1 diff --git a/build/modules.json b/build/modules.json index 3f1f64c..28c7629 100644 --- a/build/modules.json +++ b/build/modules.json @@ -693,7 +693,6 @@ "tests/ce/ve.ce.LeafNode.test.js", "tests/ce/nodes/ve.ce.TextNode.test.js", "tests/ce/nodes/ve.ce.TableNode.test.js", - "tests/init/ve.init.Platform.test.js", "tests/init/ve.init.sa.Platform.test.js", "tests/ui/ve.ui.DataTransferHandlerFactory.test.js", "tests/ui/ve.ui.Trigger.test.js", diff --git a/tests/index.html b/tests/index.html index bed485d..28f7b36 100644 --- a/tests/index.html +++ b/tests/index.html @@ -494,7 +494,6 @@ <script src="../tests/ce/ve.ce.LeafNode.test.js"></script> <script src="../tests/ce/nodes/ve.ce.TextNode.test.js"></script> <script src="../tests/ce/nodes/ve.ce.TableNode.test.js"></script> - <script src="../tests/init/ve.init.Platform.test.js"></script> <script src="../tests/init/ve.init.sa.Platform.test.js"></script> <script src="../tests/ui/ve.ui.DataTransferHandlerFactory.test.js"></script> <script src="../tests/ui/ve.ui.Trigger.test.js"></script> diff --git a/tests/init/ve.init.Platform.test.js b/tests/init/ve.init.Platform.test.js deleted file mode 100644 index 5bdcf36..0000000 --- a/tests/init/ve.init.Platform.test.js +++ /dev/null @@ -1,74 +0,0 @@ -/*! - * VisualEditor initialization tests. - * - * @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org - */ - -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-lorem': 'Lorem <&> Ipsum: $1' - } ); - - assert.strictEqual( - platform.getMessage( 'platformtest-foo' ), - 'Foo & Bar <quux action="followed">by</quux>!', - 'return plain message' - ); - - assert.strictEqual( - platform.getMessage( 'platformtest-lorem', 10 ), - 'Lorem <&> 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( - /^(<)?platformtest-quux(>)?$/.test( platform.getParsedMessage( 'platformtest-quux' ) ), - 'any brackets in fallbacks are HTML-escaped' - ); - - platform.addMessages( { - 'platformtest-foo': 'Foo & Bar <quux action="followed">by</quux>!', - 'platformtest-lorem': 'Lorem <&> Ipsum: $1' - } ); - - platform.addParsedMessages( { - 'platformtest-foo': 'Foo <quux><html></quux>' - } ); - - assert.strictEqual( - platform.getParsedMessage( 'platformtest-foo' ), - 'Foo <quux><html></quux>', - 'prefer value from parsedMessage store' - ); - - assert.strictEqual( - platform.getParsedMessage( 'platformtest-lorem', 10 ), - 'Lorem <&> Ipsum: $1', - 'fall back to html-escaped version of plain message, no $# replacements' - ); - } ); -} ); diff --git a/tests/init/ve.init.sa.Platform.test.js b/tests/init/ve.init.sa.Platform.test.js index ae8f87e..ec78099 100644 --- a/tests/init/ve.init.sa.Platform.test.js +++ b/tests/init/ve.init.sa.Platform.test.js @@ -62,3 +62,70 @@ 'multiple values persist' ); } ); + +QUnit.asyncTest( 'messages', 4, function ( assert ) { + var platform = new ve.init.sa.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-lorem': 'Lorem <&> Ipsum: $1' + } ); + + assert.strictEqual( + platform.getMessage( 'platformtest-foo' ), + 'Foo & Bar <quux action="followed">by</quux>!', + 'return plain message' + ); + + assert.strictEqual( + platform.getMessage( 'platformtest-lorem', 10 ), + 'Lorem <&> 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 = new ve.init.sa.Platform(); + + platform.getInitializedPromise().done( function () { + QUnit.start(); + assert.ok( + /^(<)?platformtest-quux(>)?$/.test( platform.getParsedMessage( 'platformtest-quux' ) ), + 'any brackets in fallbacks are HTML-escaped' + ); + + platform.addMessages( { + 'platformtest-foo': 'Foo & Bar <quux action="followed">by</quux>!', + 'platformtest-lorem': 'Lorem <&> Ipsum: $1' + } ); + + platform.addParsedMessages( { + 'platformtest-foo': 'Foo <quux><html></quux>' + } ); + + assert.strictEqual( + platform.getParsedMessage( 'platformtest-foo' ), + 'Foo <quux><html></quux>', + 'prefer value from parsedMessage store' + ); + + assert.strictEqual( + platform.getParsedMessage( 'platformtest-lorem', 10 ), + 'Lorem <&> Ipsum: $1', + 'fall back to html-escaped version of plain message, no $# replacements' + ); + } ); +} ); diff --git a/tests/ve.test.utils.js b/tests/ve.test.utils.js index 8370f07..c44713f 100644 --- a/tests/ve.test.utils.js +++ b/tests/ve.test.utils.js @@ -5,10 +5,26 @@ */ ( function () { - // Create a standalone platform and target so ve.init.platform/target are available + // Create a dummy platform and target so ve.init.platform/target are available + function DummyPlatform() { + DummyPlatform.super.apply( this, arguments ); + } + OO.inheritClass( DummyPlatform, ve.init.Platform ); + DummyPlatform.prototype.getUserLanguages = function () { return [ 'en' ]; }; + DummyPlatform.prototype.getMessage = function ( msg ) { return msg; }; + DummyPlatform.prototype.getLanguageName = function () { return 'English'; }; + DummyPlatform.prototype.getLanguageDirection = function () { return 'ltr'; }; + DummyPlatform.prototype.getExternalLinkUrlProtocolsRegExp = function () { return /^https?\:\/\//i; }; + DummyPlatform.prototype.getUnanchoredExternalLinkUrlProtocolsRegExp = function () { return /https?\:\/\//i; }; + + function DummyTarget() { + DummyTarget.super.apply( this, arguments ); + } + OO.inheritClass( DummyTarget, ve.init.Target ); + /* eslint-disable no-new */ - new ve.init.sa.Platform(); - new ve.init.sa.Target(); + new DummyPlatform(); + new DummyTarget(); /* eslint-enable no-new */ // Disable scroll animatinos @@ -294,7 +310,7 @@ return {}; }, getImportRules: function () { - return ve.init.sa.Target.static.importRules; + return ve.init.Target.static.importRules; }, getModel: function () { return model; -- To view, visit https://gerrit.wikimedia.org/r/334724 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I078c244ef524669da477a43f9b37c847252e5ad7 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits