@@ -7,7 +7,7 @@ import React, { useRef, forwardRef, useState } from "react";
77import { render , waitFor } from "@testing-library/react" ;
88import { renderHook } from "@testing-library/react-hooks" ;
99import IndexDetail , { IIndexDetailRef , IndexDetailProps } from "./IndexDetail" ;
10- import userEvent from "@testing-library/user-event" ;
10+ import userEventModule from "@testing-library/user-event" ;
1111
1212const IndexDetailOnChangeWrapper = forwardRef ( ( props : Omit < IndexDetailProps , "onChange" > , ref : any ) => {
1313 const [ value , setValue ] = useState ( props . value as any ) ;
@@ -26,6 +26,8 @@ const IndexDetailOnChangeWrapper = forwardRef((props: Omit<IndexDetailProps, "on
2626const refreshOptions : ( ) => Promise < { ok : true ; response : any [ ] } > = ( ) => Promise . resolve ( { ok : true , response : [ { alias : "test" } ] } ) ;
2727
2828describe ( "<IndexDetail /> spec" , ( ) => {
29+ const userEvent = userEventModule . setup ( ) ;
30+
2931 it ( "renders the component" , async ( ) => {
3032 const { container } = render ( < IndexDetail docVersion = "latest" refreshOptions = { refreshOptions } onChange = { ( ) => { } } /> ) ;
3133 await waitFor ( ( ) => {
@@ -63,12 +65,12 @@ describe("<IndexDetail /> spec", () => {
6365 } ) ;
6466 const ref = result . current . ref ;
6567 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" ) ;
6769 await waitFor ( async ( ) => {
6870 expect ( await ref . current ?. validate ( ) ) . toBe ( false ) ;
6971 } ) ;
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" ) ;
7274 await waitFor ( async ( ) => {
7375 expect ( await ref . current ?. validate ( ) ) . toBe ( true ) ;
7476 } ) ;
@@ -97,14 +99,14 @@ describe("<IndexDetail /> spec", () => {
9799 />
98100 ) ;
99101 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 ) ;
102104 await waitFor ( ( ) => {
103105 expect ( document . querySelector ( '[data-test-subj="comboBoxInput"] [title="test"]' ) ) . not . toBeNull ( ) ;
104106 } ) ;
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 ) ;
108110 // The Dialog should show
109111 await waitFor ( ( ) => {
110112 expect (
@@ -113,16 +115,16 @@ describe("<IndexDetail /> spec", () => {
113115 )
114116 ) . toBeInTheDocument ( ) ;
115117 } ) ;
116- userEvent . click ( getByTestId ( "simulate-confirm-confirm" ) ) ;
118+ await userEvent . click ( getByTestId ( "simulate-confirm-confirm" ) ) ;
117119 await waitFor ( ( ) => {
118120 expect ( getByTestId ( "form-name-index.number_of_replicas" ) . querySelector ( "input" ) as Element ) . toHaveAttribute ( "value" , "2" ) ;
119121 expect ( queryByText ( "The index name matches one or more index templates" ) ) . toBeInTheDocument ( ) ;
120122 } ) ;
121123
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 ) ;
126128 // The Dialog should show
127129 await waitFor ( ( ) => {
128130 expect (
@@ -131,9 +133,9 @@ describe("<IndexDetail /> spec", () => {
131133 )
132134 ) . toBeInTheDocument ( ) ;
133135 } ) ;
134- userEvent . click ( getByTestId ( "simulate-confirm-cancel" ) ) ;
136+ await userEvent . click ( getByTestId ( "simulate-confirm-cancel" ) ) ;
135137 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 " ) ;
137139 } ) ;
138140 } ) ;
139141} ) ;
0 commit comments