Revert "Export"
[platform/framework/web/web-ui-fw.git] / tests / unit-tests / button / button-tests.js
1 /*
2  * Unit Test: Button
3  *
4  * Hyunjung Kim <hjnim.kim@samsung.com>
5  *
6  */
7 $( "#checkboxpage" ).live( "pageinit", function ( event ) {
8
9         module( "button" );
10
11         var unit_button = function ( widget, type ) {
12                 var buttonClassPrefix = "ui-btn",
13                         buttonText = type,
14                         icon,
15                         position,
16                         buttonStyle,
17                         hasClass;
18
19                 ok( widget.hasClass(buttonClassPrefix), "Create - Button" );
20
21                 if ( widget.jqmData( "inline" ) ) {
22                         ok( widget.hasClass( buttonClassPrefix + "-inline"), "Style - Inline");
23                 } else {
24                         ok( !widget.hasClass( buttonClassPrefix + "-inline"), "Style - Non Inline");
25                 }
26
27                 if ( !widget.children().first().hasClass( buttonClassPrefix + "-hastxt" ) ) {
28                         buttonText = "";
29                 }
30                 // Text Trim, Cause jQueryMobile(JQM) 1.1 forced to add - "\u00a0" in buttonIcon(ButtonMarkup)
31                 // JQM 1.1 buttonMarkup code :
32                 // - if( buttonIcon ) buttonIcon.appendChild( document.createTextNode( "\u00a0" ) );
33                 equal( widget.text().trim() , buttonText , "Button Text" );
34
35                 icon = widget.jqmData("icon");
36                 if ( icon !== undefined ) {
37                         ok( widget.children().children().hasClass("ui-icon-" + icon ) , "Style - Button Icon" );
38                 }
39                 if ( icon !== undefined && buttonText != "") {
40                         position = widget.jqmData("iconpos");
41                         if ( position === undefined ) {
42                                 position = "left";
43                         }
44                         ok( widget.children().children().first().hasClass( buttonClassPrefix + "-text-padding-" + position ) , "Style - Button Icon, Text Position" );
45                 }
46
47                 buttonStyle = widget.jqmData( "style" );
48                 if ( buttonStyle !== undefined ) {
49                         switch ( buttonStyle ) {
50                         case "circle" :
51                                 hasClass = " .ui-btn-corner-circle, .ui-btn-icon_only";
52                                 break;
53                         case "edit" :
54                                 hasClass = " .ui-btn-edit";
55                                 break;
56                         case "nobg" :
57                                 hasClass = " .ui-btn-icon-nobg, .ui-btn-icon_only";
58                                 break;
59                         }
60                         ok( widget.children().is( hasClass ) );
61                 }
62
63                 // Check APIs
64                 widget.button().button( "disable" );
65                 equal( widget.attr("disabled"), "disabled", "button disable test" );
66
67                 widget.button().button( "enable" );
68                 equal( widget.attr("disable"), undefined, "button enable test" );
69
70
71         };
72
73         test ( "Button" , function () {
74                 unit_button( $("#button-0"), "Text Button" );
75         });
76
77         test ( "Button - Inline" , function () {
78                 unit_button( $("#button-1"), "Text Button Inline" );
79         });
80
81         test ( "Button - Inline, Icon" , function () {
82                 unit_button( $("#button-2"), "Call Icon" );
83         });
84
85         test ( "Button - Inline, Call Icon, Icon Position(Right)" , function () {
86                 unit_button( $("#button-3"), "Icon Text" );
87         });
88
89         test ( "Button - Inline, Only Icon(Reveal)" , function () {
90                 unit_button( $("#button-4"), "Non Text Button" );
91         });
92
93         test ( "Button - Inline, Only Icon(Send), circle" , function () {
94                 unit_button( $("#button-5"), "Non Text Button" );
95         });
96
97         test ( "Button - Inline, Only Icon(Favorite), nobackground" , function () {
98                 unit_button( $("#button-6"), "Non Text Button" );
99         });
100
101 });