tizen beta release
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / tests / unit / select / select_cached.js
1 /*
2  * mobile select unit tests
3  */
4
5 (function($){
6         var resetHash;
7
8         resetHash = function(timeout){
9                 $.testHelper.openPage( location.hash.indexOf("#default") >= 0 ? "#" : "#default" );
10         };
11
12         // https://github.com/jquery/jquery-mobile/issues/2181
13         asyncTest( "dialog sized select should alter the value of its parent select", function(){
14                 var selectButton, value;
15
16                 $.testHelper.pageSequence([
17                         resetHash,
18
19                         function(){
20                                 $.mobile.changePage( "cached.html" );
21                         },
22
23                         function(){
24                                 selectButton = $( "#cached-page-select" ).siblings( 'a' );
25                                 selectButton.click();
26                         },
27
28                         function(){
29                                 ok( $.mobile.activePage.hasClass('ui-dialog'), "the dialog came up" );
30                                 var option = $.mobile.activePage.find( "li a" ).not(":contains('" + selectButton.text() + "')").last();
31                                 value = option.text();
32                                 option.click();
33                         },
34
35                         function(){
36                                 same( value, selectButton.text(), "the selected value is propogated back to the button text" );
37                                 start();
38                         }
39                 ]);
40         });
41
42         // https://github.com/jquery/jquery-mobile/issues/2181
43         asyncTest( "dialog sized select should prevent the removal of its parent page from the dom", function(){
44                 var selectButton, parentPageId;
45
46                 expect( 2 );
47
48                 $.testHelper.pageSequence([
49                         resetHash,
50
51                         function(){
52                                 $.mobile.changePage( "cached.html" );
53                         },
54
55                         function(){
56                                 selectButton = $.mobile.activePage.find( "#cached-page-select" ).siblings( 'a' );
57                                 parentPageId = $.mobile.activePage.attr( 'id' );
58                                 same( $("#" + parentPageId).length, 1, "establish the parent page exists" );
59                                 selectButton.click();
60                         },
61
62                         function(){
63                                 same( $( "#" + parentPageId).length, 1, "make sure parent page is still there after opening the dialog" );
64                                 $.mobile.activePage.find( "li a" ).last().click();
65                         },
66
67                         start
68                 ]);
69         });
70
71         asyncTest( "dialog sized select shouldn't rebind its parent page remove handler when closing, if the parent page domCache option is true", function(){
72                 expect( 3 );
73
74                 $.testHelper.pageSequence([
75                         resetHash,
76
77                         function(){
78                                 $.mobile.changePage( "cached-dom-cache-true.html" );
79                         },
80
81                         function(){
82                                 $.mobile.activePage.find( "#domcache-page-select" ).siblings( 'a' ).click();
83                         },
84
85                         function(){
86                                 ok( $.mobile.activePage.hasClass('ui-dialog'), "the dialog came up" );
87                                 $.mobile.activePage.find( "li a" ).last().click();
88                         },
89
90                         function(){
91                                 ok( $.mobile.activePage.is( "#dialog-select-parent-domcache-test" ), "the dialog closed" );
92                                 $.mobile.changePage( $( "#default" ) );
93                         },
94
95                         function(){
96                                 same( $("#dialog-select-parent-domcache-test").length, 1, "make sure the select parent page is still cached in the dom after changing page" );
97                                 start();
98                         }
99                 ]);
100         });
101
102         asyncTest( "menupage is removed when the parent page is removed", function(){
103                 var dialogCount = $(":jqmData(role='dialog')").length;
104
105                 $.testHelper.pageSequence([
106                         resetHash,
107
108                         function(){
109
110                                 $.mobile.changePage( "uncached-dom-cached-false.html" );
111                         },
112
113                         function(){
114                                 same( $(":jqmData(role='dialog')").length, dialogCount + 1 );
115                                 window.history.back();
116                         },
117
118                         function() {
119                                 same( $(":jqmData(role='dialog')").length, dialogCount );
120                                 start();
121                         }
122                 ]);
123         });
124 })(jQuery);