|
| 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