mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
* [Infra UI] Fixes #37999 - Reset error when IP address changes to something valid * movnig the setError above try/catch
This commit is contained in:
parent
8c7c74aed8
commit
0419047178
2 changed files with 20 additions and 0 deletions
|
@ -27,6 +27,7 @@ describe('useHostIpToName Hook', () => {
|
|||
expect(result.current.loading).toBe(false);
|
||||
expect(result.current.error).toBe(null);
|
||||
});
|
||||
|
||||
it('should handle errors', async () => {
|
||||
const error = new Error('Host not found');
|
||||
mockedFetch.post.mockRejectedValue(error);
|
||||
|
@ -38,4 +39,22 @@ describe('useHostIpToName Hook', () => {
|
|||
expect(result.current.loading).toBe(false);
|
||||
expect(result.current.error).toBe(error);
|
||||
});
|
||||
|
||||
it('should reset errors', async () => {
|
||||
const error = new Error('Host not found');
|
||||
mockedFetch.post.mockRejectedValue(error);
|
||||
const { result, waitForNextUpdate, rerender } = renderUseHostIpToNameHook();
|
||||
expect(result.current.name).toBe(null);
|
||||
expect(result.current.loading).toBe(true);
|
||||
await waitForNextUpdate();
|
||||
expect(result.current.name).toBe(null);
|
||||
expect(result.current.loading).toBe(false);
|
||||
expect(result.current.error).toBe(error);
|
||||
mockedFetch.post.mockResolvedValue({ data: { host: 'example-01' } } as any);
|
||||
rerender({ ipAddress: '192.168.1.2', indexPattern: 'metricbeat-*' });
|
||||
await waitForNextUpdate();
|
||||
expect(result.current.name).toBe('example-01');
|
||||
expect(result.current.loading).toBe(false);
|
||||
expect(result.current.error).toBe(null);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ export const useHostIpToName = (ipAddress: string | null, indexPattern: string |
|
|||
() => {
|
||||
(async () => {
|
||||
setLoadingState(true);
|
||||
setError(null);
|
||||
try {
|
||||
if (ipAddress && indexPattern) {
|
||||
const response = await fetch.post<IpToHostResponse>('../api/infra/ip_to_host', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue