190fec894fe3a4fab1dcc6a8333cb62c8a5b1eb9
[framework/web/web-ui-fw.git] / tests / unit-tests / check / check-tests.js
1 /*
2  * Unit Test: Checkbox
3  *
4  * Hyunjung Kim <hjnim.kim@samsung.com>
5  */
6
7 $( "#checkpage" ).live( "pageinit", function( event ){
8
9         module("checkbox");
10
11         var unit_check = function ( widget, type ) {
12                 var checkbox,
13                         label,
14                         checkClass,
15                         classPrefix = "ui-checkbox";
16
17                 widget.checkboxradio();
18                 checkbox = widget.parent();
19                 ok( checkbox.hasClass(classPrefix) , "Create - Checkbox" );
20
21                 checkClass = classPrefix + "-on";
22                 if( !widget.is(":checked") ){
23                         checkClass = classPrefix + "-off";
24                 }
25                 if( widget.hasClass( "favorite" )){
26                         ok( checkbox.hasClass( "favorite" ), "Style - Favorite" );
27                 }
28
29                 // Text Trim, Cause jQueryMobile(JQM) 1.1 forced to add - "\u00a0" in buttonIcon(ButtonMarkup)
30                 // JQM 1.1 buttonMarkup code :
31                 // - if( buttonIcon ) buttonIcon.appendChild( document.createTextNode( "\u00a0" ) );
32                 label = checkbox.children().last();
33                 equal ( label.text().trim(), type, "label, type string must be same" );
34
35                 label.trigger( "vclick" );
36                 if( !widget.is( ":disabled" ) ) {
37                         checkClass = classPrefix + "-on";
38                         ok( label.hasClass( checkClass ) , "Click - Normal Checkbox On" );
39
40                         checkClass = classPrefix + "-off";
41                         label.trigger( "vclick" );
42                         ok( label.hasClass( checkClass ) , "Click - Normal Checkbox Off" );
43                 } else {
44                         ok( label.hasClass( checkClass ) , "Click - Disable Checkbox" );
45                 }
46         };
47
48         test( "checkbox - Normal" , function () {
49                 unit_check( $( "#checkbox-1" ), "Normal" );
50         });
51
52         test( "checkbox - Checked, Disabled" , function () {
53                 unit_check( $( "#checkbox-2" ), "Checked, Disabled" );
54         });
55
56         test( "checkbox - Disabled" , function () {
57                 unit_check( $( "#checkbox-3" ), "Disabled" );
58         });
59
60         test( "Favorite - Favorite" , function () {
61                 unit_check( $( "#checkbox-4" ), "Favorite" );
62         });
63
64         test( "Favorite - Favorite Checked, Disabled" , function () {
65                 unit_check( $( "#checkbox-5" ), "Favorite Checked, Disabled" );
66         });
67
68         test( "Favorite - Favorite, Disabled" , function () {
69                 unit_check( $( "#checkbox-6" ), "Favorite, Disabled" );
70         });
71
72 });