2009-02-02 14:36:08 +00:00
|
|
|
/*
|
|
|
|
* dialog_methods.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2009-09-15 15:42:41 +00:00
|
|
|
module("dialog: methods", {
|
|
|
|
teardown: function() {
|
|
|
|
$("body>.ui-dialog").remove();
|
|
|
|
}
|
|
|
|
});
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2009-02-04 04:35:18 +00:00
|
|
|
test("init", function() {
|
2010-08-27 18:48:17 +00:00
|
|
|
expect(6);
|
2009-02-04 04:35:18 +00:00
|
|
|
|
|
|
|
$("<div></div>").appendTo('body').dialog().remove();
|
|
|
|
ok(true, '.dialog() called on element');
|
|
|
|
|
|
|
|
$([]).dialog().remove();
|
|
|
|
ok(true, '.dialog() called on empty collection');
|
|
|
|
|
|
|
|
$('<div></div>').dialog().remove();
|
|
|
|
ok(true, '.dialog() called on disconnected DOMElement - never connected');
|
|
|
|
|
|
|
|
$('<div></div>').appendTo('body').remove().dialog().remove();
|
|
|
|
ok(true, '.dialog() called on disconnected DOMElement - removed');
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el = $('<div></div>').dialog();
|
2012-10-23 14:36:42 +00:00
|
|
|
el.dialog("option", "foo");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
ok(true, 'arbitrary option getter after init');
|
|
|
|
|
2009-11-09 01:50:23 +00:00
|
|
|
$('<div></div>').dialog().dialog("option", "foo", "bar").remove();
|
2009-02-04 04:35:18 +00:00
|
|
|
ok(true, 'arbitrary option setter after init');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
2012-11-16 18:33:55 +00:00
|
|
|
expect( 6 );
|
|
|
|
domEqual( "#dialog1", function() {
|
|
|
|
var dialog = $( "#dialog1" ).dialog().dialog( "destroy" );
|
|
|
|
equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] );
|
|
|
|
equal( dialog.index(), 0 );
|
|
|
|
});
|
|
|
|
domEqual( "#form-dialog", function() {
|
|
|
|
var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" );
|
|
|
|
equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] );
|
|
|
|
equal( dialog.index(), 2 );
|
|
|
|
});
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
2012-11-17 10:31:57 +00:00
|
|
|
test( "enable/disable disabled", function() {
|
|
|
|
expect( 2 );
|
|
|
|
var el = $( "<div></div>" ).dialog();
|
|
|
|
el.dialog( "disable" );
|
|
|
|
equal(el.dialog( "option", "disabled" ), false, "disable method doesn't do anything" );
|
|
|
|
ok( !el.dialog( "widget" ).hasClass( "ui-dialog-disabled" ), "disable method doesn't add ui-dialog-disabled class" );
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("close", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el,
|
|
|
|
expected = $('<div></div>').dialog(),
|
2009-04-15 02:33:28 +00:00
|
|
|
actual = expected.dialog('close');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(actual, expected, 'close is chainable');
|
|
|
|
|
2009-09-19 09:49:00 +00:00
|
|
|
el = $('<div></div>').dialog();
|
2012-11-03 20:17:16 +00:00
|
|
|
ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog visible before close method called');
|
2009-09-19 09:49:00 +00:00
|
|
|
el.dialog('close');
|
2012-11-03 20:17:16 +00:00
|
|
|
ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog hidden after close method called');
|
2009-02-04 04:35:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isOpen", function() {
|
|
|
|
expect(4);
|
|
|
|
|
2012-11-03 20:17:16 +00:00
|
|
|
var el = $('<div></div>').dialog();
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('isOpen'), true, "dialog is open after init");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.dialog('close');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('isOpen'), false, "dialog is closed");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
|
|
|
|
|
|
|
el = $('<div></div>').dialog({autoOpen: false});
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('isOpen'), false, "dialog is closed after init");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.dialog('open');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.dialog('isOpen'), true, "dialog is open");
|
2009-02-04 04:35:18 +00:00
|
|
|
el.remove();
|
2009-02-02 14:36:08 +00:00
|
|
|
});
|
|
|
|
|
2009-04-15 02:33:28 +00:00
|
|
|
test("moveToTop", function() {
|
2012-10-15 20:12:21 +00:00
|
|
|
expect( 5 );
|
|
|
|
function order() {
|
|
|
|
var actual = $( ".ui-dialog" ).map(function() {
|
|
|
|
return +$( this ).find( ".ui-dialog-content" ).attr( "id" ).replace( /\D+/, "" );
|
|
|
|
}).get().reverse();
|
|
|
|
deepEqual( actual, $.makeArray( arguments ) );
|
|
|
|
}
|
|
|
|
var dialog1, dialog2,
|
|
|
|
focusOn = "dialog1";
|
|
|
|
dialog1 = $( "#dialog1" ).dialog({
|
|
|
|
focus: function() {
|
|
|
|
equal( focusOn, "dialog1" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
focusOn = "dialog2";
|
|
|
|
dialog2 = $( "#dialog2" ).dialog({
|
|
|
|
focus: function() {
|
|
|
|
equal( focusOn, "dialog2" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
order( 2, 1 );
|
|
|
|
focusOn = "dialog1";
|
|
|
|
dialog1.dialog( "moveToTop" );
|
|
|
|
order( 1, 2 );
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("open", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
expect( 3 );
|
2012-11-03 20:17:16 +00:00
|
|
|
var el,
|
|
|
|
expected = $('<div></div>').dialog(),
|
2009-04-15 02:33:28 +00:00
|
|
|
actual = expected.dialog('open');
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(actual, expected, 'open is chainable');
|
2009-09-19 09:49:00 +00:00
|
|
|
|
|
|
|
el = $('<div></div>').dialog({ autoOpen: false });
|
2012-11-03 20:17:16 +00:00
|
|
|
ok(el.dialog('widget').is(':hidden') && !el.dialog('widget').is(':visible'), 'dialog hidden before open method called');
|
2009-09-19 09:49:00 +00:00
|
|
|
el.dialog('open');
|
2012-11-03 20:17:16 +00:00
|
|
|
ok(el.dialog('widget').is(':visible') && !el.dialog('widget').is(':hidden'), 'dialog visible after open method called');
|
2009-04-15 02:33:28 +00:00
|
|
|
});
|
|
|
|
|
2009-02-02 14:36:08 +00:00
|
|
|
})(jQuery);
|