@@ -3,19 +3,21 @@ import SimpleAutocomplete from "../SimpleAutocomplete.svelte"
3
3
import '@testing-library/jest-dom/extend-expect'
4
4
import '@testing-library/jest-dom'
5
5
6
- async function colors ( keyword , nb_items_max ) {
6
+ async function colors ( ) {
7
7
return [ "White" , "Red" , "Yellow" , "Green" , "Blue" , "Black" , "Mät bläck" , "<i>Jét Black</i>" ]
8
8
}
9
9
10
+ window = Object . assign ( window , { visualViewport : { height : 1500 } } )
11
+
10
12
test ( "at first, menu is empty" , async ( ) => {
11
- const { component , container } = render ( SimpleAutocomplete , { searchFunction : colors } )
13
+ render ( SimpleAutocomplete , { searchFunction : colors } )
12
14
13
15
expect ( await screen . queryByText ( 'White' ) ) . not . toBeInTheDocument ( )
14
16
expect ( await screen . queryByText ( 'Red' ) ) . not . toBeInTheDocument ( )
15
17
} )
16
18
17
19
test ( "even with the input is focused, the menu is empty" , async ( ) => {
18
- const { component , container } = render ( SimpleAutocomplete , { searchFunction : colors } )
20
+ const { container } = render ( SimpleAutocomplete , { searchFunction : colors } )
19
21
const queryInput = container . querySelector ( "input[type='text']" ) ;
20
22
21
23
await fireEvent . focus ( queryInput )
@@ -25,7 +27,7 @@ test("even with the input is focused, the menu is empty", async () => {
25
27
} )
26
28
27
29
test ( "when something is queried, only the matching items are shown" , async ( ) => {
28
- const { component , container } = render ( SimpleAutocomplete , { searchFunction : colors } )
30
+ const { container } = render ( SimpleAutocomplete , { searchFunction : colors } )
29
31
const queryInput = container . querySelector ( "input[type='text']" ) ;
30
32
31
33
await fireEvent . input ( queryInput , { target : { value : "white" } } )
@@ -36,7 +38,8 @@ test("when something is queried, only the matching items are shown", async () =>
36
38
} )
37
39
38
40
test ( "when nothing matches the query, no item is show" , async ( ) => {
39
- const { component, container } = render ( SimpleAutocomplete , { searchFunction : colors } )
41
+
42
+ const { container } = render ( SimpleAutocomplete , { searchFunction : colors } )
40
43
const queryInput = container . querySelector ( "input[type='text']" ) ;
41
44
42
45
await fireEvent . input ( queryInput , { target : { value : "not-a-color" } } )
@@ -46,9 +49,8 @@ test("when nothing matches the query, no item is show", async () => {
46
49
} )
47
50
48
51
test ( "when something is queried, the query is highlighted" , async ( ) => {
49
- const { component , container } = render ( SimpleAutocomplete , { searchFunction : colors } )
52
+ const { container } = render ( SimpleAutocomplete , { searchFunction : colors } )
50
53
const queryInput = container . querySelector ( "input[type='text']" ) ;
51
- const list = container . querySelector ( "autocomplete-list" ) ;
52
54
53
55
await fireEvent . input ( queryInput , { target : { value : "whi" } } )
54
56
0 commit comments