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

Commit 7aef437

Browse files
author
Gabriel Schulhof
committed
Pagecontainer: Test page event sequence when doing simple navigation
1 parent 60d4a21 commit 7aef437

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<div data-nstest-role="page" id="other-page">
7+
<div data-role="header"><h1>Other Page</h1></div>
8+
<div class="ui-content"><p>This is the other page.</p></div>
9+
</div>
10+
</body>
11+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Pagecontainer Event Sequence Test Suite</title>
7+
8+
<script src="../../../external/requirejs/require.js"></script>
9+
<script src="../../../js/requirejs.config.js"></script>
10+
<script src="../../../js/jquery.tag.inserter.js"></script>
11+
<script src="../../jquery.setNameSpace.js"></script>
12+
<script src="../../../tests/jquery.testHelper.js"></script>
13+
14+
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
15+
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
16+
<link rel="stylesheet" href="../../jqm-tests.css"/>
17+
<script src="../../../external/qunit/qunit.js"></script>
18+
<script>
19+
$.testHelper.asyncLoad([
20+
[ "jquery.mobile.init" ],
21+
[
22+
"page_event_sequence_core.js"
23+
]
24+
]);
25+
</script>
26+
27+
<script src="../../swarminject.js"></script>
28+
</head>
29+
<body id="the-body">
30+
<div id="qunit"></div>
31+
32+
<div data-nstest-role="page" id="start-page">
33+
<div data-role="header"><h1>Start page</h1></div>
34+
<div class="ui-content">
35+
<a href="other-page.html" id="go-to-other-page">Go to other page</a>
36+
</div>
37+
</div>
38+
</body>
39+
</html>
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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

Comments
 (0)