Skip to content
Open
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
@@ -0,0 +1,101 @@
interface MockSendRequestOptions {
response?: Record<string, unknown>;
reject?: boolean;
error?: Error | string;
delay?: number;
}
Comment on lines +1 to +6

/**
* Creates an AIIntegration mock config for use inside createWidget's client-side callback.
* Must be called inside createWidget(() => ({ ... })) since it uses window.DevExpress.
*
* @example
* ```ts
* await createWidget('dxDataGrid', () => ({
* ...getGridConfig(),
* aiAssistant: {
* enabled: true,
* aiIntegration: createAIIntegrationMock({
* response: {
Comment on lines +12 to +19
* actions: [
* {
* name: 'sorting',
* args: { dataField: 'name', sortOrder: 'asc' }
* }
* ]
* },
* }),
* },
* }));
* ```
*/
export function createAIIntegrationMock(options: MockSendRequestOptions): any {
const {
response, reject, error, delay,
} = options;

return new (window as any).DevExpress.aiIntegration.AIIntegration({
sendRequest() {
let aborted = false;

const promise = new Promise<any>((resolve, rejectFn) => {
const handle = (): void => {
if (aborted) return;

if (reject) {
rejectFn(error instanceof Error ? error : new Error(error ?? 'Mock error'));
} else {
resolve(response ?? { actions: [] });
}
};

if (delay) {
setTimeout(handle, delay);
} else {
// Use microtask to simulate async behavior
Promise.resolve().then(handle);
}
});

return {
promise,
abort: (): void => { aborted = true; },
};
},
});
}

/**
* Creates an AIIntegration mock that never resolves (for testing pending/in-flight states).
*/
export function createPendingAIIntegrationMock(): any {
return new (window as any).DevExpress.aiIntegration.AIIntegration({
sendRequest() {
return {
promise: new Promise(() => {}),
abort: (): void => {},
};
},
});
}

/**
* Creates an AIIntegration mock that captures sendRequest calls for inspection.
* The captured requests are stored in window.__aiRequests.
*/
export function createCapturingAIIntegrationMock(
response: Record<string, unknown>,
): any {
(window as any).__aiRequests = [];

return new (window as any).DevExpress.aiIntegration.AIIntegration({
sendRequest(params: any) {
(window as any).__aiRequests.push(params);

return {
promise: Promise.resolve(response),
abort: (): void => {},
};
},
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export const GRID_SELECTOR = '#container';

export const SIMPLE_DATA = [
{ id: 1, name: 'Alice', value: 30 },
{ id: 2, name: 'Bob', value: 20 },
{ id: 3, name: 'Charlie', value: 10 },
];

export const PAGED_DATA = Array.from({ length: 20 }, (_, i) => ({
id: i + 1,
name: `Name ${i + 1}`,
value: (i + 1) * 10,
}));

export const DEFAULT_COLUMNS = ['id', 'name', 'value'];

export function getBaseGridConfig(): Record<string, unknown> {
return {
dataSource: SIMPLE_DATA,
keyExpr: 'id',
columns: DEFAULT_COLUMNS,
showBorders: true,
};
}

export function getPagedGridConfig(): Record<string, unknown> {
return {
dataSource: PAGED_DATA,
keyExpr: 'id',
columns: DEFAULT_COLUMNS,
showBorders: true,
paging: {
pageSize: 5,
},
};
}
Comment on lines +1 to +36
Loading
Loading