--- /dev/null
+/*\r
+ * dialog unit tests\r
+ */\r
+\r
+//\r
+// Dialog Test Helper Functions\r
+//\r
+var el, offsetBefore, offsetAfter, dragged;\r
+\r
+var dlg = function() {\r
+ return el.data("dialog").element.parents(".ui-dialog:first");\r
+}\r
+\r
+var isOpen = function(why) {\r
+ ok(dlg().is(":visible"), why);\r
+}\r
+\r
+var isNotOpen = function(why) {\r
+ ok(!dlg().is(":visible"), why);\r
+}\r
+\r
+var drag = function(handle, dx, dy) {\r
+ var element = el.data("dialog").element;\r
+ offsetBefore = el.offset();\r
+ $(handle).simulate("drag", {\r
+ dx: dx || 0,\r
+ dy: dy || 0\r
+ });\r
+ dragged = { dx: dx, dy: dy };\r
+ offsetAfter = el.offset();\r
+}\r
+\r
+var moved = function (dx, dy, msg) {\r
+ msg = msg ? msg + "." : "";\r
+ var actual = { left: offsetAfter.left, top: offsetAfter.top };\r
+ var expected = { left: offsetBefore.left + dx, top: offsetAfter.top };\r
+ compare2(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg);\r
+}\r
+\r
+function shouldmove(why) {\r
+ var handle = $(".ui-dialog-titlebar", el.data("dialog").element);\r
+ drag(handle, 50, 50);\r
+ moved(50, 50, why);\r
+}\r
+\r
+function shouldnotmove(why) {\r
+ var handle = $(".ui-dialog-titlebar", el.data("dialog").element);\r
+ drag(handle, 50, 50);\r
+ moved(0, 0, why);\r
+}\r
+\r
+var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }\r
+\r
+var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }\r
+\r
+// Dialog Tests\r
+module("dialog");\r
+\r
+test("init", function() {\r
+ expect(6);\r
+\r
+ el = $("#dialog1").dialog();\r
+ ok(true, '.dialog() called on element');\r
+\r
+ $([]).dialog();\r
+ ok(true, '.dialog() called on empty collection');\r
+\r
+ $("<div/>").dialog();\r
+ ok(true, '.dialog() called on disconnected DOMElement');\r
+\r
+ $("<div/>").dialog().dialog("foo");\r
+ ok(true, 'arbitrary method called after init');\r
+\r
+ $("<div/>").dialog().data("foo.dialog");\r
+ ok(true, 'arbitrary option getter after init');\r
+\r
+ $("<div/>").dialog().data("foo.dialog", "bar");\r
+ ok(true, 'arbitrary option setter after init');\r
+\r
+});\r
+\r
+test("destroy", function() {\r
+ expect(6);\r
+\r
+ $("#dialog1").dialog().dialog("destroy"); \r
+ ok(true, '.dialog("destroy") called on element');\r
+\r
+ $([]).dialog().dialog("destroy");\r
+ ok(true, '.dialog("destroy") called on empty collection');\r
+\r
+ $("<div/>").dialog().dialog("destroy");\r
+ ok(true, '.dialog("destroy") called on disconnected DOMElement');\r
+\r
+ $("<div/>").dialog().dialog("destroy").dialog("foo");\r
+ ok(true, 'arbitrary method called after destroy');\r
+\r
+ $("<div/>").dialog().dialog("destroy").data("foo.dialog");\r
+ ok(true, 'arbitrary option getter after destroy');\r
+\r
+ $("<div/>").dialog().dialog("destroy").data("foo.dialog", "bar");\r
+ ok(true, 'arbitrary option setter after destroy');\r
+});\r
+\r
+/*\r
+//This one takes a while to run\r
+\r
+test("element types", function() {\r
+ var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'\r
+ + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'\r
+ + ',acronym,code,samp,kbd,var,img,object,hr'\r
+ + ',input,button,label,select,iframe').split(',');\r
+\r
+ $.each(typeNames, function(i) {\r
+ var typeName = typeNames[i];\r
+ el = $(document.createElement(typeName)).appendTo('body');\r
+ (typeName == 'table' && el.append("<tr><td>content</td></tr>"));\r
+ el.dialog();\r
+ ok(true, '$("<' + typeName + '/>").dialog()');\r
+ el.dialog("destroy");\r
+ el.remove();\r
+ });\r
+});\r
+\r
+*/\r
+\r
+test("defaults", function() {\r
+ el = $('<div/>').dialog();\r
+ var defaults = {\r
+ autoOpen: true,\r
+ buttons: {},\r
+ disabled: false,\r
+ draggable: true,\r
+ height: 200,\r
+ maxHeight: null,\r
+ maxWidth: null,\r
+ minHeight: 100,\r
+ minWidth: 150,\r
+ modal: false,\r
+ overlay: {},\r
+ position: 'center',\r
+ resizable: true,\r
+ stack: true,\r
+ title: null,\r
+ width: 300\r
+ };\r
+ $.each(defaults, function(key, val) {\r
+ var actual = el.data(key + ".dialog"), expected = val,\r
+ method = (expected && expected.constructor == Object) ?\r
+ compare2 : equals;\r
+ method(actual, expected, key);\r
+ });\r
+ el.remove();\r
+});\r
+\r
+module("dialog: Options");\r
+\r
+test("autoOpen", function() {\r
+ expect(2);\r
+\r
+ el = $("<div/>").dialog({ autoOpen: false });\r
+ isNotOpen('.dialog({ autoOpen: false })');\r
+ el.remove();\r
+\r
+ el = $("<div/>").dialog({ autoOpen: true });\r
+ isOpen('.dialog({ autoOpen: true })');\r
+ el.remove();\r
+});\r
+\r
+test("buttons", function() {\r
+ expect(6);\r
+ var buttons = {\r
+ "Ok": function() {\r
+ ok(true, "button 1 click fires callback");\r
+ },\r
+ "Cancel": function() {\r
+ ok(true, "button 2 click fires callback");\r
+ }\r
+ }\r
+ el = $("<div/>").dialog({ buttons: buttons });\r
+ var btn = $("button", dlg());\r
+ equals(btn.length, 2, "number of buttons");\r
+ var i = 0;\r
+ $.each(buttons, function(key, val) {\r
+ equals(btn.eq(i).text(), key, "text of button " + (i+1));\r
+ i += 1;\r
+ });\r
+ btn.simulate("click");\r
+ equals(btn.parent().attr('className'), 'ui-dialog-buttonpane', "buttons in container");\r
+});\r
+\r
+module("dialog: Methods");\r
+\r
+module("dialog: Callbacks");\r
+\r
+module("dialog: Tickets");\r
+\r
+test("#XXXX title", function() {\r
+ \r
+ \r
+ \r
+});\r
+\r
+module("dialog: Cleanup");\r
+\r
+test("cleanup", function() {\r
+\r
+ $(".ui-dialog").remove();\r
+\r
+});\r