@@ -7,7 +7,7 @@ import React, { useRef, forwardRef, useState } from "react";
7
7
import { render , waitFor } from "@testing-library/react" ;
8
8
import { renderHook } from "@testing-library/react-hooks" ;
9
9
import IndexDetail , { IIndexDetailRef , IndexDetailProps } from "./IndexDetail" ;
10
- import userEvent from "@testing-library/user-event" ;
10
+ import userEventModule from "@testing-library/user-event" ;
11
11
12
12
const IndexDetailOnChangeWrapper = forwardRef ( ( props : Omit < IndexDetailProps , "onChange" > , ref : any ) => {
13
13
const [ value , setValue ] = useState ( props . value as any ) ;
@@ -26,6 +26,8 @@ const IndexDetailOnChangeWrapper = forwardRef((props: Omit<IndexDetailProps, "on
26
26
const refreshOptions : ( ) => Promise < { ok : true ; response : any [ ] } > = ( ) => Promise . resolve ( { ok : true , response : [ { alias : "test" } ] } ) ;
27
27
28
28
describe ( "<IndexDetail /> spec" , ( ) => {
29
+ const userEvent = userEventModule . setup ( ) ;
30
+
29
31
it ( "renders the component" , async ( ) => {
30
32
const { container } = render ( < IndexDetail docVersion = "latest" refreshOptions = { refreshOptions } onChange = { ( ) => { } } /> ) ;
31
33
await waitFor ( ( ) => {
@@ -63,12 +65,12 @@ describe("<IndexDetail /> spec", () => {
63
65
} ) ;
64
66
const ref = result . current . ref ;
65
67
const { getByTestId, getByPlaceholderText } = result . current . container ;
66
- userEvent . type ( getByPlaceholderText ( "Specify a name for the new index." ) , "good_index" ) ;
68
+ await userEvent . type ( getByPlaceholderText ( "Specify a name for the new index." ) , "good_index" ) ;
67
69
await waitFor ( async ( ) => {
68
70
expect ( await ref . current ?. validate ( ) ) . toBe ( false ) ;
69
71
} ) ;
70
- userEvent . type ( getByTestId ( "form-name-index.number_of_shards" ) . querySelector ( "input" ) as Element , "2" ) ;
71
- userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "2" ) ;
72
+ await userEvent . type ( getByTestId ( "form-name-index.number_of_shards" ) . querySelector ( "input" ) as Element , "2" ) ;
73
+ await userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "2" ) ;
72
74
await waitFor ( async ( ) => {
73
75
expect ( await ref . current ?. validate ( ) ) . toBe ( true ) ;
74
76
} ) ;
@@ -97,14 +99,14 @@ describe("<IndexDetail /> spec", () => {
97
99
/>
98
100
) ;
99
101
await findByDisplayValue ( "some_index" ) ;
100
- userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
101
- userEvent . click ( document . body ) ;
102
+ await userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
103
+ await userEvent . click ( document . body ) ;
102
104
await waitFor ( ( ) => {
103
105
expect ( document . querySelector ( '[data-test-subj="comboBoxInput"] [title="test"]' ) ) . not . toBeNull ( ) ;
104
106
} ) ;
105
- userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "10" ) ;
106
- userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
107
- userEvent . click ( document . body ) ;
107
+ await userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "10" ) ;
108
+ await userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
109
+ await userEvent . click ( document . body ) ;
108
110
// The Dialog should show
109
111
await waitFor ( ( ) => {
110
112
expect (
@@ -113,16 +115,16 @@ describe("<IndexDetail /> spec", () => {
113
115
)
114
116
) . toBeInTheDocument ( ) ;
115
117
} ) ;
116
- userEvent . click ( getByTestId ( "simulate-confirm-confirm" ) ) ;
118
+ await userEvent . click ( getByTestId ( "simulate-confirm-confirm" ) ) ;
117
119
await waitFor ( ( ) => {
118
120
expect ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) . toHaveAttribute ( "value" , "2" ) ;
119
121
expect ( queryByText ( "The index name matches one or more index templates" ) ) . toBeInTheDocument ( ) ;
120
122
} ) ;
121
123
122
- userEvent . clear ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) ;
123
- userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "10" ) ;
124
- userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
125
- userEvent . click ( document . body ) ;
124
+ await userEvent . clear ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) ;
125
+ await userEvent . type ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element , "10" ) ;
126
+ await userEvent . click ( getByDisplayValue ( "some_index" ) ) ;
127
+ await userEvent . click ( document . body ) ;
126
128
// The Dialog should show
127
129
await waitFor ( ( ) => {
128
130
expect (
@@ -131,9 +133,9 @@ describe("<IndexDetail /> spec", () => {
131
133
)
132
134
) . toBeInTheDocument ( ) ;
133
135
} ) ;
134
- userEvent . click ( getByTestId ( "simulate-confirm-cancel" ) ) ;
136
+ await userEvent . click ( getByTestId ( "simulate-confirm-cancel" ) ) ;
135
137
await waitFor ( ( ) => {
136
- expect ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) . toHaveAttribute ( "value" , "10 " ) ;
138
+ expect ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) . toHaveAttribute ( "value" , "2 " ) ;
137
139
} ) ;
138
140
} ) ;
139
141
} ) ;
0 commit comments