11
11
*/
12
12
13
13
import { act } from '@testing-library/react' ;
14
- import { Button , ComboBox , ComboBoxContext , FieldError , Header , Input , Label , ListBox , ListBoxItem , ListBoxSection , ListLayout , Popover , Text , Virtualizer } from '../' ;
14
+ import { Button , ComboBox , ComboBoxContext , FieldError , Header , Input , Label , ListBox , ListBoxItem , ListBoxLoadMoreItem , ListBoxSection , ListLayout , Popover , Text , Virtualizer } from '../' ;
15
15
import { fireEvent , pointerMap , render , within } from '@react-spectrum/test-utils-internal' ;
16
16
import React from 'react' ;
17
17
import { User } from '@react-aria/test-utils' ;
18
18
import userEvent from '@testing-library/user-event' ;
19
19
20
+ let renderEmptyState = ( ) => {
21
+ return (
22
+ < div > No results</ div >
23
+ ) ;
24
+ } ;
25
+
20
26
let TestComboBox = ( props ) => (
21
27
< ComboBox name = "test-combobox" defaultInputValue = "C" data-foo = "bar" { ...props } >
22
28
< Label > Favorite Animal</ Label >
@@ -25,10 +31,13 @@ let TestComboBox = (props) => (
25
31
< Text slot = "description" > Description</ Text >
26
32
< Text slot = "errorMessage" > Error</ Text >
27
33
< Popover >
28
- < ListBox >
34
+ < ListBox renderEmptyState = { renderEmptyState } >
29
35
< ListBoxItem id = "1" > Cat</ ListBoxItem >
30
36
< ListBoxItem id = "2" > Dog</ ListBoxItem >
31
37
< ListBoxItem id = "3" > Kangaroo</ ListBoxItem >
38
+ < ListBoxLoadMoreItem >
39
+ loading
40
+ </ ListBoxLoadMoreItem >
32
41
</ ListBox >
33
42
</ Popover >
34
43
</ ComboBox >
@@ -384,4 +393,19 @@ describe('ComboBox', () => {
384
393
let input = getByRole ( 'combobox' ) ;
385
394
expect ( input ) . toHaveAttribute ( 'form' , 'test' ) ;
386
395
} ) ;
396
+
397
+ it ( 'should render empty state even when there is a loader provided and allowsEmptyCollection is true' , async ( ) => {
398
+ let tree = render ( < TestComboBox allowsEmptyCollection /> ) ;
399
+
400
+ let comboboxTester = testUtilUser . createTester ( 'ComboBox' , { root : tree . container } ) ;
401
+ act ( ( ) => {
402
+ comboboxTester . combobox . focus ( ) ;
403
+ } ) ;
404
+ await user . keyboard ( 'p' ) ;
405
+
406
+ let options = comboboxTester . options ( ) ;
407
+ expect ( options ) . toHaveLength ( 1 ) ;
408
+ expect ( comboboxTester . listbox ) . toBeTruthy ( ) ;
409
+ expect ( options [ 0 ] ) . toHaveTextContent ( 'No results' ) ;
410
+ } ) ;
387
411
} ) ;
0 commit comments