@@ -460,9 +460,26 @@ describe('WorldmapFoundation', () => {
460
460
} ) ;
461
461
} ) ;
462
462
463
+ function setupInteractionMocks ( ) {
464
+
465
+ // Setup interaction mock for "window.location.assign".
466
+ // https://remarkablemark.org/blog/2018/11/17/mock-window-location/
467
+ Object . defineProperty ( window . location , 'assign' , {
468
+ configurable : true ,
469
+ } ) ;
470
+ window . location . assign = jest . fn ( ) ;
471
+
472
+ // Setup interaction mock for "window.open".
473
+ Object . defineProperty ( window , 'open' , {
474
+ configurable : true ,
475
+ } ) ;
476
+ window . open = jest . fn ( ) ;
477
+
478
+ }
479
+
463
480
describe ( 'ClickthroughLinks' , ( ) => {
464
481
/*
465
- * These tests proof the clickthrough link works .
482
+ * These tests proof that " clickthrough links" work .
466
483
*
467
484
* See also https://community.hiveeyes.org/t/developing-grafana-worldmap-ng/1824/13
468
485
*/
@@ -505,17 +522,15 @@ describe('ClickthroughLinks', () => {
505
522
} ) ;
506
523
507
524
it ( 'should do its job when actually clicked' , ( ) => {
508
- // Setup interaction mock for "window.location.assign".
509
- // https://remarkablemark.org/blog/2018/11/17/mock-window-location/
510
- Object . defineProperty ( window . location , 'assign' , {
511
- configurable : true ,
512
- } ) ;
513
- window . location . assign = jest . fn ( ) ;
525
+
526
+ // Prepare interaction with window object.
527
+ setupInteractionMocks ( ) ;
514
528
515
529
// Capture interaction.
516
530
worldMap . circles [ 0 ] . fire ( 'click' ) ;
517
531
expect ( window . location . assign ) . toHaveBeenCalledWith ( 'http://foo.bar' ) ;
518
532
} ) ;
533
+
519
534
} ) ;
520
535
521
536
describe ( 'when a Worldmap is created with clickthrough-links enabled to another window' , ( ) => {
@@ -537,16 +552,14 @@ describe('ClickthroughLinks', () => {
537
552
} ) ;
538
553
539
554
it ( 'should do its job when actually clicked' , ( ) => {
540
- // Setup interaction mock for "window.open".
541
- // https://remarkablemark.org/blog/2018/11/17/mock-window-location/
542
- Object . defineProperty ( window , 'open' , {
543
- configurable : true ,
544
- } ) ;
545
- window . open = jest . fn ( ) ;
555
+
556
+ // Prepare interaction with window object.
557
+ setupInteractionMocks ( ) ;
546
558
547
559
// Capture interaction.
548
560
worldMap . circles [ 0 ] . fire ( 'click' ) ;
549
561
expect ( window . open ) . toHaveBeenCalledWith ( 'http://foo.bar' , 'test' ) ;
550
562
} ) ;
563
+
551
564
} ) ;
552
565
} ) ;
0 commit comments