Permalink
Browse files

[popup unit tests] Sequence for page -> popup -> dialog -> popup (Re: #…

  • Loading branch information...
1 parent 83947c0 commit 147ec4f914cfafe8c7926e02d018c435fa93c9c4 @gabrielschulhof gabrielschulhof committed with Aug 8, 2012
Showing with 73 additions and 1 deletion.
  1. +4 −0 tests/unit/popup/index.html
  2. +69 −1 tests/unit/popup/popup_core.js
@@ -18,6 +18,7 @@
$.testHelper.asyncLoad([
[
"widgets/popup",
+ "widgets/dialog"
],
[ "jquery.mobile.init" ],
[
@@ -49,6 +50,9 @@ <h2 id="qunit-userAgent"></h2>
<div data-nstest-role="popup" id="tolerance-test">
<p>Tolerance test popup</p>
</div>
+ <div data-nstest-role="popup" id="popup-sequence-test">
+ <a id="popup-sequence-test-open-dialog" href="popup-sequence-test-dialog.html">Dialog</a>
+ </div>
</div>
</div>
</body>
@@ -395,9 +395,77 @@
ok( identical, "Going back returns $.mobile.urlHistory to its initial value" );
ok( $.mobile.urlHistory.activeIndex === $.mobile.urlHistory.stack.length - 3, "Going back leaves exactly two entries ahead in $.mobile.urlHistory" );
- setTimeout( function() { start(); }, 300 );
+ setTimeout( function() { start(); }, 500 );
+ },
+ ]);
+ });
+
+ asyncTest( "Sequence page -> popup -> dialog -> popup works", function() {
+ var originallyActivePage = $.mobile.activePage[ 0 ];
+
+ expect( 13 );
+ $.testHelper.detailedEventCascade([
+ function() {
+ $( "#popup-sequence-test" ).popup( "open" );
+ },
+
+ {
+ opened: { src: $( "#popup-sequence-test" ), event: "popupafteropen.sequenceTestStep1" },
+ hashchange: { src: $( window ), event: "hashchange.sequenceTestStep1" }
+ },
+
+ function( result ) {
+ ok( !result.opened.timedOut, "Popup has emitted 'popupafteropen'" );
+ ok( !result.hashchange.timedOut, "A 'hashchange' event has occurred" );
+ $( "#popup-sequence-test-open-dialog" ).click();
+ },
+
+ {
+ closed: { src: $( "#popup-sequence-test" ), event: "popupafterclose.sequenceTestStep2" },
+ pagechange: { src: $.mobile.pageContainer, event: "pagechange.sequenceTestStep2" }
+ },
+
+ function( result ) {
+ ok( !result.closed.timedOut, "Popup has emitted 'popupafterclose'" );
+ ok( !result.pagechange.timedOut, "A 'pagechange' event has occurred" );
+ ok( $.mobile.activePage[ 0 ] === $( "#popup-sequence-test-dialog" )[ 0 ], "The dialog is the active page" );
+ $( "a[href='#popup-sequence-test-popup-inside-dialog']" ).click();
},
+ {
+ opened: { src: function() { return $( "#popup-sequence-test-popup-inside-dialog" ); }, event: "popupafteropen.sequenceTestStep3" },
+ hashchange: { src: $( window ), event: "hashchange.sequenceTestStep3" }
+ },
+
+ function( result ) {
+ ok( !result.opened.timedOut, "Popup inside dialog has emitted 'popupafteropen'" );
+ ok( !result.hashchange.timedOut, "Popup inside dialog has caused a 'hashchange'" );
+ window.history.back();
+ },
+
+ {
+ close: { src: function() { return $( "#popup-sequence-test-popup-inside-dialog" ); }, event: "popupafterclose.sequenceTestStep4" },
+ hashchange: { src: $( window ), event: "hashchange.sequenceTestStep4" }
+ },
+
+ function( result ) {
+ ok( !result.close.timedOut, "Popup inside dialog has emitted 'popupafterclose'" );
+ ok( !result.hashchange.timedOut, "The closing of the inside popup has resulted in a 'hashchange'" );
+ ok( $.mobile.activePage[ 0 ] === $( "#popup-sequence-test-dialog" )[ 0 ], "The dialog is once more the active page" );
+ window.history.back();
+ },
+
+ {
+ pagechange: { src: $.mobile.pageContainer, event: "pagechange.sequenceTestStep5" },
+ hashchange: { src: $( window ), event: "hashchange.sequenceTestStep5" }
+ },
+
+ function( result ) {
+ ok( !result.pagechange.timedOut, "Going back from the dialog has resulted in a 'pagechange'" );
+ ok( !result.hashchange.timedOut, "Going back from the dialog has resulted in a 'hashchange'" );
+ ok( originallyActivePage === $.mobile.activePage[ 0 ], "After going back from the dialog, the originally active page is active once more" );
+ setTimeout( function() { start(); }, 300 );
+ }
]);
});

0 comments on commit 147ec4f

Please sign in to comment.