-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 207322_fleet_server_hosts_ssl_fix
- Loading branch information
Showing
99 changed files
with
1,824 additions
and
1,582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
x-pack/platform/plugins/shared/alerting/public/hooks/use_delete_maintenance_window.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { waitFor, renderHook } from '@testing-library/react'; | ||
|
||
import { AppMockRenderer, createAppMockRenderer } from '../lib/test_utils'; | ||
import { useDeleteMaintenanceWindow } from './use_delete_maintenance_window'; | ||
|
||
const mockAddDanger = jest.fn(); | ||
const mockAddSuccess = jest.fn(); | ||
|
||
jest.mock('../utils/kibana_react', () => { | ||
const originalModule = jest.requireActual('../utils/kibana_react'); | ||
return { | ||
...originalModule, | ||
useKibana: () => { | ||
const { services } = originalModule.useKibana(); | ||
return { | ||
services: { | ||
...services, | ||
notifications: { toasts: { addSuccess: mockAddSuccess, addDanger: mockAddDanger } }, | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
jest.mock('../services/maintenance_windows_api/delete', () => ({ | ||
deleteMaintenanceWindow: jest.fn(), | ||
})); | ||
|
||
const { deleteMaintenanceWindow } = jest.requireMock('../services/maintenance_windows_api/delete'); | ||
|
||
let appMockRenderer: AppMockRenderer; | ||
|
||
describe('useDeleteMaintenanceWindow', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
appMockRenderer = createAppMockRenderer(); | ||
}); | ||
|
||
it('should call onSuccess if api succeeds', async () => { | ||
const { result } = renderHook(() => useDeleteMaintenanceWindow(), { | ||
wrapper: appMockRenderer.AppWrapper, | ||
}); | ||
|
||
result.current.mutate({ maintenanceWindowId: '123' }); | ||
|
||
await waitFor(() => expect(mockAddSuccess).toBeCalledWith('Deleted maintenance window')); | ||
}); | ||
|
||
it('should call onError if api fails', async () => { | ||
deleteMaintenanceWindow.mockRejectedValue(''); | ||
|
||
const { result } = renderHook(() => useDeleteMaintenanceWindow(), { | ||
wrapper: appMockRenderer.AppWrapper, | ||
}); | ||
|
||
result.current.mutate({ maintenanceWindowId: '123' }); | ||
|
||
await waitFor(() => | ||
expect(mockAddDanger).toBeCalledWith('Failed to delete maintenance window.') | ||
); | ||
}); | ||
}); |
Oops, something went wrong.