From 79bb8a359e8f95d85bf59a198837f3e4c0c39ef9 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 24 Feb 2012 23:13:24 +0000 Subject: [PATCH] [JSTesting] Add more mw.loader tests * Follows-up r12279, r112281 * Follows-up r110988: Adds test for @import (currently failing: bug 34669) * Adding StyleTest.css.php for making this easier and re-usable --- .../resources/mediawiki/mediawiki.test.js | 63 +++++++++++++++++-- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index 704b0e1452..b4134f7554 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -148,7 +148,7 @@ test( 'mw.loader', function() { var isAwesomeDone; - // Asynchronous ahead + // Async ahead stop(); mw.loader.testCallback = function () { @@ -157,23 +157,74 @@ test( 'mw.loader', function() { isAwesomeDone = true; }; - mw.loader.implement( 'is.awesome', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' )], {}, {} ); + mw.loader.implement( 'test.callback', [QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/callMwLoaderTestCallback.js' )], {}, {} ); - mw.loader.using( 'is.awesome', function () { + mw.loader.using( 'test.callback', function () { // /sample/awesome.js declares the "mw.loader.testCallback" function // which contains a call to start() and ok() - strictEqual(isAwesomeDone, true, "is.awesome module should've caused isAwesomeDone to be true") + strictEqual( isAwesomeDone, true, "test.callback module should've caused isAwesomeDone to be true" ); delete mw.loader.testCallback; }, function () { start(); - ok( false, 'Error callback fired while loader.using "is.awesome" module' ); + ok( false, 'Error callback fired while loader.using "test.callback" module' ); }); +}); + +test( 'mw.loader.implement', function () { + expect(5 - 2); + + var isJsExecuted, $element; + + // Async ahead + stop(); + + mw.loader.implement( + 'test.implement', + function () { + start(); + + strictEqual( isJsExecuted, undefined, 'javascript not executed multiple times' ); + isJsExecuted = true; + + equal( mw.loader.getState( 'test.implement' ), 'loaded', 'module state is "loaded" while implement() is executing javascript' ); + + $element = $( '
Foo bar
' ); + $element.appendTo( 'body' ); + + // @broken: equal( $element.css( 'text-align' ),'center', 'CSS stylesheet was applied in time. ("text-align: center")' ); + + // Marked broken due to a bug in qunit/index.html, via Special:JavaScriptTest/qunit it works fine + + // CSS @import is easily broken when concatenating stylesheets (bug 34669) + // @broken: equal( $element.css( 'float' ), 'right', 'CSS stylesheet was applied in time via @import (bug 34669). ("float: right")' ); + + equal( mw.msg( 'test-foobar' ), 'Hello Foobar, $1!', 'Messages are loaded in time' ); + + }, + { + "all": "@import url('" + + QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + + '/tests/qunit/data/styleTest.css.php?' + + $.param({ + selector: '.mw-test-loaderimplement', + prop: 'float', + val: 'right' + }) ) + + "');\n" + + '.mw-test-loaderimplement { text-align: center; }' + }, + { + "test-foobar": "Hello Foobar, $1!" + } + ); + + mw.loader.load( 'test.implement' ); }); -test( 'mw.loader.bug29107' , function() { +test( 'mw.loader bug29107' , function () { expect(2); // Message doesn't exist already -- 2.20.1