Skip to content

Commit fdc1a0b

Browse files
Merge branch '26_1' into 26_1_dx_scss_nx_infra_p
2 parents f69887d + 6954c66 commit fdc1a0b

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ describe('AIAssistantView', () => {
162162

163163
expect(mockAIAssistantController.getMessageStore).toHaveBeenCalledTimes(1);
164164
expect(aiChatConfig.chatOptions).toEqual(expect.objectContaining({
165-
dataSource: mockMessageStore,
165+
dataSource: expect.objectContaining({
166+
store: mockMessageStore,
167+
pushAggregationTimeout: 0,
168+
}),
166169
reloadOnChange: true,
167170
onMessageEntered: expect.any(Function),
168171
}));

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,73 @@ describe('AIAssistantViewController', () => {
463463
expect(getMessageStatusClass($messages.eq(0))).toBe(MessageStatus.Success);
464464
});
465465
});
466+
467+
describe('manual store push', () => {
468+
// eslint-disable-next-line @typescript-eslint/init-declarations
469+
let validateSpy;
470+
// eslint-disable-next-line @typescript-eslint/init-declarations
471+
let executeCommandsSpy;
472+
473+
beforeEach(() => {
474+
validateSpy = jest.spyOn(GridCommands.prototype, 'validate')
475+
.mockReturnValue(true);
476+
executeCommandsSpy = jest.spyOn(GridCommands.prototype, 'executeCommands')
477+
.mockResolvedValue([
478+
{ status: 'success', message: 'Done' },
479+
] as CommandResult[]);
480+
});
481+
482+
afterEach(() => {
483+
validateSpy.mockRestore();
484+
executeCommandsSpy.mockRestore();
485+
});
486+
487+
it('should not throw error when user message is manually pushed to the message store', async () => {
488+
// eslint-disable-next-line @typescript-eslint/init-declarations
489+
let chatStore;
490+
const { aiIntegration } = createMockAIIntegration();
491+
492+
await createDataGrid({
493+
dataSource: [
494+
{ id: 1, name: 'Name 1' },
495+
],
496+
columns: [
497+
{ dataField: 'id', caption: 'ID', dataType: 'number' },
498+
{ dataField: 'name', caption: 'Name', dataType: 'string' },
499+
],
500+
aiAssistant: {
501+
enabled: true,
502+
aiIntegration,
503+
chat: {
504+
user: { id: 'user' },
505+
onInitialized: (e) => {
506+
chatStore = e.component?.getDataSource().store();
507+
},
508+
},
509+
popup: {
510+
visible: true,
511+
},
512+
},
513+
});
514+
515+
try {
516+
chatStore.push([{
517+
type: 'insert',
518+
data: {
519+
id: 'manual-msg-1',
520+
author: { id: 'user', name: 'User' },
521+
text: 'Sort by name',
522+
timestamp: new Date().toISOString(),
523+
},
524+
}]);
525+
526+
await flushAsync();
527+
await flushAsync();
528+
} catch (error) {
529+
expect(error).toBeUndefined(); // Force fail if error is thrown
530+
}
531+
532+
expect(true).toBe(true);
533+
});
534+
});
466535
});

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ export class AIAssistantView extends View {
129129

130130
private getAIChatOptions(): ChatProperties {
131131
return {
132-
dataSource: this.messageStore,
132+
dataSource: {
133+
store: this.messageStore,
134+
pushAggregationTimeout: 0,
135+
},
133136
reloadOnChange: true,
134137
onMessageEntered: (e): void => {
135138
this.executeRequest(e.message);

0 commit comments

Comments
 (0)