This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
dialog_events.js
194 lines (153 loc) · 5.38 KB
/
dialog_events.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Mobile dialog unit tests
*/
define( [
"qunit",
"jquery"
], function( QUnit, $ ) {
var home = $.mobile.path.parseUrl( location.pathname ).directory,
homeWithSearch = home + location.search;
function jqmDataSelector( expression ) {
return "[data-" + $.mobile.ns + expression + "]";
}
QUnit.module( "dialog", {
setup: function() {
$.mobile.page.prototype.options.contentTheme = "d";
$.testHelper.navReset( homeWithSearch );
}
} );
QUnit.asyncTest( "Test option data-close-btn", function( assert ) {
assert.expect( 5 );
$.testHelper.pageSequence( [
function() {
// Bring up the dialog
$( "#close-button-test-link" ).click();
},
function() {
var a = $( "#close-button-test .ui-toolbar-header a" );
assert.strictEqual( a.length, 0,
"Initially, the dialog header has no anchor elements (option value 'none')" );
$( "#close-button-test" ).page( "option", "closeBtn", "left" );
a = $( "#close-button-test .ui-toolbar-header a" );
assert.strictEqual( a.length, 1,
"The dialog header has exactly one anchor when the option value is 'left'" );
assert.hasClasses( a, "ui-toolbar-header-button-left",
"Close button has class ui-toolbar-header-button-left when closeBtn is 'left'" );
$( "#close-button-test" ).page( "option", "closeBtn", "right" );
a = $( "#close-button-test .ui-toolbar-header a" );
assert.strictEqual( a.length, 1,
"The dialog header has eactly one anchor when the option value is 'right'" );
assert.hasClasses( a, "ui-toolbar-header-button-right",
"Close button has class ui-toolbar-header-button-right when closeBtn is 'right'" );
$.mobile.back();
},
function() {
QUnit.start();
}
] );
} );
QUnit.asyncTest( "dialog element with no theming", function( assert ) {
assert.expect( 4 );
$.testHelper.pageSequence( [
function() {
$( ".ui-pagecontainer" ).pagecontainer( "change", $( "#mypage" ) );
},
function() {
// Bring up the dialog
$( "#link-a" ).click();
},
function() {
var dialog = $( "#dialog-a" );
// Assert dialog theme inheritance (issue 1375):
assert.hasClasses( dialog, "ui-page-theme-a",
"Expected explicit theme ui-page-theme-a" );
assert.hasClasses( $( ".ui-pagecontainer" ), "ui-overlay-a",
"Expected default overlay theme ui-overlay-a" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=header" ) ), "ui-bar-inherit",
"Expected header to inherit from dialog" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=footer" ) ), "ui-bar-inherit",
"Expected footer to inherit from dialog" );
QUnit.start();
}
] );
} );
QUnit.asyncTest( "dialog element with data-theme", function( assert ) {
// Reset fallback theme for content
$.mobile.page.prototype.options.contentTheme = null;
assert.expect( 5 );
$.testHelper.pageSequence( [
function() {
$( ".ui-pagecontainer" ).pagecontainer( "change", $( "#mypage" ) );
},
function() {
// Bring up the dialog
$( "#link-b" ).click();
},
function() {
var dialog = $( "#dialog-b" );
// Assert dialog theme inheritance (issue 1375):
assert.hasClasses( dialog, "ui-page-theme-e",
"Expected explicit theme ui-page-theme-e" );
assert.lacksClasses( $( ".ui-pagecontainer" ), "ui-overlay-b",
"Expected no overlay theme ui-overlay-b" );
assert.hasClasses( $( ".ui-pagecontainer" ), "ui-overlay-a",
"Expected default overlay theme ui-overlay-a" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=header" ) ), "ui-bar-inherit",
"Expected header to inherit from dialog" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=footer" ) ), "ui-bar-inherit",
"Expected footer to inherit from dialog" );
QUnit.start();
}
] );
} );
QUnit.asyncTest( "dialog element with data-theme & data-overlay-theme", function( assert ) {
assert.expect( 4 );
$.testHelper.pageSequence( [
function() {
$( ".ui-pagecontainer" ).pagecontainer( "change", $( "#mypage" ) );
},
function() {
// Bring up the dialog
$( "#link-c" ).click();
},
function() {
var dialog = $( "#dialog-c" );
// Assert dialog theme inheritance (issue 1375):
assert.hasClasses( dialog, "ui-page-theme-e",
"Expected explicit theme ui-page-theme-e" );
assert.hasClasses( $( ".ui-pagecontainer" ), "ui-overlay-b",
"Expected explicit overlay theme ui-overlay-b" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=header" ) ), "ui-bar-inherit",
"Expected header to inherit from dialog" );
assert.hasClasses( dialog.find( jqmDataSelector( "type=footer" ) ), "ui-bar-inherit",
"Expected footer to inherit from dialog" );
QUnit.start();
}
] );
} );
QUnit.asyncTest( "pagecontainer is set to dialog overlayTheme at pagebeforeshow",
function( assert ) {
var pageTheme;
assert.expect( 1 );
$.testHelper.pageSequence( [
function() {
$( ".ui-pagecontainer" ).pagecontainer( "change", "#mypage" );
},
function() {
// Bring up the dialog
$( "#foo-dialog-link" ).click();
},
function() {
pageTheme = "ui-overlay-" + $.mobile.activePage.page( "option", "overlayTheme" );
$( ".ui-pagecontainer" ).removeClass( pageTheme );
$.mobile.activePage
.bind( "pagebeforeshow", function() {
assert.hasClasses( $( ".ui-pagecontainer" ), pageTheme,
"Page container has the same theme as the dialog overlayTheme on " +
"pagebeforeshow" );
QUnit.start();
} ).trigger( "pagebeforeshow" );
}
] );
} );
} );