Added explicit module names to the new unit tests.
[jquery.git] / test / unit / css.js
1 module("css");
2
3 test("css(String|Hash)", function() {
4         expect(19);
5
6         equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
7
8         ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
9         jQuery('#nothiddendiv').css({display: 'none'});
10         ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
11         jQuery('#nothiddendiv').css({display: 'block'});
12         ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
13
14         jQuery('#floatTest').css({styleFloat: 'right'});
15         equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
16         jQuery('#floatTest').css({cssFloat: 'left'});
17         equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
18         jQuery('#floatTest').css({'float': 'right'});
19         equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
20         jQuery('#floatTest').css({'font-size': '30px'});
21         equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
22
23         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
24                 jQuery('#foo').css({opacity: n});
25                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
26                 jQuery('#foo').css({opacity: parseFloat(n)});
27                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
28         });
29         jQuery('#foo').css({opacity: ''});
30         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
31 });
32
33 test("css(String, Object)", function() {
34         expect(21);
35         ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
36         jQuery('#nothiddendiv').css("display", 'none');
37         ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
38         jQuery('#nothiddendiv').css("display", 'block');
39         ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
40
41         jQuery('#floatTest').css('styleFloat', 'left');
42         equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
43         jQuery('#floatTest').css('cssFloat', 'right');
44         equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
45         jQuery('#floatTest').css('float', 'left');
46         equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
47         jQuery('#floatTest').css('font-size', '20px');
48         equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
49
50         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
51                 jQuery('#foo').css('opacity', n);
52                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
53                 jQuery('#foo').css('opacity', parseFloat(n));
54                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
55         });
56         jQuery('#foo').css('opacity', '');
57         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
58         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
59         if (jQuery.browser.msie) {
60                 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
61         }
62         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
63
64         // using contents will get comments regular, text, and comment nodes
65         var j = jQuery("#nonnodes").contents();
66         j.css("padding-left", "1px");
67         equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
68
69         // opera sometimes doesn't update 'display' correctly, see #2037
70         jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
71         equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
72 });
73
74 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
75         expect(4);
76
77         var $checkedtest = jQuery("#checkedtest");
78         // IE6 was clearing "checked" in jQuery.css(elem, "height");
79         jQuery.css($checkedtest[0], "height");
80         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
81         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
82         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
83         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
84 });