diff options
author | Felix Nagel <info@felixnagel.com> | 2012-11-10 01:40:05 +0100 |
---|---|---|
committer | Felix Nagel <info@felixnagel.com> | 2012-11-10 01:40:05 +0100 |
commit | 7ce8e0515ea7cc513c3c065946c85cf2d1aa5652 (patch) | |
tree | a0337f9f7d8d0d27a7cdb78a63ee152d8357b32f /tests/unit/dialog/dialog_options.js | |
parent | 94b3a65c66e338fc6f697d13fc77d7f19b8666ae (diff) | |
parent | d6c6b7dc3381432f50212b4f458931b2521ecb56 (diff) | |
download | jquery-ui-7ce8e0515ea7cc513c3c065946c85cf2d1aa5652.tar.gz jquery-ui-7ce8e0515ea7cc513c3c065946c85cf2d1aa5652.zip |
Merge branch 'master' into selectmenu
Diffstat (limited to 'tests/unit/dialog/dialog_options.js')
-rw-r--r-- | tests/unit/dialog/dialog_options.js | 284 |
1 files changed, 146 insertions, 138 deletions
diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index ba217c6f4..c58cf6915 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -8,12 +8,12 @@ module("dialog: options"); test("autoOpen", function() { expect(2); - el = $('<div></div>').dialog({ autoOpen: false }); - isNotOpen('.dialog({ autoOpen: false })'); + var el = $('<div></div>').dialog({ autoOpen: false }); + ok( !el.dialog("widget").is(":visible"), '.dialog({ autoOpen: false })'); el.remove(); el = $('<div></div>').dialog({ autoOpen: true }); - isOpen('.dialog({ autoOpen: true })'); + ok( el.dialog("widget").is(":visible"), '.dialog({ autoOpen: true })'); el.remove(); }); @@ -22,24 +22,24 @@ test("buttons", function() { var btn, i, newButtons, buttons = { - "Ok": function(ev, ui) { - ok(true, "button click fires callback"); - equal(this, el[0], "context of callback"); - equal(ev.target, btn[0], "event target"); + "Ok": function( ev ) { + ok(true, "button click fires callback"); + equal(this, el[0], "context of callback"); + equal(ev.target, btn[0], "event target"); + }, + "Cancel": function( ev ) { + ok(true, "button click fires callback"); + equal(this, el[0], "context of callback"); + equal(ev.target, btn[1], "event target"); + } }, - "Cancel": function(ev, ui) { - ok(true, "button click fires callback"); - equal(this, el[0], "context of callback"); - equal(ev.target, btn[1], "event target"); - } - }; + el = $('<div></div>').dialog({ buttons: buttons }); - el = $('<div></div>').dialog({ buttons: buttons }); - btn = $("button", dlg()); + btn = $("button", el.dialog('widget')); equal(btn.length, 2, "number of buttons"); i = 0; - $.each(buttons, function(key, val) { + $.each(buttons, function( key ) { equal(btn.eq(i).text(), key, "text of button " + (i+1)); i++; }); @@ -50,7 +50,7 @@ test("buttons", function() { btn.trigger("click"); newButtons = { - "Close": function(ev, ui) { + "Close": function( ev ) { ok(true, "button click fires callback"); equal(this, el[0], "context of callback"); equal(ev.target, btn[0], "event target"); @@ -61,18 +61,18 @@ test("buttons", function() { el.dialog("option", "buttons", newButtons); deepEqual(el.dialog("option", "buttons"), newButtons, '.dialog("option", "buttons", ...) setter'); - btn = $("button", dlg()); + btn = $("button", el.dialog('widget')); equal(btn.length, 1, "number of buttons after setter"); btn.trigger('click'); i = 0; - $.each(newButtons, function(key, val) { + $.each(newButtons, function( key ) { equal(btn.eq(i).text(), key, "text of button " + (i+1)); i += 1; }); el.dialog("option", "buttons", null); - btn = $("button", dlg()); + btn = $("button", el.dialog('widget')); equal(btn.length, 0, "all buttons have been removed"); equal(el.find(".ui-dialog-buttonset").length, 0, "buttonset has been removed"); equal(el.parent().hasClass('ui-dialog-buttons'), false, "dialog wrapper removes class about having buttons"); @@ -83,19 +83,21 @@ test("buttons", function() { test("buttons - advanced", function() { expect(5); - el = $("<div></div>").dialog({ - buttons: [ - { - text: "a button", - "class": "additional-class", - id: "my-button-id", - click: function() { - equal(this, el[0], "correct context"); + var buttons, + el = $("<div></div>").dialog({ + buttons: [ + { + text: "a button", + "class": "additional-class", + id: "my-button-id", + click: function() { + equal(this, el[0], "correct context"); + } } - } - ] - }); - var buttons = dlg().find("button"); + ] + }); + + buttons = el.dialog('widget').find("button"); equal(buttons.length, 1, "correct number of buttons"); equal(buttons.attr("id"), "my-button-id", "correct id"); equal(buttons.text(), "a button", "correct label"); @@ -107,40 +109,40 @@ test("buttons - advanced", function() { test("closeOnEscape", function() { expect( 6 ); - el = $('<div></div>').dialog({ closeOnEscape: false }); + var el = $('<div></div>').dialog({ closeOnEscape: false }); ok(true, 'closeOnEscape: false'); - ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC'); + ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open before ESC'); el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE }) .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE }) .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE }); - ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open after ESC'); + ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open after ESC'); el.remove(); el = $('<div></div>').dialog({ closeOnEscape: true }); ok(true, 'closeOnEscape: true'); - ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC'); + ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog is open before ESC'); el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE }) .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE }) .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE }); - ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog is closed after ESC'); + ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog is closed after ESC'); }); test("closeText", function() { expect(3); - el = $('<div></div>').dialog(); - equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'close', + var el = $('<div></div>').dialog(); + equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'close', 'default close text'); el.remove(); el = $('<div></div>').dialog({ closeText: "foo" }); - equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo', + equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'foo', 'closeText on init'); el.remove(); el = $('<div></div>').dialog().dialog('option', 'closeText', 'bar'); - equal(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar', + equal(el.dialog('widget').find('.ui-dialog-titlebar-close span').text(), 'bar', 'closeText via option method'); el.remove(); }); @@ -148,131 +150,132 @@ test("closeText", function() { test("dialogClass", function() { expect(4); - el = $('<div></div>').dialog(); - equal(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); + var el = $('<div></div>').dialog(); + equal(el.dialog('widget').is(".foo"), false, 'dialogClass not specified. foo class added'); el.remove(); el = $('<div></div>').dialog({ dialogClass: "foo" }); - equal(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); + equal(el.dialog('widget').is(".foo"), true, 'dialogClass in init. foo class added'); el.remove(); el = $('<div></div>').dialog({ dialogClass: "foo bar" }); - equal(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added'); - equal(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added'); + equal(el.dialog('widget').is(".foo"), true, 'dialogClass in init, two classes. foo class added'); + equal(el.dialog('widget').is(".bar"), true, 'dialogClass in init, two classes. bar class added'); el.remove(); }); test("draggable", function() { expect(4); - el = $('<div></div>').dialog({ draggable: false }); - shouldnotmove(); + var el = $('<div></div>').dialog({ draggable: false }); + + TestHelpers.dialog.testDrag(el, 50, -50, 0, 0); el.dialog('option', 'draggable', true); - shouldmove(); + TestHelpers.dialog.testDrag(el, 50, -50, 50, -50); el.remove(); el = $('<div></div>').dialog({ draggable: true }); - shouldmove(); + TestHelpers.dialog.testDrag(el, 50, -50, 50, -50); el.dialog('option', 'draggable', false); - shouldnotmove(); + TestHelpers.dialog.testDrag(el, 50, -50, 0, 0); el.remove(); }); test("height", function() { expect(4); - el = $('<div></div>').dialog(); - equal(dlg().outerHeight(), 150, "default height"); + var el = $('<div></div>').dialog(); + equal(el.dialog('widget').outerHeight(), 150, "default height"); el.remove(); el = $('<div></div>').dialog({ height: 237 }); - equal(dlg().outerHeight(), 237, "explicit height"); + equal(el.dialog('widget').outerHeight(), 237, "explicit height"); el.remove(); el = $('<div></div>').dialog(); el.dialog('option', 'height', 238); - equal(dlg().outerHeight(), 238, "explicit height set after init"); + equal(el.dialog('widget').outerHeight(), 238, "explicit height set after init"); el.remove(); el = $('<div></div>').css("padding", "20px") .dialog({ height: 240 }); - equal(dlg().outerHeight(), 240, "explicit height with padding"); + equal(el.dialog('widget').outerHeight(), 240, "explicit height with padding"); el.remove(); }); test("maxHeight", function() { expect(3); - el = $('<div></div>').dialog({ maxHeight: 200 }); - drag('.ui-resizable-s', 1000, 1000); - equal(heightAfter, 200, "maxHeight"); + var el = $('<div></div>').dialog({ maxHeight: 200 }); + TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000); + closeEnough(el.dialog('widget').height(), 200, 1, "maxHeight"); el.remove(); el = $('<div></div>').dialog({ maxHeight: 200 }); - drag('.ui-resizable-n', -1000, -1000); - equal(heightAfter, 200, "maxHeight"); + TestHelpers.dialog.drag(el, '.ui-resizable-n', -1000, -1000); + closeEnough(el.dialog('widget').height(), 200, 1, "maxHeight"); el.remove(); el = $('<div></div>').dialog({ maxHeight: 200 }).dialog('option', 'maxHeight', 300); - drag('.ui-resizable-s', 1000, 1000); - equal(heightAfter, 300, "maxHeight"); + TestHelpers.dialog.drag(el, '.ui-resizable-s', 1000, 1000); + closeEnough(el.dialog('widget').height(), 300, 1, "maxHeight"); el.remove(); }); test("maxWidth", function() { expect(3); - el = $('<div></div>').dialog({ maxWidth: 200 }); - drag('.ui-resizable-e', 1000, 1000); - equal(widthAfter, 200, "maxWidth"); + var el = $('<div></div>').dialog({ maxWidth: 200 }); + TestHelpers.dialog.drag(el, '.ui-resizable-e', 1000, 1000); + closeEnough(el.dialog('widget').width(), 200, 1, "maxWidth"); el.remove(); el = $('<div></div>').dialog({ maxWidth: 200 }); - drag('.ui-resizable-w', -1000, -1000); - equal(widthAfter, 200, "maxWidth"); + TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000); + closeEnough(el.dialog('widget').width(), 200, 1, "maxWidth"); el.remove(); el = $('<div></div>').dialog({ maxWidth: 200 }).dialog('option', 'maxWidth', 300); - drag('.ui-resizable-w', -1000, -1000); - equal(widthAfter, 300, "maxWidth"); + TestHelpers.dialog.drag(el, '.ui-resizable-w', -1000, -1000); + closeEnough(el.dialog('widget').width(), 300, 1, "maxWidth"); el.remove(); }); test("minHeight", function() { expect(3); - el = $('<div></div>').dialog({ minHeight: 10 }); - drag('.ui-resizable-s', -1000, -1000); - equal(heightAfter, 10, "minHeight"); + var el = $('<div></div>').dialog({ minHeight: 10 }); + TestHelpers.dialog.drag(el, '.ui-resizable-s', -1000, -1000); + closeEnough(el.dialog('widget').height(), 10, 1, "minHeight"); el.remove(); el = $('<div></div>').dialog({ minHeight: 10 }); - drag('.ui-resizable-n', 1000, 1000); - equal(heightAfter, 10, "minHeight"); + TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000); + closeEnough(el.dialog('widget').height(), 10, 1, "minHeight"); el.remove(); el = $('<div></div>').dialog({ minHeight: 10 }).dialog('option', 'minHeight', 30); - drag('.ui-resizable-n', 1000, 1000); - equal(heightAfter, 30, "minHeight"); + TestHelpers.dialog.drag(el, '.ui-resizable-n', 1000, 1000); + closeEnough(el.dialog('widget').height(), 30, 1, "minHeight"); el.remove(); }); test("minWidth", function() { expect(3); - el = $('<div></div>').dialog({ minWidth: 10 }); - drag('.ui-resizable-e', -1000, -1000); - equal(widthAfter, 10, "minWidth"); + var el = $('<div></div>').dialog({ minWidth: 10 }); + TestHelpers.dialog.drag(el, '.ui-resizable-e', -1000, -1000); + closeEnough(el.dialog('widget').width(), 10, 1, "minWidth"); el.remove(); el = $('<div></div>').dialog({ minWidth: 10 }); - drag('.ui-resizable-w', 1000, 1000); - equal(widthAfter, 10, "minWidth"); + TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000); + closeEnough(el.dialog('widget').width(), 10, 1, "minWidth"); el.remove(); el = $('<div></div>').dialog({ minWidth: 30 }).dialog('option', 'minWidth', 30); - drag('.ui-resizable-w', 1000, 1000); - equal(widthAfter, 30, "minWidth"); + TestHelpers.dialog.drag(el, '.ui-resizable-w', 1000, 1000); + closeEnough(el.dialog('widget').width(), 30, 1, "minWidth"); el.remove(); }); @@ -281,8 +284,8 @@ test("position, default center on window", function() { var el = $('<div></div>').dialog(), dialog = el.dialog('widget'), offset = dialog.offset(); - deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); - deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop()); + closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1); + closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1); el.remove(); }); @@ -291,8 +294,8 @@ test("position, top on window", function() { var el = $('<div></div>').dialog({ position: "top" }), dialog = el.dialog('widget'), offset = dialog.offset(); - deepEqual(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); - deepEqual(offset.top, $(window).scrollTop()); + closeEnough(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).scrollTop(), 1); el.remove(); }); @@ -301,54 +304,59 @@ test("position, left on window", function() { var el = $('<div></div>').dialog({ position: "left" }), dialog = el.dialog('widget'), offset = dialog.offset(); - deepEqual(offset.left, 0); - deepEqual(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop()); + closeEnough(offset.left, 0, 1); + closeEnough(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop(), 1); el.remove(); }); -test("position, right bottom on window", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ position: "right bottom" }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); - deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); - el.remove(); -}); +// todo: figure out these fails in IE7 +if ( !$.ui.ie ) { + + test("position, right bottom on window", function() { + expect( 2 ); + var el = $('<div></div>').dialog({ position: "right bottom" }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); + el.remove(); + }); -test("position, right bottom on window w/array", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ position: ["right", "bottom"] }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); - deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); - el.remove(); -}); + test("position, right bottom on window w/array", function() { + expect( 2 ); + var el = $('<div></div>').dialog({ position: ["right", "bottom"] }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); + el.remove(); + }); + + test("position, right bottom at right bottom via ui.position args", function() { + expect( 2 ); + var el = $('<div></div>').dialog({ + position: { + my: "right bottom", + at: "right bottom" + } + }), + dialog = el.dialog('widget'), + offset = dialog.offset(); + + closeEnough(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft(), 1); + closeEnough(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop(), 1); + el.remove(); + }); + +} test("position, offset from top left w/array", function() { expect( 2 ); var el = $('<div></div>').dialog({ position: [10, 10] }), dialog = el.dialog('widget'), offset = dialog.offset(); - deepEqual(offset.left, 10 + $(window).scrollLeft()); - deepEqual(offset.top, 10 + $(window).scrollTop()); - el.remove(); -}); - -test("position, right bottom at right bottom via ui.position args", function() { - expect( 2 ); - var el = $('<div></div>').dialog({ - position: { - my: "right bottom", - at: "right bottom" - } - }), - dialog = el.dialog('widget'), - offset = dialog.offset(); - - deepEqual(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); - deepEqual(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); + closeEnough(offset.left, 10 + $(window).scrollLeft(), 1); + closeEnough(offset.top, 10 + $(window).scrollTop(), 1); el.remove(); }); @@ -394,16 +402,16 @@ test("position, at another element", function() { test("resizable", function() { expect(4); - el = $('<div></div>').dialog(); - shouldresize("[default]"); + var el = $('<div></div>').dialog(); + TestHelpers.dialog.shouldResize(el, 50, 50, "[default]"); el.dialog('option', 'resizable', false); - shouldnotresize('disabled after init'); + TestHelpers.dialog.shouldResize(el, 0, 0, 'disabled after init'); el.remove(); el = $('<div></div>').dialog({ resizable: false }); - shouldnotresize("disabled in init options"); + TestHelpers.dialog.shouldResize(el, 0, 0, "disabled in init options"); el.dialog('option', 'resizable', true); - shouldresize('enabled after init'); + TestHelpers.dialog.shouldResize(el, 50, 50, 'enabled after init'); el.remove(); }); @@ -411,13 +419,13 @@ test("title", function() { expect(9); function titleText() { - return dlg().find(".ui-dialog-title").html(); + return el.dialog('widget').find(".ui-dialog-title").html(); } - el = $('<div></div>').dialog(); + var el = $('<div></div>').dialog(); // some browsers return a non-breaking space and some return " " // so we get the text to normalize to the actual non-breaking space - equal(dlg().find(".ui-dialog-title").text(), " ", "[default]"); + equal(el.dialog('widget').find(".ui-dialog-title").text(), " ", "[default]"); equal(el.dialog("option", "title"), "", "option not changed"); el.remove(); @@ -444,14 +452,14 @@ test("title", function() { test("width", function() { expect(3); - el = $('<div></div>').dialog(); - equal(dlg().width(), 300, "default width"); + var el = $('<div></div>').dialog(); + closeEnough(el.dialog('widget').width(), 300, 1, "default width"); el.remove(); el = $('<div></div>').dialog({width: 437 }); - equal(dlg().width(), 437, "explicit width"); + closeEnough(el.dialog('widget').width(), 437, 1, "explicit width"); el.dialog('option', 'width', 438); - equal(dlg().width(), 438, 'explicit width after init'); + closeEnough(el.dialog('widget').width(), 438, 1, 'explicit width after init'); el.remove(); }); |