@@ -485,7 +485,7 @@ describe('Search', () => {
485
485
} )
486
486
487
487
describe ( 'onBlur' , ( ) => {
488
- it ( 'is called with (event, data) on search input blur' , ( ) => {
488
+ it ( 'is called on search input blur' , ( ) => {
489
489
const onBlur = sandbox . spy ( )
490
490
wrapperMount ( < Search results = { options } onBlur = { onBlur } /> ) . simulate ( 'blur' , nativeEvent )
491
491
@@ -504,7 +504,7 @@ describe('Search', () => {
504
504
} )
505
505
506
506
describe ( 'onFocus' , ( ) => {
507
- it ( 'is called with (event, data) on search input focus' , ( ) => {
507
+ it ( 'is called on search input focus' , ( ) => {
508
508
const onFocus = sandbox . spy ( )
509
509
wrapperMount ( < Search results = { options } onFocus = { onFocus } /> ) . simulate ( 'focus' , nativeEvent )
510
510
@@ -514,36 +514,41 @@ describe('Search', () => {
514
514
} )
515
515
516
516
describe ( 'onResultSelect' , ( ) => {
517
- let spy
517
+ let onResultSelect
518
518
beforeEach ( ( ) => {
519
- spy = sandbox . spy ( )
519
+ onResultSelect = sandbox . spy ( )
520
520
} )
521
521
522
- it ( 'is called with event and value on item click' , ( ) => {
522
+ it ( 'is called on item click' , ( ) => {
523
523
const randomIndex = _ . random ( options . length - 1 )
524
524
const randomResult = options [ randomIndex ]
525
- wrapperMount ( < Search results = { options } minCharacters = { 0 } onResultSelect = { spy } /> )
525
+ wrapperMount ( < Search results = { options } minCharacters = { 0 } onResultSelect = { onResultSelect } /> )
526
526
527
527
// open
528
528
openSearchResults ( )
529
529
searchResultsIsOpen ( )
530
530
531
531
wrapper . find ( 'SearchResult' ) . at ( randomIndex ) . simulate ( 'click' , nativeEvent )
532
532
533
- spy . should . have . been . calledOnce ( )
534
- spy . should . have . been . calledWithMatch (
533
+ onResultSelect . should . have . been . calledOnce ( )
534
+ onResultSelect . should . have . been . calledWithMatch (
535
535
{ } ,
536
536
{
537
537
minCharacters : 0 ,
538
- result : randomResult ,
539
538
results : options ,
540
539
} ,
540
+ randomResult ,
541
541
)
542
542
} )
543
- it ( 'is called with event and value when pressing enter on a selected item' , ( ) => {
543
+ it ( 'is called when pressing enter on a selected item' , ( ) => {
544
544
const firstResult = options [ 0 ]
545
545
wrapperMount (
546
- < Search results = { options } minCharacters = { 0 } onResultSelect = { spy } selectFirstResult /> ,
546
+ < Search
547
+ results = { options }
548
+ minCharacters = { 0 }
549
+ onResultSelect = { onResultSelect }
550
+ selectFirstResult
551
+ /> ,
547
552
)
548
553
549
554
// open
@@ -552,18 +557,23 @@ describe('Search', () => {
552
557
553
558
domEvent . keyDown ( document , { key : 'Enter' } )
554
559
555
- spy . should . have . been . calledOnce ( )
556
- spy . should . have . been . calledWithMatch ( { } , { result : firstResult } )
560
+ onResultSelect . should . have . been . calledOnce ( )
561
+ onResultSelect . should . have . been . calledWithMatch ( { } , { } , firstResult )
557
562
} )
558
563
it ( 'is not called when updating the value prop' , ( ) => {
559
564
const value = _ . sample ( options ) . title
560
565
const next = _ . sample ( _ . without ( options , value ) ) . title
561
566
562
567
wrapperMount (
563
- < Search results = { options } minCharacters = { 0 } value = { value } onResultSelect = { spy } /> ,
568
+ < Search
569
+ results = { options }
570
+ minCharacters = { 0 }
571
+ value = { value }
572
+ onResultSelect = { onResultSelect }
573
+ /> ,
564
574
) . setProps ( { value : next } )
565
575
566
- spy . should . not . have . been . called ( )
576
+ onResultSelect . should . not . have . been . called ( )
567
577
} )
568
578
it ( 'does not call onResultSelect on query change' , ( ) => {
569
579
const onResultSelectSpy = sandbox . spy ( )
@@ -579,26 +589,26 @@ describe('Search', () => {
579
589
} )
580
590
581
591
describe ( 'onSearchChange' , ( ) => {
582
- it ( 'is called with (event, value) on search input change' , ( ) => {
583
- const spy = sandbox . spy ( )
584
- wrapperMount ( < Search results = { options } minCharacters = { 0 } onSearchChange = { spy } /> )
592
+ it ( 'is called on search input change' , ( ) => {
593
+ const onSearchChange = sandbox . spy ( )
594
+ wrapperMount ( < Search results = { options } minCharacters = { 0 } onSearchChange = { onSearchChange } /> )
585
595
. find ( 'input.prompt' )
586
596
. simulate ( 'change' , { target : { value : 'a' } , stopPropagation : _ . noop } )
587
597
588
- spy . should . have . been . calledOnce ( )
589
- spy . should . have . been . calledWithMatch (
598
+ onSearchChange . should . have . been . calledOnce ( )
599
+ onSearchChange . should . have . been . calledWithMatch (
590
600
{ target : { value : 'a' } } ,
591
601
{
592
602
minCharacters : 0 ,
593
603
results : options ,
594
- value : 'a' ,
595
604
} ,
605
+ 'a' ,
596
606
)
597
607
} )
598
608
} )
599
609
600
- describe ( 'onSearchChange ' , ( ) => {
601
- it ( 'is called with (event, data) when the active selection index is changed' , ( ) => {
610
+ describe ( 'onSelectionChange ' , ( ) => {
611
+ it ( 'is called when the active selection index is changed' , ( ) => {
602
612
const onSelectionChange = sandbox . spy ( )
603
613
604
614
wrapperMount (
@@ -617,9 +627,9 @@ describe('Search', () => {
617
627
{ } ,
618
628
{
619
629
minCharacters : 0 ,
620
- result : options [ 1 ] ,
621
630
results : options ,
622
631
} ,
632
+ options [ 1 ] ,
623
633
)
624
634
} )
625
635
} )
0 commit comments