Revert "Export"
[framework/web/web-ui-fw.git] / tests / unit-tests / radio / radio-tests.js
1 /*
2  * Unit Test: Radio
3  *
4  * Hyunjung Kim <hjnim.kim@samsung.com>
5  *
6  */
7 $( "#radiopage" ).live( "pageinit", function(event) {
8
9         module("Radio");
10
11         /* Single Radio */
12         var unit_radio = function ( input , type ) {
13                 var radio,
14                         label,
15                         checkClass,
16                         labelSpan,
17                         radioClassPrefix = "ui-radio";
18
19                 radio = input.parent();
20                 ok( radio.hasClass( radioClassPrefix ) , "Create - Single Radio Button" );
21
22                 label = radio.find( "label" );
23                 label.trigger( "vclick" );
24                 checkClass = radioClassPrefix + "-on";
25                 if( !input.is( ":checked" ) ) {
26                         checkClass = radioClassPrefix + "-off";
27                 }
28                 ok( label.hasClass( checkClass ), "Click - Radio button" );
29
30                 labelSpan = label.children().children();
31                 ok( labelSpan.first().is( ".ui-btn-text, .ui-btn-text-padding-left" ), "Okay - Label Padding" );
32
33                 if ( !input.is( ":disabled" ) ) {
34                         label.trigger( "vclick" );
35                 }
36
37                 // Text Trim, Cause jQueryMobile(JQM) 1.1 forced to add - "\u00a0" in buttonIcon(ButtonMarkup)
38                 // JQM 1.1 buttonMarkup code :
39                 // - if( buttonIcon ) buttonIcon.appendChild( document.createTextNode( "\u00a0" ) );
40                 equal( labelSpan.text().trim(), input.val(), "Label Text" );
41         };
42
43         /* Group Radio */
44         var unit_radio_group = function ( fieldset , type ) {
45                 var type,
46                         radios,
47                         label,
48                         labels;
49
50                 type = fieldset.jqmData( "type" );
51                 if( type === undefined ) {
52                         type = "vertical";
53                 }
54                 ok( fieldset.is( ".ui-corner-all, .ui-controlgroup, .ui-controlgroup-" + type ) , "Create - ControlGroup" );
55
56                 if( type == "horizontal" ) {
57                         labels = fieldset.find( "span.ui-btn-text" ).each( function () {
58                                 ok( ( $( this ).siblings().length == 0 && $( this ).hasClass( "ui-btn-text" ) ) ? true : false, "Alignment - ControlGroup(Horizontal, Single Radio)" );
59                         });
60                 }
61
62                 radios = fieldset.find( "input[type='radio']" );
63                 radios.each( function() {
64                         unit_radio( $( this ) , "Normal" );
65                 });
66
67                 ok( function() {
68                                 try{
69                                         for ( i = 0 ; i < raidos.lenght ; i++ ) {
70                                                 label = radios[i].find( "label" );
71                                                 label.trigger( "vclick" );
72                                                 if( !label.hasClass( "ui-radio-on" ) ){
73                                                         throw "error - other button activate";
74                                                 }
75                                                 for ( j = 0 ; j < radios.lenght ; j++) {
76                                                         if( i == j) continue;
77                                                         label = radios[j].find( "label" );
78                                                         if( label.hasClass( "ui-radio-on" ) ) {
79                                                                 throw "error - other button activate";
80                                                         }
81                                                 }
82                                         }
83                                 } catch ( Exception ) {
84                                         return false;
85                                 }
86                                 return true;
87                 }, "Click - Radio Button( Group )" );
88         };
89
90         test( "radiobutton - Single" , function () {
91                 unit_radio( $("#radio-single-1") , "Normal" );
92         });
93
94         test( "radiobutton - Single, Checked, Disabled" , function () {
95                 unit_radio( $("#radio-single-2") , "Checked, Disabled" );
96         });
97
98         test( "radiobutton - Single, Disabled" , function () {
99                 unit_radio( $("#radio-single-3") , "Disabled" );
100         });
101
102         test( "radiobutton - Group" , function() {
103                 unit_radio_group( $("#controlgroup") , "Group" );
104         });
105
106         test( "radiobutton - Group, Horizontal" , function() {
107                 unit_radio_group( $("#controlgroup2") , "Group - horizontal" );
108         });
109 });