2015-04-03 19:57:57 +00:00
|
|
|
define( [
|
2016-04-03 14:51:14 +00:00
|
|
|
"qunit",
|
2015-04-03 19:57:57 +00:00
|
|
|
"jquery",
|
2015-07-15 01:56:36 +00:00
|
|
|
"ui/widgets/autocomplete"
|
2016-04-03 14:51:14 +00:00
|
|
|
], function( QUnit, $ ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.module( "autocomplete: core" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "markup structure", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-02-27 20:11:33 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete(),
|
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
|
|
|
assert.hasClasses( element, "ui-autocomplete-input" );
|
|
|
|
assert.hasClasses( menu, "ui-autocomplete ui-widget ui-widget-content" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2015-02-27 20:11:33 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "prevent form submit on enter when menu is active", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2011-06-13 18:09:44 +00:00
|
|
|
var event,
|
|
|
|
element = $( "#autocomplete" )
|
2015-08-21 04:11:54 +00:00
|
|
|
.autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: [ "java", "javascript" ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} )
|
2011-06-13 18:09:44 +00:00
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" ),
|
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
2010-09-27 14:10:00 +00:00
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.DOWN;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( menu.find( ".ui-menu-item-wrapper.ui-state-active" ).length, 1,
|
2014-09-24 14:47:29 +00:00
|
|
|
"menu item is active" );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
2010-09-27 14:10:00 +00:00
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.ENTER;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( event.isDefaultPrevented(), "default action is prevented" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-09-27 14:10:00 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "allow form submit on enter when menu is not active", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2011-06-13 18:09:44 +00:00
|
|
|
var event,
|
|
|
|
element = $( "#autocomplete" )
|
2015-08-21 04:11:54 +00:00
|
|
|
.autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
autoFocus: false,
|
|
|
|
source: [ "java", "javascript" ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} )
|
2011-06-13 18:09:44 +00:00
|
|
|
.val( "ja" )
|
|
|
|
.autocomplete( "search" );
|
|
|
|
|
2010-09-27 14:10:00 +00:00
|
|
|
event = $.Event( "keydown" );
|
|
|
|
event.keyCode = $.ui.keyCode.ENTER;
|
2011-06-13 18:09:44 +00:00
|
|
|
element.trigger( event );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( !event.isDefaultPrevented(), "default action is prevented" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow invokes search - input", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete", true, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow invokes search - input", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete", false, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow invokes search - textarea", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete-textarea", true, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow invokes search - textarea", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete-textarea", false, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow invokes search - contenteditable", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete-contenteditable", true, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow invokes search - contenteditable", function( assert ) {
|
|
|
|
arrowsInvokeSearch( assert, "#autocomplete-contenteditable", false, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves focus - input", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete", true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves focus - input", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete", false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves focus - textarea", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete-textarea", true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves focus - textarea", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete-textarea", false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves focus - contenteditable", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete-contenteditable", true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves focus - contenteditable", function( assert ) {
|
|
|
|
arrowsMoveFocus( assert, "#autocomplete-contenteditable", false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-04-30 14:23:29 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves cursor - input", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete", true, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves cursor - input", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete", false, false );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves cursor - textarea", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete-textarea", true, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves cursor - textarea", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete-textarea", false, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "up arrow moves cursor - contenteditable", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete-contenteditable", true, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "down arrow moves cursor - contenteditable", function( assert ) {
|
|
|
|
arrowsNavigateElement( assert, "#autocomplete-contenteditable", false, true );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
function arrowsInvokeSearch( assert, id, isKeyUp, shouldMove ) {
|
|
|
|
assert.expect( 1 );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
|
|
|
var didMove = false,
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( id ).autocomplete( {
|
2011-11-28 21:33:23 +00:00
|
|
|
source: [ "a" ],
|
|
|
|
delay: 0,
|
|
|
|
minLength: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-19 15:53:35 +00:00
|
|
|
element.autocomplete( "instance" )._move = function() {
|
2011-11-28 21:33:23 +00:00
|
|
|
didMove = true;
|
|
|
|
};
|
|
|
|
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( didMove, shouldMove, "respond to arrow" );
|
2011-11-28 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
function arrowsMoveFocus( assert, id, isKeyUp ) {
|
|
|
|
assert.expect( 1 );
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( id ).autocomplete( {
|
2011-11-28 21:33:23 +00:00
|
|
|
source: [ "a" ],
|
|
|
|
delay: 0,
|
|
|
|
minLength: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-19 15:53:35 +00:00
|
|
|
element.autocomplete( "instance" )._move = function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( true, "repsond to arrow" );
|
2011-11-28 21:33:23 +00:00
|
|
|
};
|
|
|
|
element.autocomplete( "search" );
|
|
|
|
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
|
|
|
|
}
|
2013-04-30 14:23:29 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
function arrowsNavigateElement( assert, id, isKeyUp, shouldMove ) {
|
|
|
|
assert.expect( 1 );
|
2013-03-20 22:42:34 +00:00
|
|
|
|
|
|
|
var didMove = false,
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( id ).autocomplete( {
|
2013-03-20 22:42:34 +00:00
|
|
|
source: [ "a" ],
|
|
|
|
delay: 0,
|
|
|
|
minLength: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2015-05-14 01:54:08 +00:00
|
|
|
element.on( "keypress", function( e ) {
|
2013-03-20 22:42:34 +00:00
|
|
|
didMove = !e.isDefaultPrevented();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-20 22:42:34 +00:00
|
|
|
element.simulate( "keydown", { keyCode: ( isKeyUp ? $.ui.keyCode.UP : $.ui.keyCode.DOWN ) } );
|
|
|
|
element.simulate( "keypress" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( didMove, shouldMove, "respond to arrow" );
|
2013-03-20 22:42:34 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} )();
|
2011-11-28 21:33:23 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "past end of menu in multiline autocomplete", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2014-01-25 22:39:27 +00:00
|
|
|
|
|
|
|
var customVal = "custom value",
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( "#autocomplete-contenteditable" ).autocomplete( {
|
2014-01-25 22:39:27 +00:00
|
|
|
delay: 0,
|
|
|
|
source: [ "javascript" ],
|
|
|
|
focus: function( event, ui ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( ui.item.value, "javascript", "Item gained focus" );
|
2014-01-25 22:39:27 +00:00
|
|
|
$( this ).text( customVal );
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2014-01-25 22:39:27 +00:00
|
|
|
|
|
|
|
element
|
|
|
|
.simulate( "focus" )
|
|
|
|
.autocomplete( "search", "ja" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2014-01-25 22:39:27 +00:00
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.text(), customVal );
|
|
|
|
ready();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-01-25 22:39:27 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "ESCAPE in multiline autocomplete", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2014-08-01 17:30:45 +00:00
|
|
|
|
|
|
|
var customVal = "custom value",
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( "#autocomplete-contenteditable" ).autocomplete( {
|
2014-08-01 17:30:45 +00:00
|
|
|
delay: 0,
|
|
|
|
source: [ "javascript" ],
|
|
|
|
focus: function( event, ui ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( ui.item.value, "javascript", "Item gained focus" );
|
2014-08-01 17:30:45 +00:00
|
|
|
$( this ).text( customVal );
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2014-08-01 17:30:45 +00:00
|
|
|
|
|
|
|
element
|
|
|
|
.simulate( "focus" )
|
|
|
|
.autocomplete( "search", "ja" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2014-08-01 17:30:45 +00:00
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.text(), customVal );
|
|
|
|
ready();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-02-04 21:47:26 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "handle race condition", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2012-04-03 20:47:14 +00:00
|
|
|
var count = 0,
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( "#autocomplete" ).autocomplete( {
|
2012-04-03 20:47:14 +00:00
|
|
|
source: function( request, response ) {
|
|
|
|
count++;
|
|
|
|
if ( request.term.length === 1 ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( count, 1, "request with 1 character is first" );
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
response( [ "one" ] );
|
2015-02-17 15:11:58 +00:00
|
|
|
setTimeout( checkResults );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-04-03 20:47:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( count, 2, "request with 2 characters is second" );
|
2015-08-21 04:11:54 +00:00
|
|
|
response( [ "two" ] );
|
2012-04-03 20:47:14 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-04-03 20:47:14 +00:00
|
|
|
|
|
|
|
element.autocomplete( "search", "a" );
|
|
|
|
element.autocomplete( "search", "ab" );
|
|
|
|
|
|
|
|
function checkResults() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).find( ".ui-menu-item" ).text(), "two",
|
2012-04-03 20:47:14 +00:00
|
|
|
"correct results displayed" );
|
2016-04-03 14:51:14 +00:00
|
|
|
ready();
|
2012-04-03 20:47:14 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-04-03 20:47:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "simultaneous searches (#9334)", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2013-05-28 15:04:29 +00:00
|
|
|
source: function( request, response ) {
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
response( [ request.term ] );
|
|
|
|
} );
|
2013-05-28 15:04:29 +00:00
|
|
|
},
|
|
|
|
response: function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( true, "response from first instance" );
|
2013-05-28 15:04:29 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
|
|
|
element2 = $( "#autocomplete-textarea" ).autocomplete( {
|
2013-05-28 15:04:29 +00:00
|
|
|
source: function( request, response ) {
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
response( [ request.term ] );
|
|
|
|
} );
|
2013-05-28 15:04:29 +00:00
|
|
|
},
|
|
|
|
response: function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( true, "response from second instance" );
|
|
|
|
ready();
|
2013-05-28 15:04:29 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-05-28 15:04:29 +00:00
|
|
|
|
|
|
|
element.autocomplete( "search", "test" );
|
|
|
|
element2.autocomplete( "search", "test" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-05-28 15:04:29 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "ARIA", function( assert ) {
|
|
|
|
assert.expect( 13 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2012-05-22 14:09:08 +00:00
|
|
|
source: [ "java", "javascript" ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2013-03-19 15:53:35 +00:00
|
|
|
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
2012-05-22 14:09:08 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().length, 0, "Empty live region on create" );
|
|
|
|
assert.equal( liveRegion.attr( "aria-live" ), "assertive",
|
2013-12-22 16:36:43 +00:00
|
|
|
"Live region's aria-live attribute must be assertive" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.attr( "aria-relevant" ), "additions",
|
2013-12-22 16:36:43 +00:00
|
|
|
"Live region's aria-relevant attribute must be additions" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.attr( "role" ), "status",
|
2013-12-22 16:36:43 +00:00
|
|
|
"Live region's role attribute must be status" );
|
2012-05-22 14:09:08 +00:00
|
|
|
|
|
|
|
element.autocomplete( "search", "j" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().first().text(),
|
2013-12-22 16:36:43 +00:00
|
|
|
"2 results are available, use up and down arrow keys to navigate.",
|
2012-05-22 14:09:08 +00:00
|
|
|
"Live region for multiple values" );
|
|
|
|
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).text(), "java",
|
2013-12-22 16:36:43 +00:00
|
|
|
"Live region changed on keydown to announce the highlighted value" );
|
2012-05-22 14:09:08 +00:00
|
|
|
|
|
|
|
element.one( "autocompletefocus", function( event ) {
|
|
|
|
event.preventDefault();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-05-22 14:09:08 +00:00
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).text(), "javascript",
|
2012-05-22 14:09:08 +00:00
|
|
|
"Live region updated when default focus is prevented" );
|
|
|
|
|
|
|
|
element.autocomplete( "search", "javas" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).text(),
|
2013-12-22 16:36:43 +00:00
|
|
|
"1 result is available, use up and down arrow keys to navigate.",
|
2012-05-22 14:09:08 +00:00
|
|
|
"Live region for one value" );
|
|
|
|
|
|
|
|
element.autocomplete( "search", "z" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).text(), "No search results.",
|
2012-05-22 14:09:08 +00:00
|
|
|
"Live region for no values" );
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().length, 5,
|
2013-12-22 16:36:43 +00:00
|
|
|
"Should be five children in the live region after the above" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).length, 1,
|
2013-12-22 16:36:43 +00:00
|
|
|
"Only one should be still visible" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( liveRegion.children().filter( ":visible" )[ 0 ] === liveRegion.children().last()[ 0 ],
|
2013-12-22 16:36:43 +00:00
|
|
|
"The last one should be the visible one" );
|
|
|
|
|
|
|
|
element.autocomplete( "destroy" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.parent().length, 0,
|
2013-12-22 16:36:43 +00:00
|
|
|
"The liveRegion should be detached after destroy" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-12-22 16:36:43 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "ARIA, aria-label announcement", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-12-22 16:36:43 +00:00
|
|
|
$.widget( "custom.catcomplete", $.ui.autocomplete, {
|
|
|
|
_renderMenu: function( ul, items ) {
|
|
|
|
var that = this;
|
|
|
|
$.each( items, function( index, item ) {
|
|
|
|
that._renderItemData( ul, item )
|
|
|
|
.attr( "aria-label", item.category + " : " + item.label );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-12-22 16:36:43 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
var element = $( "#autocomplete" ).catcomplete( {
|
2013-12-22 16:36:43 +00:00
|
|
|
source: [ { label: "anders andersson", category: "People" } ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2013-12-22 16:36:43 +00:00
|
|
|
liveRegion = element.catcomplete( "instance" ).liveRegion;
|
|
|
|
element.catcomplete( "search", "a" );
|
|
|
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.children().filter( ":visible" ).text(), "People : anders andersson",
|
2013-12-22 16:36:43 +00:00
|
|
|
"Live region changed on keydown to announce the highlighted value's aria-label attribute" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-05-22 14:09:08 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "ARIA, init on detached input", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "<input>" ).autocomplete( {
|
2013-10-18 13:39:20 +00:00
|
|
|
source: [ "java", "javascript" ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2013-10-18 13:39:20 +00:00
|
|
|
liveRegion = element.autocomplete( "instance" ).liveRegion;
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( liveRegion.parent().length, 1, "liveRegion must have a parent" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-10-18 13:39:20 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( ".replaceWith() (#9172)", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2013-03-21 19:54:50 +00:00
|
|
|
|
|
|
|
var element = $( "#autocomplete" ).autocomplete(),
|
|
|
|
replacement = "<div>test</div>",
|
|
|
|
parent = element.parent();
|
|
|
|
element.replaceWith( replacement );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( parent.html().toLowerCase(), replacement );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2013-03-21 19:54:50 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "Search if the user retypes the same value (#7434)", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 3 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2014-05-01 13:57:38 +00:00
|
|
|
source: [ "java", "javascript" ],
|
|
|
|
delay: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2014-05-01 13:57:38 +00:00
|
|
|
menu = element.autocomplete( "instance" ).menu.element;
|
|
|
|
|
|
|
|
element.val( "j" ).simulate( "keydown" );
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "menu displays initially" );
|
2014-05-01 13:57:38 +00:00
|
|
|
element.trigger( "blur" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( !menu.is( ":visible" ), "menu hidden after blur" );
|
2014-05-01 13:57:38 +00:00
|
|
|
element.val( "j" ).simulate( "keydown" );
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "menu displays after typing the same value" );
|
|
|
|
ready();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2014-05-01 13:57:38 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "Close on click outside when focus remains", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-10-15 14:11:14 +00:00
|
|
|
|
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
|
|
|
source: [ "java", "javascript" ],
|
|
|
|
delay: 0
|
|
|
|
} );
|
|
|
|
var menu = element.autocomplete( "widget" );
|
|
|
|
|
|
|
|
$( "body" ).on( "mousedown", function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
} );
|
|
|
|
|
|
|
|
element.val( "j" ).autocomplete( "search", "j" );
|
2015-10-16 18:14:45 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "menu displays initially" );
|
2015-10-15 14:11:14 +00:00
|
|
|
$( "body" ).simulate( "mousedown" );
|
2015-10-16 18:14:45 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu closes after clicking elsewhere" );
|
|
|
|
ready();
|
2015-10-15 14:11:14 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-04-03 19:57:57 +00:00
|
|
|
} );
|