Fix jquery.client.test breakage
authorKrinkle <krinkle@users.mediawiki.org>
Sat, 28 Jan 2012 16:56:10 +0000 (16:56 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sat, 28 Jan 2012 16:56:10 +0000 (16:56 +0000)
* Remove both classes before adding one. Previously test ran normally on an "ltr" page because the loop starts with "ltr" and they matches naturally. It broke on pages that started out with "rtl". Fixed now
* Restored body classes after the test, otherwise both "rtl" and "ltr" would be gone, could influence other tests and layout stuff on the page.

* Follows-up r101845

tests/qunit/suites/resources/jquery/jquery.client.test.js

index f6eb700..7be4197 100644 (file)
@@ -285,19 +285,25 @@ test( 'test', function() {
 test( 'User-agent matches against WikiEditor\'s compatibility map', function() {
        expect( uacount * 2 ); // double since we test both LTR and RTL
 
+       var     $body = $( 'body' ),
+               bodyClasses = $body.attr( 'class' );
+
        // Loop through and run tests
-       $.each( uas, function( agent, data ) {
-               $.each( ['ltr', 'rtl'], function( i, dir ) {
-                       $('body').addClass(dir);
+       $.each( uas, function ( agent, data ) {
+               $.each( ['ltr', 'rtl'], function ( i, dir ) {
+                       $body.removeClass( 'ltr rtl' ).addClass( dir );
                        var profile = $.client.profile( {
                                userAgent: agent,
                                platform: data.platform
                        } );
                        var testMatch = $.client.test( testMap, profile );
-                       $('body').removeClass(dir);
+                       $body.removeClass( dir );
 
                        equal( testMatch, data.wikiEditor[dir], 'testing comparison based on ' + dir + ', ' + agent );
                });
        });
+
+       // Restore body classes
+       $body.attr( 'class', bodyClasses );
 });