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.
[Security Solution] Security Assistant: Data Quality dashboard _New C…
…hat_ button & API updates (elastic#16) ### Summary - adds a _New chat_ button to the Data Quality dashboard - updates the `useAssistantOverlay` API - `NewChat` takes an optional `children` prop - added `NewChatById` component - improves test coverage
- Loading branch information
1 parent
2caa3cc
commit 6f2f1bc
Showing
22 changed files
with
715 additions
and
152 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
102 changes: 102 additions & 0 deletions
102
x-pack/packages/kbn-elastic-assistant/impl/assistant/use_assistant_overlay/index.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,102 @@ | ||
/* | ||
* 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 { act, renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { useAssistantOverlay } from '.'; | ||
|
||
const mockUseAssistantContext = { | ||
registerPromptContext: jest.fn(), | ||
showAssistantOverlay: jest.fn(), | ||
unRegisterPromptContext: jest.fn(), | ||
}; | ||
jest.mock('../../assistant_context', () => { | ||
const original = jest.requireActual('../../assistant_context'); | ||
|
||
return { | ||
...original, | ||
useAssistantContext: () => mockUseAssistantContext, | ||
}; | ||
}); | ||
|
||
describe('useAssistantOverlay', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('calls registerPromptContext with the expected context', async () => { | ||
const category = 'event'; | ||
const description = 'test description'; | ||
const getPromptContext = jest.fn(() => Promise.resolve('test data')); | ||
const id = 'test-id'; | ||
const suggestedUserPrompt = 'test user prompt'; | ||
const tooltip = 'test tooltip'; | ||
|
||
renderHook(() => | ||
useAssistantOverlay( | ||
category, | ||
null, | ||
description, | ||
getPromptContext, | ||
id, | ||
suggestedUserPrompt, | ||
tooltip | ||
) | ||
); | ||
|
||
expect(mockUseAssistantContext.registerPromptContext).toHaveBeenCalledWith({ | ||
category, | ||
description, | ||
getPromptContext, | ||
id, | ||
suggestedUserPrompt, | ||
tooltip, | ||
}); | ||
}); | ||
|
||
it('calls unRegisterPromptContext on unmount', () => { | ||
const { unmount } = renderHook(() => | ||
useAssistantOverlay( | ||
'event', | ||
null, | ||
'description', | ||
() => Promise.resolve('data'), | ||
'id', | ||
null, | ||
'tooltip' | ||
) | ||
); | ||
|
||
unmount(); | ||
|
||
expect(mockUseAssistantContext.unRegisterPromptContext).toHaveBeenCalledWith('id'); | ||
}); | ||
|
||
it('calls `showAssistantOverlay` from the assistant context', () => { | ||
const { result } = renderHook(() => | ||
useAssistantOverlay( | ||
'event', | ||
'conversation-id', | ||
'description', | ||
() => Promise.resolve('data'), | ||
'id', | ||
null, | ||
'tooltip' | ||
) | ||
); | ||
|
||
act(() => { | ||
result.current.showAssistantOverlay(true); | ||
}); | ||
|
||
expect(mockUseAssistantContext.showAssistantOverlay).toHaveBeenCalledWith({ | ||
showOverlay: true, | ||
promptContextId: 'id', | ||
conversationId: 'conversation-id', | ||
}); | ||
}); | ||
}); |
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
47 changes: 0 additions & 47 deletions
47
x-pack/packages/kbn-elastic-assistant/impl/magic_button/index.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.