@@ -388,16 +388,16 @@ describe('sankey tests', function() {
388388 describe ( 'Test hover/click interactions:' , function ( ) {
389389 afterEach ( destroyGraphDiv ) ;
390390
391+ function _hover ( px , py ) {
392+ mouseEvent ( 'mousemove' , px , py ) ;
393+ mouseEvent ( 'mouseover' , px , py ) ;
394+ Lib . clearThrottle ( ) ;
395+ }
396+
391397 it ( 'should show the correct hover labels' , function ( done ) {
392398 var gd = createGraphDiv ( ) ;
393399 var mockCopy = Lib . extendDeep ( { } , mock ) ;
394400
395- function _hover ( px , py ) {
396- mouseEvent ( 'mousemove' , px , py ) ;
397- mouseEvent ( 'mouseover' , px , py ) ;
398- Lib . clearThrottle ( ) ;
399- }
400-
401401 Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
402402 _hover ( 404 , 302 ) ;
403403
@@ -464,12 +464,6 @@ describe('sankey tests', function() {
464464 var mockCopy = Lib . extendDeep ( { } , mock ) ;
465465 delete mockCopy . data [ 0 ] . link . label ;
466466
467- function _hover ( px , py ) {
468- mouseEvent ( 'mousemove' , px , py ) ;
469- mouseEvent ( 'mouseover' , px , py ) ;
470- Lib . clearThrottle ( ) ;
471- }
472-
473467 Plotly . plot ( gd , mockCopy )
474468 . then ( function ( ) {
475469 _hover ( 450 , 300 ) ;
@@ -482,6 +476,22 @@ describe('sankey tests', function() {
482476 . catch ( failTest )
483477 . then ( done ) ;
484478 } ) ;
479+
480+ it ( 'should not show labels if hovermode is false' , function ( done ) {
481+ var gd = createGraphDiv ( ) ;
482+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
483+
484+ Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
485+ return Plotly . relayout ( gd , 'hovermode' , false ) ;
486+ } )
487+ . then ( function ( ) {
488+ _hover ( 404 , 302 ) ;
489+
490+ assertNoLabel ( ) ;
491+ } )
492+ . catch ( failTest )
493+ . then ( done ) ;
494+ } ) ;
485495 } ) ;
486496
487497 describe ( 'Test hover/click event data:' , function ( ) {
@@ -527,44 +537,52 @@ describe('sankey tests', function() {
527537 mouseEvent ( 'mouseout' , pos [ 0 ] , pos [ 1 ] ) ;
528538 } ) ;
529539
530- it ( 'should output correct hover/click/unhover event data' , function ( done ) {
531- var fig = Lib . extendDeep ( { } , mock ) ;
540+ function _assert ( d , expectedPtData ) {
541+ expect ( d . event ) . toBeDefined ( 'original event reference' ) ;
532542
533- function _assert ( d , expectedPtData ) {
534- expect ( d . event ) . toBeDefined ( 'original event reference' ) ;
543+ var ptData = d . points [ 0 ] ;
544+ Object . keys ( expectedPtData ) . forEach ( function ( k ) {
545+ expect ( ptData [ k ] ) . toBe ( expectedPtData [ k ] , 'point data for ' + k ) ;
546+ } ) ;
547+ }
535548
536- var ptData = d . points [ 0 ] ;
537- Object . keys ( expectedPtData ) . forEach ( function ( k ) {
538- expect ( ptData [ k ] ) . toBe ( expectedPtData [ k ] , 'point data for ' + k ) ;
539- } ) ;
540- }
549+ it ( 'should output correct click event data' , function ( done ) {
550+ var fig = Lib . extendDeep ( { } , mock ) ;
541551
542552 Plotly . plot ( gd , fig )
543- . then ( function ( ) { return _hover ( 'node' ) ; } )
553+ . then ( function ( ) { return _click ( 'node' ) ; } )
544554 . then ( function ( d ) {
545555 _assert ( d , {
546556 curveNumber : 0 ,
547557 pointNumber : 4 ,
548558 label : 'Solid'
549559 } ) ;
550560 } )
551- . then ( function ( ) { return _hover ( 'link' ) ; } )
561+ . then ( function ( ) { return _click ( 'link' ) ; } )
552562 . then ( function ( d ) {
553563 _assert ( d , {
554564 curveNumber : 0 ,
555565 pointNumber : 61 ,
556566 value : 46.477
557567 } ) ;
558568 } )
559- . then ( function ( ) { return _click ( 'node' ) ; } )
569+ . catch ( failTest )
570+ . then ( done ) ;
571+ } ) ;
572+
573+ it ( 'should output correct hover/unhover event data' , function ( done ) {
574+ var fig = Lib . extendDeep ( { } , mock ) ;
575+
576+ Plotly . plot ( gd , fig )
577+ . then ( function ( ) { return _hover ( 'node' ) ; } )
560578 . then ( function ( d ) {
561579 _assert ( d , {
562580 curveNumber : 0 ,
563581 pointNumber : 4 ,
564582 label : 'Solid'
565583 } ) ;
566584 } )
567- . then ( function ( ) { return _click ( 'link' ) ; } )
585+ . then ( function ( ) { return _hover ( 'link' ) ; } )
568586 . then ( function ( d ) {
569587 _assert ( d , {
570588 curveNumber : 0 ,
@@ -591,6 +609,30 @@ describe('sankey tests', function() {
591609 . catch ( failTest )
592610 . then ( done ) ;
593611 } ) ;
612+
613+ it ( 'should not output hover/unhover event data when hovermoder is false' , function ( done ) {
614+ var fig = Lib . extendDeep ( { } , mock ) ;
615+
616+ Plotly . plot ( gd , fig )
617+ . then ( function ( ) { return Plotly . relayout ( gd , 'hovermode' , false ) ; } )
618+ . then ( function ( ) { return _hover ( 'node' ) ; } )
619+ . then ( failTest ) . catch ( function ( err ) {
620+ expect ( err ) . toBe ( 'plotly_hover did not get called!' ) ;
621+ } )
622+ . then ( function ( ) { return _unhover ( 'node' ) ; } )
623+ . then ( failTest ) . catch ( function ( err ) {
624+ expect ( err ) . toBe ( 'plotly_unhover did not get called!' ) ;
625+ } )
626+ . then ( function ( ) { return _hover ( 'link' ) ; } )
627+ . then ( failTest ) . catch ( function ( err ) {
628+ expect ( err ) . toBe ( 'plotly_hover did not get called!' ) ;
629+ } )
630+ . then ( function ( ) { return _unhover ( 'link' ) ; } )
631+ . then ( failTest ) . catch ( function ( err ) {
632+ expect ( err ) . toBe ( 'plotly_unhover did not get called!' ) ;
633+ } )
634+ . then ( done ) ;
635+ } ) ;
594636 } ) ;
595637} ) ;
596638
@@ -620,3 +662,8 @@ function assertLabel(content, style) {
620662 fontColor : style [ 4 ]
621663 } ) ;
622664}
665+
666+ function assertNoLabel ( ) {
667+ var g = d3 . selectAll ( '.hovertext' ) ;
668+ expect ( g . size ( ) ) . toBe ( 0 ) ;
669+ }
0 commit comments