@@ -196,8 +196,7 @@ describe( 'Basic rendering', () => {
196
196
within ( resultsList ) . getAllByRole ( 'option' ) ;
197
197
198
198
expect ( searchResultElements ) . toHaveLength (
199
- // The fauxEntitySuggestions length plus the 'Press ENTER to add this link' button.
200
- fauxEntitySuggestions . length + 1
199
+ fauxEntitySuggestions . length
201
200
) ;
202
201
203
202
// Step down into the search results, highlighting the first result item.
@@ -440,44 +439,87 @@ describe( 'Searching for a link', () => {
440
439
expect ( screen . queryByRole ( 'presentation' ) ) . not . toBeInTheDocument ( ) ;
441
440
} ) ;
442
441
443
- it ( 'should display only search suggestions when current input value is not URL-like' , async ( ) => {
444
- const user = userEvent . setup ( ) ;
445
- const searchTerm = 'Hello world' ;
446
- const firstSuggestion = fauxEntitySuggestions [ 0 ] ;
442
+ it . each ( [ 'With spaces' , 'Uppercase' , 'lowercase' ] ) (
443
+ 'should display only search suggestions (and not URL result type) when current input value (e.g. %s) is not URL-like' ,
444
+ async ( searchTerm ) => {
445
+ const user = userEvent . setup ( ) ;
446
+ const firstSuggestion = fauxEntitySuggestions [ 0 ] ;
447
447
448
- render ( < LinkControl /> ) ;
448
+ render ( < LinkControl /> ) ;
449
449
450
- // Search Input UI.
451
- const searchInput = screen . getByRole ( 'combobox' , { name : 'URL' } ) ;
450
+ // Search Input UI.
451
+ const searchInput = screen . getByRole ( 'combobox' , { name : 'URL' } ) ;
452
452
453
- // Simulate searching for a term.
454
- await user . type ( searchInput , searchTerm ) ;
453
+ // Simulate searching for a term.
454
+ await user . type ( searchInput , searchTerm ) ;
455
455
456
- const searchResultElements = within (
457
- await screen . findByRole ( 'listbox' , {
458
- name : / S e a r c h r e s u l t s f o r .* / ,
459
- } )
460
- ) . getAllByRole ( 'option' ) ;
456
+ const searchResultElements = within (
457
+ await screen . findByRole ( 'listbox' , {
458
+ name : / S e a r c h r e s u l t s f o r .* / ,
459
+ } )
460
+ ) . getAllByRole ( 'option' ) ;
461
461
462
- expect ( searchResultElements ) . toHaveLength (
463
- fauxEntitySuggestions . length
464
- ) ;
462
+ expect ( searchResultElements ) . toHaveLength (
463
+ fauxEntitySuggestions . length
464
+ ) ;
465
465
466
- expect ( searchInput ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
466
+ expect ( searchInput ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
467
467
468
- // Check that a search suggestion shows up corresponding to the data.
469
- expect ( searchResultElements [ 0 ] ) . toHaveTextContent (
470
- firstSuggestion . title
471
- ) ;
472
- expect ( searchResultElements [ 0 ] ) . toHaveTextContent (
473
- firstSuggestion . type
474
- ) ;
468
+ // Check that a search suggestion shows up corresponding to the data.
469
+ expect ( searchResultElements [ 0 ] ) . toHaveTextContent (
470
+ firstSuggestion . title
471
+ ) ;
472
+ expect ( searchResultElements [ 0 ] ) . toHaveTextContent (
473
+ firstSuggestion . type
474
+ ) ;
475
475
476
- // The fallback URL suggestion should not be shown when input is not URL-like.
477
- expect (
478
- searchResultElements [ searchResultElements . length - 1 ]
479
- ) . not . toHaveTextContent ( 'URL' ) ;
480
- } ) ;
476
+ // The fallback URL suggestion should not be shown when input is not URL-like.
477
+ expect (
478
+ searchResultElements [ searchResultElements . length - 1 ]
479
+ ) . not . toHaveTextContent ( 'URL' ) ;
480
+ }
481
+ ) ;
482
+
483
+ it . each ( [
484
+ [ 'https://wordpress.org' , 'URL' ] ,
485
+ [ 'http://wordpress.org' , 'URL' ] ,
486
+ [ 'www.wordpress.org' , 'URL' ] ,
487
+ [ 'wordpress.org' , 'URL' ] ,
488
+ [ 'ftp://wordpress.org' , 'URL' ] ,
489
+ [ 'mailto:hello@wordpress.org' , 'mailto' ] ,
490
+ [ 'tel:123456789' , 'tel' ] ,
491
+ [ '#internal' , 'internal' ] ,
492
+ ] ) (
493
+ 'should display only URL result when current input value is URL-like (e.g. %s)' ,
494
+ async ( searchTerm , type ) => {
495
+ const user = userEvent . setup ( ) ;
496
+
497
+ render ( < LinkControl /> ) ;
498
+
499
+ // Search Input UI.
500
+ const searchInput = screen . getByRole ( 'combobox' , { name : 'URL' } ) ;
501
+
502
+ // Simulate searching for a term.
503
+ await user . type ( searchInput , searchTerm ) ;
504
+
505
+ const searchResultElement = within (
506
+ await screen . findByRole ( 'listbox' , {
507
+ name : / S e a r c h r e s u l t s f o r .* / ,
508
+ } )
509
+ ) . getByRole ( 'option' ) ;
510
+
511
+ expect ( searchResultElement ) . toBeInTheDocument ( ) ;
512
+
513
+ // Should only be the `URL` suggestion.
514
+ expect ( searchInput ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
515
+
516
+ expect ( searchResultElement ) . toHaveTextContent ( searchTerm ) ;
517
+ expect ( searchResultElement ) . toHaveTextContent ( type ) ;
518
+ expect ( searchResultElement ) . toHaveTextContent (
519
+ 'Press ENTER to add this link'
520
+ ) ;
521
+ }
522
+ ) ;
481
523
482
524
it ( 'should trim search term' , async ( ) => {
483
525
const user = userEvent . setup ( ) ;
@@ -504,8 +546,7 @@ describe( 'Searching for a link', () => {
504
546
. flat ( )
505
547
. filter ( Boolean ) ;
506
548
507
- // Given we're mocking out the results we should always have 4 mark elements.
508
- expect ( searchResultTextHighlightElements ) . toHaveLength ( 4 ) ;
549
+ expect ( searchResultTextHighlightElements ) . toHaveLength ( 3 ) ;
509
550
510
551
// Make sure there are no `mark` elements which contain anything other
511
552
// than the trimmed search term (ie: no whitespace).
@@ -565,16 +606,15 @@ describe( 'Searching for a link', () => {
565
606
const lastSearchResultItem =
566
607
searchResultElements [ searchResultElements . length - 1 ] ;
567
608
568
- // We should see a search result for each of the expect search suggestions
569
- // plus 1 additional one for the fallback URL suggestion.
609
+ // We should see a search result for each of the expect search suggestions.
570
610
expect ( searchResultElements ) . toHaveLength (
571
- fauxEntitySuggestions . length + 1
611
+ fauxEntitySuggestions . length
572
612
) ;
573
613
574
- // The last item should be a URL search suggestion.
575
- expect ( lastSearchResultItem ) . toHaveTextContent ( searchTerm ) ;
576
- expect ( lastSearchResultItem ) . toHaveTextContent ( 'URL' ) ;
577
- expect ( lastSearchResultItem ) . toHaveTextContent (
614
+ // The URL search suggestion should not exist .
615
+ expect ( lastSearchResultItem ) . not . toHaveTextContent ( searchTerm ) ;
616
+ expect ( lastSearchResultItem ) . not . toHaveTextContent ( 'URL' ) ;
617
+ expect ( lastSearchResultItem ) . not . toHaveTextContent (
578
618
'Press ENTER to add this link'
579
619
) ;
580
620
}
@@ -964,8 +1004,7 @@ describe( 'Default search suggestions', () => {
964
1004
} )
965
1005
) . getAllByRole ( 'option' ) ;
966
1006
967
- // It should match any url that's like ?p= and also include a URL option.
968
- expect ( searchResultElements ) . toHaveLength ( 5 ) ;
1007
+ expect ( searchResultElements ) . toHaveLength ( 4 ) ;
969
1008
970
1009
expect ( searchInput ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
971
1010
0 commit comments