rob@77
|
1 var testCase = require('nodeunit').testCase,
|
rob@77
|
2 static_document = require('fs').readFileSync('test/fixtures/css.html', 'utf8');
|
rob@77
|
3
|
rob@77
|
4 // need to be global as helpers access these variables
|
rob@77
|
5 window = document = jQuery = $ = null;
|
rob@77
|
6
|
rob@77
|
7 var helpers = require('./helpers/helper'),
|
rob@77
|
8 q = helpers.query_ids;
|
rob@77
|
9
|
rob@77
|
10 module.exports = testCase({
|
rob@77
|
11 setUp: function (callback) {
|
rob@77
|
12 jQuery = $ = helpers.recreate_doc(static_document);
|
rob@77
|
13 callback();
|
rob@77
|
14 },
|
rob@77
|
15 tearDown: function (callback) {
|
rob@77
|
16 // clean up
|
rob@77
|
17 callback();
|
rob@77
|
18 },
|
rob@77
|
19 "css(String|Hash)": function(test) {
|
rob@77
|
20 test.expect(18);
|
rob@77
|
21
|
rob@77
|
22 //test.equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
|
rob@77
|
23
|
rob@77
|
24 test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
rob@77
|
25 jQuery('#nothiddendiv').css({display: 'none'});
|
rob@77
|
26 test.ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
rob@77
|
27 jQuery('#nothiddendiv').css({display: 'block'});
|
rob@77
|
28 test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
rob@77
|
29
|
rob@77
|
30 var div = jQuery( "<div>" );
|
rob@77
|
31
|
rob@77
|
32 // These should be "auto" (or some better value)
|
rob@77
|
33 // temporarily provide "0px" for backwards compat
|
rob@77
|
34 test.equals( div.css("width"), "0px", "Width on disconnected node." );
|
rob@77
|
35 test.equals( div.css("height"), "0px", "Height on disconnected node." );
|
rob@77
|
36
|
rob@77
|
37 div.css({ width: 4, height: 4 });
|
rob@77
|
38
|
rob@77
|
39 test.equals( div.css("width"), "4px", "Width on disconnected node." );
|
rob@77
|
40 test.equals( div.css("height"), "4px", "Height on disconnected node." );
|
rob@77
|
41
|
rob@77
|
42 var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
|
rob@77
|
43
|
rob@77
|
44 test.equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
|
rob@77
|
45 test.equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
|
rob@77
|
46 test.equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
|
rob@77
|
47
|
rob@77
|
48 div2.remove();
|
rob@77
|
49
|
rob@77
|
50 // handle negative numbers by ignoring #1599, #4216
|
rob@77
|
51 jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
|
rob@77
|
52
|
rob@77
|
53 var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
|
rob@77
|
54 jQuery('#nothiddendiv').css({ width: -1, height: -1 });
|
rob@77
|
55 //test.equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
|
rob@77
|
56 //test.equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
|
rob@77
|
57
|
rob@77
|
58 test.equals( jQuery('<div style="display: none;">').css('display'), 'none', 'Styles on disconnected nodes');
|
rob@77
|
59
|
rob@77
|
60 //jQuery('#floatTest').css('float', 'right');
|
rob@77
|
61 //test.equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
|
rob@77
|
62 //jQuery('#floatTest').css({'font-size': '30px'});
|
rob@77
|
63 //test.equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
|
rob@77
|
64
|
rob@77
|
65 /*jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
rob@77
|
66 jQuery('#foo').css({opacity: n});
|
rob@77
|
67 test.equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
rob@77
|
68 jQuery('#foo').css({opacity: parseFloat(n)});
|
rob@77
|
69 test.equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
rob@77
|
70 });*/
|
rob@77
|
71 jQuery('#foo').css({opacity: ''});
|
rob@77
|
72 test.equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
rob@77
|
73
|
rob@77
|
74 //test.equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
|
rob@77
|
75 //jQuery('#empty').css({ opacity: '1' });
|
rob@77
|
76 //test.equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
|
rob@77
|
77
|
rob@77
|
78 var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
|
rob@77
|
79
|
rob@77
|
80 //test.equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
|
rob@77
|
81 //test.equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
|
rob@77
|
82 //test.equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
|
rob@77
|
83 //test.equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
|
rob@77
|
84
|
rob@77
|
85 child.css("height", "100%");
|
rob@77
|
86 test.equals( child[0].style.height, "100%", "Make sure the height is being set correctly." );
|
rob@77
|
87
|
rob@77
|
88 child.attr("class", "em");
|
rob@77
|
89 //test.equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
|
rob@77
|
90
|
rob@77
|
91 // Have to verify this as the result depends upon the browser's CSS
|
rob@77
|
92 // support for font-size percentages
|
rob@77
|
93 child.attr("class", "prct");
|
rob@77
|
94 var prctval = parseInt(child.css("fontSize")), checkval = 0;
|
rob@77
|
95 if ( prctval === 16 || prctval === 24 ) {
|
rob@77
|
96 checkval = prctval;
|
rob@77
|
97 }
|
rob@77
|
98
|
rob@77
|
99 //test.equals( prctval, checkval, "Verify fontSize % set." );
|
rob@77
|
100
|
rob@77
|
101 test.equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
|
rob@77
|
102
|
rob@77
|
103 var old = child[0].style.height;
|
rob@77
|
104
|
rob@77
|
105 // Test NaN
|
rob@77
|
106 child.css("height", parseFloat("zoo"));
|
rob@77
|
107 test.equals( child[0].style.height, old, "Make sure height isn't changed on NaN." );
|
rob@77
|
108
|
rob@77
|
109 // Test null
|
rob@77
|
110 child.css("height", null);
|
rob@77
|
111 test.equals( child[0].style.height, old, "Make sure height isn't changed on null." );
|
rob@77
|
112
|
rob@77
|
113 old = child[0].style.fontSize;
|
rob@77
|
114
|
rob@77
|
115 // Test NaN
|
rob@77
|
116 child.css("font-size", parseFloat("zoo"));
|
rob@77
|
117 test.equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
|
rob@77
|
118
|
rob@77
|
119 // Test null
|
rob@77
|
120 child.css("font-size", null);
|
rob@77
|
121 test.equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
|
rob@77
|
122 test.done();
|
rob@77
|
123 }
|
rob@77
|
124 });
|