r113720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113719‎ | r113720 | r113721 >
Date:13:49, 13 March 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/js/fixtures.js (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/js/test_toggle.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/tests/js/fixtures.js
@@ -1,4 +1,12 @@
2 -var showText = "show", hideText = "hide";
 2+var mwMobileFrontendConfig = {
 3+ messages: {
 4+ showText: "show",
 5+ hideText: "hide"
 6+ },
 7+ settings: {
 8+ scriptPath: "/"
 9+ }
 10+};
311
412 window.MobileFrontendTests = {
513 cleanFixtures: function() {
Index: trunk/extensions/MobileFrontend/tests/js/test_toggle.js
@@ -1,3 +1,10 @@
 2+function applyCss() {
 3+ $(".hide").show();
 4+ $(".show").hide();
 5+ $(".openSection .hide").hide();
 6+ $(".openSection .show").show();
 7+}
 8+
29 module("MobileFrontend toggle.js: wm_toggle_section", {
310 setup: function() {
411 MFET.createFixtures();
@@ -2,4 +9,4 @@
310 MFE.toggle.init();
 11+ $("#section_1").addClass("openSection");
412 $("#content_1,#anchor_1,#section_1 .hide").hide();
5 - $("#section_1 .show").show();
613 },
@@ -12,14 +19,18 @@
1320 });
1421
1522 test("wm_toggle_section", function() {
 23+ strictEqual($("#section_1").hasClass("openSection"), true, "openSection class present");
1624 MFE.toggle.wm_toggle_section("1");
 25+ applyCss();
1726 strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle");
1827 strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle");
 28+ strictEqual($("#section_1").hasClass("openSection"), false, "openSection class removed");
1929 strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible");
2030 strictEqual($("#section_1 .show").is(":visible"), false, "check show button now hidden");
2131
2232 // perform second toggle
2333 MFE.toggle.wm_toggle_section("1");
 34+ applyCss();
2435 strictEqual($("#content_1").is(":visible"), false, "check content is hidden on a toggle");
2536 strictEqual($("#anchor_1").is(":visible"), false, "check anchor is hidden on toggle");
2637 strictEqual($("#section_1 .hide").is(":visible"), false, "check hide button now hidden");
@@ -28,6 +39,7 @@
2940
3041 test("wm_reveal_for_hash", function() {
3142 MFE.toggle.wm_reveal_for_hash("#First_Section");
 43+ applyCss();
3244 strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle");
3345 strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle");
3446 strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible");
@@ -36,6 +48,7 @@
3749
3850 test("wm_reveal_for_hash", function() {
3951 MFE.toggle.wm_reveal_for_hash("#First_Section_2");
 52+ applyCss();
4053 strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle");
4154 strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle");
4255 strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible");
@@ -44,6 +57,7 @@
4558
4659 test("clicking hash links", function() {
4760 MFET.triggerEvent($("[href=#First_Section_2]")[0], "click");
 61+ applyCss();
4862 strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle");
4963 strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle");
5064 strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible");
@@ -53,6 +67,7 @@
5468 test("clicking a heading toggles it", function() {
5569 var visibilityStart = $("#content_1").is(":visible");
5670 MFET.triggerEvent($("#section_1")[0], "click");
 71+ applyCss();
5772 strictEqual(visibilityStart, false, "check content is hidden at start");
5873 strictEqual($("#content_1").is(":visible"), true, "check content is hidden on a toggle");
5974 });
Index: trunk/extensions/MobileFrontend/javascripts/toggle.js
@@ -58,8 +58,8 @@
5959 p, section_idx;
6060 if ( targetel ) {
6161 p = targetel;
62 - while ( p && p.className !== 'content_block' &&
63 - p.className !== 'section_heading' ) {
 62+ while ( p && !u(p).hasClass( 'content_block' ) &&
 63+ !u(p).hasClass( 'section_heading' ) ) {
6464 p = p.parentNode;
6565 }
6666 if ( p && p.style.display !== 'block' ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r114201MFT r113486, r113488, r113512, r113553, r113640, r113642, r113644, r113645, r...awjrichards22:18, 19 March 2012

Status & tagging log