Skip to content

Commit e5e6d15

Browse files
authored
TreeList - AI Column: Fix module order (#31626)
Co-authored-by: Alyar <>
1 parent c6be797 commit e5e6d15

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Column } from '@js/ui/tree_list';
2+
import TreeList from '@js/ui/tree_list';
3+
4+
import { GridCoreModel } from '../../../../grid_core/__tests__/__mock__/model/grid_core';
5+
6+
export class TreeListModel extends GridCoreModel<TreeList> {
7+
protected NAME = 'dxTreeList';
8+
9+
public getInstance(): TreeList {
10+
return TreeList.getInstance(this.root) as TreeList;
11+
}
12+
13+
public apiGetVisibleColumns(headerLevel?: number): Column[] {
14+
if (headerLevel === undefined) {
15+
return this.getInstance().getVisibleColumns();
16+
}
17+
18+
return this.getInstance().getVisibleColumns(headerLevel);
19+
}
20+
}

packages/devextreme/js/__internal/grids/tree_list/m_widget_base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const TREELIST_CLASS = 'dx-treelist';
2121
treeListCore.registerModulesOrder([
2222
'stateStoring',
2323
'columns',
24-
'aiColumn',
2524
'selection',
2625
'editorFactory',
2726
'columnChooser',
@@ -35,6 +34,7 @@ treeListCore.registerModulesOrder([
3534
'adaptivity',
3635
'data',
3736
'virtualScrolling',
37+
'aiColumn',
3838
'columnHeaders',
3939
'filterRow',
4040
'headerPanel',
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import {
2+
afterEach, beforeEach, describe, expect, it, jest,
3+
} from '@jest/globals';
4+
import type { GenerateGridColumnCommandResponse } from '@js/common/ai-integration';
5+
import type { dxElementWrapper } from '@js/core/renderer';
6+
import $ from '@js/core/renderer';
7+
import type { Properties as TreeListProperties } from '@js/ui/tree_list';
8+
import TreeList from '@js/ui/tree_list';
9+
import { AIIntegration } from '@ts/core/ai_integration/core/ai_integration';
10+
import { TreeListModel } from '@ts/grids/tree_list/__tests__/__mock__/model/tree_list';
11+
12+
const SELECTORS = {
13+
treeListContainer: '#treeListContainer',
14+
};
15+
16+
const TREELIST_CONTAINER_ID = 'treeListContainer';
17+
18+
const items = [
19+
{
20+
id: 1, parentId: 0, name: 'Name 1', value: 10,
21+
},
22+
{
23+
id: 2, parentId: 1, name: 'Name 2', value: 20,
24+
},
25+
];
26+
27+
interface RequestResult {
28+
promise: Promise<GenerateGridColumnCommandResponse>;
29+
abort: () => void;
30+
}
31+
32+
const createTreeList = async (
33+
options: TreeListProperties = {},
34+
): Promise<{
35+
$container: dxElementWrapper;
36+
component: TreeListModel;
37+
instance: TreeList;
38+
}> => new Promise((resolve) => {
39+
const $container = $('<div>')
40+
.attr('id', TREELIST_CONTAINER_ID)
41+
.appendTo(document.body);
42+
43+
const instance = new TreeList($container.get(0) as HTMLDivElement, options);
44+
const component = new TreeListModel($container.get(0) as HTMLElement);
45+
46+
jest.runAllTimers();
47+
48+
resolve({
49+
$container,
50+
component,
51+
instance,
52+
});
53+
});
54+
55+
const beforeTest = (): void => {
56+
jest.useFakeTimers();
57+
};
58+
59+
const afterTest = (): void => {
60+
const $container = $(SELECTORS.treeListContainer);
61+
const treeList = ($container as any).dxTreeList('instance') as TreeList;
62+
63+
treeList.dispose();
64+
$container.remove();
65+
jest.clearAllMocks();
66+
jest.useRealTimers();
67+
};
68+
69+
describe('AI data', () => {
70+
beforeEach(beforeTest);
71+
afterEach(afterTest);
72+
73+
describe('when prompt is set', () => {
74+
it('should be rendered', async () => {
75+
const { component } = await createTreeList({
76+
dataSource: items,
77+
keyExpr: 'id',
78+
parentIdExpr: 'parentId',
79+
autoExpandAll: true,
80+
columns: [
81+
{ dataField: 'id', caption: 'ID' },
82+
{ dataField: 'name', caption: 'Name' },
83+
{ dataField: 'value', caption: 'Value' },
84+
{
85+
type: 'ai',
86+
caption: 'AI Column',
87+
name: 'myColumn',
88+
ai: {
89+
prompt: 'Initial prompt',
90+
aiIntegration: new AIIntegration({
91+
sendRequest(): RequestResult {
92+
return {
93+
promise: new Promise<string>((resolve) => {
94+
resolve('{"1":"AI Response 1","2":"AI Response 2"}');
95+
}),
96+
abort: (): void => {},
97+
};
98+
},
99+
}),
100+
},
101+
},
102+
],
103+
});
104+
105+
expect(component.getDataCell(0, 3).getText()).toBe('AI Response 1');
106+
expect(component.getDataCell(1, 3).getText()).toBe('AI Response 2');
107+
});
108+
});
109+
});

0 commit comments

Comments
 (0)