rob@77: var testCase = require('nodeunit').testCase,
rob@77: static_document = require('fs').readFileSync('test/fixtures/css.html', 'utf8');
rob@77:
rob@77: // need to be global as helpers access these variables
rob@77: window = document = jQuery = $ = null;
rob@77:
rob@77: var helpers = require('./helpers/helper'),
rob@77: q = helpers.query_ids;
rob@77:
rob@77: module.exports = testCase({
rob@77: setUp: function (callback) {
rob@77: jQuery = $ = helpers.recreate_doc(static_document);
rob@77: callback();
rob@77: },
rob@77: tearDown: function (callback) {
rob@77: // clean up
rob@77: callback();
rob@77: },
rob@77: "css(String|Hash)": function(test) {
rob@77: test.expect(18);
rob@77:
rob@77: //test.equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
rob@77:
rob@77: test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
rob@77: jQuery('#nothiddendiv').css({display: 'none'});
rob@77: test.ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
rob@77: jQuery('#nothiddendiv').css({display: 'block'});
rob@77: test.ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
rob@77:
rob@77: var div = jQuery( "
" );
rob@77:
rob@77: // These should be "auto" (or some better value)
rob@77: // temporarily provide "0px" for backwards compat
rob@77: test.equals( div.css("width"), "0px", "Width on disconnected node." );
rob@77: test.equals( div.css("height"), "0px", "Height on disconnected node." );
rob@77:
rob@77: div.css({ width: 4, height: 4 });
rob@77:
rob@77: test.equals( div.css("width"), "4px", "Width on disconnected node." );
rob@77: test.equals( div.css("height"), "4px", "Height on disconnected node." );
rob@77:
rob@77: var div2 = jQuery( "
").appendTo("body");
rob@77:
rob@77: test.equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
rob@77: test.equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
rob@77: test.equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
rob@77:
rob@77: div2.remove();
rob@77:
rob@77: // handle negative numbers by ignoring #1599, #4216
rob@77: jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
rob@77:
rob@77: var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
rob@77: jQuery('#nothiddendiv').css({ width: -1, height: -1 });
rob@77: //test.equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
rob@77: //test.equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
rob@77:
rob@77: test.equals( jQuery('
').css('display'), 'none', 'Styles on disconnected nodes');
rob@77:
rob@77: //jQuery('#floatTest').css('float', 'right');
rob@77: //test.equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
rob@77: //jQuery('#floatTest').css({'font-size': '30px'});
rob@77: //test.equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
rob@77:
rob@77: /*jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
rob@77: jQuery('#foo').css({opacity: n});
rob@77: test.equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
rob@77: jQuery('#foo').css({opacity: parseFloat(n)});
rob@77: test.equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
rob@77: });*/
rob@77: jQuery('#foo').css({opacity: ''});
rob@77: test.equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
rob@77:
rob@77: //test.equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
rob@77: //jQuery('#empty').css({ opacity: '1' });
rob@77: //test.equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
rob@77:
rob@77: var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
rob@77:
rob@77: //test.equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
rob@77: //test.equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
rob@77: //test.equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
rob@77: //test.equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
rob@77:
rob@77: child.css("height", "100%");
rob@77: test.equals( child[0].style.height, "100%", "Make sure the height is being set correctly." );
rob@77:
rob@77: child.attr("class", "em");
rob@77: //test.equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
rob@77:
rob@77: // Have to verify this as the result depends upon the browser's CSS
rob@77: // support for font-size percentages
rob@77: child.attr("class", "prct");
rob@77: var prctval = parseInt(child.css("fontSize")), checkval = 0;
rob@77: if ( prctval === 16 || prctval === 24 ) {
rob@77: checkval = prctval;
rob@77: }
rob@77:
rob@77: //test.equals( prctval, checkval, "Verify fontSize % set." );
rob@77:
rob@77: test.equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
rob@77:
rob@77: var old = child[0].style.height;
rob@77:
rob@77: // Test NaN
rob@77: child.css("height", parseFloat("zoo"));
rob@77: test.equals( child[0].style.height, old, "Make sure height isn't changed on NaN." );
rob@77:
rob@77: // Test null
rob@77: child.css("height", null);
rob@77: test.equals( child[0].style.height, old, "Make sure height isn't changed on null." );
rob@77:
rob@77: old = child[0].style.fontSize;
rob@77:
rob@77: // Test NaN
rob@77: child.css("font-size", parseFloat("zoo"));
rob@77: test.equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
rob@77:
rob@77: // Test null
rob@77: child.css("font-size", null);
rob@77: test.equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
rob@77: test.done();
rob@77: }
rob@77: });