Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 3d7ef95

Browse files
author
Gabriel Schulhof
committed
Popup unit tests: Add test for checking whether popup goes back two history entries instead of just one.
1 parent 6161878 commit 3d7ef95

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

tests/unit/popup/back-two.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"></meta>
5+
</head>
6+
<body>
7+
<div data-nstest-role="page" id="another-page">
8+
<div data-nstest-role="popup" id="back-twice-test-popup">
9+
<p>Back twice test popup</p>
10+
</div>
11+
<a id="open-back-twice-test-popup" href="#back-twice-test-popup" data-nstest-rel="popup">Pop</a>
12+
</div>
13+
</body>
14+
</html>

tests/unit/popup/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
1515
<link rel="stylesheet" href="../../../external/qunit.css"/>
1616
<script src="../../../external/qunit.js"></script>
17+
<script>
18+
( function( $, undefined ) {
19+
// Set the default transition to "fade" if specified in the query
20+
if ( !!~location.search.indexOf( "setFadeTransition" ) ) {
21+
$( document ).one( "mobileinit", function() {
22+
$.mobile.popup.prototype.options.transition = "fade";
23+
});
24+
}
25+
})( jQuery );
26+
</script>
1727
<script>
1828
$.testHelper.asyncLoad([
1929
[
@@ -33,7 +43,7 @@
3343
<body>
3444
<div id="qunit"></div>
3545

36-
<div data-nstest-role="page">
46+
<div data-nstest-role="page" id="start-page">
3747
<div data-nstest-role="content" id="page-content">
3848
<div data-nstest-role="popup" id="test-popup">
3949
<p>This is the test popup</p>
@@ -66,6 +76,7 @@
6676
<div data-nstest-role="popup" id="test-popup-dismissible" data-nstest-dismissible="false">
6777
<p>This is the test popup</p>
6878
</div>
79+
<a id="go-to-another-page" href="back-two.html">Go</a>
6980
</div>
7081
</div>
7182

tests/unit/popup/popup_core.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,52 @@
7878
ok( $container.children().is( $payload ), "After destroying on-the-fly popup, its payload is returned to its original location" );
7979
});
8080

81+
asyncTest( "Popup does not go back in history twice when opening on separate page", function() {
82+
var eventNs = ".backTwice", popup = function() { return $( "#back-twice-test-popup" ); };
83+
$.testHelper.detailedEventCascade([
84+
function() {
85+
$( "#go-to-another-page" ).click();
86+
},
87+
{
88+
navigate: { src: $( document ), event: "navigate" + eventNs + "1" },
89+
pagechange: { src: $.mobile.pageContainer, event: "pagechange" + eventNs + "1" }
90+
},
91+
function() {
92+
deepEqual( $.mobile.activePage.attr( "id" ), "another-page", "Reached another page" );
93+
$( "#open-back-twice-test-popup" ).click();
94+
},
95+
{
96+
popupafteropen: { src: popup, event: "popupafteropen" + eventNs + "2" },
97+
navigate: { src: $(document), event: "navigate" + eventNs + "2" }
98+
},
99+
function( result ) {
100+
deepEqual( result.popupafteropen.timedOut, false, "popupafteropen event did arrive" );
101+
deepEqual( result.navigate.timedOut, false, "navigate event did arrive" );
102+
$( "#back-twice-test-popup-screen" ).click();
103+
},
104+
{
105+
popupafterclose: { src: popup, event: "popupafterclose" + eventNs + "3" },
106+
navigate: { src: $( document ), event: "navigate" + eventNs + "3" },
107+
pagechange: { src: $( document ), event: "pagechange" + eventNs + "3" }
108+
},
109+
function( result ) {
110+
deepEqual( result.popupafterclose.timedOut, false, "popupafterclose event did arrive" );
111+
deepEqual( result.navigate.timedOut, false, "navigate event did arrived" );
112+
deepEqual( result.pagechange.timedOut, false, "pagechange event did arrive" );
113+
deepEqual( $.mobile.activePage.attr( "id" ), "another-page", "Back to another page" );
114+
$.mobile.back();
115+
},
116+
{
117+
navigate: { src: $( document ), event: "navigate" + eventNs + "4" }
118+
},
119+
function( result ) {
120+
deepEqual( result.navigate.timedOut, false, "navigate event did arrive" );
121+
deepEqual( $.mobile.activePage.attr( "id" ), "start-page", "Back to start page" );
122+
start();
123+
}
124+
]);
125+
});
126+
81127
asyncTest( "Popup opens and closes", function() {
82128
var $popup = $( "#test-popup" );
83129
expect( 9 );

0 commit comments

Comments
 (0)