4 * Hyunjung Kim <hjnim.kim@samsung.com>
6 /*jslint browser: true*/
7 /*global $, jQuery, test, equal, ok*/
8 $("#checkpage").live("pageinit", function ( event ) {
12 var unit_check = function ( widget, type ) {
16 classPrefix = "ui-checkbox";
18 widget.checkboxradio( );
19 checkbox = widget.parent( );
20 ok( checkbox.hasClass( classPrefix ) , "Create - Checkbox");
22 checkClass = classPrefix + "-on";
23 if ( !widget.is(":checked") ) {
24 checkClass = classPrefix + "-off";
26 if ( widget.hasClass("favorite") ) {
27 ok( checkbox.hasClass("favorite"), "Style - Favorite");
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 label = checkbox.children( ).last( );
34 equal ( label.text( ).trim( ), type, "label, type string must be same");
36 label.trigger("vclick");
37 if ( !widget.is(":disabled") ) {
38 checkClass = classPrefix + "-on";
39 ok( label.hasClass( checkClass ) , "Click - Normal Checkbox On");
41 checkClass = classPrefix + "-off";
42 label.trigger("vclick");
43 ok( label.hasClass( checkClass ) , "Click - Normal Checkbox Off");
45 ok( label.hasClass( checkClass ) , "Click - Disable Checkbox");
46 label.trigger("vclick");
47 ok( label.hasClass( checkClass ) , "Click - click event doesn't have effect");
51 ok( label.find('.ui-btn-hastxt'), "Markup check for text");
52 ok( label.find('.ui-btn-text') , "Markup check for text");
53 equal( label.find('.ui-btn-hastxt span.ui-btn-text').last( ).html( ), type , "Markup check for text value");
57 widget.checkboxradio('disable') ;
58 equal( widget.is(":disabled") , true, "API check disable") ;
59 ok( checkbox.hasClass("ui-disabled") , "API disable - Disable Checkbox");
61 widget.checkboxradio('enable') ;
62 equal( widget.is(":disabled") , false, "API check enable") ;
63 equal( checkbox.hasClass("ui-disabled") , false, "API enable - Disable Checkbox");
68 unit_check_events = function ( widget, type ) {
69 var createEvent = false,
74 widget.checkboxradio({create: function ( ) {
77 checkbox = widget.parent( );
78 label = checkbox.children( ).last( );
80 widget.bind("change", function ( ) {
84 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
85 ok( createEvent , "Checkbox Create Event");
87 widget.trigger("click");
88 ok( changeEvent , "Checkbox Change Event");
91 test("checkbox - Normal", function ( ) {
92 unit_check( $("#checkbox-1"), "Normal");
95 test("checkbox - Checked, Disabled", function ( ) {
96 unit_check( $("#checkbox-2"), "Checked, Disabled");
99 test("checkbox - Disabled", function ( ) {
100 unit_check( $("#checkbox-3"), "Disabled");
103 test("Favorite - Favorite", function ( ) {
104 unit_check( $("#checkbox-4"), "Favorite");
107 test("Favorite - Favorite Checked, Disabled", function ( ) {
108 unit_check( $("#checkbox-5"), "Favorite Checked, Disabled");
111 test("Favorite - Favorite, Disabled", function ( ) {
112 unit_check( $("#checkbox-6"), "Favorite, Disabled");
115 test("checkbox - Normal Dynamic", function ( ) {
118 //remove all controls form content
119 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
121 markup = '<input type= "checkbox"name= "checkbox-1"id= "checkbox-1"/><label for= "checkbox-1">Normal Dynamic</label>';
122 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
123 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
125 unit_check( $("#checkbox-1"), "Normal Dynamic");
129 test("checkbox - Checked, Disabled Dynamic", function ( ) {
132 //remove all controls form content
133 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
135 markup = '<input type= "checkbox"name= "checkbox-2"id= "checkbox-2"checked= "checked"disabled= "true"/><label for= "checkbox-2">Checked, Disabled Dymanic</label>';
136 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
137 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
138 unit_check( $("#checkbox-2"), "Checked, Disabled Dymanic");
141 test("checkbox - Disabled Dynamic", function ( ) {
143 //remove all controls form content
144 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
146 markup = '<input type= "checkbox"name= "checkbox-3"id= "checkbox-3"disabled= "true"/><label for= "checkbox-3">Disabled Dynamic</label>';
147 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
148 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
149 unit_check( $("#checkbox-3"), "Disabled Dynamic");
152 test("Favorite - Favorite Dynamic", function ( ) {
154 //remove all controls form content
155 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
157 markup = '<input type= "checkbox"name= "checkbox-4"id= "checkbox-4"class= "favorite"/><label for= "checkbox-4">Favorite Dynamic</label>';
158 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
159 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
160 unit_check( $("#checkbox-4"), "Favorite Dynamic");
163 test("Favorite - Favorite Checked, Disabled Dynamic", function ( ) {
165 //remove all controls form content
166 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
168 markup = '<input type= "checkbox"name= "checkbox-5"id= "checkbox-5"checked= "checked"disabled= "true"class= "favorite"/><label for= "checkbox-5">Favorite Checked, Disabled Dynamic</label>';
169 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
170 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
171 unit_check( $("#checkbox-5"), "Favorite Checked, Disabled Dynamic");
174 test("Favorite - Favorite, Disabled Dynamic", function ( ) {
176 //remove all controls form content
177 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
179 markup = '<input type= "checkbox"name= "checkbox-6"id= "checkbox-6"disabled= "disabled"class= "favorite"/><label for= "checkbox-6">Favorite, Disabled Dynamic</label>';
180 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
181 $('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
182 unit_check( $("#checkbox-6"), "Favorite, Disabled Dynamic");
185 test("Favorite - Favorite, Disabled Dynamic Events", function ( ) {
187 //remove all controls form content
188 $('#checkpage').find(":jqmData(role=controlgroup)").empty( );
190 markup = '<input type= "checkbox"name= "checkbox-6"id= "checkbox-6"disabled= "disabled"class= "favorite"/><label for= "checkbox-6">Favorite, Disabled Dynamic Events</label>';
191 $('#checkpage').find(":jqmData(role=controlgroup)").append( markup ) ;
192 //$('#checkpage').find(":jqmData(role=controlgroup)").trigger('create') ;
193 unit_check_events( $("#checkbox-6"), "Favorite, Disabled Dynamic Events");