@@ -7,7 +7,7 @@ import React from 'react';
77import { mount } from 'enzyme' ;
88import { act } from 'react-dom/test-utils' ;
99import { MemoryRouter } from 'react-router-dom' ;
10- import { EuiFieldText , EuiTextArea , EuiSelect } from '@elastic/eui' ;
10+ import { EuiTextArea , EuiSelect } from '@elastic/eui' ;
1111import { ConfigureS3DatasourcePanelWithRouter } from './configure_amazon_s3_data_source' ;
1212import { AuthMethod } from '../../../constants' ;
1313
@@ -122,61 +122,80 @@ describe('ConfigureS3DatasourcePanel', () => {
122122 textArea . simulate ( 'change' , { target : { value : 'New details' } } ) ;
123123 textArea . simulate ( 'blur' , { target : { value : 'New details' } } ) ;
124124 } ) ;
125- setTimeout ( ( ) => {
126- expect ( mockSetDetailsForRequest ) . toHaveBeenCalledWith ( 'New details' ) ;
127- } , 1000 ) ;
125+ expect ( mockSetDetailsForRequest ) . toHaveBeenCalledWith ( 'New details' ) ;
128126 } ) ;
129127
130128 it ( 'updates ARN state on change' , async ( ) => {
131129 const wrapper = mountComponent ( ) ;
132- const arnField = wrapper . find ( EuiFieldText ) . at ( 0 ) ;
130+ const arnField = wrapper . find ( '[data-test-subj="role-ARN"]' ) . first ( ) ;
131+
133132 await act ( async ( ) => {
134- arnField . simulate ( 'change' , { target : { value : 'New ARN' } } ) ;
135- arnField . simulate ( 'blur' , { target : { value : 'New ARN' } } ) ;
133+ const onChange = arnField . prop ( 'onChange' ) ;
134+ if ( onChange ) {
135+ onChange ( { target : { value : 'New ARN' } } as any ) ;
136+ }
136137 } ) ;
137- setTimeout ( ( ) => {
138- expect ( mockSetArnForRequest ) . toHaveBeenCalledWith ( 'New ARN' ) ;
139- } , 1000 ) ;
138+
139+ await act ( async ( ) => {
140+ const onBlur = arnField . prop ( 'onBlur' ) ;
141+ if ( onBlur ) {
142+ onBlur ( { target : { value : 'New ARN' } } as any ) ;
143+ }
144+ } ) ;
145+
146+ expect ( mockSetArnForRequest ) . toHaveBeenCalledWith ( 'New ARN' ) ;
140147 } ) ;
141148
142149 it ( 'updates store URI state on change' , async ( ) => {
143150 const wrapper = mountComponent ( ) ;
144- const storeField = wrapper . find ( EuiFieldText ) . at ( 1 ) ;
151+ const storeField = wrapper . find ( '[data-test-subj="index-URI"]' ) . first ( ) ;
152+
145153 await act ( async ( ) => {
146- storeField . simulate ( 'change' , { target : { value : 'New Store URI' } } ) ;
147- storeField . simulate ( 'blur' , { target : { value : 'New Store URI' } } ) ;
154+ const onChange = storeField . prop ( 'onChange' ) ;
155+ if ( onChange ) {
156+ onChange ( { target : { value : 'New Store URI' } } as any ) ;
157+ }
148158 } ) ;
149- setTimeout ( ( ) => {
150- expect ( mockSetStoreForRequest ) . toHaveBeenCalledWith ( 'New Store URI' ) ;
151- } , 1000 ) ;
159+
160+ await act ( async ( ) => {
161+ const onBlur = storeField . prop ( 'onBlur' ) ;
162+ if ( onBlur ) {
163+ onBlur ( { target : { value : 'New Store URI' } } as any ) ;
164+ }
165+ } ) ;
166+
167+ expect ( mockSetStoreForRequest ) . toHaveBeenCalledWith ( 'New Store URI' ) ;
152168 } ) ;
153169
154170 it ( 'updates auth method on select change' , async ( ) => {
155171 const wrapper = mountComponent ( ) ;
156- const select = wrapper . find ( EuiSelect ) . at ( 0 ) ;
172+ const select = wrapper . find ( EuiSelect ) ;
157173 await act ( async ( ) => {
158- select . simulate ( 'change' , { target : { value : 'noauth' } } ) ;
174+ const onChange = select . prop ( 'onChange' ) ;
175+ if ( onChange ) {
176+ onChange ( { target : { value : 'noauth' } } as any ) ;
177+ }
159178 } ) ;
160- setTimeout ( ( ) => {
161- expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'noauth' ) ;
162- } , 1000 ) ;
179+ expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'noauth' ) ;
163180 } ) ;
164181
165182 it ( 'displays authentication fields based on auth method' , async ( ) => {
166183 const wrapper = mountComponent ( ) ;
167- const select = wrapper . find ( EuiSelect ) . at ( 0 ) ;
184+ const select = wrapper . find ( EuiSelect ) ;
168185 await act ( async ( ) => {
169- select . simulate ( 'change' , { target : { value : 'noauth' } } ) ;
186+ const onChange = select . prop ( 'onChange' ) ;
187+ if ( onChange ) {
188+ onChange ( { target : { value : 'noauth' } } as any ) ;
189+ }
170190 } ) ;
171- setTimeout ( ( ) => {
172- expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'noauth' ) ;
173- } , 1000 ) ;
191+ expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'noauth' ) ;
174192
175193 await act ( async ( ) => {
176- select . simulate ( 'change' , { target : { value : 'basicauth' } } ) ;
194+ const onChange = select . prop ( 'onChange' ) ;
195+ if ( onChange ) {
196+ onChange ( { target : { value : 'basicauth' } } as any ) ;
197+ }
177198 } ) ;
178- setTimeout ( ( ) => {
179- expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'basicauth' ) ;
180- } , 1000 ) ;
199+ expect ( mockSetAuthMethodForRequest ) . toHaveBeenCalledWith ( 'basicauth' ) ;
181200 } ) ;
182201} ) ;
0 commit comments