Skip to content

Commit f973602

Browse files
committed
feat: enhance ObjectDataTable to handle API response structure and add DOM simulation tests
1 parent 58bd908 commit f973602

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

examples/app-react-crud/src/components/ObjectDataTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ export function ObjectDataTable({ client, objectApiName, onEdit }: ObjectDataTab
2222
if (!client) return;
2323
try {
2424
// Get definition via proper API
25-
const found = await client.meta.getItem('object', objectApiName);
26-
if (mounted && found) setDef(found);
25+
const found: any = await client.meta.getItem('object', objectApiName);
26+
if (mounted && found) {
27+
const def = found.data || found;
28+
setDef(def);
29+
}
2730
} catch (err) {
2831
console.error('Failed to load definition', err);
2932
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
3+
import { simulateBrowser } from '../src/mocks/simulateBrowser';
4+
5+
describe('DOM Simulation', () => {
6+
let env: any;
7+
8+
beforeAll(async () => {
9+
env = await simulateBrowser();
10+
await env.client.connect();
11+
});
12+
13+
afterAll(() => {
14+
if (env) env.cleanup();
15+
});
16+
17+
it('simulates ObjectDataTable structure verifying columns exist', async () => {
18+
const { client } = env;
19+
20+
// 1. Fetch Definition
21+
const result: any = await client.meta.getItem('object', 'todo_task');
22+
const def = result.data || result;
23+
24+
console.log('Definition Check:', {
25+
hasData: !!result.data,
26+
name: def.name,
27+
fieldCount: Object.keys(def.fields || {}).length
28+
});
29+
30+
expect(def.name).toBe('todo_task');
31+
expect(Object.keys(def.fields).length).toBeGreaterThan(0);
32+
33+
// 2. Fetch Data
34+
const dataResult: any = await client.data.find('todo_task');
35+
let records = [];
36+
if (dataResult.success && dataResult.data) records = dataResult.data;
37+
else if (Array.isArray(dataResult)) records = dataResult;
38+
39+
console.log('Data Check:', {
40+
recordCount: records.length,
41+
firstRecord: records[0]
42+
});
43+
44+
// 3. Simulate Render Logic (pure JS, matching React)
45+
const fields = def.fields || {};
46+
const columns = Object.keys(fields).map(key => {
47+
const f = fields[key];
48+
return {
49+
name: f.name || key,
50+
label: f.label || key
51+
};
52+
}).filter(c => !['formatted_summary', 'password'].includes(c.name));
53+
54+
const headers = columns.map(c => c.label);
55+
console.log('Resolved Columns:', headers);
56+
57+
// Fail if no columns (would result in empty table body)
58+
expect(columns.length).toBeGreaterThan(0);
59+
expect(headers).toContain('Subject'); // Assuming Field.text({ label }) works or fallback uses key
60+
});
61+
});

0 commit comments

Comments
 (0)