Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / tests / unit / textinput / textinput_core.js
1 /*
2  * mobile textinput unit tests
3  */
4 (function($){
5         module( "jquery.mobile.forms.textinput.js" );
6
7         // NOTE this test isn't run because the event data isn't easily accessible
8         // and with the advent of the widget _on method we are actually testing the
9         // widget from UI which has it's own test suite for these sorts of things
10         // ie, don't test your dependencies / framework
11         if( !( $.fn.jquery.match(/^1.8/) )){
12                 test( "input is cleaned up on destroy", function(){
13                         var input = $( "#destroycorrectly" ),
14                         win = $( window ),
15                         loadLen;
16
17                         loadLen = win.data("events").load.length;
18
19                         input.remove();
20
21                         equal(win.data("events").load.length, (loadLen-1), "window load event was not removed");
22                 });
23         }
24
25         test( "inputs without type specified are enhanced", function(){
26                 ok( $( "#typeless-input" ).hasClass( "ui-input-text" ) );
27         });
28
29         $.mobile.page.prototype.options.keepNative = "textarea.should-be-native";
30
31         // not testing the positive case here since's it's obviously tested elsewhere
32         test( "textarea in the keepNative set shouldn't be enhanced", function() {
33                 ok( !$("textarea.should-be-native").is("ui-input-text") );
34         });
35
36         asyncTest( "textarea should autogrow on document ready", function() {
37                 var test = $( "#init-autogrow" );
38
39                 setTimeout(function() {
40                         ok( $( "#reference-autogrow" )[0].clientHeight < test[0].clientHeight, "the height is greater than the reference text area with no content" );
41                         ok( test[0].clientHeight > 100, "autogrow text area's height is greater than any style padding");
42                         start();
43                 }, 400);
44         });
45
46         asyncTest( "textarea should autogrow when text is added via the keyboard", function() {
47                 var test = $( "#keyup-autogrow" ),
48                         originalHeight = test[0].clientHeight;
49
50                 test.keyup(function() {
51                         setTimeout(function() {
52                                 ok( test[0].clientHeight > originalHeight, "the height is greater than original with no content" );
53                                 ok( test[0].clientHeight > 100, "autogrow text area's height is greater any style/padding");
54                                 start();
55                         }, 400);
56                 });
57
58                 test.val("foo\n\n\n\n\n\n\n\n\n\n\n\n\n\n").trigger("keyup");
59         });
60
61         asyncTest( "text area should auto grow when the parent page is loaded via ajax", function() {
62                 $.testHelper.pageSequence([
63                         function() {
64                                 $("#external").click();
65                         },
66
67                         function() {
68                                 setTimeout(function() {
69                                         ok($.mobile.activePage.find( "textarea" )[0].clientHeight > 100, "text area's height has grown");
70                                         window.history.back();
71                                 }, 1000);
72                         },
73
74                         function() {
75                                 start();
76                         }
77                 ]);
78         });
79
80         // NOTE init binding to alter the setting is in settings.js
81         test( "'clear text' button for search inputs should use configured text", function(){
82                 strictEqual( $( "#search-input" ).closest( ".ui-input-search" ).find( ".ui-input-clear" ).attr( "title" ), "custom value" );
83         });
84 })(jQuery);