0
+test("Basic requirements", function() {
0
+ ok( Array.prototype.push, "Array.push()" );
0
+ ok( Function.prototype.apply, "Function.apply()" );
0
+ ok( document.getElementById, "getElementById" );
0
+ ok( document.getElementsByTagName, "getElementsByTagName" );
0
+ ok( RegExp, "RegExp" );
0
+ ok( jQuery, "jQuery" );
0
+test("$()", function() {
0
+ var main = $("#main");
0
+ isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
0
+ // make sure this is handled
0
+ ok( true, "Check for \\r and \\n in jQuery()" );
0
+ /* // Disabled until we add this functionality in
0
+ $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
0
+ ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
0
+ var code = $("<code/>");
0
+ equals( code.length, 1, "Correct number of elements generated for code" );
0
+ var img = $("<img/>");
0
+ equals( img.length, 1, "Correct number of elements generated for img" );
0
+ var div = $("<div/><hr/><code/><b/>");
0
+ equals( div.length, 4, "Correct number of elements generated for div hr code b" );
0
+test("noConflict", function() {
0
+ var newjQuery = jQuery.noConflict();
0
+ ok( newjQuery == old, "noConflict returned the jQuery object" );
0
+ ok( jQuery == old, "Make sure jQuery wasn't touched." );
0
+ ok( $ == "$", "Make sure $ was reverted." );
0
+ newjQuery = jQuery.noConflict(true);
0
+ ok( newjQuery == old, "noConflict returned the jQuery object" );
0
+ ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
0
+ ok( $ == "$", "Make sure $ was reverted." );
0
+test("isFunction", function() {
0
+ // Make sure that false values return false
0
+ ok( !jQuery.isFunction(), "No Value" );
0
+ ok( !jQuery.isFunction( null ), "null Value" );
0
+ ok( !jQuery.isFunction( undefined ), "undefined Value" );
0
+ ok( !jQuery.isFunction( "" ), "Empty String Value" );
0
+ ok( !jQuery.isFunction( 0 ), "0 Value" );
0
+ // Safari uses "(Internal Function)"
0
+ ok( jQuery.isFunction(String), "String Function" );
0
+ ok( jQuery.isFunction(Array), "Array Function" );
0
+ ok( jQuery.isFunction(Object), "Object Function" );
0
+ ok( jQuery.isFunction(Function), "Function Function" );
0
+ // When stringified, this could be misinterpreted
0
+ var mystr = "function";
0
+ ok( !jQuery.isFunction(mystr), "Function String" );
0
+ // When stringified, this could be misinterpreted
0
+ var myarr = [ "function" ];
0
+ ok( !jQuery.isFunction(myarr), "Function Array" );
0
+ // When stringified, this could be misinterpreted
0
+ var myfunction = { "function": "test" };
0
+ ok( !jQuery.isFunction(myfunction), "Function Object" );
0
+ // Make sure normal functions still work
0
+ var fn = function(){};
0
+ ok( jQuery.isFunction(fn), "Normal Function" );
0
+ var obj = document.createElement("object");
0
+ // Firefox says this is a function
0
+ ok( !jQuery.isFunction(obj), "Object Element" );
0
+ // IE says this is an object
0
+ ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
0
+ var nodes = document.body.childNodes;
0
+ // Safari says this is a function
0
+ ok( !jQuery.isFunction(nodes), "childNodes Property" );
0
+ var first = document.body.firstChild;
0
+ // Normal elements are reported ok everywhere
0
+ ok( !jQuery.isFunction(first), "A normal DOM Element" );
0
+ var input = document.createElement("input");
0
+ document.body.appendChild( input );
0
+ // IE says this is an object
0
+ ok( jQuery.isFunction(input.focus), "A default function property" );
0
+ document.body.removeChild( input );
0
+ var a = document.createElement("a");
0
+ a.href = "some-function";
0
+ document.body.appendChild( a );
0
+ // This serializes with the word 'function' in it
0
+ ok( !jQuery.isFunction(a), "Anchor Element" );
0
+ document.body.removeChild( a );
0
+ // Recursive function calls have lengths and array-like properties
0
+ function callme(callback){
0
+ function fn(response){
0
+ ok( jQuery.isFunction(fn), "Recursive Function Call" );
0
+test("$('html')", function() {
0
+ var s = $("<script>var foo='test';</script>")[0];
0
+ ok( s, "Creating a script" );
0
+ ok( !foo, "Make sure the script wasn't executed prematurely" );
0
+ ok( foo, "Executing a scripts contents in the right context" );
0
+ ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
0
+test("length", function() {
0
+ ok( $("p").length == 6, "Get Number of Elements Found" );
0
+test("size()", function() {
0
+ ok( $("p").size() == 6, "Get Number of Elements Found" );
0
+test("get()", function() {
0
+ isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
0
+test("get(Number)", function() {
0
+ ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
0
+test("add(String|Element|Array)", function() {
0
+ isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
0
+ isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
0
+ ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
0
+ var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
0
+ ok( x[0].id == "x1", "Check on-the-fly element1" );
0
+ ok( x[1].id == "x2", "Check on-the-fly element2" );
0
+ var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
0
+ ok( x[0].id == "x1", "Check on-the-fly element1" );
0
+ ok( x[1].id == "x2", "Check on-the-fly element2" );
0
+test("each(Function)", function() {
0
+ div.each(function(){this.foo = 'zoo';});
0
+ for ( var i = 0; i < div.size(); i++ ) {
0
+ if ( div.get(i).foo != "zoo" ) pass = false;
0
+ ok( pass, "Execute a function, Relative" );
0
+test("index(Object)", function() {
0
+ ok( $([window, document]).index(window) == 0, "Check for index of elements" );
0
+ ok( $([window, document]).index(document) == 1, "Check for index of elements" );
0
+ var inputElements = $('#radio1,#radio2,#check1,#check2');
0
+ ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
0
+ ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
0
+ ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
0
+ ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
0
+ ok( inputElements.index(window) == -1, "Check for not found index" );
0
+ ok( inputElements.index(document) == -1, "Check for not found index" );
0
+test("attr(String)", function() {
0
+ ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
0
+ ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
0
+ ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
0
+ ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
0
+ ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
0
+ ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
0
+ ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
0
+ ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
0
+ ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
0
+ ok( $('#name').attr('name') == "name", 'Check for name attribute' );
0
+ ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
0
+ ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
0
+ $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
0
+ ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
0
+ test("attr(String) in XML Files", function() {
0
+ $.get("data/dashboard.xml", function(xml) {
0
+ ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
0
+ ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
0
+test("attr(String, Function)", function() {
0
+ ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
0
+ ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
0
+test("attr(Hash)", function() {
0
+ $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
0
+ if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
0
+ ok( pass, "Set Multiple Attributes" );
0
+test("attr(String, Object)", function() {
0
+ div.attr("foo", "bar");
0
+ for ( var i = 0; i < div.size(); i++ ) {
0
+ if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
0
+ ok( pass, "Set Attribute" );
0
+ ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
0
+ $("#name").attr('name', 'something');
0
+ ok( $("#name").attr('name') == 'something', 'Set name attribute' );
0
+ $("#check2").attr('checked', true);
0
+ ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
0
+ $("#check2").attr('checked', false);
0
+ ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
0
+ $("#text1").attr('readonly', true);
0
+ ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
0
+ $("#text1").attr('readonly', false);
0
+ ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
0
+ $("#name").attr('maxlength', '5');
0
+ ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
0
+ var type = $("#check2").attr('type');
0
+ $("#check2").attr('type','hidden');
0
+ ok( thrown, "Exception thrown when trying to change type property" );
0
+ equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
0
+ var check = document.createElement("input");
0
+ $(check).attr('type','checkbox');
0
+ ok( thrown, "Exception thrown when trying to change type property" );
0
+ equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
0
+ test("attr(String, Object) - Loaded via XML document", function() {
0
+ $.get('data/dashboard.xml', function(xml) {
0
+ $('tab', xml).each(function() {
0
+ titles.push($(this).attr('title'));
0
+ ok( titles[0] == 'Location', 'attr() in XML context: Check first title' );
0
+ ok( titles[1] == 'Users', 'attr() in XML context: Check second title' );
0
+test("css(String|Hash)", function() {
0
+ ok( $('#main').css("display") == 'none', 'Check for css property "display"');
0
+ ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
0
+ $('#foo').css({display: 'none'});
0
+ ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
0
+ $('#foo').css({display: 'block'});
0
+ ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
0
+ $('#floatTest').css({styleFloat: 'right'});
0
+ ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
0
+ $('#floatTest').css({cssFloat: 'left'});
0
+ ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
0
+ $('#floatTest').css({'float': 'right'});
0
+ ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
0
+ $('#floatTest').css({'font-size': '30px'});
0
+ ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
0
+ $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
0
+ $('#foo').css({opacity: n});
0
+ ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
0
+ $('#foo').css({opacity: parseFloat(n)});
0
+ ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
0
+ $('#foo').css({opacity: ''});
0
+ ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
0
+test("css(String, Object)", function() {
0
+ ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
0
+ $('#foo').css('display', 'none');
0
+ ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
0
+ $('#foo').css('display', 'block');
0
+ ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
0
+ $('#floatTest').css('styleFloat', 'left');
0
+ ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
0
+ $('#floatTest').css('cssFloat', 'right');
0
+ ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
0
+ $('#floatTest').css('float', 'left');
0
+ ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
0
+ $('#floatTest').css('font-size', '20px');
0
+ ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
0
+ $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
0
+ $('#foo').css('opacity', n);
0
+ ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
0
+ $('#foo').css('opacity', parseFloat(n));
0
+ ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
0
+ $('#foo').css('opacity', '');
0
+ ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
0
+test("text()", function() {
0
+ var expected = "This link has class=\"blog\": Simon Willison's Weblog";
0
+ ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
0
+test("wrap(String|Element)", function() {
0
+ var defaultText = 'Try them out:'
0
+ var result = $('#first').wrap('<div class="red"><span></span></div>').text();
0
+ ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
0
+ ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
0
+ var defaultText = 'Try them out:'
0
+ var result = $('#first').wrap(document.getElementById('empty')).parent();
0
+ ok( result.is('ol'), 'Check for element wrapping' );
0
+ ok( result.text() == defaultText, 'Check for element wrapping' );
0
+ $('#check1').click(function() {
0
+ ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
0
+ $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
0
+ ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
0
+test("wrapAll(String|Element)", function() {
0
+ var prev = $("#first")[0].previousSibling;
0
+ var p = $("#first")[0].parentNode;
0
+ var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
0
+ equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
0
+ ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
0
+ ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
0
+ equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
0
+ equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
0
+ var prev = $("#first")[0].previousSibling;
0
+ var p = $("#first")[0].parentNode;
0
+ var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
0
+ equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
0
+ equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
0
+ equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
0
+test("wrapInner(String|Element)", function() {
0
+ var num = $("#first").children().length;
0
+ var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
0
+ equals( $("#first").children().length, 1, "Only one child" );
0
+ ok( $("#first").children().is(".red"), "Verify Right Element" );
0
+ equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
0
+ var num = $("#first").children().length;
0
+ var result = $('#first').wrapInner(document.getElementById('empty'));
0
+ equals( $("#first").children().length, 1, "Only one child" );
0
+ ok( $("#first").children().is("#empty"), "Verify Right Element" );
0
+ equals( $("#first").children().children().length, num, "Verify Elements Intact" );
0
+test("append(String|Element|Array<Element>|jQuery)", function() {
0
+ var defaultText = 'Try them out:'
0
+ var result = $('#first').append('<b>buga</b>');
0
+ ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
0
+ ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
0
+ var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
0
+ $('#sap').append(document.getElementById('first'));
0
+ ok( expected == $('#sap').text(), "Check for appending of element" );