forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[search source] consolidate warnings logic in kbn-search-response-war…
…nings package (elastic#168531) prerequisite for elastic#167906 PR consolidates all warnings logic into kbn-search-response-warnings package --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
699b30d
commit b5aa375
Showing
46 changed files
with
350 additions
and
458 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
12 changes: 7 additions & 5 deletions
12
.../components/search_response_warnings/__snapshots__/search_response_warnings.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
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
117 changes: 117 additions & 0 deletions
117
packages/kbn-search-response-warnings/src/handle_warnings.test.ts
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,117 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { estypes } from '@elastic/elasticsearch'; | ||
import type { ThemeServiceStart } from '@kbn/core/public'; | ||
import type { I18nStart } from '@kbn/core-i18n-browser'; | ||
import { notificationServiceMock } from '@kbn/core-notifications-browser-mocks'; | ||
import type { Start as InspectorStart, RequestAdapter } from '@kbn/inspector-plugin/public'; | ||
import { handleWarnings } from './handle_warnings'; | ||
|
||
describe('handleWarnings', () => { | ||
const notifications = notificationServiceMock.createStartContract(); | ||
|
||
beforeEach(() => { | ||
notifications.toasts.addWarning.mockClear(); | ||
}); | ||
|
||
it('should not show notifications when there are no warnings', () => { | ||
handleWarnings({ | ||
request: {} as unknown as estypes.SearchRequest, | ||
requestAdapter: {} as unknown as RequestAdapter, | ||
requestId: '1234', | ||
response: { | ||
timed_out: false, | ||
_shards: { | ||
failed: 0, | ||
total: 9000, | ||
}, | ||
} as estypes.SearchResponse, | ||
services: { | ||
i18n: {} as unknown as I18nStart, | ||
inspector: {} as unknown as InspectorStart, | ||
notifications, | ||
theme: {} as unknown as ThemeServiceStart, | ||
}, | ||
}); | ||
|
||
expect(notifications.toasts.addWarning).toBeCalledTimes(0); | ||
}); | ||
|
||
it('should show notifications for warnings when there is no callback', () => { | ||
handleWarnings({ | ||
request: {} as unknown as estypes.SearchRequest, | ||
requestAdapter: {} as unknown as RequestAdapter, | ||
requestId: '1234', | ||
response: { | ||
took: 999, | ||
timed_out: true, | ||
_shards: {} as estypes.ShardStatistics, | ||
hits: { hits: [] }, | ||
} as estypes.SearchResponse, | ||
services: { | ||
i18n: {} as unknown as I18nStart, | ||
inspector: {} as unknown as InspectorStart, | ||
notifications, | ||
theme: {} as unknown as ThemeServiceStart, | ||
}, | ||
}); | ||
|
||
expect(notifications.toasts.addWarning).toBeCalledTimes(1); | ||
}); | ||
|
||
it('should show notifications for warnings not handled by callback', () => { | ||
const callbackMock = jest.fn(() => false); | ||
handleWarnings({ | ||
callback: callbackMock, | ||
request: {} as unknown as estypes.SearchRequest, | ||
requestAdapter: {} as unknown as RequestAdapter, | ||
requestId: '1234', | ||
response: { | ||
took: 999, | ||
timed_out: true, | ||
_shards: {} as estypes.ShardStatistics, | ||
hits: { hits: [] }, | ||
} as estypes.SearchResponse, | ||
services: { | ||
i18n: {} as unknown as I18nStart, | ||
inspector: {} as unknown as InspectorStart, | ||
notifications, | ||
theme: {} as unknown as ThemeServiceStart, | ||
}, | ||
}); | ||
|
||
expect(callbackMock).toBeCalledTimes(1); | ||
expect(notifications.toasts.addWarning).toBeCalledTimes(1); | ||
}); | ||
|
||
it('should not show notifications for warnings handled by callback', () => { | ||
const callbackMock = jest.fn(() => true); | ||
handleWarnings({ | ||
callback: callbackMock, | ||
request: {} as unknown as estypes.SearchRequest, | ||
requestAdapter: {} as unknown as RequestAdapter, | ||
requestId: '1234', | ||
response: { | ||
took: 999, | ||
timed_out: true, | ||
_shards: {} as estypes.ShardStatistics, | ||
hits: { hits: [] }, | ||
} as estypes.SearchResponse, | ||
services: { | ||
i18n: {} as unknown as I18nStart, | ||
inspector: {} as unknown as InspectorStart, | ||
notifications, | ||
theme: {} as unknown as ThemeServiceStart, | ||
}, | ||
}); | ||
|
||
expect(callbackMock).toBeCalledTimes(1); | ||
expect(notifications.toasts.addWarning).toBeCalledTimes(0); | ||
}); | ||
}); |
Oops, something went wrong.