-
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.
[Security Solution] Adds Connector Selector to Assistant Title Header (…
…#163666) ## Summary Adds a new `ConnectorSelectorInline` component that is displayed below the Assistant title header. Default: <p align="center"> <img width="500" src="https://github.com/elastic/kibana/assets/2946766/83e6a884-103f-43c4-9a30-a0281d9941a2" /> </p> Overflow: <p align="center"> <img width="500" src="https://github.com/elastic/kibana/assets/2946766/f0d8a04e-963d-4053-90f5-2417f1c8eaca" /> </p> Missing: <p align="center"> <img width="500" src="https://github.com/elastic/kibana/assets/2946766/eff04e75-a5ab-468c-b801-1e056d527e6a" /> </p> Open: <p align="center"> <img width="500" src="https://github.com/elastic/kibana/assets/2946766/b7b97244-91a5-41ec-a096-b296e0cde644" /> </p> ### Checklist Delete any items that are not applicable to this PR. - [X] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [X] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- Loading branch information
Showing
7 changed files
with
494 additions
and
31 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
116 changes: 116 additions & 0 deletions
116
...assistant/impl/connectorland/connector_selector_inline/connector_selector_inline.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,116 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import { noop } from 'lodash/fp'; | ||
import { TestProviders } from '../../mock/test_providers/test_providers'; | ||
import { ConnectorSelectorInline } from './connector_selector_inline'; | ||
import * as i18n from '../translations'; | ||
import { Conversation } from '../../..'; | ||
import { useLoadConnectors } from '../use_load_connectors'; | ||
|
||
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/constants', () => ({ | ||
loadActionTypes: jest.fn(() => { | ||
return Promise.resolve([ | ||
{ | ||
id: '.gen-ai', | ||
name: 'Gen AI', | ||
enabled: true, | ||
enabledInConfig: true, | ||
enabledInLicense: true, | ||
minimumLicenseRequired: 'basic', | ||
}, | ||
]); | ||
}), | ||
})); | ||
|
||
jest.mock('../use_load_connectors', () => ({ | ||
useLoadConnectors: jest.fn(() => { | ||
return { | ||
data: [], | ||
error: null, | ||
isSuccess: true, | ||
}; | ||
}), | ||
})); | ||
|
||
const mockConnectors = [ | ||
{ | ||
id: 'connectorId', | ||
name: 'Captain Connector', | ||
isMissingSecrets: false, | ||
actionTypeId: '.gen-ai', | ||
config: { | ||
apiProvider: 'OpenAI', | ||
}, | ||
}, | ||
]; | ||
|
||
(useLoadConnectors as jest.Mock).mockReturnValue({ | ||
data: mockConnectors, | ||
error: null, | ||
isSuccess: true, | ||
}); | ||
|
||
describe('ConnectorSelectorInline', () => { | ||
it('renders empty view if no selected conversation is provided', () => { | ||
const { getByText } = render( | ||
<TestProviders> | ||
<ConnectorSelectorInline | ||
isDisabled={false} | ||
onConnectorModalVisibilityChange={noop} | ||
onConnectorSelectionChange={noop} | ||
selectedConnectorId={undefined} | ||
selectedConversation={undefined} | ||
/> | ||
</TestProviders> | ||
); | ||
expect(getByText(i18n.INLINE_CONNECTOR_PLACEHOLDER)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders empty view if selectedConnectorId is NOT in list of connectors', () => { | ||
const conversation: Conversation = { | ||
id: 'conversation_id', | ||
messages: [], | ||
apiConfig: {}, | ||
}; | ||
const { getByText } = render( | ||
<TestProviders> | ||
<ConnectorSelectorInline | ||
isDisabled={false} | ||
onConnectorModalVisibilityChange={noop} | ||
onConnectorSelectionChange={noop} | ||
selectedConnectorId={'missing-connector-id'} | ||
selectedConversation={conversation} | ||
/> | ||
</TestProviders> | ||
); | ||
expect(getByText(i18n.INLINE_CONNECTOR_PLACEHOLDER)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders selected connector if selected selectedConnectorId is in list of connectors', () => { | ||
const conversation: Conversation = { | ||
id: 'conversation_id', | ||
messages: [], | ||
apiConfig: {}, | ||
}; | ||
const { getByText } = render( | ||
<TestProviders> | ||
<ConnectorSelectorInline | ||
isDisabled={false} | ||
onConnectorModalVisibilityChange={noop} | ||
onConnectorSelectionChange={noop} | ||
selectedConnectorId={mockConnectors[0].id} | ||
selectedConversation={conversation} | ||
/> | ||
</TestProviders> | ||
); | ||
expect(getByText(mockConnectors[0].name)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.