diff options
author | Amanpreet Singh <apsdehal@gmail.com> | 2016-04-03 21:40:09 +0530 |
---|---|---|
committer | Amanpreet Singh <apsdehal@gmail.com> | 2016-04-14 00:06:12 +0530 |
commit | 86fd11d5a73c1500d0efef07653f69c0e58e2db3 (patch) | |
tree | 23170d66901fda310296fe047dba86d3a414441c /tests | |
parent | e8e886770757bc21ddb1151fbbd956c031a8e2c4 (diff) | |
download | jquery-ui-86fd11d5a73c1500d0efef07653f69c0e58e2db3.tar.gz jquery-ui-86fd11d5a73c1500d0efef07653f69c0e58e2db3.zip |
Dialog: Shift to use no globals
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/dialog/core.js | 129 | ||||
-rw-r--r-- | tests/unit/dialog/deprecated.js | 9 | ||||
-rw-r--r-- | tests/unit/dialog/events.js | 301 | ||||
-rw-r--r-- | tests/unit/dialog/helper.js | 13 | ||||
-rw-r--r-- | tests/unit/dialog/methods.js | 159 | ||||
-rw-r--r-- | tests/unit/dialog/options.js | 274 |
6 files changed, 454 insertions, 431 deletions
diff --git a/tests/unit/dialog/core.js b/tests/unit/dialog/core.js index 7008a832d..3b89a6638 100644 --- a/tests/unit/dialog/core.js +++ b/tests/unit/dialog/core.js @@ -1,13 +1,14 @@ define( [ + "qunit", "jquery", "ui/widgets/dialog" -], function( $ ) { +], function( QUnit, $ ) { // TODO add teardown callback to remove dialogs -module( "dialog: core" ); +QUnit.module( "dialog: core" ); -test( "markup structure", function( assert ) { - expect( 11 ); +QUnit.test( "markup structure", function( assert ) { + assert.expect( 11 ); var element = $( "<div>" ).dialog( { buttons: [ { @@ -25,20 +26,20 @@ test( "markup structure", function( assert ) { assert.hasClasses( widget, "ui-dialog ui-dialog-buttons ui-widget ui-widget-content" ); assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" ); - equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); + assert.equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" ); - equal( close.length, 1, "Titlebar has exactly one close button" ); - equal( title.length, 1, "Titlebar has exactly one title" ); + assert.equal( close.length, 1, "Titlebar has exactly one close button" ); + assert.equal( title.length, 1, "Titlebar has exactly one title" ); assert.hasClasses( element, "ui-dialog-content ui-widget-content" ); assert.hasClasses( buttonpane, "ui-dialog-buttonpane ui-widget-content" ); - equal( buttonpane.length, 1, "Dialog has exactly one buttonpane" ); - equal( buttonset.length, 1, "Buttonpane has exactly one buttonset" ); - equal( buttons.length, 1, "Buttonset contains exactly 1 button when created with 1" ); + assert.equal( buttonpane.length, 1, "Dialog has exactly one buttonpane" ); + assert.equal( buttonset.length, 1, "Buttonpane has exactly one buttonset" ); + assert.equal( buttons.length, 1, "Buttonset contains exactly 1 button when created with 1" ); } ); -test( "markup structure - no buttons", function( assert ) { - expect( 7 ); +QUnit.test( "markup structure - no buttons", function( assert ) { + assert.expect( 7 ); var element = $( "<div>" ).dialog(), widget = element.dialog( "widget" ), @@ -48,48 +49,49 @@ test( "markup structure - no buttons", function( assert ) { assert.hasClasses( widget, "ui-dialog ui-widget ui-widget-content" ); assert.hasClasses( titlebar, "ui-dialog-titlebar ui-widget-header" ); - equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); + assert.equal( titlebar.length, 1, "Dialog has exactly one titlebar" ); assert.hasClasses( close, "ui-dialog-titlebar-close ui-widget" ); - equal( close.length, 1, "Titlebar has exactly one close button" ); - equal( title.length, 1, "Titlebar has exactly one title" ); + assert.equal( close.length, 1, "Titlebar has exactly one close button" ); + assert.equal( title.length, 1, "Titlebar has exactly one title" ); assert.hasClasses( element, "ui-dialog-content ui-widget-content" ); } ); -test( "title id", function() { - expect( 1 ); +QUnit.test( "title id", function( assert ) { + assert.expect( 1 ); var titleId, element = $( "<div>" ).dialog(); titleId = element.dialog( "widget" ).find( ".ui-dialog-title" ).attr( "id" ); - ok( /ui-id-\d+$/.test( titleId ), "auto-numbered title id" ); + assert.ok( /ui-id-\d+$/.test( titleId ), "auto-numbered title id" ); element.remove(); } ); -test( "ARIA", function() { - expect( 4 ); +QUnit.test( "ARIA", function( assert ) { + assert.expect( 4 ); var element = $( "<div>" ).dialog(), wrapper = element.dialog( "widget" ); - equal( wrapper.attr( "role" ), "dialog", "dialog role" ); - equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) ); - equal( wrapper.attr( "aria-describedby" ), element.attr( "id" ), "aria-describedby added" ); + assert.equal( wrapper.attr( "role" ), "dialog", "dialog role" ); + assert.equal( wrapper.attr( "aria-labelledby" ), wrapper.find( ".ui-dialog-title" ).attr( "id" ) ); + assert.equal( wrapper.attr( "aria-describedby" ), element.attr( "id" ), "aria-describedby added" ); element.remove(); element = $( "<div><div aria-describedby='section2'><p id='section2'>descriotion</p></div></div>" ).dialog(); - equal( element.dialog( "widget" ).attr( "aria-describedby" ), null, "no aria-describedby added, as already present in markup" ); + assert.equal( element.dialog( "widget" ).attr( "aria-describedby" ), null, "no aria-describedby added, as already present in markup" ); element.remove(); } ); -test( "widget method", function() { - expect( 1 ); +QUnit.test( "widget method", function( assert ) { + assert.expect( 1 ); var dialog = $( "<div>" ).appendTo( "#qunit-fixture" ).dialog(); - deepEqual( dialog.parent()[ 0 ], dialog.dialog( "widget" )[ 0 ] ); + assert.deepEqual( dialog.parent()[ 0 ], dialog.dialog( "widget" )[ 0 ] ); dialog.remove(); } ); -asyncTest( "focus tabbable", function() { - expect( 8 ); +QUnit.test( "focus tabbable", function( assert ) { + var ready = assert.async(); + assert.expect( 8 ); var element, options = { buttons: [ { @@ -119,7 +121,7 @@ asyncTest( "focus tabbable", function() { var input = element.find( "input:last" ).trigger( "focus" ).trigger( "blur" ); element.dialog( "instance" )._focusTabbable(); setTimeout( function() { - equal( document.activeElement, input[ 0 ], + assert.equal( document.activeElement, input[ 0 ], "1. an element that was focused previously." ); done(); } ); @@ -128,7 +130,7 @@ asyncTest( "focus tabbable", function() { function step2() { checkFocus( "<div><input><input autofocus></div>", options, function( done ) { - equal( document.activeElement, element.find( "input" )[ 1 ], + assert.equal( document.activeElement, element.find( "input" )[ 1 ], "2. first element inside the dialog matching [autofocus]" ); done(); }, step3 ); @@ -136,7 +138,7 @@ asyncTest( "focus tabbable", function() { function step3() { checkFocus( "<div><input><input></div>", options, function( done ) { - equal( document.activeElement, element.find( "input" )[ 0 ], + assert.equal( document.activeElement, element.find( "input" )[ 0 ], "3. tabbable element inside the content element" ); done(); }, step4 ); @@ -144,7 +146,7 @@ asyncTest( "focus tabbable", function() { function step4() { checkFocus( "<div>text</div>", options, function( done ) { - equal( document.activeElement, + assert.equal( document.activeElement, element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" )[ 0 ], "4. tabbable element inside the buttonpane" ); done(); @@ -153,7 +155,7 @@ asyncTest( "focus tabbable", function() { function step5() { checkFocus( "<div>text</div>", {}, function( done ) { - equal( document.activeElement, + assert.equal( document.activeElement, element.dialog( "widget" ).find( ".ui-dialog-titlebar .ui-dialog-titlebar-close" )[ 0 ], "5. the close button" ); done(); @@ -165,7 +167,7 @@ asyncTest( "focus tabbable", function() { element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).hide(); element.dialog( "open" ); setTimeout( function() { - equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" ); + assert.equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" ); done(); } ); }, step7 ); @@ -184,36 +186,39 @@ asyncTest( "focus tabbable", function() { } }, function( done ) { - var inputs = element.find( "input" ); - equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" ); + var inputs = element.find( "input" + ); + assert.equal + ( document.activeElement, inputs[ 1 ], "Focus starts on second input" ); inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB } ); setTimeout( function() { - equal( document.activeElement, inputs[ 0 ], + assert.equal( document.activeElement, inputs[ 0 ], "Honor preventDefault, allowing custom focus management" ); done(); }, 50 ); }, - start + ready ); } step1(); } ); -test( "#7960: resizable handles below modal overlays", function() { - expect( 1 ); +QUnit.test( "#7960: resizable handles below modal overlays", function( assert ) { + assert.expect( 1 ); var resizable = $( "<div>" ).resizable(), dialog = $( "<div>" ).dialog( { modal: true } ), resizableZindex = parseInt( resizable.find( ".ui-resizable-handle" ).css( "zIndex" ), 10 ), overlayZindex = parseInt( $( ".ui-widget-overlay" ).css( "zIndex" ), 10 ); - ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" ); + assert.ok( resizableZindex < overlayZindex, "Resizable handles have lower z-index than modal overlay" ); dialog.dialog( "destroy" ); } ); -asyncTest( "Prevent tabbing out of dialogs", function() { - expect( 3 ); +QUnit.test( "Prevent tabbing out of dialogs", function( assert ) { + var ready = assert.async(); + assert.expect( 3 ); var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(), inputs = element.find( "input" ); @@ -222,7 +227,7 @@ asyncTest( "Prevent tabbing out of dialogs", function() { element.dialog( "widget" ).find( ".ui-button" ).remove(); function checkTab() { - equal( document.activeElement, inputs[ 0 ], "Tab key event moved focus within the modal" ); + assert.equal( document.activeElement, inputs[ 0 ], "Tab key event move d focus within the modal" ); // Check shift tab $( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true } ); @@ -230,23 +235,25 @@ asyncTest( "Prevent tabbing out of dialogs", function() { } function checkShiftTab() { - equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" ); + assert.equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" ); element.remove(); - setTimeout( start ); + setTimeout( ready ); } inputs[ 1 ].focus(); setTimeout( function() { - equal( document.activeElement, inputs[ 1 ], "Focus set on second input" ); + assert.equal( document.activeElement, inputs[ 1 ], "Focus set on second input" ); inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } ); setTimeout( checkTab ); } ); } ); -asyncTest( "#9048: multiple modal dialogs opened and closed in different order", function() { - expect( 1 ); +QUnit.test( "#9048: multiple modal dialogs opened and closed in different order", + function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); $( "#dialog1, #dialog2" ).dialog( { autoOpen: false, modal:true } ); $( "#dialog1" ).dialog( "open" ); $( "#dialog2" ).dialog( "open" ); @@ -254,19 +261,20 @@ asyncTest( "#9048: multiple modal dialogs opened and closed in different order", setTimeout( function() { $( "#dialog2" ).dialog( "close" ); $( "#favorite-animal" ).trigger( "focus" ); - ok( true, "event handlers cleaned up (no errors thrown)" ); - start(); + assert.ok( true, "event handlers cleaned up (no errors thrown)" ); + ready(); } ); } ); -asyncTest( "interaction between overlay and other dialogs", function() { +QUnit.test( "interaction between overlay and other dialogs", function( assert ) { + var ready = assert.async(); $.widget( "ui.testWidget", $.ui.dialog, { options: { modal: true, autoOpen: false } } ); - expect( 2 ); + assert.expect( 2 ); var first = $( "<div><input id='input-1'></div>" ).dialog( { modal: true } ), @@ -281,25 +289,28 @@ asyncTest( "interaction between overlay and other dialogs", function() { // Wait for the modal to init setTimeout( function() { - second.testWidget( "open" ); - // Simulate user tabbing from address bar to an element outside the dialog + second. + testWidget + ( "open" ); + + // Simulate user tabbing from address bar to an element outside the dialog $( "#favorite-animal" ).trigger( "focus" ); setTimeout( function() { - equal( document.activeElement, secondInput[ 0 ] ); + assert.equal( document.activeElement, secondInput[ 0 ] ); // Last active dialog must receive focus firstInput.trigger( "focus" ); $( "#favorite-animal" ).trigger( "focus" ); setTimeout( function() { - equal( document.activeElement, firstInput[ 0 ] ); + assert.equal( document.activeElement, firstInput[ 0 ] ); // Cleanup first.remove(); second.remove(); delete $.ui.testWidget; delete $.fn.testWidget; - start(); + ready(); } ); } ); } ); diff --git a/tests/unit/dialog/deprecated.js b/tests/unit/dialog/deprecated.js index 1a6794338..960bf0dc4 100644 --- a/tests/unit/dialog/deprecated.js +++ b/tests/unit/dialog/deprecated.js @@ -1,12 +1,13 @@ define( [ + "qunit", "jquery", "ui/widgets/dialog" -], function( $ ) { +], function( QUnit, $ ) { -module( "dialog (deprecated): options" ); +QUnit.module( "dialog (deprecated): options" ); -test( "dialogClass", function( assert ) { - expect( 5 ); +QUnit.test( "dialogClass", function( assert ) { + assert.expect( 5 ); var element = $( "<div>" ).dialog(), widget = element.dialog( "widget" ); diff --git a/tests/unit/dialog/events.js b/tests/unit/dialog/events.js index dd1f4055a..a5030a9f4 100644 --- a/tests/unit/dialog/events.js +++ b/tests/unit/dialog/events.js @@ -1,22 +1,23 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/dialog" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "dialog: events" ); +QUnit.module( "dialog: events" ); -test( "open", function() { - expect( 13 ); +QUnit.test( "open", function( assert ) { + assert.expect( 13 ); var element = $( "<div></div>" ); element.dialog( { open: function( ev, ui ) { - ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); - ok( true, "autoOpen: true fires open callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogopen", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); + assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); + assert.ok( true, "autoOpen: true fires open callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogopen", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); } } ); element.remove(); @@ -25,23 +26,23 @@ test( "open", function() { element.dialog( { autoOpen: false, open: function( ev, ui ) { - ok( true, ".dialog('open') fires open callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogopen", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); + assert.ok( true, ".dialog('open') fires open callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogopen", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); } } ).on( "dialogopen", function( ev, ui ) { - ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); - ok( true, "dialog('open') fires open event" ); - equal( this, element[ 0 ], "context of event" ); - deepEqual( ui, {}, "ui hash in event" ); + assert.ok( element.dialog( "instance" )._isOpen, "interal _isOpen flag is set" ); + assert.ok( true, "dialog('open') fires open event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.deepEqual( ui, {}, "ui hash in event" ); } ); element.dialog( "open" ); element.remove(); } ); -test( "focus", function() { - expect( 5 ); +QUnit.test( "focus", function( assert ) { + assert.expect( 5 ); var element, other; element = $( "#dialog1" ).dialog( { autoOpen: false @@ -51,27 +52,27 @@ test( "focus", function() { } ); element.one( "dialogopen", function() { - ok( true, "open, just once" ); + assert.ok( true, "open, just once" ); } ); element.one( "dialogfocus", function() { - ok( true, "focus on open" ); + assert.ok( true, "focus on open" ); } ); other.dialog( "open" ); element.one( "dialogfocus", function() { - ok( true, "when opening and already open and wasn't on top" ); + assert.ok( true, "when opening and already open and wasn't on top" ); } ); other.dialog( "open" ); element.dialog( "open" ); element.one( "dialogfocus", function() { - ok( true, "when calling moveToTop and wasn't on top" ); + assert.ok( true, "when calling moveToTop and wasn't on top" ); } ); other.dialog( "moveToTop" ); element.dialog( "moveToTop" ); element.on( "dialogfocus", function() { - ok( true, "when mousedown anywhere on the dialog and it wasn't on top" ); + assert.ok( true, "when mousedown anywhere on the dialog and it wasn't on top" ); } ); other.dialog( "moveToTop" ); element.trigger( "mousedown" ); @@ -84,23 +85,23 @@ test( "focus", function() { element.add( other ).remove(); } ); -test( "dragStart", function() { - expect( 9 ); +QUnit.test( "dragStart", function( assert ) { + assert.expect( 9 ); var handle, element = $( "<div></div>" ).dialog( { dragStart: function( ev, ui ) { - ok( true, "dragging fires dragStart callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogdragstart", "event type in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires dragStart callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogdragstart", "event type in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); } } ).on( "dialogdragstart", function( ev, ui ) { - ok( true, "dragging fires dialogdragstart event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires dialogdragstart event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); } ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); @@ -108,27 +109,27 @@ test( "dragStart", function() { element.remove(); } ); -test( "drag", function() { - expect( 9 ); +QUnit.test( "drag", function( assert ) { + assert.expect( 9 ); var handle, hasDragged = false, element = $( "<div></div>" ).dialog( { drag: function( ev, ui ) { if ( !hasDragged ) { - ok( true, "dragging fires drag callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogdrag", "event type in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires drag callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogdrag", "event type in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); hasDragged = true; } } } ).one( "dialogdrag", function( ev, ui ) { - ok( true, "dragging fires dialogdrag event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires dialogdrag event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); } ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); @@ -136,23 +137,23 @@ test( "drag", function() { element.remove(); } ); -test( "dragStop", function() { - expect( 9 ); +QUnit.test( "dragStop", function( assert ) { + assert.expect( 9 ); var handle, element = $( "<div></div>" ).dialog( { dragStop: function( ev, ui ) { - ok( true, "dragging fires dragStop callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogdragstop", "event type in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires dragStop callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogdragstop", "event type in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); } } ).on( "dialogdragstop", function( ev, ui ) { - ok( true, "dragging fires dialogdragstop event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.offset !== undefined, "ui.offset in callback" ); + assert.ok( true, "dragging fires dialogdragstop event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.offset !== undefined, "ui.offset in callback" ); } ); handle = $( ".ui-dialog-titlebar", element.dialog( "widget" ) ); @@ -160,27 +161,27 @@ test( "dragStop", function() { element.remove(); } ); -test( "resizeStart", function() { - expect( 13 ); +QUnit.test( "resizeStart", function( assert ) { + assert.expect( 13 ); var handle, element = $( "<div></div>" ).dialog( { resizeStart: function( ev, ui ) { - ok( true, "resizing fires resizeStart callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogresizestart", "event type in callback" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires resizeStart callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogresizestart", "event type in callback" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); } } ).on( "dialogresizestart", function( ev, ui ) { - ok( true, "resizing fires dialogresizestart event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires dialogresizestart event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); } ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); @@ -188,31 +189,31 @@ test( "resizeStart", function() { element.remove(); } ); -test( "resize", function() { - expect( 13 ); +QUnit.test( "resize", function( assert ) { + assert.expect( 13 ); var handle, hasResized = false, element = $( "<div></div>" ).dialog( { resize: function( ev, ui ) { if ( !hasResized ) { - ok( true, "resizing fires resize callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogresize", "event type in callback" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires resize callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogresize", "event type in callback" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); hasResized = true; } } } ).one( "dialogresize", function( ev, ui ) { - ok( true, "resizing fires dialogresize event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires dialogresize event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); } ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); @@ -220,27 +221,27 @@ test( "resize", function() { element.remove(); } ); -test( "resizeStop", function() { - expect( 13 ); +QUnit.test( "resizeStop", function( assert ) { + assert.expect( 13 ); var handle, element = $( "<div></div>" ).dialog( { resizeStop: function( ev, ui ) { - ok( true, "resizing fires resizeStop callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogresizestop", "event type in callback" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires resizeStop callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogresizestop", "event type in callback" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); } } ).on( "dialogresizestop", function( ev, ui ) { - ok( true, "resizing fires dialogresizestop event" ); - equal( this, element[ 0 ], "context of event" ); - ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); - ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); - ok( ui.position !== undefined, "ui.position in callback" ); - ok( ui.size !== undefined, "ui.size in callback" ); + assert.ok( true, "resizing fires dialogresizestop event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.ok( ui.originalPosition !== undefined, "ui.originalPosition in callback" ); + assert.ok( ui.originalSize !== undefined, "ui.originalSize in callback" ); + assert.ok( ui.position !== undefined, "ui.position in callback" ); + assert.ok( ui.size !== undefined, "ui.size in callback" ); } ); handle = $( ".ui-resizable-se", element.dialog( "widget" ) ); @@ -248,20 +249,21 @@ test( "resizeStop", function() { element.remove(); } ); -asyncTest( "close", function() { - expect( 14 ); +QUnit.test( "close", function( assert ) { + var ready = assert.async(); + assert.expect( 14 ); var element = $( "<div></div>" ).dialog( { close: function( ev, ui ) { - ok( true, ".dialog('close') fires close callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogclose", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); + assert.ok( true, ".dialog('close') fires close callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogclose", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); } } ).on( "dialogclose", function( ev, ui ) { - ok( true, ".dialog('close') fires dialogclose event" ); - equal( this, element[ 0 ], "context of event" ); - deepEqual( ui, {}, "ui hash in event" ); + assert.ok( true, ".dialog('close') fires dialogclose event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.deepEqual( ui, {}, "ui hash in event" ); } ); element.dialog( "close" ); element.remove(); @@ -270,100 +272,101 @@ asyncTest( "close", function() { element = $( "<div></div>" ).dialog( { hide: 10, close: function( ev, ui ) { - ok( true, ".dialog('close') fires close callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogclose", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); - start(); + assert.ok( true, ".dialog('close') fires close callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogclose", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); + ready(); } } ).on( "dialogclose", function( ev, ui ) { - ok( true, ".dialog('close') fires dialogclose event" ); - equal( this, element[ 0 ], "context of event" ); - deepEqual( ui, {}, "ui hash in event" ); + assert.ok( true, ".dialog('close') fires dialogclose event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.deepEqual( ui, {}, "ui hash in event" ); } ); element.dialog( "close" ); } ); -test( "beforeClose", function() { - expect( 14 ); +QUnit.test( "beforeClose", function( assert ) { + assert.expect( 14 ); var element = $( "<div></div>" ).dialog( { beforeClose: function( ev, ui ) { - ok( true, ".dialog('close') fires beforeClose callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogbeforeclose", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); + assert.ok( true, ".dialog('close') fires beforeClose callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogbeforeclose", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); return false; } } ); element.dialog( "close" ); - ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); element.remove(); element = $( "<div></div>" ).dialog(); element.dialog( "option", "beforeClose", function( ev, ui ) { - ok( true, ".dialog('close') fires beforeClose callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.type, "dialogbeforeclose", "event type in callback" ); - deepEqual( ui, {}, "ui hash in callback" ); + assert.ok( true, ".dialog('close') fires beforeClose callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.type, "dialogbeforeclose", "event type in callback" ); + assert.deepEqual( ui, {}, "ui hash in callback" ); return false; } ); element.dialog( "close" ); - ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ), "beforeClose callback should prevent dialog from closing" ); element.remove(); element = $( "<div></div>" ).dialog().on( "dialogbeforeclose", function( ev, ui ) { - ok( true, ".dialog('close') triggers dialogbeforeclose event" ); - equal( this, element[ 0 ], "context of event" ); - deepEqual( ui, {}, "ui hash in event" ); + assert.ok( true, ".dialog('close') triggers dialogbeforeclose event" ); + assert.equal( this, element[ 0 ], "context of event" ); + assert.deepEqual( ui, {}, "ui hash in event" ); return false; } ); element.dialog( "close" ); - ok( element.dialog( "widget" ).is( ":visible" ), "dialogbeforeclose event should prevent dialog from closing" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ), "dialogbeforeclose event should prevent dialog from closing" ); element.remove(); } ); // #8789 and #8838 -asyncTest( "ensure dialog's container doesn't scroll on resize and focus", function() { - expect( 2 ); +QUnit.test( "ensure dialog's container doesn't scroll on resize and focus", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var element = $( "#dialog1" ).dialog(), initialScroll = $( window ).scrollTop(); element.dialog( "option", "height", 600 ); - equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after height change" ); + assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after height change" ); setTimeout( function() { $( ".ui-dialog-titlebar-close" ).simulate( "mousedown" ); - equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog" ); + assert.equal( $( window ).scrollTop(), initialScroll, "scroll hasn't moved after focus moved to dialog" ); element.dialog( "destroy" ); - start(); + ready(); } ); } ); -test( "#5184: isOpen in dialogclose event is true", function() { - expect( 3 ); +QUnit.test( "#5184: isOpen in dialogclose event is true", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog( { close: function() { - ok( !element.dialog( "isOpen" ), "dialog is not open during close" ); + assert.ok( !element.dialog( "isOpen" ), "dialog is not open during close" ); } } ); - ok( element.dialog( "isOpen" ), "dialog is open after init" ); + assert.ok( element.dialog( "isOpen" ), "dialog is open after init" ); element.dialog( "close" ); - ok( !element.dialog( "isOpen" ), "dialog is not open after close" ); + assert.ok( !element.dialog( "isOpen" ), "dialog is not open after close" ); element.remove(); } ); -test( "ensure dialog keeps focus when clicking modal overlay", function() { - expect( 2 ); +QUnit.test( "ensure dialog keeps focus when clicking modal overlay", function( assert ) { + assert.expect( 2 ); var element = $( "<div></div>" ).dialog( { modal: true } ); - equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" ); + assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is in dialog" ); $( ".ui-widget-overlay" ).simulate( "mousedown" ); - equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" ); + assert.equal( $( document.activeElement ).closest( ".ui-dialog" ).length, 1, "focus is still in dialog" ); element.remove(); } ); diff --git a/tests/unit/dialog/helper.js b/tests/unit/dialog/helper.js index 9db5b5613..04c23202e 100644 --- a/tests/unit/dialog/helper.js +++ b/tests/unit/dialog/helper.js @@ -1,21 +1,22 @@ define( [ + "qunit", "jquery", "lib/helper", "ui/widgets/dialog" -], function( $, helper ) { +], function( QUnit, $, helper ) { return $.extend( helper, { drag: function( element, handle, dx, dy ) { var d = element.dialog( "widget" ); - //this mouseover is to work around a limitation in resizable + //This mouseover is to work around a limitation in resizable //TODO: fix resizable so handle doesn't require mouseover in order to be used $( handle, d ).simulate( "mouseover" ).simulate( "drag", { dx: dx, dy: dy } ); }, - testDrag: function( element, dx, dy, expectedDX, expectedDY, msg ) { + testDrag: function( assert, element, dx, dy, expectedDX, expectedDY, msg ) { var actualDX, actualDY, offsetAfter, d = element.dialog( "widget" ), handle = $( ".ui-dialog-titlebar", d ), @@ -29,13 +30,13 @@ return $.extend( helper, { actualDX = offsetAfter.left - offsetBefore.left; actualDY = offsetAfter.top - offsetBefore.top; - ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg ); + assert.ok( expectedDX - actualDX <= 1 && expectedDY - actualDY <= 1, "dragged[" + expectedDX + ", " + expectedDY + "] " + msg ); }, // TODO switch back to checking the size of the .ui-dialog element (var d) // once we switch to using box-sizing: border-box (#9845) that should work fine // using the element's dimensions to avoid subpixel errors - shouldResize: function( element, dw, dh, msg ) { + shouldResize: function( assert, element, dw, dh, msg ) { var heightAfter, widthAfter, actual, expected, d = element.dialog( "widget" ), handle = $( ".ui-resizable-se", d ), @@ -50,7 +51,7 @@ return $.extend( helper, { msg = msg ? msg + "." : ""; actual = { width: widthAfter, height: heightAfter }, expected = { width: widthBefore + dw, height: heightBefore + dh }; - deepEqual( actual, expected, "resized[" + 50 + ", " + 50 + "] " + msg ); + assert.deepEqual( actual, expected, "resized[" + 50 + ", " + 50 + "] " + msg ); } } ); diff --git a/tests/unit/dialog/methods.js b/tests/unit/dialog/methods.js index acb0f885a..a3e63ce7a 100644 --- a/tests/unit/dialog/methods.js +++ b/tests/unit/dialog/methods.js @@ -1,53 +1,54 @@ define( [ + "qunit", "jquery", "ui/widgets/dialog" -], function( $ ) { +], function( QUnit, $ ) { -module( "dialog: methods", { - teardown: function() { +QUnit.module( "dialog: methods", { + afterEach: function() { $( "body>.ui-dialog" ).remove(); } } ); -test( "init", function() { - expect( 6 ); +QUnit.test( "init", function( assert ) { + assert.expect( 6 ); $( "<div></div>" ).appendTo( "body" ).dialog().remove(); - ok( true, ".dialog() called on element" ); + assert.ok( true, ".dialog() called on element" ); $( [] ).dialog().remove(); - ok( true, ".dialog() called on empty collection" ); + assert.ok( true, ".dialog() called on empty collection" ); $( "<div></div>" ).dialog().remove(); - ok( true, ".dialog() called on disconnected DOMElement - never connected" ); + assert.ok( true, ".dialog() called on disconnected DOMElement - never connected" ); $( "<div></div>" ).appendTo( "body" ).remove().dialog().remove(); - ok( true, ".dialog() called on disconnected DOMElement - removed" ); + assert.ok( true, ".dialog() called on disconnected DOMElement - removed" ); var element = $( "<div></div>" ).dialog(); element.dialog( "option", "foo" ); element.remove(); - ok( true, "arbitrary option getter after init" ); + assert.ok( true, "arbitrary option getter after init" ); $( "<div></div>" ).dialog().dialog( "option", "foo", "bar" ).remove(); - ok( true, "arbitrary option setter after init" ); + assert.ok( true, "arbitrary option setter after init" ); } ); -test( "destroy", function( assert ) { - expect( 17 ); +QUnit.test( "destroy", function( assert ) { + assert.expect( 17 ); var element, element2; $( "#dialog1, #form-dialog" ).hide(); assert.domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); - equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); - equal( dialog.index(), 0 ); + assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); + assert.equal( dialog.index(), 0 ); } ); assert.domEqual( "#form-dialog", function() { var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" ); - equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); - equal( dialog.index(), 2 ); + assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); + assert.equal( dialog.index(), 2 ); } ); // Ensure dimensions are restored (#8119) @@ -62,102 +63,103 @@ test( "destroy", function( assert ) { // Don't throw errors when destroying a never opened modal dialog (#9004) $( "#dialog1" ).dialog( { autoOpen: false, modal: true } ).dialog( "destroy" ); - equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" ); - equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); + assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" ); + assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); element = $( "#dialog1" ).dialog( { modal: true } ), element2 = $( "#dialog2" ).dialog( { modal: true } ); - equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" ); - equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" ); + assert.equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" ); + assert.equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "close" ); - equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" ); - equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); + assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" ); + assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "destroy" ); - equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" ); - equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); + assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" ); + assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element2.dialog( "destroy" ); - equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" ); - equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); + assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" ); + assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); } ); -asyncTest( "#9000: Dialog leaves broken event handler after close/destroy in certain cases", function() { - expect( 1 ); +QUnit.test( "#9000: Dialog leaves broken event handler after close/destroy in certain cases", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); $( "#dialog1" ).dialog( { modal:true } ).dialog( "close" ).dialog( "destroy" ); setTimeout( function() { $( "#favorite-animal" ).trigger( "focus" ); - ok( true, "close and destroy modal dialog before its really opened" ); - start(); + assert.ok( true, "close and destroy modal dialog before its really opened" ); + ready(); } ); } ); -test( "#4980: Destroy should place element back in original DOM position", function() { - expect( 2 ); +QUnit.test( "#4980: Destroy should place element back in original DOM position", function( assert ) { + assert.expect( 2 ); var container = $( "<div id='container'><div id='modal'>Content</div></div>" ), modal = container.find( "#modal" ); modal.dialog(); - ok( !$.contains( container[ 0 ], modal[ 0 ] ), "dialog should move modal element to outside container element" ); + assert.ok( !$.contains( container[ 0 ], modal[ 0 ] ), "dialog should move modal element to outside container element" ); modal.dialog( "destroy" ); - ok( $.contains( container[ 0 ], modal[ 0 ] ), "dialog(destroy) should place element back in original DOM position" ); + assert.ok( $.contains( container[ 0 ], modal[ 0 ] ), "dialog(destroy) should place element back in original DOM position" ); } ); -test( "enable/disable disabled", function( assert ) { - expect( 3 ); +QUnit.test( "enable/disable disabled", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog(); element.dialog( "disable" ); - equal( element.dialog( "option", "disabled" ), false, "disable method doesn't do anything" ); + assert.equal( element.dialog( "option", "disabled" ), false, "disable method doesn't do anything" ); assert.lacksClasses( element, "ui-dialog-disabled ui-state-disabled", "disable method doesn't add classes" ); - ok( !element.dialog( "widget" ).attr( "aria-disabled" ), "disable method doesn't add aria-disabled" ); + assert.ok( !element.dialog( "widget" ).attr( "aria-disabled" ), "disable method doesn't add aria-disabled" ); } ); -test( "close", function() { - expect( 3 ); +QUnit.test( "close", function( assert ) { + assert.expect( 3 ); var element, expected = $( "<div></div>" ).dialog(), actual = expected.dialog( "close" ); - equal( actual, expected, "close is chainable" ); + assert.equal( actual, expected, "close is chainable" ); element = $( "<div></div>" ).dialog(); - ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible before close method called" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible before close method called" ); element.dialog( "close" ); - ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden after close method called" ); + assert.ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden after close method called" ); } ); -test( "isOpen", function() { - expect( 4 ); +QUnit.test( "isOpen", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - equal( element.dialog( "isOpen" ), true, "dialog is open after init" ); + assert.equal( element.dialog( "isOpen" ), true, "dialog is open after init" ); element.dialog( "close" ); - equal( element.dialog( "isOpen" ), false, "dialog is closed" ); + assert.equal( element.dialog( "isOpen" ), false, "dialog is closed" ); element.remove(); element = $( "<div></div>" ).dialog( { autoOpen: false } ); - equal( element.dialog( "isOpen" ), false, "dialog is closed after init" ); + assert.equal( element.dialog( "isOpen" ), false, "dialog is closed after init" ); element.dialog( "open" ); - equal( element.dialog( "isOpen" ), true, "dialog is open" ); + assert.equal( element.dialog( "isOpen" ), true, "dialog is open" ); element.remove(); } ); -test( "moveToTop", function() { - expect( 5 ); +QUnit.test( "moveToTop", function( assert ) { + assert.expect( 5 ); function order() { var actual = $( ".ui-dialog" ).map( function() { return +$( this ).css( "z-index" ); } ).get(); - deepEqual( actual, $.makeArray( arguments ) ); + assert.deepEqual( actual, $.makeArray( arguments ) ); } var dialog1, dialog2, focusOn = "dialog1"; dialog1 = $( "#dialog1" ).dialog( { focus: function() { - equal( focusOn, "dialog1" ); + assert.equal( focusOn, "dialog1" ); } } ); focusOn = "dialog2"; dialog2 = $( "#dialog2" ).dialog( { focus: function() { - equal( focusOn, "dialog2" ); + assert.equal( focusOn, "dialog2" ); } } ); order( 100, 101 ); @@ -166,57 +168,58 @@ test( "moveToTop", function() { order( 102, 101 ); } ); -test( "moveToTop: content scroll stays intact", function() { - expect( 2 ); +QUnit.test( "moveToTop: content scroll stays intact", function( assert ) { + assert.expect( 2 ); var otherDialog = $( "#dialog1" ).dialog(), scrollDialog = $( "#form-dialog" ).dialog( { height: 200 } ); scrollDialog.scrollTop( 50 ); - equal( scrollDialog.scrollTop(), 50 ); + assert.equal( scrollDialog.scrollTop(), 50 ); otherDialog.dialog( "moveToTop" ); - equal( scrollDialog.scrollTop(), 50 ); + assert.equal( scrollDialog.scrollTop(), 50 ); } ); -test( "open", function() { - expect( 3 ); +QUnit.test( "open", function( assert ) { + assert.expect( 3 ); var element, expected = $( "<div></div>" ).dialog(), actual = expected.dialog( "open" ); - equal( actual, expected, "open is chainable" ); + assert.equal( actual, expected, "open is chainable" ); element = $( "<div></div>" ).dialog( { autoOpen: false } ); - ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden before open method called" ); + assert.ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden before open method called" ); element.dialog( "open" ); - ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible after open method called" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible after open method called" ); } ); // http://bugs.jqueryui.com/ticket/6137 -test( "Ensure form elements don't reset when opening a dialog", function() { - expect( 2 ); +QUnit.test( "Ensure form elements don't reset when opening a dialog", function( assert ) { + assert.expect( 2 ); var d1 = $( "<form><input type='radio' name='radio' id='a' value='a' checked='checked'></input>" + "<input type='radio' name='radio' id='b' value='b'>b</input></form>" ).appendTo( "body" ).dialog( { autoOpen: false } ); d1.find( "#b" ).prop( "checked", true ); - equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); + assert.equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); d1.dialog( "open" ); - equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); + assert.equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); d1.remove(); } ); -asyncTest( "#8958: dialog can be opened while opening", function() { - expect( 1 ); +QUnit.test( "#8958: dialog can be opened while opening", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "<div>" ).dialog( { autoOpen: false, modal: true, open: function() { - equal( $( ".ui-widget-overlay" ).length, 1 ); - start(); + assert.equal( $( ".ui-widget-overlay" ).length, 1 ); + ready(); } } ); @@ -244,24 +247,24 @@ asyncTest( "#8958: dialog can be opened while opening", function() { .trigger( "focus" ); } ); -test( "#5531: dialog width should be at least minWidth on creation", function() { - expect( 4 ); +QUnit.test( "#5531: dialog width should be at least minWidth on creation", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog( { width: 200, minWidth: 300 } ); - equal( element.dialog( "option", "width" ), 300, "width is minWidth" ); + assert.equal( element.dialog( "option", "width" ), 300, "width is minWidth" ); element.dialog( "option", "width", 200 ); - equal( element.dialog( "option", "width" ), 300, "width unchanged when set to < minWidth" ); + assert.equal( element.dialog( "option", "width" ), 300, "width unchanged when set to < minWidth" ); element.dialog( "option", "width", 320 ); - equal( element.dialog( "option", "width" ), 320, "width changed if set to > minWidth" ); + assert.equal( element.dialog( "option", "width" ), 320, "width changed if set to > minWidth" ); element.remove(); element = $( "<div></div>" ).dialog( { minWidth: 300 } ); - ok( element.dialog( "option", "width" ) >= 300, "width is at least 300" ); + assert.ok( element.dialog( "option", "width" ) >= 300, "width is at least 300" ); element.remove(); } ); diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index ab9ace259..1be2888e3 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -1,110 +1,111 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/dialog", "ui/effects/effect-blind", "ui/effects/effect-explode" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "dialog: options" ); +QUnit.module( "dialog: options" ); -test( "appendTo", function() { - expect( 16 ); +QUnit.test( "appendTo", function( assert ) { + assert.expect( 16 ); var detached = $( "<div>" ), element = $( "#dialog1" ).dialog( { modal: true } ); - equal( element.dialog( "widget" ).parent()[ 0 ], document.body, "defaults to body" ); - equal( $( ".ui-widget-overlay" ).parent()[ 0 ], document.body, "overlay defaults to body" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], document.body, "defaults to body" ); + assert.equal( $( ".ui-widget-overlay" ).parent()[ 0 ], document.body, "overlay defaults to body" ); element.dialog( "destroy" ); element.dialog( { appendTo: ".wrap", modal: true } ); - equal( element.dialog( "widget" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "first found element" ); - equal( $( ".ui-widget-overlay" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "overlay first found element" ); - equal( $( "#wrap2 .ui-dialog" ).length, 0, "only appends to one element" ); - equal( $( "#wrap2 .ui-widget-overlay" ).length, 0, "overlay only appends to one element" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "first found element" ); + assert.equal( $( ".ui-widget-overlay" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "overlay first found element" ); + assert.equal( $( "#wrap2 .ui-dialog" ).length, 0, "only appends to one element" ); + assert.equal( $( "#wrap2 .ui-widget-overlay" ).length, 0, "overlay only appends to one element" ); element.dialog( "destroy" ); element.dialog( { appendTo: null, modal: true } ); - equal( element.dialog( "widget" ).parent()[ 0 ], document.body, "null" ); - equal( $( ".ui-widget-overlay" ).parent()[ 0 ], document.body, "overlay null" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], document.body, "null" ); + assert.equal( $( ".ui-widget-overlay" ).parent()[ 0 ], document.body, "overlay null" ); element.dialog( "destroy" ); element.dialog( { autoOpen: false, modal: true } ).dialog( "option", "appendTo", "#wrap1" ).dialog( "open" ); - equal( element.dialog( "widget" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "modified after init" ); - equal( $( ".ui-widget-overlay" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "overlay modified after init" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "modified after init" ); + assert.equal( $( ".ui-widget-overlay" ).parent()[ 0 ], $( "#wrap1" )[ 0 ], "overlay modified after init" ); element.dialog( "destroy" ); element.dialog( { appendTo: detached, modal: true } ); - equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached jQuery object" ); - equal( detached.find( ".ui-widget-overlay" ).parent()[ 0 ], detached[ 0 ], "overlay detached jQuery object" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached jQuery object" ); + assert.equal( detached.find( ".ui-widget-overlay" ).parent()[ 0 ], detached[ 0 ], "overlay detached jQuery object" ); element.dialog( "destroy" ); element.dialog( { appendTo: detached[ 0 ], modal: true } ); - equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached DOM element" ); - equal( detached.find( ".ui-widget-overlay" ).parent()[ 0 ], detached[ 0 ], "overlay detached DOM element" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached DOM element" ); + assert.equal( detached.find( ".ui-widget-overlay" ).parent()[ 0 ], detached[ 0 ], "overlay detached DOM element" ); element.dialog( "destroy" ); element.dialog( { autoOpen: false, modal: true } ).dialog( "option", "appendTo", detached ); - equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached DOM element via option()" ); - equal( detached.find( ".ui-widget-overlay" ).length, 0, "overlay detached DOM element via option()" ); + assert.equal( element.dialog( "widget" ).parent()[ 0 ], detached[ 0 ], "detached DOM element via option()" ); + assert.equal( detached.find( ".ui-widget-overlay" ).length, 0, "overlay detached DOM element via option()" ); element.dialog( "destroy" ); } ); -test( "autoOpen", function() { - expect( 2 ); +QUnit.test( "autoOpen", function( assert ) { + assert.expect( 2 ); var element = $( "<div></div>" ).dialog( { autoOpen: false } ); - ok( !element.dialog( "widget" ).is( ":visible" ), ".dialog({ autoOpen: false })" ); + assert.ok( !element.dialog( "widget" ).is( ":visible" ), ".dialog({ autoOpen: false })" ); element.remove(); element = $( "<div></div>" ).dialog( { autoOpen: true } ); - ok( element.dialog( "widget" ).is( ":visible" ), ".dialog({ autoOpen: true })" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ), ".dialog({ autoOpen: true })" ); element.remove(); } ); -test( "buttons", function( assert ) { - expect( 21 ); +QUnit.test( "buttons", function( assert ) { + assert.expect( 21 ); var btn, i, newButtons, buttons = { "Ok": function( ev ) { - ok( true, "button click fires callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.target, btn[ 0 ], "event target" ); + assert.ok( true, "button click fires callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.target, btn[ 0 ], "event target" ); }, "Cancel": function( ev ) { - ok( true, "button click fires callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.target, btn[ 1 ], "event target" ); + assert.ok( true, "button click fires callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.target, btn[ 1 ], "event target" ); } }, element = $( "<div></div>" ).dialog( { buttons: buttons } ); btn = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); - equal( btn.length, 2, "number of buttons" ); + assert.equal( btn.length, 2, "number of buttons" ); i = 0; $.each( buttons, function( key ) { - equal( btn.eq( i ).text(), key, "text of button " + ( i + 1 ) ); + assert.equal( btn.eq( i ).text(), key, "text of button " + ( i + 1 ) ); i++; } ); @@ -115,36 +116,36 @@ test( "buttons", function( assert ) { newButtons = { "Close": function( ev ) { - ok( true, "button click fires callback" ); - equal( this, element[ 0 ], "context of callback" ); - equal( ev.target, btn[ 0 ], "event target" ); + assert.ok( true, "button click fires callback" ); + assert.equal( this, element[ 0 ], "context of callback" ); + assert.equal( ev.target, btn[ 0 ], "event target" ); } }; - deepEqual( element.dialog( "option", "buttons" ), buttons, ".dialog('option', 'buttons') getter" ); + assert.deepEqual( element.dialog( "option", "buttons" ), buttons, ".dialog('option', 'buttons') getter" ); element.dialog( "option", "buttons", newButtons ); - deepEqual( element.dialog( "option", "buttons" ), newButtons, ".dialog('option', 'buttons', ...) setter" ); + assert.deepEqual( element.dialog( "option", "buttons" ), newButtons, ".dialog('option', 'buttons', ...) setter" ); btn = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); - equal( btn.length, 1, "number of buttons after setter" ); + assert.equal( btn.length, 1, "number of buttons after setter" ); btn.trigger( "click" ); i = 0; $.each( newButtons, function( key ) { - equal( btn.eq( i ).text(), key, "text of button " + ( i + 1 ) ); + assert.equal( btn.eq( i ).text(), key, "text of button " + ( i + 1 ) ); i += 1; } ); element.dialog( "option", "buttons", null ); btn = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); - equal( btn.length, 0, "all buttons have been removed" ); - equal( element.find( ".ui-dialog-buttonset" ).length, 0, "buttonset has been removed" ); + assert.equal( btn.length, 0, "all buttons have been removed" ); + assert.equal( element.find( ".ui-dialog-buttonset" ).length, 0, "buttonset has been removed" ); assert.lacksClasses( element.parent(), "ui-dialog-buttons" ); element.remove(); } ); -test( "buttons - advanced", function( assert ) { - expect( 7 ); +QUnit.test( "buttons - advanced", function( assert ) { + assert.expect( 7 ); var buttons, element = $( "<div></div>" ).dialog( { @@ -154,7 +155,7 @@ test( "buttons - advanced", function( assert ) { "class": "additional-class", id: "my-button-id", click: function() { - equal( this, element[ 0 ], "correct context" ); + assert.equal( this, element[ 0 ], "correct context" ); }, icon: "ui-icon-cancel", showLabel: false @@ -163,113 +164,113 @@ test( "buttons - advanced", function( assert ) { } ); buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); - equal( buttons.length, 1, "correct number of buttons" ); - equal( buttons.attr( "id" ), "my-button-id", "correct id" ); - equal( $.trim( buttons.text() ), "a button", "correct label" ); + assert.equal( buttons.length, 1, "correct number of buttons" ); + assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" ); + assert.equal( $.trim( buttons.text() ), "a button", "correct label" ); assert.hasClasses( buttons, "additional-class" ); - deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" ); - equal( buttons.button( "option", "showLabel" ), false ); + assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" ); + assert.equal( buttons.button( "option", "showLabel" ), false ); buttons.trigger( "click" ); element.remove(); } ); -test( "#9043: buttons with Array.prototype modification", function() { - expect( 1 ); +QUnit.test( "#9043: buttons with Array.prototype modification", function( assert ) { + assert.expect( 1 ); Array.prototype.test = $.noop; var element = $( "<div></div>" ).dialog(); - equal( element.dialog( "widget" ).find( ".ui-dialog-buttonpane" ).length, 0, + assert.equal( element.dialog( "widget" ).find( ".ui-dialog-buttonpane" ).length, 0, "no button pane" ); element.remove(); delete Array.prototype.test; } ); -test( "closeOnEscape", function() { - expect( 6 ); +QUnit.test( "closeOnEscape", function( assert ) { + assert.expect( 6 ); var element = $( "<div></div>" ).dialog( { closeOnEscape: false } ); - ok( true, "closeOnEscape: false" ); - ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open before ESC" ); + assert.ok( true, "closeOnEscape: false" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open before ESC" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ) .simulate( "keypress", { keyCode: $.ui.keyCode.ESCAPE } ) .simulate( "keyup", { keyCode: $.ui.keyCode.ESCAPE } ); - ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open after ESC" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open after ESC" ); element.remove(); element = $( "<div></div>" ).dialog( { closeOnEscape: true } ); - ok( true, "closeOnEscape: true" ); - ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open before ESC" ); + assert.ok( true, "closeOnEscape: true" ); + assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog is open before ESC" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ) .simulate( "keypress", { keyCode: $.ui.keyCode.ESCAPE } ) .simulate( "keyup", { keyCode: $.ui.keyCode.ESCAPE } ); - ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog is closed after ESC" ); + assert.ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog is closed after ESC" ); } ); -test( "closeText", function() { - expect( 4 ); +QUnit.test( "closeText", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close", + assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "Close", "default close text" ); element.remove(); element = $( "<div></div>" ).dialog( { closeText: "foo" } ); - equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo", + assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "foo", "closeText on init" ); element.remove(); element = $( "<div></div>" ).dialog().dialog( "option", "closeText", "bar" ); - equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar", + assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "bar", "closeText via option method" ); element.remove(); element = $( "<div></div>" ).dialog( { closeText: "<span>foo</span>" } ); - equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>", + assert.equal( $.trim( element.dialog( "widget" ).find( ".ui-dialog-titlebar-close" ).text() ), "<span>foo</span>", "closeText is escaped" ); element.remove(); } ); -test( "draggable", function() { - expect( 4 ); +QUnit.test( "draggable", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog( { draggable: false } ); - testHelper.testDrag( element, 50, -50, 0, 0 ); + testHelper.testDrag( assert, element, 50, -50, 0, 0 ); element.dialog( "option", "draggable", true ); - testHelper.testDrag( element, 50, -50, 50, -50 ); + testHelper.testDrag( assert, element, 50, -50, 50, -50 ); element.remove(); element = $( "<div></div>" ).dialog( { draggable: true } ); - testHelper.testDrag( element, 50, -50, 50, -50 ); + testHelper.testDrag( assert, element, 50, -50, 50, -50 ); element.dialog( "option", "draggable", false ); - testHelper.testDrag( element, 50, -50, 0, 0 ); + testHelper.testDrag( assert, element, 50, -50, 0, 0 ); element.remove(); } ); -test( "height", function() { - expect( 4 ); +QUnit.test( "height", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - equal( element.dialog( "widget" ).outerHeight(), 150, "default height" ); + assert.equal( element.dialog( "widget" ).outerHeight(), 150, "default height" ); element.remove(); element = $( "<div></div>" ).dialog( { height: 237 } ); - equal( element.dialog( "widget" ).outerHeight(), 237, "explicit height" ); + assert.equal( element.dialog( "widget" ).outerHeight(), 237, "explicit height" ); element.remove(); element = $( "<div></div>" ).dialog(); element.dialog( "option", "height", 238 ); - equal( element.dialog( "widget" ).outerHeight(), 238, "explicit height set after init" ); + assert.equal( element.dialog( "widget" ).outerHeight(), 238, "explicit height set after init" ); element.remove(); element = $( "<div></div>" ).css( "padding", "20px" ) .dialog( { height: 240 } ); - equal( element.dialog( "widget" ).outerHeight(), 240, "explicit height with padding" ); + assert.equal( element.dialog( "widget" ).outerHeight(), 240, "explicit height with padding" ); element.remove(); } ); -test( "maxHeight", function( assert ) { - expect( 3 ); +QUnit.test( "maxHeight", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog( { maxHeight: 200 } ); testHelper.drag( element, ".ui-resizable-s", 1000, 1000 ); @@ -287,8 +288,8 @@ test( "maxHeight", function( assert ) { element.remove(); } ); -test( "maxWidth", function( assert ) { - expect( 3 ); +QUnit.test( "maxWidth", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog( { maxWidth: 200 } ); testHelper.drag( element, ".ui-resizable-e", 1000, 1000 ); @@ -306,8 +307,8 @@ test( "maxWidth", function( assert ) { element.remove(); } ); -test( "minHeight", function( assert ) { - expect( 3 ); +QUnit.test( "minHeight", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog( { minHeight: 10 } ); testHelper.drag( element, ".ui-resizable-s", -1000, -1000 ); @@ -325,8 +326,8 @@ test( "minHeight", function( assert ) { element.remove(); } ); -test( "minWidth", function( assert ) { - expect( 3 ); +QUnit.test( "minWidth", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog( { minWidth: 10 } ); testHelper.drag( element, ".ui-resizable-e", -1000, -1000 ); @@ -344,8 +345,8 @@ test( "minWidth", function( assert ) { element.remove(); } ); -test( "position, default center on window", function( assert ) { - expect( 2 ); +QUnit.test( "position, default center on window", function( assert ) { + assert.expect( 2 ); // Dialogs alter the window width and height in Firefox // so we collect that information before creating the dialog @@ -360,8 +361,8 @@ test( "position, default center on window", function( assert ) { element.remove(); } ); -test( "position, right bottom at right bottom via ui.position args", function( assert ) { - expect( 2 ); +QUnit.test( "position, right bottom at right bottom via ui.position args", function( assert ) { + assert.expect( 2 ); // Dialogs alter the window width and height in Firefox // so we collect that information before creating the dialog @@ -382,8 +383,8 @@ test( "position, right bottom at right bottom via ui.position args", function( a element.remove(); } ); -test( "position, at another element", function( assert ) { - expect( 4 ); +QUnit.test( "position, at another element", function( assert ) { + assert.expect( 4 ); var parent = $( "<div></div>" ).css( { position: "absolute", top: 400, @@ -423,24 +424,24 @@ test( "position, at another element", function( assert ) { parent.remove(); } ); -test( "resizable", function() { - expect( 4 ); +QUnit.test( "resizable", function( assert ) { + assert.expect( 4 ); var element = $( "<div></div>" ).dialog(); - testHelper.shouldResize( element, 50, 50, "[default]" ); + testHelper.shouldResize( assert, element, 50, 50, "[default]" ); element.dialog( "option", "resizable", false ); - testHelper.shouldResize( element, 0, 0, "disabled after init" ); + testHelper.shouldResize( assert, element, 0, 0, "disabled after init" ); element.remove(); element = $( "<div></div>" ).dialog( { resizable: false } ); - testHelper.shouldResize( element, 0, 0, "disabled in init options" ); + testHelper.shouldResize( assert, element, 0, 0, "disabled in init options" ); element.dialog( "option", "resizable", true ); - testHelper.shouldResize( element, 50, 50, "enabled after init" ); + testHelper.shouldResize( assert, element, 50, 50, "enabled after init" ); element.remove(); } ); -test( "title", function() { - expect( 11 ); +QUnit.test( "title", function( assert ) { + assert.expect( 11 ); function titleText() { return element.dialog( "widget" ).find( ".ui-dialog-title" ).html(); @@ -448,43 +449,43 @@ test( "title", function() { var element = $( "<div></div>" ).dialog(); - // some browsers return a non-breaking space and some return " " + // Some browsers return a non-breaking space and some return " " // so we generate a non-breaking space for comparison - equal( titleText(), $( "<span> </span>" ).html(), "[default]" ); - equal( element.dialog( "option", "title" ), null, "option not changed" ); + assert.equal( titleText(), $( "<span> </span>" ).html(), "[default]" ); + assert.equal( element.dialog( "option", "title" ), null, "option not changed" ); element.remove(); element = $( "<div title='foo'>" ).dialog(); - equal( titleText(), "foo", "title in element attribute" ); - equal( element.dialog( "option", "title" ), "foo", "option updated from attribute" ); + assert.equal( titleText(), "foo", "title in element attribute" ); + assert.equal( element.dialog( "option", "title" ), "foo", "option updated from attribute" ); element.remove(); element = $( "<div></div>" ).dialog( { title: "foo" } ); - equal( titleText(), "foo", "title in init options" ); - equal( element.dialog( "option", "title" ), "foo", "opiton set from options hash" ); + assert.equal( titleText(), "foo", "title in init options" ); + assert.equal( element.dialog( "option", "title" ), "foo", "opiton set from options hash" ); element.remove(); element = $( "<div title='foo'>" ).dialog( { title: "bar" } ); - equal( titleText(), "bar", "title in init options should override title in element attribute" ); - equal( element.dialog( "option", "title" ), "bar", "opiton set from options hash" ); + assert.equal( titleText(), "bar", "title in init options should override title in element attribute" ); + assert.equal( element.dialog( "option", "title" ), "bar", "opiton set from options hash" ); element.remove(); element = $( "<div></div>" ).dialog().dialog( "option", "title", "foo" ); - equal( titleText(), "foo", "title after init" ); + assert.equal( titleText(), "foo", "title after init" ); element.remove(); // Make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement element = $( "<form><input name='title'></form>" ).dialog(); - // some browsers return a non-breaking space and some return " " + // Some browsers return a non-breaking space and some return " " // so we get the text to normalize to the actual non-breaking space - equal( titleText(), $( "<span> </span>" ).html(), "[default]" ); - equal( element.dialog( "option", "title" ), null, "option not changed" ); + assert.equal( titleText(), $( "<span> </span>" ).html(), "[default]" ); + assert.equal( element.dialog( "option", "title" ), null, "option not changed" ); element.remove(); } ); -test( "width", function( assert ) { - expect( 3 ); +QUnit.test( "width", function( assert ) { + assert.expect( 3 ); var element = $( "<div></div>" ).dialog(); assert.close( element.dialog( "widget" ).width(), 300, 1, "default width" ); @@ -497,60 +498,63 @@ test( "width", function( assert ) { element.remove(); } ); -test( "#4826: setting resizable false toggles resizable on dialog", function() { - expect( 6 ); +QUnit.test( "#4826: setting resizable false toggles resizable on dialog", function( assert ) { + assert.expect( 6 ); var i, element = $( "<div></div>" ).dialog( { resizable: false } ); - testHelper.shouldResize( element, 0, 0, "[default]" ); + testHelper.shouldResize( assert, element, 0, 0, "[default]" ); for ( i = 0; i < 2; i++ ) { element.dialog( "close" ).dialog( "open" ); - testHelper.shouldResize( element, 0, 0, "initialized with resizable false toggle (" + ( i + 1 ) + ")" ); + testHelper.shouldResize( assert, element, 0, 0, "initialized with resizable false toggle (" + ( i + 1 ) + ")" ); } element.remove(); element = $( "<div></div>" ).dialog( { resizable: true } ); - testHelper.shouldResize( element, 50, 50, "[default]" ); + testHelper.shouldResize( assert, element, 50, 50, "[default]" ); for ( i = 0; i < 2; i++ ) { element.dialog( "close" ).dialog( "option", "resizable", false ).dialog( "open" ); - testHelper.shouldResize( element, 0, 0, "set option resizable false toggle (" + ( i + 1 ) + ")" ); + testHelper.shouldResize( assert, element, 0, 0, "set option resizable false toggle (" + ( i + 1 ) + ")" ); } element.remove(); } ); -asyncTest( "#8051 - 'Explode' dialog animation causes crash in IE 6, 7 and 8", function() { - expect( 1 ); +QUnit.test( "#8051 - 'Explode' dialog animation causes crash in IE 6, 7 and 8", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "<div></div>" ).dialog( { show: "explode", focus: function() { - ok( true, "dialog opened with animation" ); + assert.ok( true, "dialog opened with animation" ); element.remove(); - start(); + ready(); } } ); } ); -asyncTest( "#4421 - Focus lost from dialog which uses show-effect", function() { - expect( 1 ); +QUnit.test( "#4421 - Focus lost from dialog which uses show-effect", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "<div></div>" ).dialog( { show: "blind", focus: function() { - equal( element.dialog( "widget" ).find( document.activeElement ).length, 1, "dialog maintains focus" ); + assert.equal( element.dialog( "widget" ).find( document.activeElement ).length, 1, "dialog maintains focus" ); element.remove(); - start(); + ready(); } } ); } ); -asyncTest( "Open followed by close during show effect", function() { - expect( 1 ); +QUnit.test( "Open followed by close during show effect", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "<div></div>" ).dialog( { show: "blind", close: function() { - ok( true, "dialog closed properly during animation" ); + assert.ok( true, "dialog closed properly during animation" ); element.remove(); - start(); + ready(); } } ); |