jquery-ui/tests/unit/dialog/dialog_events.js

217 lines
5.7 KiB
JavaScript

/*
* dialog_events.js
*/
(function($) {
module("dialog: events");
test("open", function() {
expect(11);
el = $("<div></div>");
el.dialog({
open: function(ev, ui) {
ok(true, 'autoOpen: true fires open callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogopen', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
});
el.remove();
el = $("<div></div>");
el.dialog({
autoOpen: false,
open: function(ev, ui) {
ok(true, '.dialog("open") fires open callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogopen', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogopen', function(ev, ui) {
ok(true, 'dialog("open") fires open event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
el.dialog("open");
el.remove();
});
test("dragStart", function() {
expect(7);
el = $('<div></div>').dialog({
dragStart: function(ev, ui) {
ok(true, 'dragging fires dragStart callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogdragStart', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogdragStart', function(ev, ui) {
ok(true, 'dragging fires dialogdragStart event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-dialog-titlebar", dlg());
drag(handle, 50, 50);
el.remove();
});
test("drag", function() {
expect(7);
var hasDragged = false;
el = $('<div></div>').dialog({
drag: function(ev, ui) {
if (!hasDragged) {
ok(true, 'dragging fires drag callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogdrag', 'event type in callback');
same(ui, {}, 'ui hash in callback');
hasDragged = true;
}
}
}).one('dialogdrag', function(ev, ui) {
ok(true, 'dragging fires dialogdrag event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-dialog-titlebar", dlg());
drag(handle, 50, 50);
el.remove();
});
test("dragStop", function() {
expect(7);
el = $('<div></div>').dialog({
dragStart: function(ev, ui) {
ok(true, 'dragging fires dragStop callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogdragStop', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogdragStop', function(ev, ui) {
ok(true, 'dragging fires dialogdragStop event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-dialog-titlebar", dlg());
drag(handle, 50, 50);
el.remove();
});
test("resizeStart", function() {
expect(7);
el = $('<div></div>').dialog({
resizeStart: function(ev, ui) {
ok(true, 'resizing fires resizeStart callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogresizeStart', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogresizeStart', function(ev, ui) {
ok(true, 'resizing fires dialogresizeStart event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-resizable-se", dlg());
drag(handle, 50, 50);
el.remove();
});
test("resize", function() {
expect(7);
var hasResized = false;
el = $('<div></div>').dialog({
resize: function(ev, ui) {
if (!hasResized) {
ok(true, 'resizing fires resize callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogresize', 'event type in callback');
same(ui, {}, 'ui hash in callback');
hasResized = true;
}
}
}).one('dialogresize', function(ev, ui) {
ok(true, 'resizing fires dialogresize event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-resizable-se", dlg());
drag(handle, 50, 50);
el.remove();
});
test("resizeStop", function() {
expect(7);
el = $('<div></div>').dialog({
resizeStop: function(ev, ui) {
ok(true, 'resizing fires resizeStop callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogresizeStop', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogresizeStop', function(ev, ui) {
ok(true, 'resizing fires dialogresizeStop event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
var handle = $(".ui-resizable-se", dlg());
drag(handle, 50, 50);
el.remove();
});
test("close", function() {
expect(7);
el = $('<div></div>').dialog({
close: function(ev, ui) {
ok(true, '.dialog("close") fires close callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogclose', 'event type in callback');
same(ui, {}, 'ui hash in callback');
}
}).bind('dialogclose', function(ev, ui) {
ok(true, '.dialog("close") fires dialogclose event');
equals(this, el[0], 'context of event');
same(ui, {}, 'ui hash in event');
});
el.dialog('close');
el.remove();
});
test("beforeclose", function() {
expect(9);
el = $('<div></div>').dialog({
beforeclose: function(ev, ui) {
ok(true, '.dialog("close") fires beforeclose callback');
equals(this, el[0], "context of callback");
equals(ev.type, 'dialogbeforeclose', 'event type in callback');
same(ui, {}, 'ui hash in callback');
return false;
}
});
el.dialog('close');
isOpen('beforeclose callback should prevent dialog from closing');
el.remove();
el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) {
ok(true, '.dialog("close") triggers dialogbeforeclose event');
equals(this, el[0], "context of event");
same(ui, {}, 'ui hash in event');
return false;
});
el.dialog('close');
isOpen('dialogbeforeclose event should prevent dialog from closing');
el.remove();
});
})(jQuery);