Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@

import { render, screen } from '@testing-library/react';
import React from 'react';

import userEvent from '@testing-library/user-event';
import {
mockAssistantAvailability,
TestProviders,
} from '../../../mock/test_providers/test_providers';
import { SettingsContextMenu } from './settings_context_menu';
import { AI_ASSISTANT_MENU } from './translations';
import { alertConvo, conversationWithContentReferences } from '../../../mock/conversation';
import {
alertConvo,
conversationWithContentReferences,
customConvo,
welcomeConvo,
} from '../../../mock/conversation';
import { SecurityPageName } from '@kbn/deeplinks-security';
import { KNOWLEDGE_BASE_TAB } from '../const';

const props = {
selectedConversation: welcomeConvo,
};
describe('SettingsContextMenu', () => {
it('renders an accessible menu button icon', () => {
render(
<TestProviders>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -32,7 +39,7 @@ describe('SettingsContextMenu', () => {
it('renders all menu items', () => {
render(
<TestProviders>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -43,10 +50,24 @@ describe('SettingsContextMenu', () => {
expect(screen.getByTestId('clear-chat')).toBeInTheDocument();
});

it('triggers the reset conversation modal when clicking RESET_CONVERSATION', () => {
it('renders menu items without clear-chat when empty convo', async () => {
render(
<TestProviders>
<SettingsContextMenu selectedConversation={customConvo} />
</TestProviders>
);

await userEvent.click(screen.getByTestId('chat-context-menu'));
expect(screen.getByTestId('alerts-to-analyze')).toBeInTheDocument();
expect(screen.getByTestId('anonymize-values')).toBeInTheDocument();
expect(screen.getByTestId('show-citations')).toBeInTheDocument();
expect(screen.queryByTestId('clear-chat')).not.toBeInTheDocument();
});

it('triggers the reset conversation modal when clicking RESET_CONVERSATION', async () => {
render(
<TestProviders>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -59,7 +80,7 @@ describe('SettingsContextMenu', () => {
it('disables the anonymize values switch when no anonymized fields are present', () => {
render(
<TestProviders>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -85,7 +106,7 @@ describe('SettingsContextMenu', () => {
it('disables the show citations switch when no citations are present', () => {
render(
<TestProviders>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -112,7 +133,7 @@ describe('SettingsContextMenu', () => {
const mockNavigateToApp = jest.fn();
render(
<TestProviders providerContext={{ navigateToApp: mockNavigateToApp }}>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -134,7 +155,7 @@ describe('SettingsContextMenu', () => {
}}
providerContext={{ navigateToApp: mockNavigateToApp }}
>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -150,7 +171,7 @@ describe('SettingsContextMenu', () => {
const mockNavigateToApp = jest.fn();
render(
<TestProviders providerContext={{ navigateToApp: mockNavigateToApp }}>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand All @@ -172,7 +193,7 @@ describe('SettingsContextMenu', () => {
}}
providerContext={{ navigateToApp: mockNavigateToApp }}
>
<SettingsContextMenu />
<SettingsContextMenu {...props} />
</TestProviders>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
[selectedConversation]
);

const selectedConversationExists = useMemo(
() => selectedConversation && selectedConversation.id !== '',
[selectedConversation]
);

const items = useMemo(
() => [
<EuiContextMenuItem
Expand Down Expand Up @@ -324,20 +329,23 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
</EuiFlexItem>
</EuiFlexGroup>
</EuiContextMenuItem>

<EuiHorizontalRule margin="none" />
<EuiContextMenuItem
aria-label={'clear-chat'}
key={'clear-chat'}
onClick={showDestroyModal}
icon={'refresh'}
data-test-subj={'clear-chat'}
css={css`
color: ${euiThemeVars.euiColorDanger};
`}
>
{i18n.RESET_CONVERSATION}
</EuiContextMenuItem>
{selectedConversationExists && (
<>
<EuiHorizontalRule margin="none" />
<EuiContextMenuItem
aria-label={'clear-chat'}
key={'clear-chat'}
onClick={showDestroyModal}
icon={'refresh'}
data-test-subj={'clear-chat'}
css={css`
color: ${euiThemeVars.euiColorDanger};
`}
>
{i18n.RESET_CONVERSATION}
</EuiContextMenuItem>
</>
)}
</EuiPanel>,
],
[
Expand All @@ -351,6 +359,7 @@ export const SettingsContextMenu: React.FC<Params> = React.memo(
handleShowAlertsModal,
knowledgeBase.latestAlerts,
showDestroyModal,
selectedConversationExists,
selectedConversationHasCitations,
selectedConversationHasAnonymizedValues,
]
Expand Down