|
| 1 | +( function() { |
| 2 | + |
| 3 | +var eventSequence, |
| 4 | + eventsList = [ |
| 5 | + |
| 6 | + // Deprecated as of 1.4.x |
| 7 | + "pagebeforechange", |
| 8 | + "pagebeforeload", |
| 9 | + "pageload", |
| 10 | + "pagebeforehide", |
| 11 | + "pagebeforeshow", |
| 12 | + "pagehide", |
| 13 | + "pageshow", |
| 14 | + "pagechange", |
| 15 | + |
| 16 | + // Valid as of 1.4.x |
| 17 | + "pagecontainerbeforechange", |
| 18 | + "pagecontainerbeforeload", |
| 19 | + "pagecontainerload", |
| 20 | + "pagebeforecreate", |
| 21 | + "pagecreate", |
| 22 | + "pageinit", |
| 23 | + "pagecontainerbeforetransition", |
| 24 | + "pagecontainerbeforehide", |
| 25 | + "pagecontainerbeforeshow", |
| 26 | + "pagecontainerhide", |
| 27 | + "pagecontainershow", |
| 28 | + "pagecontainertransition", |
| 29 | + "pagecontainerchange" |
| 30 | + ].join( " " ), |
| 31 | + dataItem = function( item ) { |
| 32 | + return ( item ? |
| 33 | + ( item.jquery ? |
| 34 | + item.attr( "id" ) : |
| 35 | + $.type( item ) === "string" ? |
| 36 | + item : |
| 37 | + "unknown" ) : |
| 38 | + undefined ); |
| 39 | + }, |
| 40 | + recordEvent = function( event, data ) { |
| 41 | + eventSequence.push({ |
| 42 | + type: event.type, |
| 43 | + target: event.target.getAttribute( "id" ), |
| 44 | + data: { |
| 45 | + prevPage: data && dataItem( data.prevPage ), |
| 46 | + nextPage: data && dataItem( data.nextPage ), |
| 47 | + toPage: data && dataItem( data.toPage ) |
| 48 | + } |
| 49 | + }); |
| 50 | + }; |
| 51 | + |
| 52 | +module( "Page event sequence tests", { |
| 53 | + setup: function() { |
| 54 | + eventSequence = []; |
| 55 | + |
| 56 | + $( document ).on( eventsList, recordEvent ); |
| 57 | + }, |
| 58 | + teardown: function() { |
| 59 | + $( document ).off( eventsList, recordEvent ); |
| 60 | + } |
| 61 | +}); |
| 62 | + |
| 63 | +asyncTest( "Event sequence during navigation to another page", function() { |
| 64 | + var parsedUrl = $.mobile.path.parseLocation(), |
| 65 | + otherPageUrl = $.mobile.path.getLocation( $.extend( parsedUrl, { |
| 66 | + filename: "other-page.html", |
| 67 | + pathname: parsedUrl.directory + "other-page.html" |
| 68 | + })), |
| 69 | + expectedEventSequence = [ |
| 70 | + |
| 71 | + // Deprecated as of 1.4.0 |
| 72 | + { type: "pagebeforechange", target: "the-body", |
| 73 | + data: { prevPage: "start-page", nextPage: undefined, toPage: otherPageUrl } }, |
| 74 | + |
| 75 | + // Valid |
| 76 | + { type: "pagecontainerbeforechange", target: "the-body", |
| 77 | + data: { prevPage: "start-page", nextPage: undefined, toPage: otherPageUrl } }, |
| 78 | + |
| 79 | + // Deprecated as of 1.4.0 |
| 80 | + { type: "pagebeforeload", target: "the-body", |
| 81 | + data: { prevPage: "start-page", nextPage: undefined, toPage: otherPageUrl } }, |
| 82 | + |
| 83 | + // Valid |
| 84 | + { type: "pagecontainerbeforeload", target: "the-body", |
| 85 | + data: { prevPage: "start-page", nextPage: undefined, toPage: otherPageUrl } }, |
| 86 | + |
| 87 | + // Deprecated as of 1.4.0 |
| 88 | + { type: "pageload", target: "the-body", |
| 89 | + data: { prevPage: undefined, nextPage: undefined, toPage: undefined } }, |
| 90 | + |
| 91 | + // Valid |
| 92 | + { type: "pagecontainerload", target: "the-body", |
| 93 | + data: { prevPage: undefined, nextPage: undefined, toPage: undefined } }, |
| 94 | + |
| 95 | + // Valid - page widget events |
| 96 | + { type: "pagebeforecreate", target: "other-page", |
| 97 | + data: { prevPage: undefined, nextPage: undefined, toPage: undefined } }, |
| 98 | + { type: "pagecreate", target: "other-page", |
| 99 | + data: { prevPage: undefined, nextPage: undefined, toPage: undefined } }, |
| 100 | + { type: "pageinit", target: "other-page", |
| 101 | + data: { prevPage: undefined, nextPage: undefined, toPage: undefined } }, |
| 102 | + |
| 103 | + // Deprecated as of 1.4.0 |
| 104 | + { type: "pagebeforechange", target: "the-body", |
| 105 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 106 | + |
| 107 | + // Valid |
| 108 | + { type: "pagecontainerbeforechange", target: "the-body", |
| 109 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 110 | + |
| 111 | + // Valid |
| 112 | + { type: "pagecontainerbeforetransition", target: "the-body", |
| 113 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 114 | + |
| 115 | + // Deprecated as of 1.4.0 |
| 116 | + { type: "pagebeforehide", target: "start-page", |
| 117 | + data: { prevPage: "start-page", nextPage: "other-page", toPage: "other-page" } }, |
| 118 | + |
| 119 | + // Valid, but nextPage is deprecated as of 1.4.0 |
| 120 | + { type: "pagecontainerbeforehide", target: "the-body", |
| 121 | + data: { prevPage: "start-page", nextPage: "other-page", toPage: "other-page" } }, |
| 122 | + |
| 123 | + // Deprecated as of 1.4.0 |
| 124 | + { type: "pagebeforeshow", target: "other-page", |
| 125 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 126 | + |
| 127 | + // Valid |
| 128 | + { type: "pagecontainerbeforeshow", target: "the-body", |
| 129 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 130 | + |
| 131 | + // Deprecated as of 1.4.0 |
| 132 | + { type: "pagehide", target: "start-page", |
| 133 | + data: { prevPage: "start-page", nextPage: "other-page", toPage: "other-page" } }, |
| 134 | + |
| 135 | + // Valid, but nextPage is deprecated as of 1.4.0 |
| 136 | + { type: "pagecontainerhide", target: "the-body", |
| 137 | + data: { prevPage: "start-page", nextPage: "other-page", toPage: "other-page" } }, |
| 138 | + |
| 139 | + // Deprecated as of 1.4.0 |
| 140 | + { type: "pageshow", target: "other-page", |
| 141 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 142 | + |
| 143 | + // Valid |
| 144 | + { type: "pagecontainershow", target: "the-body", |
| 145 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 146 | + |
| 147 | + // Valid |
| 148 | + { type: "pagecontainertransition", target: "the-body", |
| 149 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 150 | + |
| 151 | + // Deprecated as of 1.4.0 |
| 152 | + { type: "pagechange", target: "the-body", |
| 153 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } }, |
| 154 | + |
| 155 | + // Valid |
| 156 | + { type: "pagecontainerchange", target: "the-body", |
| 157 | + data: { prevPage: "start-page", nextPage: undefined, toPage: "other-page" } } |
| 158 | + ]; |
| 159 | + |
| 160 | + $.testHelper.pageSequence([ |
| 161 | + function() { |
| 162 | + $( "#go-to-other-page" ).click(); |
| 163 | + }, |
| 164 | + function() { |
| 165 | + deepEqual( eventSequence, expectedEventSequence, "Event sequence as expected" ); |
| 166 | + $( ":mobile-pagecontainer" ).pagecontainer( "back" ); |
| 167 | + }, |
| 168 | + function() { |
| 169 | + deepEqual( true, true, "Works" ); |
| 170 | + start(); |
| 171 | + } |
| 172 | + ]); |
| 173 | +}); |
| 174 | + |
| 175 | +})(); |
0 commit comments