@@ -2345,62 +2345,141 @@ QUnit.module('accessibility', {
23452345 assert . strictEqual ( $overlay . attr ( 'role' ) , 'dialog' ) ;
23462346 } ) ;
23472347
2348- QUnit . test ( 'should hide visible popover on esc press' , function ( assert ) {
2349- const popover = new Popover ( $ ( '#what' ) , {
2350- target : '#where' ,
2351- visible : true ,
2352- } ) ;
2353- const $target = $ ( '#where' ) . attr ( 'tabindex' , 0 ) ;
2354- const keyboard = keyboardMock ( $target ) ;
2348+ QUnit . module ( 'WCAG - dismissible' , ( ) => {
2349+ QUnit . test ( 'should hide visible popover on esc press' , function ( assert ) {
2350+ const popover = new Popover ( $ ( '#what' ) , {
2351+ target : '#where' ,
2352+ visible : true ,
2353+ } ) ;
2354+ const $target = $ ( '#where' ) . attr ( 'tabindex' , 0 ) ;
2355+ const keyboard = keyboardMock ( $target ) ;
23552356
2356- keyboard . keyDown ( 'esc' ) ;
2357+ keyboard . keyDown ( 'esc' ) ;
23572358
2358- assert . strictEqual ( popover . option ( 'visible' ) , false , 'popover is hidden' ) ;
2359- } ) ;
2359+ assert . strictEqual ( popover . option ( 'visible' ) , false , 'popover is hidden' ) ;
2360+ } ) ;
23602361
2361- QUnit . test ( 'should hide only topmost popover on esc press' , function ( assert ) {
2362- const $markup = $ ( '<div id="popover1"></div>' +
2362+ QUnit . test ( 'should hide only topmost popover on esc press' , function ( assert ) {
2363+ const $markup = $ ( '<div id="popover1"></div>' +
23632364 '<div id="popover2"></div>' +
23642365 '<div id="target1" tabindex="0"></div>' +
23652366 '<div id="target2" tabindex="0"></div>' )
2366- . appendTo ( 'body' ) ;
2367+ . appendTo ( 'body' ) ;
23672368
23682369
2369- const bottomPopover = new Popover ( $ ( '#popover1' ) , {
2370- target : '#target1' ,
2371- visible : true ,
2372- } ) ;
2373- const topPopover = new Popover ( $ ( '#popover2' ) , {
2374- target : '#target2' ,
2375- visible : true ,
2370+ const bottomPopover = new Popover ( $ ( '#popover1' ) , {
2371+ target : '#target1' ,
2372+ visible : true ,
2373+ } ) ;
2374+ const topPopover = new Popover ( $ ( '#popover2' ) , {
2375+ target : '#target2' ,
2376+ visible : true ,
2377+ } ) ;
2378+
2379+ const keyboard = keyboardMock ( $ ( '#target2' ) ) ;
2380+
2381+ keyboard . keyDown ( 'esc' ) ;
2382+
2383+ assert . strictEqual ( topPopover . option ( 'visible' ) , false , 'top popover is hidden' ) ;
2384+ assert . strictEqual ( bottomPopover . option ( 'visible' ) , true , 'bottom popover is still visible' ) ;
2385+
2386+ $markup . remove ( ) ;
23762387 } ) ;
23772388
2378- const keyboard = keyboardMock ( $ ( '#target2' ) ) ;
2389+ QUnit . test ( 'should not call hide for hidden popover on esc press' , function ( assert ) {
2390+ const popover = new Popover ( $ ( '#what' ) , {
2391+ target : '#where' ,
2392+ visible : true ,
2393+ animation : null ,
2394+ } ) ;
2395+ const hideSpy = sinon . spy ( popover , 'hide' ) ;
2396+ const $target = $ ( '#where' ) . attr ( 'tabindex' , 0 ) ;
2397+ const keyboard = keyboardMock ( $target ) ;
23792398
2380- keyboard . keyDown ( 'esc' ) ;
2399+ popover . hide ( ) ;
2400+ hideSpy . resetHistory ( ) ;
23812401
2382- assert . strictEqual ( topPopover . option ( 'visible' ) , false , 'top popover is hidden' ) ;
2383- assert . strictEqual ( bottomPopover . option ( 'visible' ) , true , 'bottom popover is still visible' ) ;
2402+ keyboard . keyDown ( 'esc' ) ;
23842403
2385- $markup . remove ( ) ;
2404+ assert . strictEqual ( hideSpy . callCount , 0 , 'hide is not called' ) ;
2405+ assert . strictEqual ( popover . option ( 'visible' ) , false , 'popover remains hidden' ) ;
2406+ } ) ;
23862407 } ) ;
23872408
2388- QUnit . test ( 'should not call hide for hidden popover on esc press' , function ( assert ) {
2389- const popover = new Popover ( $ ( '#what' ) , {
2390- target : '#where' ,
2391- visible : true ,
2392- animation : null ,
2409+ QUnit . module ( 'WCAG - hoverable' , {
2410+ beforeEach : function ( ) {
2411+ this . clock = sinon . useFakeTimers ( ) ;
2412+ } ,
2413+ afterEach : function ( ) {
2414+ this . clock . restore ( ) ;
2415+ }
2416+ } , ( ) => {
2417+ QUnit . test ( 'should stay visible when pointer moves from target to overlay content' , function ( assert ) {
2418+ const instance = new Popover ( $ ( '#what' ) , {
2419+ target : '#where' ,
2420+ showEvent : 'mouseenter' ,
2421+ hideEvent : 'mouseleave' ,
2422+ visible : true ,
2423+ } ) ;
2424+
2425+ const $overlayContent = wrapper ( ) . find ( `.${ OVERLAY_CONTENT_CLASS } ` ) ;
2426+
2427+ $ ( '#where' ) . trigger ( 'mouseleave' ) ;
2428+ $overlayContent . trigger ( 'mouseenter' ) ;
2429+ this . clock . tick ( 200 ) ;
2430+
2431+ assert . ok ( instance . option ( 'visible' ) , 'popover remains visible after pointer moves to overlay content' ) ;
2432+ } ) ;
2433+
2434+ QUnit . test ( 'should hide when pointer leaves overlay content' , function ( assert ) {
2435+ const instance = new Popover ( $ ( '#what' ) , {
2436+ target : '#where' ,
2437+ showEvent : 'mouseenter' ,
2438+ hideEvent : 'mouseleave' ,
2439+ visible : true ,
2440+ } ) ;
2441+
2442+ const $overlayContent = wrapper ( ) . find ( `.${ OVERLAY_CONTENT_CLASS } ` ) ;
2443+
2444+ $overlayContent . trigger ( 'mouseenter' ) ;
2445+ $overlayContent . trigger ( 'mouseleave' ) ;
2446+
2447+ assert . notOk ( instance . option ( 'visible' ) , 'popover hides when pointer leaves overlay content' ) ;
2448+ } ) ;
2449+
2450+ QUnit . test ( 'should stay visible when pointer moves from overlay back to target' , function ( assert ) {
2451+ const instance = new Popover ( $ ( '#what' ) , {
2452+ target : '#where' ,
2453+ showEvent : 'mouseenter' ,
2454+ hideEvent : 'mouseleave' ,
2455+ visible : true ,
2456+ } ) ;
2457+
2458+ const $overlayContent = wrapper ( ) . find ( `.${ OVERLAY_CONTENT_CLASS } ` ) ;
2459+
2460+ $overlayContent . trigger ( 'mouseenter' ) ;
2461+
2462+ const mouseLeaveEvent = $ . Event ( 'mouseleave' ) ;
2463+ mouseLeaveEvent . relatedTarget = $ ( '#where' ) [ 0 ] ;
2464+ $overlayContent . trigger ( mouseLeaveEvent ) ;
2465+
2466+ this . clock . tick ( 200 ) ;
2467+
2468+ assert . ok ( instance . option ( 'visible' ) , 'popover stays visible when pointer moves from overlay back to target' ) ;
23932469 } ) ;
2394- const hideSpy = sinon . spy ( popover , 'hide' ) ;
2395- const $target = $ ( '#where' ) . attr ( 'tabindex' , 0 ) ;
2396- const keyboard = keyboardMock ( $target ) ;
23972470
2398- popover . hide ( ) ;
2399- hideSpy . resetHistory ( ) ;
2471+ QUnit . test ( 'should not apply hoverable behavior for non-hover hide events' , function ( assert ) {
2472+ const instance = new Popover ( $ ( '#what' ) , {
2473+ target : '#where' ,
2474+ showEvent : 'dxclick' ,
2475+ hideEvent : 'dxclick' ,
2476+ visible : true ,
2477+ } ) ;
24002478
2401- keyboard . keyDown ( 'esc' ) ;
2479+ $ ( '#where' ) . trigger ( 'dxclick' ) ;
2480+ this . clock . tick ( 0 ) ;
24022481
2403- assert . strictEqual ( hideSpy . callCount , 0 , 'hide is not called ') ;
2404- assert . strictEqual ( popover . option ( 'visible' ) , false , 'popover remains hidden' ) ;
2482+ assert . notOk ( instance . option ( 'visible' ) , 'popover hides immediately for non-hover hide event ') ;
2483+ } ) ;
24052484 } ) ;
24062485} ) ;
0 commit comments