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 @@ -140,7 +140,7 @@ describe('AIAssistantView', () => {
expect(AIChat).toHaveBeenCalledTimes(1);
});

it('should pass container, createComponent, popupOptions, chatOptions, onChatCleared, and onRegenerate to AIChat', () => {
it('should pass container, createComponent, popupOptions, chatOptions, and onRegenerate to AIChat', () => {
const { aiAssistantView } = createAIAssistantView();

expect(AIChat).toHaveBeenCalledWith(
Expand All @@ -149,7 +149,6 @@ describe('AIAssistantView', () => {
createComponent: expect.any(Function),
popupOptions: expect.any(Object),
chatOptions: expect.any(Object),
onChatCleared: expect.any(Function),
onRegenerate: expect.any(Function),
}),
);
Expand Down Expand Up @@ -293,20 +292,6 @@ describe('AIAssistantView', () => {
});

describe('chat event handlers', () => {
describe('onChatCleared', () => {
it('should call clear on aiChatInstance when triggered', () => {
createAIAssistantView();

const aiChatInstance = (AIChat as jest.Mock)
.mock.results[0].value as { clear: jest.Mock };

const aiChatConfig = (AIChat as jest.Mock).mock.calls[0][0] as AIChatOptions;
aiChatConfig.onChatCleared?.();

expect(aiChatInstance.clear).toHaveBeenCalledTimes(1);
});
});

describe('onRegenerate', () => {
it('should send request to AI with the AI message', () => {
mockAIAssistantController.sendRequestToAI.mockReturnValue(Promise.resolve());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export class AIAssistantView extends View {
return {
container: this.element(),
createComponent: this._createComponent.bind(this),
onChatCleared: (): void => {
this.aiChatInstance.clear();
},
onRegenerate: (aiMessage: AIMessage): void => {
this.executeRequest(aiMessage);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ describe('AIChat', () => {
});

describe('clearChatButton', () => {
it('should include toolbarItems with clear chat button when onChatCleared is provided', () => {
const onChatCleared = jest.fn();
createAIChat({ onChatCleared });
it('should include toolbarItems with clear chat button', () => {
createAIChat();

const popupConfig = getPopupConfig();

Expand All @@ -232,18 +231,25 @@ describe('AIChat', () => {
location: 'after',
options: expect.objectContaining({
icon: CLEAR_CHAT_ICON,
onClick: onChatCleared,
onClick: expect.any(Function),
}),
}),
]);
});

it('should not include toolbarItems when onChatCleared is not provided', () => {
it('should call clear when clear chat button is clicked', () => {
const mockStore = { clear: jest.fn() };
mockDataSource.store.mockReturnValue(mockStore);

createAIChat();
triggerContentTemplate();

const popupConfig = getPopupConfig();
const clearButton = popupConfig.toolbarItems[0];
clearButton.options.onClick();

expect(popupConfig.toolbarItems).toBeUndefined();
expect(mockStore.clear).toHaveBeenCalledTimes(1);
expect(mockDataSource.reload).toHaveBeenCalledTimes(1);
});
});

Expand Down Expand Up @@ -780,8 +786,7 @@ describe('AIChat', () => {
});

it('should disable clear button via popup toolbarItems option', () => {
const onChatCleared = jest.fn();
const { aiChat } = createAIChat({ onChatCleared });
const { aiChat } = createAIChat();
triggerContentTemplate();

aiChat.setDisabled(true);
Expand All @@ -790,8 +795,7 @@ describe('AIChat', () => {
});

it('should enable clear button via popup toolbarItems option', () => {
const onChatCleared = jest.fn();
const { aiChat } = createAIChat({ onChatCleared });
const { aiChat } = createAIChat();
triggerContentTemplate();

aiChat.setDisabled(true);
Expand All @@ -800,18 +804,6 @@ describe('AIChat', () => {
expect(mockClearChatButtonInstance.option).toHaveBeenCalledWith('disabled', false);
});

it('should not update popup toolbarItems when onChatCleared is not provided', () => {
const { aiChat } = createAIChat();
triggerContentTemplate();

aiChat.setDisabled(true);

expect(mockClearChatButtonInstance.option).not.toHaveBeenCalledWith(
'disabled',
expect.anything(),
);
});

it('should not update when setting same disabled value', () => {
const { aiChat } = createAIChat();
triggerContentTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import messageLocalization from '@js/common/core/localization/message';
import type { ArrayStore } from '@js/common/data';
import type { dxElementWrapper } from '@js/core/renderer';
import $ from '@js/core/renderer';
import type { InitializedEvent } from '@js/ui/button';
import type dxButton from '@js/ui/button';
import type { Message, Properties as ChatProperties } from '@js/ui/chat';
import Chat from '@js/ui/chat';
import type { Properties as PopupProperties, ToolbarItem } from '@js/ui/popup';
import { MessageStatus } from '@ts/grids/grid_core/ai_assistant/const';
import type Button from '@ts/ui/button';
import {
CHAT_MESSAGELIST_EMPTY_IMAGE_CLASS,
CHAT_MESSAGELIST_EMPTY_MESSAGE_CLASS,
Expand Down Expand Up @@ -44,7 +45,7 @@ export class AIChat {

private chatInstance?: Chat;

private clearChatButtonInstance?: Button;
private clearChatButtonInstance?: dxButton;

private disabled = false;

Expand Down Expand Up @@ -124,12 +125,6 @@ export class AIChat {
}

private getClearChatButton(): ToolbarItem | undefined {
const { onChatCleared } = this.options;

if (!onChatCleared) {
return undefined;
}

return {
widget: 'dxButton',
toolbar: 'top',
Expand All @@ -138,8 +133,10 @@ export class AIChat {
options: {
icon: CLEAR_CHAT_ICON,
hint: messageLocalization.format('dxDataGrid-aiAssistantClearButtonText'),
onClick: onChatCleared,
onInitialized: (e): void => {
onClick: (): void => {
Comment thread
dmirgaev marked this conversation as resolved.
this.clear();
},
onInitialized: (e: InitializedEvent): void => {
this.clearChatButtonInstance = e.component;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export interface AIChatOptions {
createComponent: CreateComponent<any>;
popupOptions?: PopupProperties;
chatOptions?: ChatProperties;
onChatCleared?: () => void;
onRegenerate?: (aiMessage: AIMessage) => void;
}
Loading