How to use keydown method in Playwright Internal

Best JavaScript code snippet using playwright-internal

events.js

Source:events.js Github

copy

Full Screen

1define( [2 "qunit",3 "jquery",4 "./helper",5 "ui/widgets/menu"6], function( QUnit, $, testHelper ) {7var log = testHelper.log,8 logOutput = testHelper.logOutput,9 click = testHelper.click;10QUnit.module( "menu: events", {11 beforeEach: function() {12 testHelper.clearLog();13 }14} );15QUnit.test( "handle click on menu", function( assert ) {16 assert.expect( 1 );17 var element = $( "#menu1" ).menu( {18 select: function() {19 log();20 }21 } );22 log( "click", true );23 click( element, "1" );24 log( "afterclick" );25 click( element, "2" );26 click( element, "3" );27 click( element, "1" );28 assert.equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );29} );30QUnit.test( "handle click on custom item menu", function( assert ) {31 assert.expect( 1 );32 var element = $( "#menu5" ).menu( {33 select: function() {34 log();35 },36 menus: ".menu"37 } );38 log( "click", true );39 click( element, "1" );40 log( "afterclick" );41 click( element, "2" );42 click( element, "3" );43 click( element, "1" );44 assert.equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );45} );46QUnit.test( "handle blur", function( assert ) {47 var ready = assert.async();48 assert.expect( 2 );49 var blurHandled = false,50 index = 1,51 element = $( "#menu1" ).menu( {52 blur: function( event, ui ) {53 // Ignore duplicate blur event fired by IE54 if ( !blurHandled ) {55 blurHandled = true;56 assert.equal( event.type, "menublur", "blur event.type is 'menublur'" );57 assert.strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" );58 }59 }60 } );61 click( element, index );62 setTimeout( function() {63 element.trigger( "blur" );64 setTimeout( function() {65 ready();66 }, 350 );67 } );68} );69QUnit.test( "handle blur via click outside", function( assert ) {70 var ready = assert.async();71 assert.expect( 2 );72 var blurHandled = false,73 index = 1,74 element = $( "#menu1" ).menu( {75 blur: function( event, ui ) {76 // Ignore duplicate blur event fired by IE77 if ( !blurHandled ) {78 blurHandled = true;79 assert.equal( event.type, "menublur", "blur event.type is 'menublur'" );80 assert.strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" );81 }82 }83 } );84 click( element, index );85 setTimeout( function() {86 $( "<a>", { id: "remove" } ).appendTo( "body" ).trigger( "click" );87 setTimeout( function() {88 ready();89 }, 350 );90 } );91} );92QUnit.test( "handle focus of menu with active item", function( assert ) {93 var ready = assert.async();94 assert.expect( 1 );95 var element = $( "#menu1" ).menu( {96 focus: function( event ) {97 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );98 }99 } );100 log( "focus", true );101 element[ 0 ].focus();102 setTimeout( function() {103 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );104 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );105 element[ 0 ].blur();106 setTimeout( function() {107 element[ 0 ].focus();108 setTimeout( function() {109 assert.equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );110 ready();111 } );112 } );113 } );114} );115QUnit.test( "handle mouseenter on nested menu item", function( assert ) {116 assert.expect( 8 );117 $.ui.menu.prototype.delay = 1;118 var activeItem,119 done = assert.async(),120 element = $( "#menu2" ).menu();121 element122 .menu( "previous" )123 .menu( "expand" );124 function checkSubmenus() {125 assert.equal( element.find( "ul[aria-expanded='true']" ).length, 2, "both submenus expanded" );126 }127 function menumouseenter1() {128 element.menu( "expand" );129 setTimeout( menumouseenter2, 25 );130 }131 function menumouseenter2() {132 checkSubmenus();133 activeItem = $( "#" + element.attr( "aria-activedescendant" ) );134 assert.hasClasses( activeItem, "ui-state-active" );135 activeItem.trigger( "mouseleave" );136 setTimeout( menumouseenter3, 25 );137 }138 function menumouseenter3() {139 checkSubmenus();140 assert.lacksClasses( activeItem, "ui-state-active" );141 activeItem.trigger( "mouseenter" );142 setTimeout( menumouseenter4, 25 );143 }144 function menumouseenter4() {145 checkSubmenus();146 activeItem.parents( ".ui-menu-item" ).each( function( index, item ) {147 assert.hasClasses( $( item ).children( ".ui-menu-item-wrapper" ), "ui-state-active" );148 } );149 $.ui.menu.prototype.delay = 300;150 done();151 }152 setTimeout( menumouseenter1, 25 );153} );154QUnit.test( "handle submenu auto collapse: mouseleave, default markup", function( assert ) {155 var ready = assert.async();156 assert.expect( 4 );157 $.ui.menu.prototype.delay = 1;158 var element = $( "#menu2" ).menu(),159 event = $.Event( "mouseenter" );160 function menumouseleave1() {161 assert.equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );162 element.menu( "focus", event, element.find( "li:nth-child(7) li:first" ) );163 setTimeout( menumouseleave2, 25 );164 }165 function menumouseleave2() {166 assert.equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );167 element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );168 setTimeout( menumouseleave3, 25 );169 }170 function menumouseleave3() {171 assert.equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" );172 element.trigger( "mouseleave" );173 setTimeout( menumouseleave4, 25 );174 }175 function menumouseleave4() {176 assert.equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );177 $.ui.menu.prototype.delay = 300;178 ready();179 }180 element.find( "li:nth-child(7)" ).trigger( "mouseenter" );181 setTimeout( menumouseleave1, 25 );182} );183QUnit.test( "handle submenu auto collapse: mouseleave, custom markup", function( assert ) {184 var ready = assert.async();185 assert.expect( 4 );186 $.ui.menu.prototype.delay = 1;187 var element = $( "#menu5" ).menu( { menus: ".menu" } ),188 event = $.Event( "mouseenter" );189 function menumouseleave1() {190 assert.equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );191 element.menu( "focus", event, element.find( ":nth-child(7)" ).find( ".menu" ).eq( 0 ).children().eq( 0 ) );192 setTimeout( menumouseleave2, 25 );193 }194 function menumouseleave2() {195 assert.equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );196 element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );197 setTimeout( menumouseleave3, 25 );198 }199 function menumouseleave3() {200 assert.equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" );201 element.trigger( "mouseleave" );202 setTimeout( menumouseleave4, 25 );203 }204 function menumouseleave4() {205 assert.equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );206 $.ui.menu.prototype.delay = 300;207 ready();208 }209 element.find( ":nth-child(7)" ).trigger( "mouseenter" );210 setTimeout( menumouseleave1, 25 );211} );212QUnit.test( "handle keyboard navigation on menu without scroll and without submenus", function( assert ) {213 var ready = assert.async();214 assert.expect( 12 );215 var element = $( "#menu1" ).menu( {216 select: function( event, ui ) {217 log( $( ui.item[ 0 ] ).text() );218 },219 focus: function( event ) {220 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );221 }222 } );223 log( "keydown", true );224 element[ 0 ].focus();225 setTimeout( function() {226 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );227 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );228 assert.equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );229 log( "keydown", true );230 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );231 assert.equal( logOutput(), "keydown,1", "Keydown UP" );232 log( "keydown", true );233 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );234 assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );235 log( "keydown", true );236 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );237 assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );238 log( "keydown", true );239 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );240 assert.equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" );241 log( "keydown", true );242 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );243 assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );244 log( "keydown", true );245 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );246 assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );247 log( "keydown", true );248 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );249 assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );250 log( "keydown", true );251 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );252 assert.equal( logOutput(), "keydown,4", "Keydown END" );253 log( "keydown", true );254 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );255 assert.equal( logOutput(), "keydown,0", "Keydown HOME" );256 log( "keydown", true );257 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );258 assert.equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );259 log( "keydown", true );260 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );261 assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );262 ready();263 } );264} );265QUnit.test( "handle keyboard navigation on menu without scroll and with submenus", function( assert ) {266 var ready = assert.async();267 assert.expect( 16 );268 var element = $( "#menu2" ).menu( {269 select: function( event, ui ) {270 log( $( ui.item[ 0 ] ).text() );271 },272 focus: function( event ) {273 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );274 }275 } );276 log( "keydown", true );277 element.one( "menufocus", function() {278 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );279 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );280 assert.equal( logOutput(), "keydown,1,2", "Keydown DOWN" );281 setTimeout( menukeyboard1 );282 } );283 element.trigger( "focus" );284 function menukeyboard1() {285 log( "keydown", true );286 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );287 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );288 assert.equal( logOutput(), "keydown,1,0", "Keydown UP" );289 log( "keydown", true );290 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );291 assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );292 log( "keydown", true );293 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );294 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );295 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );296 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );297 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );298 setTimeout( function() {299 assert.equal( logOutput(), "keydown,1,2,3,4,0", "Keydown RIGHT (open submenu)" );300 setTimeout( menukeyboard2 );301 } );302 }303 function menukeyboard2() {304 log( "keydown", true );305 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );306 assert.equal( logOutput(), "keydown,4", "Keydown LEFT (close submenu)" );307 // Re-open submenu308 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );309 setTimeout( menukeyboard3 );310 }311 function menukeyboard3() {312 log( "keydown", true );313 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );314 assert.equal( logOutput(), "keydown,2", "Keydown PAGE_DOWN" );315 log( "keydown", true );316 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );317 assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );318 log( "keydown", true );319 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );320 assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );321 log( "keydown", true );322 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );323 assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );324 log( "keydown", true );325 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );326 assert.equal( logOutput(), "keydown,2", "Keydown END" );327 log( "keydown", true );328 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );329 assert.equal( logOutput(), "keydown,0", "Keydown HOME" );330 log( "keydown", true );331 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );332 assert.equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );333 log( "keydown", true );334 element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } );335 setTimeout( menukeyboard4 );336 }337 function menukeyboard4() {338 assert.equal( logOutput(), "keydown,0", "Keydown SPACE (open submenu)" );339 log( "keydown", true );340 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );341 assert.equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );342 log( "keydown", true );343 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );344 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );345 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );346 setTimeout( function() {347 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );348 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );349 setTimeout( function() {350 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );351 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );352 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );353 assert.equal( logOutput(), "keydown,5,6,0,1,0,2,4,0", "Keydown skip dividers" );354 log( "keydown", true );355 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );356 setTimeout( menukeyboard6 );357 } );358 } );359 }360 function menukeyboard6() {361 assert.equal( logOutput(), "keydown,Ada", "Keydown ENTER (open submenu)" );362 ready();363 }364} );365QUnit.test( "handle keyboard navigation on menu with scroll and without submenus", function( assert ) {366 var ready = assert.async();367 assert.expect( 14 );368 var element = $( "#menu3" ).menu( {369 select: function( event, ui ) {370 log( $( ui.item[ 0 ] ).text() );371 },372 focus: function( event ) {373 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );374 }375 } );376 log( "keydown", true );377 element[ 0 ].focus();378 setTimeout( function() {379 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );380 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );381 assert.equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );382 log( "keydown", true );383 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );384 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );385 assert.equal( logOutput(), "keydown,1,0", "Keydown UP" );386 log( "keydown", true );387 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );388 assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );389 log( "keydown", true );390 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );391 assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );392 log( "keydown", true );393 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );394 assert.equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" );395 log( "keydown", true );396 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );397 assert.equal( logOutput(), "keydown,34", "Keydown PAGE_DOWN" );398 log( "keydown", true );399 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );400 assert.equal( logOutput(), "keydown,17", "Keydown PAGE_UP" );401 log( "keydown", true );402 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );403 assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );404 log( "keydown", true );405 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );406 assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );407 log( "keydown", true );408 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );409 assert.equal( logOutput(), "keydown,37", "Keydown END" );410 log( "keydown", true );411 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );412 assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );413 log( "keydown", true );414 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );415 assert.equal( logOutput(), "keydown,0", "Keydown HOME" );416 log( "keydown", true );417 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );418 assert.equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );419 log( "keydown", true );420 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );421 assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );422 ready();423 } );424} );425QUnit.test( "handle keyboard navigation on menu with scroll and with submenus", function( assert ) {426 var ready = assert.async();427 assert.expect( 14 );428 var element = $( "#menu4" ).menu( {429 select: function( event, ui ) {430 log( $( ui.item[ 0 ] ).text() );431 },432 focus: function( event ) {433 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active:last" ).parent().index() );434 }435 } );436 log( "keydown", true );437 element.one( "menufocus", function() {438 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );439 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );440 assert.equal( logOutput(), "keydown,1,2", "Keydown DOWN" );441 setTimeout( menukeyboard1 );442 } );443 element.trigger( "focus" );444 function menukeyboard1() {445 log( "keydown", true );446 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );447 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );448 assert.equal( logOutput(), "keydown,1,0", "Keydown UP" );449 log( "keydown", true );450 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );451 assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );452 log( "keydown", true );453 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );454 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );455 setTimeout( function() {456 assert.equal( logOutput(), "keydown,1,0", "Keydown RIGHT (open submenu)" );457 }, 50 );458 setTimeout( menukeyboard2, 50 );459 }460 function menukeyboard2() {461 log( "keydown", true );462 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );463 assert.equal( logOutput(), "keydown,1", "Keydown LEFT (close submenu)" );464 // Re-open submenu465 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );466 setTimeout( menukeyboard3, 50 );467 }468 function menukeyboard3() {469 log( "keydown", true );470 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );471 assert.equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" );472 log( "keydown", true );473 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );474 assert.equal( logOutput(), "keydown,27", "Keydown PAGE_DOWN" );475 log( "keydown", true );476 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );477 assert.equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );478 log( "keydown", true );479 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );480 assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );481 log( "keydown", true );482 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );483 assert.equal( logOutput(), "keydown,27", "Keydown END" );484 log( "keydown", true );485 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );486 assert.equal( logOutput(), "keydown,0", "Keydown HOME" );487 log( "keydown", true );488 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );489 assert.equal( logOutput(), "keydown,1", "Keydown ESCAPE (close submenu)" );490 log( "keydown", true );491 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );492 setTimeout( menukeyboard4, 50 );493 }494 function menukeyboard4() {495 assert.equal( logOutput(), "keydown,0", "Keydown ENTER (open submenu)" );496 log( "keydown", true );497 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );498 assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER (select item)" );499 ready();500 }501} );502QUnit.test( "handle keyboard navigation and mouse click on menu with disabled items", function( assert ) {503 var ready = assert.async();504 assert.expect( 6 );505 var element = $( "#menu6" ).menu( {506 select: function( event, ui ) {507 log( $( ui.item[ 0 ] ).text() );508 },509 focus: function( event ) {510 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );511 }512 } );513 log( "keydown", true );514 element.one( "menufocus", function() {515 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );516 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );517 assert.equal( logOutput(), "keydown,1", "Keydown focus but not select disabled item" );518 setTimeout( menukeyboard1, 50 );519 } );520 element.trigger( "focus" );521 function menukeyboard1() {522 log( "keydown", true );523 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );524 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );525 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );526 assert.equal( logOutput(), "keydown,2,3,4", "Keydown focus disabled item with submenu" );527 log( "keydown", true );528 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );529 assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );530 log( "keydown", true );531 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );532 setTimeout( function() {533 assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect on disabled sub-menu)" );534 log( "keydown", true );535 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );536 setTimeout( function() {537 assert.equal( logOutput(), "keydown", "Keydown ENTER (no effect on disabled sub-menu)" );538 log( "click", true );539 click( element, "1" );540 assert.equal( logOutput(), "click", "Click disabled item (no effect)" );541 ready();542 }, 50 );543 }, 50 );544 }545} );546QUnit.test( "handle keyboard navigation and mouse click on menu with dividers and group labels", function( assert ) {547 var ready = assert.async();548 assert.expect( 2 );549 var element = $( "#menu7" ).menu( {550 items: "> :not('.ui-menu-group')",551 select: function( event, ui ) {552 log( $( ui.item[ 0 ] ).text() );553 },554 focus: function( event ) {555 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );556 }557 } );558 log( "keydown", true );559 element.one( "menufocus", function() {560 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );561 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );562 assert.equal( logOutput(), "keydown,2,Ada", "Keydown skips initial group label" );563 setTimeout( menukeyboard1, 50 );564 } );565 element.trigger( "focus" );566 function menukeyboard1() {567 log( "keydown", true );568 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );569 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );570 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );571 assert.equal( logOutput(), "keydown,3,4,7", "Keydown focus skips divider and group label" );572 ready();573 }574} );575QUnit.test( "handle keyboard navigation with spelling of menu items", function( assert ) {576 var ready = assert.async();577 assert.expect( 3 );578 var element = $( "#menu2" ).menu( {579 focus: function( event ) {580 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );581 }582 } );583 log( "keydown", true );584 element.one( "menufocus", function() {585 element.simulate( "keydown", { keyCode: 65 } );586 element.simulate( "keydown", { keyCode: 68 } );587 element.simulate( "keydown", { keyCode: 68 } );588 assert.equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" );589 element.simulate( "keydown", { keyCode: 68 } );590 assert.equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" );591 element.simulate( "keydown", { keyCode: 83 } );592 assert.equal( logOutput(), "keydown,0,1,3,4,5", "Keydown focus Saarland ignoring leading space" );593 ready();594 } );595 element[ 0 ].focus();596} );597QUnit.test( "Keep focus on selected item (see #10644)", function( assert ) {598 var ready = assert.async();599 assert.expect( 1 );600 var element = $( "#menu2" ).menu( {601 focus: function( event ) {602 log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() );603 }604 } );605 log( "keydown", true );606 element.one( "menufocus", function() {607 element.simulate( "keydown", { keyCode: 65 } );608 element.simulate( "keydown", { keyCode: 68 } );609 element.simulate( "keydown", { keyCode: 68 } );610 element.simulate( "keydown", { keyCode: 89 } );611 element.simulate( "keydown", { keyCode: 83 } );612 assert.equal( logOutput(), "keydown,0,1,3,3,3",613 "Focus stays on 'Addyston', even after other options are eliminated" );614 ready();615 } );616 element[ 0 ].focus();617} );618QUnit.test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function( assert ) {619 assert.expect( 1 );620 var element = $( "#menu1" ).menu( {621 select: function( event ) {622 log();623 event.stopPropagation();624 }625 } );626 click( element, "1" );627 click( element, "2" );628 assert.equal( logOutput(), "1,2", "Both select events were not triggered." );629} );630QUnit.test( "#10571: When typing in a menu, only menu-items should be focused", function( assert ) {631 var ready = assert.async();632 assert.expect( 3 );633 var element = $( "#menu8" ).menu( {634 focus: function( event, ui ) {635 assert.equal( ui.item.length, 1, "There should only be one match when filtering" );636 assert.hasClasses( ui.item, "ui-menu-item" );637 assert.equal( ui.item.text(), "-Saarland", "element has correct text" );638 }639 } );640 setTimeout( function() {641 element.menu( "widget" ).simulate( "keydown", { keyCode: "-".charCodeAt( 0 ) } );642 ready();643 } );644} );...

Full Screen

Full Screen

menu_events.js

Source:menu_events.js Github

copy

Full Screen

1(function( $ ) {2var log = TestHelpers.menu.log,3 logOutput = TestHelpers.menu.logOutput,4 click = TestHelpers.menu.click;5module( "menu: events", {6 setup: function() {7 TestHelpers.menu.clearLog();8 }9});10test( "handle click on menu", function() {11 expect( 1 );12 var element = $( "#menu1" ).menu({13 select: function() {14 log();15 }16 });17 log( "click", true );18 click( $( "#menu1" ), "1" );19 log( "afterclick" );20 click( element, "2" );21 click( $( "#menu1" ), "3" );22 click( element, "1" );23 equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );24});25test( "handle click on custom item menu", function() {26 expect( 1 );27 var element = $( "#menu5" ).menu({28 select: function() {29 log();30 },31 menus: "div"32 });33 log( "click", true );34 click( $( "#menu5" ), "1" );35 log( "afterclick" );36 click( element, "2" );37 click( $( "#menu5" ), "3" );38 click( element, "1" );39 equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." );40});41asyncTest( "handle blur", function() {42 expect( 1 );43 var blurHandled = false,44 element = $( "#menu1" ).menu({45 blur: function( event ) {46 // Ignore duplicate blur event fired by IE47 if ( !blurHandled ) {48 blurHandled = true;49 equal( event.type, "menublur", "blur event.type is 'menublur'" );50 }51 }52 });53 click( element, "1" );54 setTimeout(function() {55 element.blur();56 setTimeout(function() {57 start();58 }, 350 );59 });60});61asyncTest( "handle blur via click outside", function() {62 expect( 1 );63 var blurHandled = false,64 element = $( "#menu1" ).menu({65 blur: function( event ) {66 // Ignore duplicate blur event fired by IE67 if ( !blurHandled ) {68 blurHandled = true;69 equal( event.type, "menublur", "blur event.type is 'menublur'" );70 }71 }72 });73 click( element, "1" );74 setTimeout(function() {75 $( "<a>", { id: "remove"} ).appendTo( "body" ).trigger( "click" );76 setTimeout(function() {77 start();78 }, 350 );79 });80});81asyncTest( "handle focus of menu with active item", function() {82 expect( 1 );83 var element = $( "#menu1" ).menu({84 focus: function( event ) {85 log( $( event.target ).find( ".ui-state-focus" ).parent().index() );86 }87 });88 log( "focus", true );89 element[0].focus();90 setTimeout(function() {91 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );92 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );93 element[0].blur();94 setTimeout(function() {95 element[0].focus();96 setTimeout(function() {97 equal( logOutput(), "focus,0,1,2,2", "current active item remains active" );98 start();99 });100 });101 });102});103asyncTest( "handle submenu auto collapse: mouseleave", function() {104 expect( 4 );105 var element = $( "#menu2" ).menu(),106 event = $.Event( "mouseenter" );107 function menumouseleave1() {108 equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" );109 element.menu( "focus", event, element.find( "li:nth-child(7) li:first" ) );110 setTimeout( menumouseleave2, 350 );111 }112 function menumouseleave2() {113 equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" );114 element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" );115 setTimeout( menumouseleave3, 350 );116 }117 function menumouseleave3() {118 equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" );119 element.trigger( "mouseleave" );120 setTimeout( menumouseleave4, 350 );121 }122 function menumouseleave4() {123 equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" );124 start();125 }126 element.find( "li:nth-child(7)" ).trigger( "mouseenter" );127 setTimeout( menumouseleave1, 350 );128});129asyncTest( "handle submenu auto collapse: mouseleave", function() {130 expect( 4 );131 var element = $( "#menu5" ).menu({ menus: "div" }),132 event = $.Event( "mouseenter" );133 function menumouseleave1() {134 equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" );135 element.menu( "focus", event, element.find( ":nth-child(7)" ).find( "div" ).eq( 0 ).children().eq( 0 ) );136 setTimeout( menumouseleave2, 350 );137 }138 function menumouseleave2() {139 equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" );140 element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" );141 setTimeout( menumouseleave3, 350 );142 }143 function menumouseleave3() {144 equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" );145 element.trigger( "mouseleave" );146 setTimeout( menumouseleave4, 350 );147 }148 function menumouseleave4() {149 equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" );150 start();151 }152 element.find( ":nth-child(7)" ).trigger( "mouseenter" );153 setTimeout( menumouseleave1, 350 );154});155asyncTest( "handle keyboard navigation on menu without scroll and without submenus", function() {156 expect( 12 );157 var element = $( "#menu1" ).menu({158 select: function( event, ui ) {159 log( $( ui.item[0] ).text() );160 },161 focus: function( event ) {162 log( $( event.target ).find( ".ui-state-focus" ).parent().index() );163 }164 });165 log( "keydown", true );166 element[0].focus();167 setTimeout(function() {168 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );169 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );170 equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );171 log( "keydown", true );172 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );173 equal( logOutput(), "keydown,1", "Keydown UP" );174 log( "keydown", true );175 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );176 equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );177 log( "keydown", true );178 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );179 equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );180 log( "keydown", true );181 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );182 equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" );183 log( "keydown", true );184 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );185 equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );186 log( "keydown", true );187 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );188 equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );189 log( "keydown", true );190 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );191 equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );192 log( "keydown", true );193 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );194 equal( logOutput(), "keydown,4", "Keydown END" );195 log( "keydown", true );196 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );197 equal( logOutput(), "keydown,0", "Keydown HOME" );198 log( "keydown", true );199 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );200 equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );201 log( "keydown", true );202 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );203 equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );204 start();205 });206});207asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() {208 expect( 16 );209 var element = $( "#menu2" ).menu({210 select: function( event, ui ) {211 log( $( ui.item[0] ).text() );212 },213 focus: function( event ) {214 log( $( event.target ).find( ".ui-state-focus" ).parent().index() );215 }216 });217 log( "keydown", true );218 element.one( "menufocus", function() {219 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );220 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );221 equal( logOutput(), "keydown,1,2", "Keydown DOWN" );222 setTimeout( menukeyboard1, 50 );223 });224 element.focus();225 function menukeyboard1() {226 log( "keydown", true );227 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );228 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );229 equal( logOutput(), "keydown,1,0", "Keydown UP" );230 log( "keydown", true );231 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );232 equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );233 log( "keydown", true );234 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );235 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );236 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );237 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );238 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );239 setTimeout(function() {240 equal( logOutput(), "keydown,1,2,3,4,0", "Keydown RIGHT (open submenu)" );241 setTimeout( menukeyboard2, 50 );242 }, 50 );243 }244 function menukeyboard2() {245 log( "keydown", true );246 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );247 equal( logOutput(), "keydown,4", "Keydown LEFT (close submenu)" );248 // re-open submenu249 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );250 setTimeout( menukeyboard3, 50 );251 }252 function menukeyboard3() {253 log( "keydown", true );254 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );255 equal( logOutput(), "keydown,2", "Keydown PAGE_DOWN" );256 log( "keydown", true );257 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );258 equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );259 log( "keydown", true );260 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );261 equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );262 log( "keydown", true );263 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );264 equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );265 log( "keydown", true );266 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );267 equal( logOutput(), "keydown,2", "Keydown END" );268 log( "keydown", true );269 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );270 equal( logOutput(), "keydown,0", "Keydown HOME" );271 log( "keydown", true );272 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );273 equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );274 log( "keydown", true );275 element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } );276 setTimeout( menukeyboard4, 50 );277 }278 function menukeyboard4() {279 equal( logOutput(), "keydown,0", "Keydown SPACE (open submenu)" );280 log( "keydown", true );281 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );282 equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" );283 log( "keydown", true );284 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );285 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );286 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );287 setTimeout( function() {288 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );289 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );290 setTimeout( function() {291 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );292 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );293 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );294 equal( logOutput(), "keydown,5,6,0,1,0,2,4,0", "Keydown skip dividers and items without anchors" );295 log( "keydown", true );296 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );297 setTimeout( menukeyboard6, 50 );298 }, 50 );299 }, 50 );300 }301 function menukeyboard6() {302 equal( logOutput(), "keydown,Ada", "Keydown ENTER (open submenu)" );303 start();304 }305});306asyncTest( "handle keyboard navigation on menu with scroll and without submenus", function() {307 expect( 14 );308 var element = $( "#menu3" ).menu({309 select: function( event, ui ) {310 log( $( ui.item[0] ).text() );311 },312 focus: function( event ) {313 log( $( event.target ).find( ".ui-state-focus" ).parent().index());314 }315 });316 log( "keydown", true );317 element[0].focus();318 setTimeout(function() {319 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );320 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );321 equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" );322 log( "keydown", true );323 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );324 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );325 equal( logOutput(), "keydown,1,0", "Keydown UP" );326 log( "keydown", true );327 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );328 equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );329 log( "keydown", true );330 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );331 equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" );332 log( "keydown", true );333 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );334 equal( logOutput(), "keydown,10", "Keydown PAGE_DOWN" );335 log( "keydown", true );336 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );337 equal( logOutput(), "keydown,20", "Keydown PAGE_DOWN" );338 log( "keydown", true );339 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );340 equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );341 log( "keydown", true );342 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );343 equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );344 log( "keydown", true );345 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );346 equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" );347 log( "keydown", true );348 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );349 equal( logOutput(), "keydown,37", "Keydown END" );350 log( "keydown", true );351 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );352 equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" );353 log( "keydown", true );354 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );355 equal( logOutput(), "keydown,0", "Keydown HOME" );356 log( "keydown", true );357 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );358 equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" );359 log( "keydown", true );360 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );361 equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" );362 start();363 });364});365asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() {366 expect( 14 );367 var element = $( "#menu4" ).menu({368 select: function( event, ui ) {369 log( $( ui.item[0] ).text() );370 },371 focus: function( event ) {372 log( $( event.target ).find( ".ui-state-focus" ).parent().index());373 }374 });375 log( "keydown", true );376 element.one( "menufocus", function() {377 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );378 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );379 equal( logOutput(), "keydown,1,2", "Keydown DOWN" );380 setTimeout( menukeyboard1, 50 );381 });382 element.focus();383 function menukeyboard1() {384 log( "keydown", true );385 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );386 element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );387 equal( logOutput(), "keydown,1,0", "Keydown UP" );388 log( "keydown", true );389 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );390 equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );391 log( "keydown", true );392 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );393 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );394 setTimeout( function() {395 equal( logOutput(), "keydown,1,0", "Keydown RIGHT (open submenu)" );396 }, 50 );397 setTimeout( menukeyboard2, 50 );398 }399 function menukeyboard2() {400 log( "keydown", true );401 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );402 equal( logOutput(), "keydown,1", "Keydown LEFT (close submenu)" );403 // re-open submenu404 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );405 setTimeout( menukeyboard3, 50 );406 }407 function menukeyboard3() {408 log( "keydown", true );409 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );410 equal( logOutput(), "keydown,10", "Keydown PAGE_DOWN" );411 log( "keydown", true );412 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );413 equal( logOutput(), "keydown,20", "Keydown PAGE_DOWN" );414 log( "keydown", true );415 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );416 equal( logOutput(), "keydown,10", "Keydown PAGE_UP" );417 log( "keydown", true );418 element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );419 equal( logOutput(), "keydown,0", "Keydown PAGE_UP" );420 log( "keydown", true );421 element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );422 equal( logOutput(), "keydown,27", "Keydown END" );423 log( "keydown", true );424 element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );425 equal( logOutput(), "keydown,0", "Keydown HOME" );426 log( "keydown", true );427 element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );428 equal( logOutput(), "keydown,1", "Keydown ESCAPE (close submenu)" );429 log( "keydown", true );430 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );431 setTimeout( menukeyboard4, 50 );432 }433 function menukeyboard4() {434 equal( logOutput(), "keydown,0", "Keydown ENTER (open submenu)" );435 log( "keydown", true );436 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );437 equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER (select item)" );438 start();439 }440});441asyncTest( "handle keyboard navigation and mouse click on menu with disabled items", function() {442 expect( 6 );443 var element = $( "#menu6" ).menu({444 select: function( event, ui ) {445 log( $( ui.item[0] ).text() );446 },447 focus: function( event ) {448 log( $( event.target ).find( ".ui-state-focus" ).parent().index());449 }450 });451 log( "keydown", true );452 element.one( "menufocus", function() {453 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );454 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );455 equal( logOutput(), "keydown,1", "Keydown focus but not select disabled item" );456 setTimeout( menukeyboard1, 50 );457 });458 element.focus();459 function menukeyboard1() {460 log( "keydown", true );461 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );462 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );463 element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );464 equal( logOutput(), "keydown,2,3,4", "Keydown focus disabled item with submenu" );465 log( "keydown", true );466 element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );467 equal( logOutput(), "keydown", "Keydown LEFT (no effect)" );468 log( "keydown", true );469 element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );470 setTimeout( function() {471 equal( logOutput(), "keydown", "Keydown RIGHT (no effect on disabled sub-menu)" );472 log( "keydown", true );473 element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );474 setTimeout( function() {475 equal( logOutput(), "keydown", "Keydown ENTER (no effect on disabled sub-menu)" );476 log( "click", true );477 click( element, "1" );478 equal( logOutput(), "click", "Click disabled item (no effect)" );479 start();480 }, 50 );481 }, 50 );482 }483});484asyncTest( "handle keyboard navigation with spelling of menu items", function() {485 expect( 2 );486 var element = $( "#menu2" ).menu({487 focus: function( event ) {488 log( $( event.target ).find( ".ui-state-focus" ).parent().index() );489 }490 });491 log( "keydown", true );492 element.one( "menufocus", function() {493 element.simulate( "keydown", { keyCode: 65 } );494 element.simulate( "keydown", { keyCode: 68 } );495 element.simulate( "keydown", { keyCode: 68 } );496 equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" );497 element.simulate( "keydown", { keyCode: 68 } );498 equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" );499 start();500 });501 element[0].focus();502});...

Full Screen

Full Screen

slider_core.js

Source:slider_core.js Github

copy

Full Screen

1/*2 * slider unit tests3 */4(function($) {5//6// Slider Test Helper Functions7//8var el, options;9function handle() {10 return el.find(".ui-slider-handle");11}12// Slider Tests13module("slider: core");14test("keydown HOME on handle sets value to min", function() {15 el = $('<div></div>');16 options = {17 max: 5,18 min: -5,19 orientation: 'horizontal',20 step: 121 };22 el.slider(options);23 el.slider("value", 0);24 handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME });25 equals(el.slider("value"), options.min);26 el.slider('destroy'); 27 el = $('<div></div>');28 options = {29 max: 5,30 min: -5,31 orientation: 'vertical',32 step: 133 };34 el.slider(options);35 el.slider("value", 0);36 handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME });37 equals(el.slider("value"), options.min);38 el.slider('destroy');39});40test("keydown END on handle sets value to max", function() {41 el = $('<div></div>');42 options = {43 max: 5,44 min: -5,45 orientation: 'horizontal',46 step: 147 };48 el.slider(options);49 el.slider("value", 0);50 handle().simulate("keydown", { keyCode: $.ui.keyCode.END });51 equals(el.slider("value"), options.max);52 el.slider('destroy'); 53 el = $('<div></div>');54 options = {55 max: 5,56 min: -5,57 orientation: 'vertical',58 step: 159 };60 el.slider(options);61 el.slider("value", 0);62 handle().simulate("keydown", { keyCode: $.ui.keyCode.END });63 equals(el.slider("value"), options.max);64 el.slider('destroy');65});66test("keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() {67 $.each(['horizontal', 'vertical'], function(i, orientation) {68 el = $('<div></div>');69 options = {70 max: 100,71 min: 0,72 orientation: orientation,73 step: 174 };75 el.slider(options);76 el.slider("value", 70);77 handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });78 equals(el.slider("value"), 90);79 handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });80 equals(el.slider("value"), 100);81 el.slider("destroy");82 });83});84test("keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() {85 $.each(['horizontal', 'vertical'], function(i, orientation) {86 el = $('<div></div>');87 options = {88 max: 100,89 min: 0,90 orientation: orientation,91 step: 192 };93 el.slider(options);94 el.slider("value", 30);95 handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });96 equals(el.slider("value"), 10);97 handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });98 equals(el.slider("value"), 0);99 el.slider("destroy");100 });101});102test("keydown UP on handle increases value by step, not greater than max", function() {103 el = $('<div></div>');104 options = {105 max: 5,106 min: -5,107 orientation: 'horizontal',108 step: 1109 };110 el.slider(options);111 el.slider("value", options.max - options.step);112 handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });113 equals(el.slider("value"), options.max);114 handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });115 equals(el.slider("value"), options.max);116 el.slider("destroy"); 117 el = $('<div></div>');118 options = {119 max: 5,120 min: -5,121 orientation: 'vertical',122 step: 1123 };124 el.slider(options);125 el.slider("value", options.max - options.step);126 handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });127 equals(el.slider("value"), options.max);128 handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });129 equals(el.slider("value"), options.max);130 el.slider("destroy"); 131});132test("keydown RIGHT on handle increases value by step, not greater than max", function() {133 el = $('<div></div>');134 options = {135 max: 5,136 min: -5,137 orientation: 'horizontal',138 step: 1139 };140 el.slider(options);141 el.slider("value", options.max - options.step);142 handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });143 equals(el.slider("value"), options.max);144 handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });145 equals(el.slider("value"), options.max);146 el.slider("destroy"); 147 el = $('<div></div>');148 options = {149 max: 5,150 min: -5,151 orientation: 'vertical',152 step: 1153 };154 el.slider(options);155 el.slider("value", options.max - options.step);156 handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });157 equals(el.slider("value"), options.max);158 handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });159 equals(el.slider("value"), options.max);160 el.slider("destroy"); 161});162test("keydown DOWN on handle decreases value by step, not less than min", function() {163 el = $('<div></div>');164 options = {165 max: 5,166 min: -5,167 orientation: 'horizontal',168 step: 1169 };170 el.slider(options);171 el.slider("value", options.min + options.step);172 handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });173 equals(el.slider("value"), options.min);174 handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });175 equals(el.slider("value"), options.min);176 el.slider("destroy"); 177 el = $('<div></div>');178 options = {179 max: 5,180 min: -5,181 orientation: 'vertical',182 step: 1183 };184 el.slider(options);185 el.slider("value", options.min + options.step);186 handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });187 equals(el.slider("value"), options.min);188 handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });189 equals(el.slider("value"), options.min);190 el.slider("destroy"); 191});192test("keydown LEFT on handle decreases value by step, not less than min", function() {193 el = $('<div></div>');194 options = {195 max: 5,196 min: -5,197 orientation: 'horizontal',198 step: 1199 };200 el.slider(options);201 el.slider("value", options.min + options.step);202 handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });203 equals(el.slider("value"), options.min);204 handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });205 equals(el.slider("value"), options.min);206 el.slider("destroy"); 207 el = $('<div></div>');208 options = {209 max: 5,210 min: -5,211 orientation: 'vertical',212 step: 1213 };214 el.slider(options);215 el.slider("value", options.min + options.step);216 handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });217 equals(el.slider("value"), options.min);218 handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });219 equals(el.slider("value"), options.min);220 el.slider("destroy"); 221});...

Full Screen

Full Screen

browsers.js

Source:browsers.js Github

copy

Full Screen

1(function(){2 Syn.key.browsers = {3 webkit : {4 'prevent':5 {"keyup":[],"keydown":["char","keypress"],"keypress":["char"]},6 'character':7 {"keydown":[0,"key"],"keypress":["char","char"],"keyup":[0,"key"]},8 'specialChars':9 {"keydown":[0,"char"],"keyup":[0,"char"]},10 'navigation':11 {"keydown":[0,"key"],"keyup":[0,"key"]},12 'special':13 {"keydown":[0,"key"],"keyup":[0,"key"]},14 'tab':15 {"keydown":[0,"char"],"keyup":[0,"char"]},16 'pause-break':17 {"keydown":[0,"key"],"keyup":[0,"key"]},18 'caps':19 {"keydown":[0,"key"],"keyup":[0,"key"]},20 'escape':21 {"keydown":[0,"key"],"keyup":[0,"key"]},22 'num-lock':23 {"keydown":[0,"key"],"keyup":[0,"key"]},24 'scroll-lock':25 {"keydown":[0,"key"],"keyup":[0,"key"]},26 'print':27 {"keyup":[0,"key"]},28 'function':29 {"keydown":[0,"key"],"keyup":[0,"key"]},30 '\r':31 {"keydown":[0,"key"],"keypress":["char","key"],"keyup":[0,"key"]}32 },33 gecko : {34 'prevent':35 {"keyup":[],"keydown":["char"],"keypress":["char"]},36 'character':37 {"keydown":[0,"key"],"keypress":["char",0],"keyup":[0,"key"]},38 'specialChars':39 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]},40 'navigation':41 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]},42 'special':43 {"keydown":[0,"key"],"keyup":[0,"key"]},44 '\t':45 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]},46 'pause-break':47 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]},48 'caps':49 {"keydown":[0,"key"],"keyup":[0,"key"]},50 'escape':51 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]},52 'num-lock':53 {"keydown":[0,"key"],"keyup":[0,"key"]},54 'scroll-lock':55 {"keydown":[0,"key"],"keyup":[0,"key"]},56 'print':57 {"keyup":[0,"key"]},58 'function':59 {"keydown":[0,"key"],"keyup":[0,"key"]},60 '\r':61 {"keydown":[0,"key"],"keypress":[0,"key"],"keyup":[0,"key"]}62 },63 msie : {64 'prevent':{"keyup":[],"keydown":["char","keypress"],"keypress":["char"]},65 'character':{"keydown":[null,"key"],"keypress":[null,"char"],"keyup":[null,"key"]},66 'specialChars':{"keydown":[null,"char"],"keyup":[null,"char"]},67 'navigation':{"keydown":[null,"key"],"keyup":[null,"key"]},68 'special':{"keydown":[null,"key"],"keyup":[null,"key"]},69 'tab':{"keydown":[null,"char"],"keyup":[null,"char"]},70 'pause-break':{"keydown":[null,"key"],"keyup":[null,"key"]},71 'caps':{"keydown":[null,"key"],"keyup":[null,"key"]},72 'escape':{"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]},73 'num-lock':{"keydown":[null,"key"],"keyup":[null,"key"]},74 'scroll-lock':{"keydown":[null,"key"],"keyup":[null,"key"]},75 'print':{"keyup":[null,"key"]},76 'function':{"keydown":[null,"key"],"keyup":[null,"key"]},77 '\r':{"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]} 78 },79 opera : {80 'prevent':81 {"keyup":[],"keydown":[],"keypress":["char"]},82 'character':83 {"keydown":[null,"key"],"keypress":[null,"char"],"keyup":[null,"key"]},84 'specialChars':85 {"keydown":[null,"char"],"keypress":[null,"char"],"keyup":[null,"char"]},86 'navigation':87 {"keydown":[null,"key"],"keypress":[null,"key"]},88 'special':89 {"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]},90 'tab':91 {"keydown":[null,"char"],"keypress":[null,"char"],"keyup":[null,"char"]},92 'pause-break':93 {"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]},94 'caps':95 {"keydown":[null,"key"],"keyup":[null,"key"]},96 'escape':97 {"keydown":[null,"key"],"keypress":[null,"key"]},98 'num-lock':99 {"keyup":[null,"key"],"keydown":[null,"key"],"keypress":[null,"key"]},100 'scroll-lock':101 {"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]},102 'print':103 {},104 'function':105 {"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]},106 '\r':107 {"keydown":[null,"key"],"keypress":[null,"key"],"keyup":[null,"key"]} 108 }109 };110 111 Syn.mouse.browsers = {112 webkit : {"right":{"mousedown":{"button":2,"which":3},"mouseup":{"button":2,"which":3},"contextmenu":{"button":2,"which":3}},113 "left":{"mousedown":{"button":0,"which":1},"mouseup":{"button":0,"which":1},"click":{"button":0,"which":1}}},114 opera: {"right":{"mousedown":{"button":2,"which":3},"mouseup":{"button":2,"which":3}},115 "left":{"mousedown":{"button":0,"which":1},"mouseup":{"button":0,"which":1},"click":{"button":0,"which":1}}},116 msie: { "right":{"mousedown":{"button":2},"mouseup":{"button":2},"contextmenu":{"button":0}},117 "left":{"mousedown":{"button":1},"mouseup":{"button":1},"click":{"button":0}}},118 chrome : {"right":{"mousedown":{"button":2,"which":3},"mouseup":{"button":2,"which":3},"contextmenu":{"button":2,"which":3}},119 "left":{"mousedown":{"button":0,"which":1},"mouseup":{"button":0,"which":1},"click":{"button":0,"which":1}}},120 gecko: {"left":{"mousedown":{"button":0,"which":1},"mouseup":{"button":0,"which":1},"click":{"button":0,"which":1}},121 "right":{"mousedown":{"button":2,"which":3},"mouseup":{"button":2,"which":3},"contextmenu":{"button":2,"which":3}}}122 }123 124 //set browser125 Syn.key.browser = 126 (function(){127 if(Syn.key.browsers[window.navigator.userAgent]){128 return Syn.key.browsers[window.navigator.userAgent];129 }130 for(var browser in Syn.browser){131 if(Syn.browser[browser] && Syn.key.browsers[browser]){132 return Syn.key.browsers[browser]133 }134 }135 return Syn.key.browsers.gecko;136 })();137 138 Syn.mouse.browser = 139 (function(){140 if(Syn.mouse.browsers[window.navigator.userAgent]){141 return Syn.mouse.browsers[window.navigator.userAgent];142 }143 for(var browser in Syn.browser){144 if(Syn.browser[browser] && Syn.mouse.browsers[browser]){145 return Syn.mouse.browsers[browser]146 }147 }148 return Syn.mouse.browsers.gecko;149 })();...

