Skip to content

Commit a2ea7a2

Browse files
TackAdamAdam Tackett
andauthored
Test fix: ciGroup3 (#10846)
* fix flaky test due to timing Signed-off-by: Adam Tackett <[email protected]> * mor fixes Signed-off-by: Adam Tackett <[email protected]> * fix test Signed-off-by: Adam Tackett <[email protected]> * test fix Signed-off-by: Adam Tackett <[email protected]> * test fix Signed-off-by: Adam Tackett <[email protected]> --------- Signed-off-by: Adam Tackett <[email protected]> Co-authored-by: Adam Tackett <[email protected]>
1 parent 47553b6 commit a2ea7a2

File tree

2 files changed

+83
-54
lines changed

2 files changed

+83
-54
lines changed

src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_source_configuration/amazon_s3/configure_amazon_s3_data_source.test.tsx

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
import { mount } from 'enzyme';
88
import { act } from 'react-dom/test-utils';
99
import { MemoryRouter } from 'react-router-dom';
10-
import { EuiFieldText, EuiTextArea, EuiSelect } from '@elastic/eui';
10+
import { EuiTextArea, EuiSelect } from '@elastic/eui';
1111
import { ConfigureS3DatasourcePanelWithRouter } from './configure_amazon_s3_data_source';
1212
import { 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
});

src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_source_configuration/prometheus/configure_prometheus_data_source.test.tsx

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
import { mount } from 'enzyme';
88
import { act } from 'react-dom/test-utils';
99
import { MemoryRouter } from 'react-router-dom';
10-
import { EuiFieldText, EuiTextArea, EuiSelect } from '@elastic/eui';
10+
import { EuiTextArea, EuiSelect } from '@elastic/eui';
1111
import { ConfigurePrometheusDatasourcePanel } from './configure_prometheus_data_source';
1212
import { AuthMethod } from '../../../constants';
1313

@@ -128,49 +128,59 @@ describe('ConfigurePrometheusDatasourcePanel', () => {
128128
textArea.simulate('change', { target: { value: 'New details' } });
129129
textArea.simulate('blur', { target: { value: 'New details' } });
130130
});
131-
setTimeout(() => {
132-
expect(mockSetDetailsForRequest).toHaveBeenCalledWith('New details');
133-
}, 1000);
131+
expect(mockSetDetailsForRequest).toHaveBeenCalledWith('New details');
134132
});
135133

136134
it('updates store URI state on change', async () => {
137135
const wrapper = mountComponent();
138-
const storeField = wrapper.find(EuiFieldText).at(0);
136+
const storeField = wrapper.find('[data-test-subj="Prometheus-URI"]').first();
137+
139138
await act(async () => {
140-
storeField.simulate('change', { target: { value: 'New Store URI' } });
141-
storeField.simulate('blur', { target: { value: 'New Store URI' } });
139+
const onChange = storeField.prop('onChange');
140+
if (onChange) {
141+
onChange({ target: { value: 'New Store URI' } } as any);
142+
}
142143
});
143-
setTimeout(() => {
144-
expect(mockSetStoreForRequest).toHaveBeenCalledWith('New Store URI');
145-
}, 1000);
144+
145+
await act(async () => {
146+
const onBlur = storeField.prop('onBlur');
147+
if (onBlur) {
148+
onBlur({ target: { value: 'New Store URI' } } as any);
149+
}
150+
});
151+
152+
expect(mockSetStoreForRequest).toHaveBeenCalledWith('New Store URI');
146153
});
147154

148155
it('updates auth method on select change', async () => {
149156
const wrapper = mountComponent();
150-
const select = wrapper.find(EuiSelect).at(0);
157+
const select = wrapper.find(EuiSelect);
151158
await act(async () => {
152-
select.simulate('change', { target: { value: 'awssigv4' } });
159+
const onChange = select.prop('onChange');
160+
if (onChange) {
161+
onChange({ target: { value: 'awssigv4' } } as any);
162+
}
153163
});
154-
setTimeout(() => {
155-
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('awssigv4');
156-
}, 1000);
164+
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('awssigv4');
157165
});
158166

159167
it('displays authentication fields based on auth method', async () => {
160168
const wrapper = mountComponent();
161-
const select = wrapper.find(EuiSelect).at(0);
169+
const select = wrapper.find(EuiSelect);
162170
await act(async () => {
163-
select.simulate('change', { target: { value: 'awssigv4' } });
171+
const onChange = select.prop('onChange');
172+
if (onChange) {
173+
onChange({ target: { value: 'awssigv4' } } as any);
174+
}
164175
});
165-
setTimeout(() => {
166-
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('awssigv4');
167-
}, 100);
176+
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('awssigv4');
168177

169178
await act(async () => {
170-
select.simulate('change', { target: { value: 'basicauth' } });
179+
const onChange = select.prop('onChange');
180+
if (onChange) {
181+
onChange({ target: { value: 'basicauth' } } as any);
182+
}
171183
});
172-
setTimeout(() => {
173-
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('basicauth');
174-
}, 1000);
184+
expect(mockSetAuthMethodForRequest).toHaveBeenCalledWith('basicauth');
175185
});
176186
});

0 commit comments

Comments
 (0)