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 | +}; |
3 | 11 | |
4 | 12 | window.MobileFrontendTests = { |
5 | 13 | 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 | + |
2 | 9 | module("MobileFrontend toggle.js: wm_toggle_section", { |
3 | 10 | setup: function() { |
4 | 11 | MFET.createFixtures(); |
— | — | @@ -2,4 +9,4 @@ |
3 | 10 | MFE.toggle.init(); |
| 11 | + $("#section_1").addClass("openSection"); |
4 | 12 | $("#content_1,#anchor_1,#section_1 .hide").hide(); |
5 | | - $("#section_1 .show").show(); |
6 | 13 | }, |
— | — | @@ -12,14 +19,18 @@ |
13 | 20 | }); |
14 | 21 | |
15 | 22 | test("wm_toggle_section", function() { |
| 23 | + strictEqual($("#section_1").hasClass("openSection"), true, "openSection class present"); |
16 | 24 | MFE.toggle.wm_toggle_section("1"); |
| 25 | + applyCss(); |
17 | 26 | strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle"); |
18 | 27 | strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle"); |
| 28 | + strictEqual($("#section_1").hasClass("openSection"), false, "openSection class removed"); |
19 | 29 | strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible"); |
20 | 30 | strictEqual($("#section_1 .show").is(":visible"), false, "check show button now hidden"); |
21 | 31 | |
22 | 32 | // perform second toggle |
23 | 33 | MFE.toggle.wm_toggle_section("1"); |
| 34 | + applyCss(); |
24 | 35 | strictEqual($("#content_1").is(":visible"), false, "check content is hidden on a toggle"); |
25 | 36 | strictEqual($("#anchor_1").is(":visible"), false, "check anchor is hidden on toggle"); |
26 | 37 | strictEqual($("#section_1 .hide").is(":visible"), false, "check hide button now hidden"); |
— | — | @@ -28,6 +39,7 @@ |
29 | 40 | |
30 | 41 | test("wm_reveal_for_hash", function() { |
31 | 42 | MFE.toggle.wm_reveal_for_hash("#First_Section"); |
| 43 | + applyCss(); |
32 | 44 | strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle"); |
33 | 45 | strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle"); |
34 | 46 | strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible"); |
— | — | @@ -36,6 +48,7 @@ |
37 | 49 | |
38 | 50 | test("wm_reveal_for_hash", function() { |
39 | 51 | MFE.toggle.wm_reveal_for_hash("#First_Section_2"); |
| 52 | + applyCss(); |
40 | 53 | strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle"); |
41 | 54 | strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle"); |
42 | 55 | strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible"); |
— | — | @@ -44,6 +57,7 @@ |
45 | 58 | |
46 | 59 | test("clicking hash links", function() { |
47 | 60 | MFET.triggerEvent($("[href=#First_Section_2]")[0], "click"); |
| 61 | + applyCss(); |
48 | 62 | strictEqual($("#content_1").is(":visible"), true, "check content is visible on a toggle"); |
49 | 63 | strictEqual($("#anchor_1").is(":visible"), true, "check anchor is visible on toggle"); |
50 | 64 | strictEqual($("#section_1 .hide").is(":visible"), true, "check hide button now visible"); |
— | — | @@ -53,6 +67,7 @@ |
54 | 68 | test("clicking a heading toggles it", function() { |
55 | 69 | var visibilityStart = $("#content_1").is(":visible"); |
56 | 70 | MFET.triggerEvent($("#section_1")[0], "click"); |
| 71 | + applyCss(); |
57 | 72 | strictEqual(visibilityStart, false, "check content is hidden at start"); |
58 | 73 | strictEqual($("#content_1").is(":visible"), true, "check content is hidden on a toggle"); |
59 | 74 | }); |
Index: trunk/extensions/MobileFrontend/javascripts/toggle.js |
— | — | @@ -58,8 +58,8 @@ |
59 | 59 | p, section_idx; |
60 | 60 | if ( targetel ) { |
61 | 61 | 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' ) ) { |
64 | 64 | p = p.parentNode; |
65 | 65 | } |
66 | 66 | if ( p && p.style.display !== 'block' ) { |