Full Screen

Full Screen

key-codes.js

Source:key-codes.js Github

copy

Full Screen

1var KeyCodes;2(function (KeyCodes) {3 var KeyDown;4 (function (KeyDown) {5 KeyDown.Backspace = 8;6 KeyDown.Tab = 9;7 KeyDown.Enter = 13;8 KeyDown.Shift = 16;9 KeyDown.Ctrl = 17;10 KeyDown.Alt = 18;11 KeyDown.PauseBreak = 19;12 KeyDown.CapsLock = 20;13 KeyDown.Escape = 27;14 KeyDown.Spacebar = 32;15 KeyDown.PageUp = 33;16 KeyDown.PageDown = 34;17 KeyDown.End = 35;18 KeyDown.Home = 36;19 KeyDown.LeftArrow = 37;20 KeyDown.UpArrow = 38;21 KeyDown.RightArrow = 39;22 KeyDown.DownArrow = 40;23 KeyDown.PrintScrn = 44;24 KeyDown.Insert = 45;25 KeyDown.Delete = 46;26 KeyDown.Zero = 48;27 KeyDown.One = 49;28 KeyDown.Two = 50;29 KeyDown.Three = 51;30 KeyDown.Four = 52;31 KeyDown.Five = 53;32 KeyDown.Six = 54;33 KeyDown.Seven = 55;34 KeyDown.Eight = 56;35 KeyDown.Nine = 57;36 KeyDown.a = 65;37 KeyDown.b = 66;38 KeyDown.c = 67;39 KeyDown.d = 68;40 KeyDown.e = 69;41 KeyDown.f = 70;42 KeyDown.g = 71;43 KeyDown.h = 72;44 KeyDown.i = 73;45 KeyDown.j = 74;46 KeyDown.k = 75;47 KeyDown.l = 76;48 KeyDown.m = 77;49 KeyDown.n = 78;50 KeyDown.o = 79;51 KeyDown.p = 80;52 KeyDown.q = 81;53 KeyDown.r = 82;54 KeyDown.s = 83;55 KeyDown.t = 84;56 KeyDown.u = 85;57 KeyDown.v = 86;58 KeyDown.w = 87;59 KeyDown.x = 88;60 KeyDown.y = 89;61 KeyDown.z = 90;62 KeyDown.LeftWindowKey = 91;63 KeyDown.RightWindowKey = 92;64 KeyDown.SelectKey = 93;65 KeyDown.Numpad0 = 96;66 KeyDown.Numpad1 = 97;67 KeyDown.Numpad2 = 98;68 KeyDown.Numpad3 = 99;69 KeyDown.Numpad4 = 100;70 KeyDown.Numpad5 = 101;71 KeyDown.Numpad6 = 102;72 KeyDown.Numpad7 = 103;73 KeyDown.Numpad8 = 104;74 KeyDown.Numpad9 = 105;75 KeyDown.Multiply = 106;76 KeyDown.NumpadPlus = 107;77 KeyDown.NumpadMinus = 109;78 KeyDown.DecimalPoint = 110;79 KeyDown.Divide = 111;80 KeyDown.F1 = 112;81 KeyDown.F2 = 113;82 KeyDown.F3 = 114;83 KeyDown.F4 = 115;84 KeyDown.F5 = 116;85 KeyDown.F6 = 117;86 KeyDown.F7 = 118;87 KeyDown.F8 = 119;88 KeyDown.F9 = 120;89 KeyDown.F10 = 121;90 KeyDown.F11 = 122;91 KeyDown.F12 = 123;92 KeyDown.NumLock = 144;93 KeyDown.ScrollLock = 145;94 KeyDown.Semicolon = 186;95 KeyDown.Equals = 187;96 KeyDown.Comma = 188;97 KeyDown.LessThan = 188;98 KeyDown.Dash = 189;99 KeyDown.Period = 190;100 KeyDown.GreaterThan = 190;101 KeyDown.ForwardSlash = 191;102 KeyDown.QuestionMark = 191;103 KeyDown.GraveAccent = 192;104 KeyDown.Tilde = 192;105 KeyDown.OpenCurlyBracket = 219;106 KeyDown.OpenSquareBracket = 219;107 KeyDown.BackSlash = 220;108 KeyDown.VerticalPipe = 220;109 KeyDown.CloseCurlyBracket = 221;110 KeyDown.CloseSquareBracket = 221;111 KeyDown.Quote = 222;112 KeyDown.CommandFF = 224;113 })(KeyDown = KeyCodes.KeyDown || (KeyCodes.KeyDown = {}));114})(KeyCodes || (KeyCodes = {}));115var KeyCodes;116(function (KeyCodes) {117 var KeyPress;118 (function (KeyPress) {119 KeyPress.Backspace = 8;120 KeyPress.Enter = 13;121 KeyPress.Spacebar = 32;122 KeyPress.Hash = 35;123 KeyPress.GraveAccent = 39;124 KeyPress.ForwardSlash = 32;125 KeyPress.Asterisk = 42;126 KeyPress.Plus = 43;127 KeyPress.Comma = 44;128 KeyPress.Minus = 45;129 KeyPress.Period = 46;130 KeyPress.ForwardSlash = 47;131 KeyPress.Zero = 48;132 KeyPress.One = 49;133 KeyPress.Two = 50;134 KeyPress.Three = 51;135 KeyPress.Four = 52;136 KeyPress.Five = 53;137 KeyPress.Six = 54;138 KeyPress.Seven = 55;139 KeyPress.Eight = 56;140 KeyPress.Nine = 57;141 KeyPress.Colon = 58;142 KeyPress.Semicolon = 59;143 KeyPress.LessThan = 60;144 KeyPress.Equals = 61;145 KeyPress.GreaterThan = 62;146 KeyPress.QuestionMark = 63;147 KeyPress.At = 64;148 KeyPress.OpenSquareBracket = 91;149 KeyPress.BackSlash = 92;150 KeyPress.CloseSquareBracket = 93;151 KeyPress.a = 97;152 KeyPress.b = 98;153 KeyPress.c = 99;154 KeyPress.d = 100;155 KeyPress.e = 101;156 KeyPress.f = 102;157 KeyPress.g = 103;158 KeyPress.h = 104;159 KeyPress.i = 105;160 KeyPress.j = 106;161 KeyPress.k = 107;162 KeyPress.l = 108;163 KeyPress.m = 109;164 KeyPress.n = 110;165 KeyPress.o = 111;166 KeyPress.p = 112;167 KeyPress.q = 113;168 KeyPress.r = 114;169 KeyPress.s = 115;170 KeyPress.t = 116;171 KeyPress.u = 117;172 KeyPress.v = 118;173 KeyPress.w = 119;174 KeyPress.x = 120;175 KeyPress.y = 121;176 KeyPress.z = 122;177 KeyPress.OpenCurlyBracket = 123;178 KeyPress.VerticalPipe = 124;179 KeyPress.CloseCurlyBracket = 125;180 KeyPress.Tilde = 126;181 })(KeyPress = KeyCodes.KeyPress || (KeyCodes.KeyPress = {}));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.down('KeyA');7 await page.keyboard.up('KeyA');8 await page.keyboard.down('KeyB');9 await page.keyboard.up('KeyB');10 await page.keyboard.down('KeyC');11 await page.keyboard.up('KeyC');12 await page.keyboard.down('KeyD');13 await page.keyboard.up('KeyD');14 await page.keyboard.down('KeyE');15 await page.keyboard.up('KeyE');16 await page.keyboard.down('KeyF');17 await page.keyboard.up('KeyF');18 await page.keyboard.down('KeyG');19 await page.keyboard.up('KeyG');20 await page.keyboard.down('KeyH');21 await page.keyboard.up('KeyH');22 await page.keyboard.down('KeyI');23 await page.keyboard.up('KeyI');24 await page.keyboard.down('KeyJ');25 await page.keyboard.up('KeyJ');26 await page.keyboard.down('KeyK');27 await page.keyboard.up('KeyK');28 await page.keyboard.down('KeyL');29 await page.keyboard.up('KeyL');30 await page.keyboard.down('KeyM');31 await page.keyboard.up('KeyM');32 await page.keyboard.down('KeyN');33 await page.keyboard.up('KeyN');34 await page.keyboard.down('KeyO');35 await page.keyboard.up('KeyO');36 await page.keyboard.down('KeyP');37 await page.keyboard.up('KeyP');38 await page.keyboard.down('KeyQ');39 await page.keyboard.up('KeyQ');40 await page.keyboard.down('KeyR');41 await page.keyboard.up('KeyR');42 await page.keyboard.down('KeyS');43 await page.keyboard.up('KeyS');44 await page.keyboard.down('KeyT');45 await page.keyboard.up('KeyT');46 await page.keyboard.down('KeyU');47 await page.keyboard.up('KeyU');48 await page.keyboard.down('KeyV');49 await page.keyboard.up('KeyV');50 await page.keyboard.down('KeyW');51 await page.keyboard.up('KeyW');52 await page.keyboard.down('KeyX');53 await page.keyboard.up('KeyX');54 await page.keyboard.down('KeyY');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.press('ArrowRight');7 await page.keyboard.press('ArrowLeft');8 await page.keyboard.press('ArrowUp');9 await page.keyboard.press('ArrowDown');10 await page.keyboard.press('Enter');11 await page.keyboard.press('Escape');12 await page.keyboard.press('Backspace');13 await page.keyboard.press('Delete');14 await page.keyboard.press('PageUp');15 await page.keyboard.press('PageDown');16 await page.keyboard.press('Home');17 await page.keyboard.press('End');18 await page.keyboard.press('Insert');19 await page.keyboard.press('F1');20 await page.keyboard.press('F12');21 await page.keyboard.press('Digit0');22 await page.keyboard.press('Digit9');23 await page.keyboard.press('KeyA');24 await page.keyboard.press('KeyZ');25 await page.keyboard.press('Semicolon');26 await page.keyboard.press('Quote');27 await page.keyboard.press('BracketLeft');28 await page.keyboard.press('BracketRight');29 await page.keyboard.press('Backslash');30 await page.keyboard.press('Comma');31 await page.keyboard.press('Period');32 await page.keyboard.press('Slash');33 await page.keyboard.press('Numpad0');34 await page.keyboard.press('Numpad9');35 await page.keyboard.press('NumpadAdd');36 await page.keyboard.press('NumpadSubtract');37 await page.keyboard.press('NumpadMultiply');38 await page.keyboard.press('NumpadDivide');39 await page.keyboard.press('NumpadDecimal');40 await page.keyboard.press('NumpadEnter');41 await page.keyboard.press('ShiftLeft');42 await page.keyboard.press('ControlLeft');43 await page.keyboard.press('AltLeft');44 await page.keyboard.press('MetaLeft');45 await page.keyboard.press('ShiftRight');46 await page.keyboard.press('ControlRight');47 await page.keyboard.press('AltRight');48 await page.keyboard.press('MetaRight');49 await page.keyboard.press('ContextMenu');50 await page.keyboard.press('Tab');51 await page.keyboard.press('Space');52 await page.keyboard.press('Minus');53 await page.keyboard.press('Equal');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.press('ArrowUp');7 await page.keyboard.press('ArrowDown');8 await page.keyboard.press('ArrowLeft');9 await page.keyboard.press('ArrowRight');10 await page.keyboard.press('Enter');11 await page.keyboard.press('Escape');12 await page.keyboard.press('Backspace');13 await page.keyboard.press('Delete');14 await page.keyboard.press('PageUp');15 await page.keyboard.press('PageDown');16 await page.keyboard.press('Home');17 await page.keyboard.press('End');18 await page.keyboard.press('Tab');19 await page.keyboard.press('Shift');20 await page.keyboard.press('Control');21 await page.keyboard.press('Alt');22 await page.keyboard.press('Meta');23 await page.keyboard.press('F1');24 await page.keyboard.press('F2');25 await page.keyboard.press('F3');26 await page.keyboard.press('F4');27 await page.keyboard.press('F5');28 await page.keyboard.press('F6');29 await page.keyboard.press('F7');30 await page.keyboard.press('F8');31 await page.keyboard.press('F9');32 await page.keyboard.press('F10');33 await page.keyboard.press('F11');34 await page.keyboard.press('F12');35 await page.keyboard.press('NumLock');36 await page.keyboard.press('ScrollLock');37 await page.keyboard.press('Pause');38 await page.keyboard.press('Insert');39 await page.keyboard.press('PrintScreen');40 await page.keyboard.press('ContextMenu');41 await page.keyboard.press('Power');42 await page.keyboard.press('AudioVolumeMute');43 await page.keyboard.press('AudioVolumeDown');44 await page.keyboard.press('AudioVolumeUp');45 await page.keyboard.press('Numpad0');46 await page.keyboard.press('Numpad1');47 await page.keyboard.press('Numpad2');48 await page.keyboard.press('Numpad3');49 await page.keyboard.press('Numpad4');50 await page.keyboard.press('Numpad5');51 await page.keyboard.press('Numpad6');52 await page.keyboard.press('Numpad7');53 await page.keyboard.press('Numpad8');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.keyboard.press('ArrowLeft');7 await browser.close();8})();9I am currently working on a project which requires me to use the internal API of playwright. I have been trying to use the keyboard.press() method but I keep getting the error: "TypeError: page.keyboard.press is not a function". I have tried using the keyboard.down() method but it does not work either. I am using the latest version of playwright. I have also tried using the method in the following way:10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.keyboard.press('ArrowLeft');16 await browser.close();17})();18const { chromium } = require('playwright');19(async () => {20 const browser = await chromium.launch();21 const context = await browser.newContext();22 const page = await context.newPage();23 await page.keyboard.press('ArrowLeft');24 await browser.close();25})();26const { chromium } = require('playwright');27(async () => {28 const browser = await chromium.launch();29 const context = await browser.newContext();30 const page = await context.newPage();31 await page.keyboard.press('ArrowLeft');32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 const page = await context.newPage();39 await page.keyboard.press('ArrowLeft');40 await browser.close();41})();42const { chromium } = require('playwright');43(async () => {44 const browser = await chromium.launch();45 const context = await browser.newContext();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.keyboard.down('Shift');6 await page.screenshot({ path: `example.png` });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const page = await browser.newPage();13 await page.keyboard.down('Shift');14 await page.screenshot({ path: `example.png` });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const page = await browser.newPage();21 await page.keyboard.down('Shift');22 await page.screenshot({ path: `example.png` });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const page = await browser.newPage();29 await page.keyboard.down('Shift');30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const page = await browser.newPage();37 await page.keyboard.down('Shift');38 await page.screenshot({ path: `example.png` });39 await browser.close();40})();41const { chromium } = require('playwright');42(async () => {43 const browser = await chromium.launch();44 const page = await browser.newPage();45 await page.keyboard.down('Shift');46 await page.screenshot({ path

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Keyboard, Mouse } = require('@playwright/test/lib/server/input');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 const keyboard = new Keyboard(page);8 await keyboard.down('Shift');9 await keyboard.down('KeyA');10 await keyboard.up('KeyA');11 await keyboard.up('Shift');12 const mouse = new Mouse(page);13 await mouse.move(100, 100);14 await mouse.down();15 await mouse.move(200, 200);16 await mouse.up();17 await browser.close();18})();19const { test } = require('@playwright/test');20test('My test', async ({ page }) => {21 await page.click('text=Sign in');22 await page.click('input[name="identifier"]');23 await page.fill('input[name="identifier"]', 'test');24 await page.keyboard.press('Enter');25 await page.click('input[name="password"]');26 await page.fill('input[name="password"]', 'test');27 await page.keyboard.press('Enter');28 await page.click('text=Google Search');29});

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2const {Key} = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.click('input[name="q"]');7 await page.keyboard.down(Key.SHIFT);8 await page.keyboard.press('a');9 await page.keyboard.up(Key.SHIFT);10 await page.keyboard.press('b');11 await page.keyboard.down(Key.SHIFT);12 await page.keyboard.press('c');13 await page.keyboard.up(Key.SHIFT);14 await page.keyboard.press('d');15 await page.keyboard.down(Key.SHIFT);16 await page.keyboard.press('e');17 await page.keyboard.up(Key.SHIFT);18 await page.keyboard.press('f');19 await page.keyboard.down(Key.SHIFT);20 await page.keyboard.press('g');21 await page.keyboard.up(Key.SHIFT);22 await page.keyboard.press('h');23 await page.keyboard.down(Key.SHIFT);24 await page.keyboard.press('i');25 await page.keyboard.up(Key.SHIFT);26 await page.keyboard.press('j');27 await page.keyboard.down(Key.SHIFT);28 await page.keyboard.press('k');29 await page.keyboard.up(Key.SHIFT);30 await page.keyboard.press('l');31 await page.keyboard.down(Key.SHIFT);32 await page.keyboard.press('m');33 await page.keyboard.up(Key.SHIFT);34 await page.keyboard.press('n');35 await page.keyboard.down(Key.SHIFT);36 await page.keyboard.press('o');37 await page.keyboard.up(Key.SHIFT);38 await page.keyboard.press('p');39 await page.keyboard.down(Key.SHIFT);40 await page.keyboard.press('q');41 await page.keyboard.up(Key.SHIFT);42 await page.keyboard.press('r');43 await page.keyboard.down(Key.SHIFT);44 await page.keyboard.press('s');45 await page.keyboard.up(Key.SHIFT);46 await page.keyboard.press('t');47 await page.keyboard.down(Key.SHIFT);48 await page.keyboard.press('u');49 await page.keyboard.up(Key.SHIFT);50 await page.keyboard.press('v');51 await page.keyboard.down(Key.SHIFT);52 await page.keyboard.press('w');53 await page.keyboard.up(Key.SHIFT);54 await page.keyboard.press('x');55 await page.keyboard.down(Key.SHIFT);56 await page.keyboard.press('y');

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful