https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113720

Revision: 113720
Author:   jdlrobson
Date:     2012-03-13 13:49:19 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
fix broken toggling tests

introduce fixture for the config variable
className is not sufficient use hasClass instead

Modified Paths:
--------------
    trunk/extensions/MobileFrontend/javascripts/toggle.js
    trunk/extensions/MobileFrontend/tests/js/fixtures.js
    trunk/extensions/MobileFrontend/tests/js/test_toggle.js

Modified: trunk/extensions/MobileFrontend/javascripts/toggle.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/toggle.js       2012-03-13 
13:48:49 UTC (rev 113719)
+++ trunk/extensions/MobileFrontend/javascripts/toggle.js       2012-03-13 
13:49:19 UTC (rev 113720)
@@ -58,8 +58,8 @@
                        p, section_idx;
                if ( targetel ) {
                        p = targetel;
-                       while ( p && p.className !== 'content_block' &&
-                               p.className !== 'section_heading' ) {
+                       while ( p && !u(p).hasClass( 'content_block' ) &&
+                               !u(p).hasClass( 'section_heading' ) ) {
                                p = p.parentNode;
                        }
                        if ( p && p.style.display !== 'block' ) {

Modified: trunk/extensions/MobileFrontend/tests/js/fixtures.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/fixtures.js        2012-03-13 
13:48:49 UTC (rev 113719)
+++ trunk/extensions/MobileFrontend/tests/js/fixtures.js        2012-03-13 
13:49:19 UTC (rev 113720)
@@ -1,4 +1,12 @@
-var showText = "show", hideText = "hide";
+var mwMobileFrontendConfig = {
+       messages: {
+               showText: "show",
+               hideText: "hide"
+       },
+       settings: {
+               scriptPath: "/"
+       }
+};
 
 window.MobileFrontendTests = {
        cleanFixtures: function() {

Modified: trunk/extensions/MobileFrontend/tests/js/test_toggle.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/test_toggle.js     2012-03-13 
13:48:49 UTC (rev 113719)
+++ trunk/extensions/MobileFrontend/tests/js/test_toggle.js     2012-03-13 
13:49:19 UTC (rev 113720)
@@ -1,3 +1,10 @@
+function applyCss() {
+       $(".hide").show();
+       $(".show").hide();
+       $(".openSection .hide").hide();
+       $(".openSection .show").show();
+}
+
 module("MobileFrontend toggle.js: wm_toggle_section", {
        setup: function() {
                MFET.createFixtures();
@@ -2,4 +9,4 @@
                MFE.toggle.init();
+               $("#section_1").addClass("openSection");
                $("#content_1,#anchor_1,#section_1 .hide").hide();
-               $("#section_1 .show").show();
        },
@@ -12,14 +19,18 @@
 });
 
 test("wm_toggle_section", function() {
+       strictEqual($("#section_1").hasClass("openSection"), true, "openSection 
class present");
        MFE.toggle.wm_toggle_section("1");
+       applyCss();
        strictEqual($("#content_1").is(":visible"), true, "check content is 
visible on a toggle");
        strictEqual($("#anchor_1").is(":visible"), true, "check anchor is 
visible on toggle");
+       strictEqual($("#section_1").hasClass("openSection"), false, 
"openSection class removed");
        strictEqual($("#section_1 .hide").is(":visible"), true, "check hide 
button now visible");
        strictEqual($("#section_1 .show").is(":visible"), false, "check show 
button now hidden");
        
        // perform second toggle
        MFE.toggle.wm_toggle_section("1");
+       applyCss();
        strictEqual($("#content_1").is(":visible"), false, "check content is 
hidden on a toggle");
        strictEqual($("#anchor_1").is(":visible"), false, "check anchor is 
hidden on toggle");
        strictEqual($("#section_1 .hide").is(":visible"), false, "check hide 
button now hidden");
@@ -28,6 +39,7 @@
 
 test("wm_reveal_for_hash", function() {
        MFE.toggle.wm_reveal_for_hash("#First_Section");
+       applyCss();
        strictEqual($("#content_1").is(":visible"), true, "check content is 
visible on a toggle");
        strictEqual($("#anchor_1").is(":visible"), true, "check anchor is 
visible on toggle");
        strictEqual($("#section_1 .hide").is(":visible"), true, "check hide 
button now visible");
@@ -36,6 +48,7 @@
 
 test("wm_reveal_for_hash", function() {
        MFE.toggle.wm_reveal_for_hash("#First_Section_2");
+       applyCss();
        strictEqual($("#content_1").is(":visible"), true, "check content is 
visible on a toggle");
        strictEqual($("#anchor_1").is(":visible"), true, "check anchor is 
visible on toggle");
        strictEqual($("#section_1 .hide").is(":visible"), true, "check hide 
button now visible");
@@ -44,6 +57,7 @@
 
 test("clicking hash links", function() {
        MFET.triggerEvent($("[href=#First_Section_2]")[0], "click");
+       applyCss();
        strictEqual($("#content_1").is(":visible"), true, "check content is 
visible on a toggle");
        strictEqual($("#anchor_1").is(":visible"), true, "check anchor is 
visible on toggle");
        strictEqual($("#section_1 .hide").is(":visible"), true, "check hide 
button now visible");
@@ -53,6 +67,7 @@
 test("clicking a heading toggles it", function() {
        var visibilityStart = $("#content_1").is(":visible");
        MFET.triggerEvent($("#section_1")[0], "click");
+       applyCss();
        strictEqual(visibilityStart, false, "check content is hidden at start");
        strictEqual($("#content_1").is(":visible"), true, "check content is 
hidden on a toggle");
 });


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to