]> source.dussan.org Git - jquery-ui.git/commitdiff
test dialog - first dialog unit tests
authorRichard Worth <rdworth@gmail.com>
Sun, 8 Jun 2008 02:29:44 +0000 (02:29 +0000)
committerRichard Worth <rdworth@gmail.com>
Sun, 8 Jun 2008 02:29:44 +0000 (02:29 +0000)
tests/dialog.html [new file with mode: 0644]
tests/dialog.js [new file with mode: 0644]

diff --git a/tests/dialog.html b/tests/dialog.html
new file mode 100644 (file)
index 0000000..a5704a6
--- /dev/null
@@ -0,0 +1,40 @@
+<!DOCTYPE html>\r
+<html lang="en">\r
+<head>\r
+       <title>jQuery UI Dialog Test Suite</title>\r
+\r
+       <link rel="stylesheet" href="qunit/testsuite.css" type="text/css" media="screen">\r
+       <!--link rel="stylesheet" href="../themes/flora/flora.dialog.css" type="text/css" media="screen"-->\r
+       \r
+       <script type="text/javascript" src="../jquery-1.2.6.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.core.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.dialog.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.draggable.js"></script>\r
+       <script type="text/javascript" src="../ui/ui.resizable.js"></script>\r
+       \r
+       <script type="text/javascript" src="qunit/testrunner.js"></script>\r
+       <script type="text/javascript" src="simulate/jquery.simulate.js"></script>\r
+       \r
+       <script type="text/javascript" src="dialog.js"></script>\r
+       \r
+       <style type="text/css">\r
+               html { border: 0; }\r
+       </style>\r
+\r
+\r
+\r
+</head>\r
+<body class="flora">\r
+\r
+<h1 id="header">jQuery UI Dialog Test Suite</h1>\r
+<h2 id="banner"></h2>\r
+<h2 id="userAgent"></h2>\r
+\r
+<ol id="tests"></ol>\r
+\r
+<div id="main" style="position: absolute; top: -10000px; border: 1px solid black; padding: 10px; margin: 10px;">\r
+       <div id="dialog1">Dialog Content</div>\r
+</div>\r
+\r
+</body>\r
+</html>\r
diff --git a/tests/dialog.js b/tests/dialog.js
new file mode 100644 (file)
index 0000000..e4efbe8
--- /dev/null
@@ -0,0 +1,209 @@
+/*\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, '$("&lt;' + typeName + '/&gt").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