/* * dialog unit tests */ // // Dialog Test Helper Functions // var el, offsetBefore, offsetAfter, dragged; var dlg = function() { return el.data("dialog").element.parents(".ui-dialog:first"); } var isOpen = function(why) { ok(dlg().is(":visible"), why); } var isNotOpen = function(why) { ok(!dlg().is(":visible"), why); } var drag = function(handle, dx, dy) { var element = el.data("dialog").element; offsetBefore = el.offset(); $(handle).simulate("drag", { dx: dx || 0, dy: dy || 0 }); dragged = { dx: dx, dy: dy }; offsetAfter = el.offset(); } var moved = function (dx, dy, msg) { msg = msg ? msg + "." : ""; var actual = { left: offsetAfter.left, top: offsetAfter.top }; var expected = { left: offsetBefore.left + dx, top: offsetAfter.top }; compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); } function shouldmove(why) { var handle = $(".ui-dialog-titlebar", dlg()); drag(handle, 50, 50); moved(50, 50, why); } function shouldnotmove(why) { var handle = $(".ui-dialog-titlebar", dlg()); drag(handle, 50, 50); moved(0, 0, why); } var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } // Dialog Tests module("dialog"); test("init", function() { expect(6); el = $("#dialog1").dialog(); ok(true, '.dialog() called on element'); $([]).dialog(); ok(true, '.dialog() called on empty collection'); $("
").dialog(); ok(true, '.dialog() called on disconnected DOMElement'); $("").dialog().dialog("foo"); ok(true, 'arbitrary method called after init'); $("").dialog().data("foo.dialog"); ok(true, 'arbitrary option getter after init'); $("").dialog().data("foo.dialog", "bar"); ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { expect(6); $("#dialog1").dialog().dialog("destroy"); ok(true, '.dialog("destroy") called on element'); $([]).dialog().dialog("destroy"); ok(true, '.dialog("destroy") called on empty collection'); $("").dialog().dialog("destroy"); ok(true, '.dialog("destroy") called on disconnected DOMElement'); $("").dialog().dialog("destroy").dialog("foo"); ok(true, 'arbitrary method called after destroy'); $("").dialog().dialog("destroy").data("foo.dialog"); ok(true, 'arbitrary option getter after destroy'); $("").dialog().dialog("destroy").data("foo.dialog", "bar"); ok(true, 'arbitrary option setter after destroy'); }); /* //This one takes a while to run test("element types", function() { var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + ',acronym,code,samp,kbd,var,img,object,hr' + ',input,button,label,select,iframe').split(','); $.each(typeNames, function(i) { var typeName = typeNames[i]; el = $(document.createElement(typeName)).appendTo('body'); (typeName == 'table' && el.append("