diff --git a/tests/unit/autocomplete/common.js b/tests/unit/autocomplete/common.js index 94e98048d..a4d57f95d 100644 --- a/tests/unit/autocomplete/common.js +++ b/tests/unit/autocomplete/common.js @@ -22,7 +22,7 @@ common.testWidget( "autocomplete", { }, source: null, - // callbacks + // Callbacks change: null, close: null, create: null, @@ -32,6 +32,6 @@ common.testWidget( "autocomplete", { search: null, select: null } -}); +} ); } ); diff --git a/tests/unit/autocomplete/core.js b/tests/unit/autocomplete/core.js index d57f2a980..41be5ae6a 100644 --- a/tests/unit/autocomplete/core.js +++ b/tests/unit/autocomplete/core.js @@ -12,15 +12,15 @@ test( "markup structure", function( assert ) { assert.hasClasses( element, "ui-autocomplete-input" ); assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" ); -}); +} ); test( "prevent form submit on enter when menu is active", function() { expect( 2 ); var event, element = $( "#autocomplete" ) - .autocomplete({ + .autocomplete( { source: [ "java", "javascript" ] - }) + } ) .val( "ja" ) .autocomplete( "search" ), menu = element.autocomplete( "widget" ); @@ -35,16 +35,16 @@ test( "prevent form submit on enter when menu is active", function() { event.keyCode = $.ui.keyCode.ENTER; element.trigger( event ); ok( event.isDefaultPrevented(), "default action is prevented" ); -}); +} ); test( "allow form submit on enter when menu is not active", function() { expect( 1 ); var event, element = $( "#autocomplete" ) - .autocomplete({ + .autocomplete( { autoFocus: false, source: [ "java", "javascript" ] - }) + } ) .val( "ja" ) .autocomplete( "search" ); @@ -52,90 +52,90 @@ test( "allow form submit on enter when menu is not active", function() { event.keyCode = $.ui.keyCode.ENTER; element.trigger( event ); ok( !event.isDefaultPrevented(), "default action is prevented" ); -}); +} ); -(function() { +( function() { test( "up arrow invokes search - input", function() { arrowsInvokeSearch( "#autocomplete", true, true ); - }); + } ); test( "down arrow invokes search - input", function() { arrowsInvokeSearch( "#autocomplete", false, true ); - }); + } ); test( "up arrow invokes search - textarea", function() { arrowsInvokeSearch( "#autocomplete-textarea", true, false ); - }); + } ); test( "down arrow invokes search - textarea", function() { arrowsInvokeSearch( "#autocomplete-textarea", false, false ); - }); + } ); test( "up arrow invokes search - contenteditable", function() { arrowsInvokeSearch( "#autocomplete-contenteditable", true, false ); - }); + } ); test( "down arrow invokes search - contenteditable", function() { arrowsInvokeSearch( "#autocomplete-contenteditable", false, false ); - }); + } ); test( "up arrow moves focus - input", function() { arrowsMoveFocus( "#autocomplete", true ); - }); + } ); test( "down arrow moves focus - input", function() { arrowsMoveFocus( "#autocomplete", false ); - }); + } ); test( "up arrow moves focus - textarea", function() { arrowsMoveFocus( "#autocomplete-textarea", true ); - }); + } ); test( "down arrow moves focus - textarea", function() { arrowsMoveFocus( "#autocomplete-textarea", false ); - }); + } ); test( "up arrow moves focus - contenteditable", function() { arrowsMoveFocus( "#autocomplete-contenteditable", true ); - }); + } ); test( "down arrow moves focus - contenteditable", function() { arrowsMoveFocus( "#autocomplete-contenteditable", false ); - }); + } ); test( "up arrow moves cursor - input", function() { arrowsNavigateElement( "#autocomplete", true, false ); - }); + } ); test( "down arrow moves cursor - input", function() { arrowsNavigateElement( "#autocomplete", false, false ); - }); + } ); test( "up arrow moves cursor - textarea", function() { arrowsNavigateElement( "#autocomplete-textarea", true, true ); - }); + } ); test( "down arrow moves cursor - textarea", function() { arrowsNavigateElement( "#autocomplete-textarea", false, true ); - }); + } ); test( "up arrow moves cursor - contenteditable", function() { arrowsNavigateElement( "#autocomplete-contenteditable", true, true ); - }); + } ); test( "down arrow moves cursor - contenteditable", function() { arrowsNavigateElement( "#autocomplete-contenteditable", false, true ); - }); + } ); function arrowsInvokeSearch( id, isKeyUp, shouldMove ) { expect( 1 ); var didMove = false, - element = $( id ).autocomplete({ + element = $( id ).autocomplete( { source: [ "a" ], delay: 0, minLength: 0 - }); + } ); element.autocomplete( "instance" )._move = function() { didMove = true; }; @@ -146,11 +146,11 @@ test( "allow form submit on enter when menu is not active", function() { function arrowsMoveFocus( id, isKeyUp ) { expect( 1 ); - var element = $( id ).autocomplete({ + var element = $( id ).autocomplete( { source: [ "a" ], delay: 0, minLength: 0 - }); + } ); element.autocomplete( "instance" )._move = function() { ok( true, "repsond to arrow" ); }; @@ -162,25 +162,25 @@ test( "allow form submit on enter when menu is not active", function() { expect( 1 ); var didMove = false, - element = $( id ).autocomplete({ + element = $( id ).autocomplete( { source: [ "a" ], delay: 0, minLength: 0 - }); + } ); element.on( "keypress", function( e ) { didMove = !e.isDefaultPrevented(); - }); + } ); element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } ); element.simulate( "keypress" ); equal( didMove, shouldMove, "respond to arrow" ); } -})(); +} )(); asyncTest( "past end of menu in multiline autocomplete", function() { expect( 2 ); var customVal = "custom value", - element = $( "#autocomplete-contenteditable" ).autocomplete({ + element = $( "#autocomplete-contenteditable" ).autocomplete( { delay: 0, source: [ "javascript" ], focus: function( event, ui ) { @@ -188,25 +188,25 @@ asyncTest( "past end of menu in multiline autocomplete", function() { $( this ).text( customVal ); event.preventDefault(); } - }); + } ); element .simulate( "focus" ) .autocomplete( "search", "ja" ); - setTimeout(function() { + setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); equal( element.text(), customVal ); start(); - }); -}); + } ); +} ); asyncTest( "ESCAPE in multiline autocomplete", function() { expect( 2 ); var customVal = "custom value", - element = $( "#autocomplete-contenteditable" ).autocomplete({ + element = $( "#autocomplete-contenteditable" ).autocomplete( { delay: 0, source: [ "javascript" ], focus: function( event, ui ) { @@ -214,38 +214,38 @@ asyncTest( "ESCAPE in multiline autocomplete", function() { $( this ).text( customVal ); event.preventDefault(); } - }); + } ); element .simulate( "focus" ) .autocomplete( "search", "ja" ); - setTimeout(function() { + setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); equal( element.text(), customVal ); start(); - }); -}); + } ); +} ); asyncTest( "handle race condition", function() { expect( 3 ); var count = 0, - element = $( "#autocomplete" ).autocomplete({ + element = $( "#autocomplete" ).autocomplete( { source: function( request, response ) { count++; if ( request.term.length === 1 ) { equal( count, 1, "request with 1 character is first" ); - setTimeout(function() { - response([ "one" ]); + setTimeout( function() { + response( [ "one" ] ); setTimeout( checkResults ); - }); + } ); return; } equal( count, 2, "request with 2 characters is second" ); - response([ "two" ]); + response( [ "two" ] ); } - }); + } ); element.autocomplete( "search", "a" ); element.autocomplete( "search", "ab" ); @@ -255,41 +255,41 @@ asyncTest( "handle race condition", function() { "correct results displayed" ); start(); } -}); +} ); asyncTest( "simultaneous searches (#9334)", function() { expect( 2 ); - var element = $( "#autocomplete" ).autocomplete({ + var element = $( "#autocomplete" ).autocomplete( { source: function( request, response ) { - setTimeout(function() { - response([ request.term ]); - }); + setTimeout( function() { + response( [ request.term ] ); + } ); }, response: function() { ok( true, "response from first instance" ); } - }), - element2 = $( "#autocomplete-textarea" ).autocomplete({ + } ), + element2 = $( "#autocomplete-textarea" ).autocomplete( { source: function( request, response ) { - setTimeout(function() { - response([ request.term ]); - }); + setTimeout( function() { + response( [ request.term ] ); + } ); }, response: function() { ok( true, "response from second instance" ); start(); } - }); + } ); element.autocomplete( "search", "test" ); element2.autocomplete( "search", "test" ); -}); +} ); test( "ARIA", function() { expect( 13 ); - var element = $( "#autocomplete" ).autocomplete({ + var element = $( "#autocomplete" ).autocomplete( { source: [ "java", "javascript" ] - }), + } ), liveRegion = element.autocomplete( "instance" ).liveRegion; equal( liveRegion.children().length, 0, "Empty live region on create" ); @@ -311,7 +311,7 @@ test( "ARIA", function() { element.one( "autocompletefocus", function( event ) { event.preventDefault(); - }); + } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); equal( liveRegion.children().filter( ":visible" ).text(), "javascript", "Live region updated when default focus is prevented" ); @@ -335,7 +335,7 @@ test( "ARIA", function() { element.autocomplete( "destroy" ); equal( liveRegion.parent().length, 0, "The liveRegion should be detached after destroy" ); -}); +} ); test( "ARIA, aria-label announcement", function() { expect( 1 ); @@ -345,27 +345,27 @@ test( "ARIA, aria-label announcement", function() { $.each( items, function( index, item ) { that._renderItemData( ul, item ) .attr( "aria-label", item.category + " : " + item.label ); - }); + } ); } - }); - var element = $( "#autocomplete" ).catcomplete({ + } ); + var element = $( "#autocomplete" ).catcomplete( { source: [ { label: "anders andersson", category: "People" } ] - }), + } ), liveRegion = element.catcomplete( "instance" ).liveRegion; element.catcomplete( "search", "a" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson", "Live region changed on keydown to announce the highlighted value's aria-label attribute" ); -}); +} ); test( "ARIA, init on detached input", function() { expect( 1 ); - var element = $( "" ).autocomplete({ + var element = $( "" ).autocomplete( { source: [ "java", "javascript" ] - }), + } ), liveRegion = element.autocomplete( "instance" ).liveRegion; equal( liveRegion.parent().length, 1, "liveRegion must have a parent" ); -}); +} ); test( ".replaceWith() (#9172)", function() { expect( 1 ); @@ -375,27 +375,27 @@ test( ".replaceWith() (#9172)", function() { parent = element.parent(); element.replaceWith( replacement ); equal( parent.html().toLowerCase(), replacement ); -}); +} ); asyncTest( "Search if the user retypes the same value (#7434)", function() { expect( 3 ); - var element = $( "#autocomplete" ).autocomplete({ + var element = $( "#autocomplete" ).autocomplete( { source: [ "java", "javascript" ], delay: 0 - }), + } ), menu = element.autocomplete( "instance" ).menu.element; element.val( "j" ).simulate( "keydown" ); - setTimeout(function() { + setTimeout( function() { ok( menu.is( ":visible" ), "menu displays initially" ); element.trigger( "blur" ); ok( !menu.is( ":visible" ), "menu hidden after blur" ); element.val( "j" ).simulate( "keydown" ); - setTimeout(function() { + setTimeout( function() { ok( menu.is( ":visible" ), "menu displays after typing the same value" ); start(); - }); - }); -}); + } ); + } ); +} ); } ); diff --git a/tests/unit/autocomplete/events.js b/tests/unit/autocomplete/events.js index 59d5dd540..688763f7e 100644 --- a/tests/unit/autocomplete/events.js +++ b/tests/unit/autocomplete/events.js @@ -7,7 +7,7 @@ module( "autocomplete: events" ); var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ]; -$.each([ +$.each( [ { type: "input", selector: "#autocomplete", @@ -27,7 +27,7 @@ $.each([ asyncTest( "all events - " + settings.type, function() { expect( 13 ); var element = $( settings.selector ) - .autocomplete({ + .autocomplete( { autoFocus: false, delay: 0, source: data, @@ -63,40 +63,41 @@ $.each([ ok( menu.is( ":hidden" ), "menu closed on change" ); start(); } - }), + } ), menu = element.autocomplete( "widget" ); element.simulate( "focus" )[ settings.valueMethod ]( "j" ).trigger( "keydown" ); - setTimeout(function() { + setTimeout( function() { ok( menu.is( ":visible" ), "menu is visible after delay" ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - // blur must be async for IE to handle it properly - setTimeout(function() { + + // Blur must be async for IE to handle it properly + setTimeout( function() { element.simulate( "blur" ); - }); - }); - }); -}); + } ); + } ); + } ); +} ); asyncTest( "change without selection", function() { expect( 1 ); - var element = $( "#autocomplete" ).autocomplete({ + var element = $( "#autocomplete" ).autocomplete( { delay: 0, source: data, change: function( event, ui ) { strictEqual( ui.item, null ); start(); } - }); + } ); element.triggerHandler( "focus" ); element.val( "ja" ).triggerHandler( "blur" ); -}); +} ); asyncTest( "cancel search", function() { expect( 6 ); var first = true, - element = $( "#autocomplete" ).autocomplete({ + element = $( "#autocomplete" ).autocomplete( { delay: 0, source: data, search: function() { @@ -110,76 +111,76 @@ asyncTest( "cancel search", function() { open: function() { ok( true, "menu opened" ); } - }), + } ), menu = element.autocomplete( "widget" ); element.val( "ja" ).trigger( "keydown" ); - setTimeout(function() { + setTimeout( function() { ok( menu.is( ":hidden" ), "menu is hidden after first search" ); element.val( "java" ).trigger( "keydown" ); - setTimeout(function() { + setTimeout( function() { ok( menu.is( ":visible" ), "menu is visible after second search" ); equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" ); start(); - }); - }); -}); + } ); + } ); +} ); asyncTest( "cancel focus", function() { expect( 1 ); var customVal = "custom value", - element = $( "#autocomplete" ).autocomplete({ + element = $( "#autocomplete" ).autocomplete( { delay: 0, source: data, focus: function() { $( this ).val( customVal ); return false; } - }); + } ); element.val( "ja" ).trigger( "keydown" ); - setTimeout(function() { + setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); equal( element.val(), customVal ); start(); - }); -}); + } ); +} ); asyncTest( "cancel select", function() { expect( 1 ); var customVal = "custom value", - element = $( "#autocomplete" ).autocomplete({ + element = $( "#autocomplete" ).autocomplete( { delay: 0, source: data, select: function() { $( this ).val( customVal ); return false; } - }); + } ); element.val( "ja" ).trigger( "keydown" ); - setTimeout(function() { + setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); equal( element.val(), customVal ); start(); - }); -}); + } ); +} ); asyncTest( "blur during remote search", function() { expect( 1 ); - var ac = $( "#autocomplete" ).autocomplete({ + var ac = $( "#autocomplete" ).autocomplete( { delay: 0, source: function( request, response ) { ok( true, "trigger request" ); ac.simulate( "blur" ); - setTimeout(function() { - response([ "result" ]); + setTimeout( function() { + response( [ "result" ] ); start(); - }, 25); + }, 25 ); }, open: function() { ok( false, "opened after a blur" ); } - }); + } ); ac.val( "ro" ).trigger( "keydown" ); -}); +} ); } ); diff --git a/tests/unit/autocomplete/methods.js b/tests/unit/autocomplete/methods.js index f614c13cd..0ebdc0d7e 100644 --- a/tests/unit/autocomplete/methods.js +++ b/tests/unit/autocomplete/methods.js @@ -9,16 +9,16 @@ test( "destroy", function( assert ) { expect( 1 ); assert.domEqual( "#autocomplete", function() { $( "#autocomplete" ).autocomplete().autocomplete( "destroy" ); - }); -}); + } ); +} ); test( "search, close", function() { expect( 6 ); var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ], - element = $( "#autocomplete" ).autocomplete({ + element = $( "#autocomplete" ).autocomplete( { source: data, minLength: 0 - }), + } ), menu = element.autocomplete( "widget" ); ok( menu.is( ":hidden" ), "menu is hidden on init" ); @@ -35,7 +35,7 @@ test( "search, close", function() { element.autocomplete( "close" ); ok( menu.is( ":hidden" ), "menu is hidden after close" ); -}); +} ); test( "widget", function( assert ) { expect( 2 ); @@ -43,6 +43,6 @@ test( "widget", function( assert ) { widgetElement = element.autocomplete( "widget" ); equal( widgetElement.length, 1, "one element" ); assert.hasClasses( widgetElement, "ui-menu" ); -}); +} ); } ); diff --git a/tests/unit/autocomplete/options.js b/tests/unit/autocomplete/options.js index 7d281fb31..76c13e754 100644 --- a/tests/unit/autocomplete/options.js +++ b/tests/unit/autocomplete/options.js @@ -14,16 +14,16 @@ test( "appendTo: null", function() { equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body, "defaults to body" ); element.autocomplete( "destroy" ); -}); +} ); test( "appendTo: explicit", function() { expect( 6 ); var detached = $( "